t_parser_test.go: changed all error values to string values
This commit is contained in:
parent
896844e772
commit
307027d23d
@ -5,7 +5,6 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -49,13 +48,13 @@ func TestGeneralParser(t *testing.T) {
|
||||
/* 34 */ {`(((1)))`, int64(1), nil},
|
||||
/* 35 */ {`var2="abc"; "uno_" + var2`, `uno_abc`, nil},
|
||||
/* 36 */ {`0 || 0.0 && "hello"`, false, nil},
|
||||
/* 37 */ {`"s" + true`, nil, errors.New(`[1:6] left operand 's' [string] and right operand 'true' [bool] are not compatible with operator "+"`)},
|
||||
/* 38 */ {`+false`, nil, errors.New(`[1:2] prefix/postfix operator "+" do not support operand 'false' [bool]`)},
|
||||
/* 37 */ {`"s" + true`, nil, `[1:6] left operand 's' [string] and right operand 'true' [bool] are not compatible with operator "+"`},
|
||||
/* 38 */ {`+false`, nil, `[1:2] prefix/postfix operator "+" do not support operand 'false' [bool]`},
|
||||
/* 39 */ {`false // very simple expression`, false, nil},
|
||||
/* 40 */ {`1 + // Missing right operator`, nil, errors.New(`[1:4] infix operator "+" requires two non-nil operands, got 1`)},
|
||||
/* 40 */ {`1 + // Missing right operator`, nil, `[1:4] infix operator "+" requires two non-nil operands, got 1`},
|
||||
/* 41 */ {"", nil, nil},
|
||||
/* 42 */ {"4!", int64(24), nil},
|
||||
/* 43 */ {"(-4)!", nil, errors.New(`factorial of a negative integer (-4) is not allowed`)},
|
||||
/* 43 */ {"(-4)!", nil, `factorial of a negative integer (-4) is not allowed`},
|
||||
/* 44 */ {"-4!", int64(-24), nil},
|
||||
/* 45 */ {"1.5 < 7", true, nil},
|
||||
/* 46 */ {"1.5 > 7", false, nil},
|
||||
@ -67,20 +66,20 @@ func TestGeneralParser(t *testing.T) {
|
||||
/* 52 */ {`"1.5" > "7"`, false, nil},
|
||||
/* 53 */ {`"1.5" == "7"`, false, nil},
|
||||
/* 54 */ {`"1.5" != "7"`, true, nil},
|
||||
/* 55 */ {"1.5 < ", nil, errors.New(`[1:6] infix operator "<" requires two non-nil operands, got 1`)},
|
||||
/* 56 */ {"1.5 > ", nil, errors.New(`[1:6] infix operator ">" requires two non-nil operands, got 1`)},
|
||||
/* 57 */ {"1.5 <= ", nil, errors.New(`[1:6] infix operator "<=" requires two non-nil operands, got 1`)},
|
||||
/* 58 */ {"1.5 >= ", nil, errors.New(`[1:6] infix operator ">=" requires two non-nil operands, got 1`)},
|
||||
/* 59 */ {"1.5 != ", nil, errors.New(`[1:6] infix operator "!=" requires two non-nil operands, got 1`)},
|
||||
/* 60 */ {"1.5 == ", nil, errors.New(`[1:6] infix operator "==" requires two non-nil operands, got 1`)},
|
||||
/* 61 */ {`"1.5" < `, nil, errors.New(`[1:8] infix operator "<" requires two non-nil operands, got 1`)},
|
||||
/* 62 */ {`"1.5" > `, nil, errors.New(`[1:8] infix operator ">" requires two non-nil operands, got 1`)},
|
||||
/* 63 */ {`"1.5" == `, nil, errors.New(`[1:8] infix operator "==" requires two non-nil operands, got 1`)},
|
||||
/* 64 */ {`"1.5" != `, nil, errors.New(`[1:8] infix operator "!=" requires two non-nil operands, got 1`)},
|
||||
/* 55 */ {"1.5 < ", nil, `[1:6] infix operator "<" requires two non-nil operands, got 1`},
|
||||
/* 56 */ {"1.5 > ", nil, `[1:6] infix operator ">" requires two non-nil operands, got 1`},
|
||||
/* 57 */ {"1.5 <= ", nil, `[1:6] infix operator "<=" requires two non-nil operands, got 1`},
|
||||
/* 58 */ {"1.5 >= ", nil, `[1:6] infix operator ">=" requires two non-nil operands, got 1`},
|
||||
/* 59 */ {"1.5 != ", nil, `[1:6] infix operator "!=" requires two non-nil operands, got 1`},
|
||||
/* 60 */ {"1.5 == ", nil, `[1:6] infix operator "==" requires two non-nil operands, got 1`},
|
||||
/* 61 */ {`"1.5" < `, nil, `[1:8] infix operator "<" requires two non-nil operands, got 1`},
|
||||
/* 62 */ {`"1.5" > `, nil, `[1:8] infix operator ">" requires two non-nil operands, got 1`},
|
||||
/* 63 */ {`"1.5" == `, nil, `[1:8] infix operator "==" requires two non-nil operands, got 1`},
|
||||
/* 64 */ {`"1.5" != `, nil, `[1:8] infix operator "!=" requires two non-nil operands, got 1`},
|
||||
/* 65 */ {"+1.5", float64(1.5), nil},
|
||||
/* 66 */ {"+", nil, errors.New(`[1:2] prefix operator "+" requires one not nil operand`)},
|
||||
/* 67 */ {"4 / 0", nil, errors.New(`division by zero`)},
|
||||
/* 68 */ {"4.0 / 0", nil, errors.New(`division by zero`)},
|
||||
/* 66 */ {"+", nil, `[1:2] prefix operator "+" requires one not nil operand`},
|
||||
/* 67 */ {"4 / 0", nil, `division by zero`},
|
||||
/* 68 */ {"4.0 / 0", nil, `division by zero`},
|
||||
/* 69 */ {"4.0 / \n2", float64(2.0), nil},
|
||||
/* 70 */ {`123`, int64(123), nil},
|
||||
/* 71 */ {`1.`, float64(1.0), nil},
|
||||
@ -92,7 +91,7 @@ func TestGeneralParser(t *testing.T) {
|
||||
/* 77 */ {`5 % 2`, int64(1), nil},
|
||||
/* 78 */ {`5 % (-2)`, int64(1), nil},
|
||||
/* 79 */ {`-5 % 2`, int64(-1), nil},
|
||||
/* 80 */ {`5 % 2.0`, nil, errors.New(`[1:4] left operand '5' [integer] and right operand '2' [float] are not compatible with operator "%"`)},
|
||||
/* 80 */ {`5 % 2.0`, nil, `[1:4] left operand '5' [integer] and right operand '2' [float] are not compatible with operator "%"`},
|
||||
/* 81 */ {`"a" < "b" AND NOT (2 < 1)`, true, nil},
|
||||
/* 82 */ {`"a" < "b" AND NOT (2 == 1)`, true, nil},
|
||||
/* 83 */ {`"a" < "b" AND ~ 2 == 1`, true, nil},
|
||||
@ -105,12 +104,12 @@ func TestGeneralParser(t *testing.T) {
|
||||
/* 90 */ {`x=2 but x*10`, int64(20), nil},
|
||||
/* 91 */ {`false and true`, false, nil},
|
||||
/* 92 */ {`false and (x==2)`, false, nil},
|
||||
/* 93 */ {`false and (x=2 but x==2) or x==2`, nil, errors.New(`undefined variable or function "x"`)},
|
||||
/* 93 */ {`false and (x=2 but x==2) or x==2`, nil, `undefined variable or function "x"`},
|
||||
/* 94 */ {`false or true`, true, nil},
|
||||
/* 95 */ {`false or (x==2)`, nil, errors.New(`undefined variable or function "x"`)},
|
||||
/* 95 */ {`false or (x==2)`, nil, `undefined variable or function "x"`},
|
||||
/* 96 */ {`a=5; a`, int64(5), nil},
|
||||
/* 97 */ {`2=5`, nil, errors.New(`[1:2] left operand of "=" must be a variable or a collection's item`)},
|
||||
/* 98 */ {`2+a=5`, nil, errors.New(`[1:3] left operand of "=" must be a variable or a collection's item`)},
|
||||
/* 97 */ {`2=5`, nil, `[1:2] left operand of "=" must be a variable or a collection's item`},
|
||||
/* 98 */ {`2+a=5`, nil, `[1:3] left operand of "=" must be a variable or a collection's item`},
|
||||
/* 99 */ {`2+(a=5)`, int64(7), nil},
|
||||
/* 100 */ {`x ?? "default"`, "default", nil},
|
||||
/* 101 */ {`x="hello"; x ?? "default"`, "hello", nil},
|
||||
@ -120,22 +119,22 @@ func TestGeneralParser(t *testing.T) {
|
||||
/* 105 */ {`1 ? {"a"} : {"b"}`, "b", nil},
|
||||
/* 106 */ {`10 ? {"a"} : {"b"} :: {"c"}`, "c", nil},
|
||||
/* 107 */ {`10 ? {"a"} :[true, 2+8] {"b"} :: {"c"}`, "b", nil},
|
||||
/* 108 */ {`10 ? {"a"} :[true, 2+8] {"b"} ::[10] {"c"}`, nil, errors.New(`[1:34] case list in default clause`)},
|
||||
/* 108 */ {`10 ? {"a"} :[true, 2+8] {"b"} ::[10] {"c"}`, nil, `[1:34] case list in default clause`},
|
||||
/* 109 */ {`10 ? {"a"} :[10] {x="b" but x} :: {"c"}`, "b", nil},
|
||||
/* 110 */ {`10 ? {"a"} :[10] {x="b"; x} :: {"c"}`, "b", nil},
|
||||
/* 111 */ {`10 ? {"a"} : {"b"}`, nil, errors.New(`[1:3] no case catches the value (10) of the selection expression`)},
|
||||
/* 112 */ {`10 ? {"a"} :: {"b"} : {"c"}`, nil, errors.New(`[1:22] selector-case outside of a selector context`)},
|
||||
/* 111 */ {`10 ? {"a"} : {"b"}`, nil, `[1:3] no case catches the value (10) of the selection expression`},
|
||||
/* 112 */ {`10 ? {"a"} :: {"b"} : {"c"}`, nil, `[1:22] selector-case outside of a selector context`},
|
||||
/* 113 */ {`1 ? {"a"} : {"b"} ? ["a"] {"A"} :["b"] {"B"}`, "B", nil},
|
||||
/* 114 */ {`2 + 1 ? {"a"} : {"b"} * 3`, "2bbb", nil},
|
||||
/* 115 */ {`nil`, nil, nil},
|
||||
/* 116 */ {`null`, nil, errors.New(`undefined variable or function "null"`)},
|
||||
/* 117 */ {`{"key"}`, nil, errors.New(`[1:8] expected ":", got "}"`)},
|
||||
/* 118 */ {`{"key":}`, nil, errors.New(`[1:9] expected "dictionary-value", got "}"`)},
|
||||
/* 116 */ {`null`, nil, `undefined variable or function "null"`},
|
||||
/* 117 */ {`{"key"}`, nil, `[1:8] expected ":", got "}"`},
|
||||
/* 118 */ {`{"key":}`, nil, `[1:9] expected "dictionary-value", got "}"`},
|
||||
/* 119 */ {`{}`, &DictType{}, nil},
|
||||
/* 120 */ {`v=10; v++; v`, int64(11), nil},
|
||||
/* 121 */ {`1+1|2+0.5`, float64(2), nil},
|
||||
/* 122 */ {`1.2()`, newFraction(6, 5), nil},
|
||||
/* 123 */ {`1|(2-2)`, nil, errors.New(`division by zero`)},
|
||||
/* 123 */ {`1|(2-2)`, nil, `division by zero`},
|
||||
}
|
||||
|
||||
// t.Setenv("EXPR_PATH", ".")
|
||||
|
Loading…
Reference in New Issue
Block a user