github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/expressions/exp03_test.go (about) 1 package expressions 2 3 import "testing" 4 5 func TestExpMultiplyStrict(t *testing.T) { 6 tests := []expressionTestT{ 7 { 8 Expression: `"foo" * "bar"`, 9 Error: true, 10 }, 11 { 12 Expression: `"foo"* "bar"`, 13 Error: true, 14 }, 15 /// 16 { 17 Expression: `1 * 2`, 18 Expected: float64(2), 19 }, 20 { 21 Expression: `1* 2`, 22 Expected: float64(2), 23 }, 24 { 25 Expression: `1*-2`, 26 Expected: float64(-2), 27 }, 28 { 29 Expression: `1* -2`, 30 Expected: float64(-2), 31 }, 32 { 33 Expression: `1 *-2`, 34 Expected: float64(-2), 35 }, 36 { 37 Expression: `1 * -2`, 38 Expected: float64(-2), 39 }, 40 /// 41 { 42 Expression: `1 * "2"`, 43 Error: true, 44 }, 45 } 46 47 testExpression(t, tests, true) 48 } 49 50 func TestExpDivide(t *testing.T) { 51 tests := []expressionTestT{ 52 { 53 Expression: `"foo" / "bar"`, 54 Error: true, 55 }, 56 { 57 Expression: `"foo"/ "bar"`, 58 Error: true, 59 }, 60 /// 61 { 62 Expression: `1 / 2`, 63 Expected: float64(0.5), 64 }, 65 { 66 Expression: `1/ 2`, 67 Expected: float64(0.5), 68 }, 69 { 70 Expression: `1/-2`, 71 Expected: float64(-0.5), 72 }, 73 { 74 Expression: `1 /-2`, 75 Expected: float64(-0.5), 76 }, 77 { 78 Expression: `1/ -2`, 79 Expected: float64(-0.5), 80 }, 81 { 82 Expression: `1 / -2`, 83 Expected: float64(-0.5), 84 }, 85 /// 86 { 87 Expression: `1 / "2"`, 88 Error: true, 89 }, 90 } 91 92 testExpression(t, tests, true) 93 }