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

     1  package expressions
     2  
     3  import "testing"
     4  
     5  func TestExpressions(t *testing.T) {
     6  	tests := []expressionTestT{
     7  		{
     8  			Expression: `1 + 1 + 1 + 1 + 1 + 1`,
     9  			Expected:   float64(6),
    10  		},
    11  		{
    12  			Expression: `1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1`,
    13  			Expected:   float64(10),
    14  		},
    15  		{
    16  			Expression: `1 + 2 * 3`,
    17  			Expected:   float64(7),
    18  		},
    19  		{
    20  			Expression: `1 + 2 * 3 == 7`,
    21  			Expected:   true,
    22  		},
    23  		{
    24  			Expression: `(1 + 2) * 3`,
    25  			Expected:   float64(9),
    26  		},
    27  		{
    28  			Expression: `(1 + 2) * 3 == 7`,
    29  			Expected:   false,
    30  		},
    31  		{
    32  			Expression: `(1 + 2) * 3 == 9`,
    33  			Expected:   true,
    34  		},
    35  		{
    36  			Expression: `7 == 1 + 2 * 3`,
    37  			Expected:   true,
    38  		},
    39  		{
    40  			Expression: `7 == 4+4`,
    41  			Expected:   false,
    42  		},
    43  		{
    44  			Expression: `7 == 4 + 4`,
    45  			Expected:   false,
    46  		},
    47  		{
    48  			Expression: `7 == 4 + 4 - 1`,
    49  			Expected:   true,
    50  		},
    51  		{
    52  			Expression: `(7 == 7) == true`,
    53  			Expected:   true,
    54  		},
    55  		{
    56  			Expression: `(7 == 5) == true`,
    57  			Expected:   false,
    58  		},
    59  		{
    60  			Expression: `(7 == 7) == false`,
    61  			Expected:   false,
    62  		},
    63  		{
    64  			Expression: `(7 == 5) == false`,
    65  			Expected:   true,
    66  		},
    67  		{
    68  			Expression: `'bob' == "bob"`,
    69  			Expected:   true,
    70  		},
    71  		{
    72  			Expression: `"bob" == "bob"`,
    73  			Expected:   true,
    74  		},
    75  		{
    76  			Expression: `"bob" == 'bob'`,
    77  			Expected:   true,
    78  		},
    79  		{
    80  			Expression: `'bob' == 'bob'`,
    81  			Expected:   true,
    82  		},
    83  		{
    84  			Expression: `bob=5`,
    85  			Expected:   nil,
    86  		},
    87  		{
    88  			Expression: `bob =5`,
    89  			Expected:   nil,
    90  		},
    91  		{
    92  			Expression: `bob= 5`,
    93  			Expected:   nil,
    94  		},
    95  		{
    96  			Expression: `bob = 5`,
    97  			Expected:   nil,
    98  		},
    99  		{
   100  			Expression: `bob = (5==5)`,
   101  			Expected:   nil,
   102  		},
   103  		{
   104  			Expression: `bob=(5==5)`,
   105  			Expected:   nil,
   106  		},
   107  		{
   108  			Expression: `bob=("5"=="5")`,
   109  			Expected:   nil,
   110  		},
   111  		{
   112  			Expression: `bob = 5==5`,
   113  			Expected:   nil,
   114  		},
   115  		{
   116  			Expression: `bob=5==5`,
   117  			Expected:   nil,
   118  		},
   119  		{
   120  			Expression: `bob="5"=="5"`,
   121  			Expected:   nil,
   122  		},
   123  		{
   124  			Expression: `bob=(5*5)`,
   125  			Expected:   nil,
   126  		},
   127  	}
   128  
   129  	testExpression(t, tests, true)
   130  }
   131  
   132  func TestStupidOffByOneErrorsInSubExpressions(t *testing.T) {
   133  	tests := []expressionTestT{
   134  		{
   135  			Expression: `bob = 1+1`,
   136  			Expected:   nil,
   137  		},
   138  		{
   139  			Expression: `10*(1+2)*10`,
   140  			Expected:   float64(300),
   141  		},
   142  		{
   143  			Expression: `2*(10*(1+2)*10)`,
   144  			Expected:   float64(600),
   145  		},
   146  		{
   147  			Expression: `(10*(1+2)*10)*2`,
   148  			Expected:   float64(600),
   149  		},
   150  		{
   151  			Expression: `2*((10*(1+2)*10)+2)`,
   152  			Expected:   float64(604),
   153  		},
   154  		{
   155  			Expression: `2*((10*(1+2)*10)+2)*2`,
   156  			Expected:   float64(1208),
   157  		},
   158  		{
   159  			Expression: `1+(2*((10*(1+2)*10)+2)*2)-1`,
   160  			Expected:   float64(1208),
   161  		},
   162  	}
   163  
   164  	testExpression(t, tests, true)
   165  }