github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/expressions/exp14_test.go (about)

     1  package expressions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test"
     7  )
     8  
     9  func TestExpAssign(t *testing.T) {
    10  	tests := []expressionTestT{
    11  		{
    12  			Expression: `foo = 5`,
    13  			Expected:   nil,
    14  		},
    15  		{
    16  			Expression: `foo = "bar"`,
    17  			Expected:   nil,
    18  		},
    19  		{
    20  			Expression: `foo = bar`,
    21  			Error:      true,
    22  		},
    23  		{
    24  			Expression: `foo = >`,
    25  			Error:      true,
    26  		},
    27  	}
    28  
    29  	testExpression(t, tests, true)
    30  }
    31  
    32  func TestExpAssignAdd(t *testing.T) {
    33  	tests := []expressionTestT{
    34  		{
    35  			Expression: `TestExpAssignAdd0 += 5`,
    36  			Expected:   nil,
    37  		},
    38  		{
    39  			Expression: `TestExpAssignAdd1 += "bar"`,
    40  			Expected:   nil,
    41  		},
    42  		{
    43  			Expression: `TestExpAssignAdd2 += bar`,
    44  			Error:      true,
    45  		},
    46  		{
    47  			Expression: `TestExpAssignAdd3 += true`,
    48  			Error:      true,
    49  		},
    50  		{
    51  			Expression: `TestExpAssignAdd4 += >`,
    52  			Error:      true,
    53  		},
    54  	}
    55  
    56  	testExpression(t, tests, true)
    57  }
    58  
    59  func TestExpAssignSubtract(t *testing.T) {
    60  	tests := []expressionTestT{
    61  		{
    62  			Expression: `TestExpAssignSubtract0 -= 5`,
    63  			Expected:   nil,
    64  		},
    65  		{
    66  			Expression: `TestExpAssignSubtract1 -= "bar"`,
    67  			Error:      true,
    68  		},
    69  		{
    70  			Expression: `TestExpAssignSubtract2 -= bar`,
    71  			Error:      true,
    72  		},
    73  		{
    74  			Expression: `TestExpAssignSubtract3 -= true`,
    75  			Error:      true,
    76  		},
    77  		{
    78  			Expression: `TestExpAssignSubtract4 -= >`,
    79  			Error:      true,
    80  		},
    81  	}
    82  
    83  	testExpression(t, tests, true)
    84  }
    85  
    86  func TestExpAssignMultiply(t *testing.T) {
    87  	tests := []expressionTestT{
    88  		{
    89  			Expression: `TestExpAssignMultiply0 *= 5`,
    90  			Expected:   nil,
    91  		},
    92  		{
    93  			Expression: `TestExpAssignMultiply1 *= "bar"`,
    94  			Error:      true,
    95  		},
    96  		{
    97  			Expression: `TestExpAssignMultiply2 *= bar`,
    98  			Error:      true,
    99  		},
   100  		{
   101  			Expression: `TestExpAssignMultiply3 *= true`,
   102  			Error:      true,
   103  		},
   104  		{
   105  			Expression: `TestExpAssignMultiply4 *= >`,
   106  			Error:      true,
   107  		},
   108  	}
   109  
   110  	testExpression(t, tests, true)
   111  }
   112  
   113  func TestExpAssignDivide(t *testing.T) {
   114  	tests := []expressionTestT{
   115  		{
   116  			Expression: `TestExpAssignDivide0 /= 5`,
   117  			Expected:   nil,
   118  		},
   119  		{
   120  			Expression: `TestExpAssignDivide1 /= "bar"`,
   121  			Error:      true,
   122  		},
   123  		{
   124  			Expression: `TestExpAssignDivide2 /= bar`,
   125  			Error:      true,
   126  		},
   127  		{
   128  			Expression: `TestExpAssignDivide3 /= true`,
   129  			Error:      true,
   130  		},
   131  		{
   132  			Expression: `TestExpAssignDivide4 /= >`,
   133  			Error:      true,
   134  		},
   135  	}
   136  
   137  	testExpression(t, tests, true)
   138  }
   139  
   140  func TestLazyAssigns(t *testing.T) {
   141  	tests := []test.MurexTest{
   142  		{
   143  			Block:  "TestLazyAssignsAdd1 += 5; $TestLazyAssignsAdd1 += 5; $TestLazyAssignsAdd1",
   144  			Stdout: "10",
   145  		},
   146  		{
   147  			Block:  "TestLazyAssignsSubtract1 -= 5; $TestLazyAssignsSubtract1 -= 5; $TestLazyAssignsSubtract1",
   148  			Stdout: "-10",
   149  		},
   150  		{
   151  			Block:  "TestLazyAssignsMultiply1 *= 5; $TestLazyAssignsMultiply1 *= 5; $TestLazyAssignsMultiply1",
   152  			Stdout: "0",
   153  		},
   154  		{
   155  			Block:  "TestLazyAssignsDivide1 /= 5; $TestLazyAssignsDivide1 /= 5; $TestLazyAssignsDivide1",
   156  			Stdout: "0",
   157  		},
   158  	}
   159  
   160  	test.RunMurexTests(tests, t)
   161  }