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

     1  package expressions
     2  
     3  import "testing"
     4  
     5  func TestExpAdd(t *testing.T) {
     6  	tests := []expressionTestT{
     7  		/*{
     8  			Expression: `"foo" + "bar"`,
     9  			Expected:   `foobar`,
    10  		},
    11  		{
    12  			Expression: `"foo"+ "bar"`,
    13  			Expected:   `foobar`,
    14  		},*/
    15  		///
    16  		{
    17  			Expression: `1 + 2`,
    18  			Expected:   float64(3),
    19  		},
    20  		{
    21  			Expression: `1+ 2`,
    22  			Expected:   float64(3),
    23  		},
    24  		///
    25  		{
    26  			Expression: `1 + "2"`,
    27  			Error:      true,
    28  		},
    29  	}
    30  
    31  	testExpression(t, tests, true)
    32  }
    33  
    34  func TestExpSubtract(t *testing.T) {
    35  	tests := []expressionTestT{
    36  		{
    37  			Expression: `"foo" - "bar"`,
    38  			Error:      true,
    39  		},
    40  		///
    41  		{
    42  			Expression: `1 - 2`,
    43  			Expected:   float64(-1),
    44  		},
    45  		{
    46  			Expression: `-1 - 2`,
    47  			Expected:   float64(-3),
    48  		},
    49  		{
    50  			Expression: `1 - -2`,
    51  			Expected:   float64(3),
    52  		},
    53  		{
    54  			Expression: `-1 - -2`,
    55  			Expected:   float64(1),
    56  		},
    57  		{
    58  			Expression: `-1- -2`,
    59  			Expected:   float64(1),
    60  		},
    61  		{
    62  			Expression: `-1--2`,
    63  			Expected:   float64(1),
    64  		},
    65  		///
    66  		{
    67  			Expression: `1 - "2"`,
    68  			Error:      true,
    69  		},
    70  	}
    71  
    72  	testExpression(t, tests, true)
    73  }