%q replaced by %s in some error messages
This commit is contained in:
parent
1a772597cb
commit
e09806c716
@ -97,7 +97,7 @@ func doTest(t *testing.T, ctx ExprContext, section string, input *inputType, cou
|
||||
|
||||
if gotErr != wantErr {
|
||||
if wantErr == nil || gotErr == nil || (gotErr.Error() != wantErr.Error()) {
|
||||
t.Errorf("%d: %q -> got-err = <%v>, expected-err = <%v>", count, input.source, gotErr, wantErr)
|
||||
t.Errorf("%d: %s -> got-err = <%v>, expected-err = <%v>", count, input.source, gotErr, wantErr)
|
||||
good = false
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func TestDictParser(t *testing.T) {
|
||||
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`{}`, map[any]any{}, nil},
|
||||
/* 2 */ {`{123}`, nil, errors.New(`[1:6] expected ":", got "}"`)},
|
||||
/* 2 */ {`{123}`, nil, errors.New("[1:6] expected `:`, got `}`")},
|
||||
/* 3 */ {`{1:"one",2:"two",3:"three"}`, map[int64]any{int64(1): "one", int64(2): "two", int64(3): "three"}, nil},
|
||||
/* 4 */ {`{1:"one",2:"two",3:"three"}[3]`, "three", nil},
|
||||
/* 5 */ {`#{1:"one",2:"two",3:"three"}`, int64(3), nil},
|
||||
@ -32,7 +32,12 @@ func TestDictParser(t *testing.T) {
|
||||
/* 9 */ {`D={"a":1, "b":2}; D["z"]=9; D`, map[any]any{"z": 9, "a": 1, "b": 2}, nil},
|
||||
/* 10 */ {`D={"a":1, "b":2}; D[nil]=9`, nil, errors.New(`[1:21] index/key is nil`)},
|
||||
/* 11 */ {`D={"a":1, "b":2}; D["a"]`, int64(1), nil},
|
||||
}
|
||||
/* 12 */ {`m={
|
||||
"a":1,
|
||||
//"b":2,
|
||||
"c":3
|
||||
}`, map[any]any{"a": 1, "c": 3}, nil},
|
||||
}
|
||||
|
||||
succeeded := 0
|
||||
failed := 0
|
||||
|
@ -27,7 +27,7 @@ func TestFuncs(t *testing.T) {
|
||||
/* 14 */ {`two=func(){2}; two(123)`, nil, `two(): too much params -- expected 0, got 1`},
|
||||
/* 15 */ {`f=func(x,n=2){x+n}; f(3)`, int64(5), nil},
|
||||
/* 16 */ {`f=func(x,n=2,y){x+n}`, nil, `[1:16] can't mix default and non-default parameters`},
|
||||
/* 17 */ {`f=func(x,n){1}; f(3,4,)`, nil, `[1:24] expected "function-param-value", got ")"`},
|
||||
/* 17 */ {`f=func(x,n){1}; f(3,4,)`, nil, "[1:24] expected `function-param-value`, got `)`"},
|
||||
/* 18 */ {`factory=func(base){func(){@base=base+1}}; inc10=factory(10); inc5=factory(5); inc10(); inc5(); inc10()`, int64(12), nil},
|
||||
/* 19 */ {`f=func(a,y=1,z="sos"){}; string(f)`, `f(a, y=1, z="sos"):any{}`, nil},
|
||||
// /* 20 */ {`a=[func(){3}]; a[0]()`, int64(3), nil},
|
||||
|
@ -128,8 +128,8 @@ func TestGeneralParser(t *testing.T) {
|
||||
/* 114 */ {`2 + 1 ? {"a"} : {"b"} * 3`, "2bbb", nil},
|
||||
/* 115 */ {`nil`, nil, nil},
|
||||
/* 116 */ {`null`, nil, `undefined variable or function "null"`},
|
||||
/* 117 */ {`{"key"}`, nil, `[1:8] expected ":", got "}"`},
|
||||
/* 118 */ {`{"key":}`, nil, `[1:9] expected "dictionary-value", got "}"`},
|
||||
/* 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},
|
||||
@ -144,6 +144,6 @@ func TestGeneralParser(t *testing.T) {
|
||||
}
|
||||
|
||||
// t.Setenv("EXPR_PATH", ".")
|
||||
// parserTestSpec(t, section, inputs, 102)
|
||||
//runTestSuiteSpec(t, section, inputs, 130)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
6
token.go
6
token.go
@ -28,7 +28,7 @@ func (tk *Token) DevString() string {
|
||||
func (tk *Token) String() string {
|
||||
if tk.Value != nil {
|
||||
if s, ok := tk.Value.(string); ok {
|
||||
return fmt.Sprintf("%q", s)
|
||||
return s //fmt.Sprintf("%q", s)
|
||||
} else {
|
||||
return fmt.Sprintf("%v", tk.Value)
|
||||
}
|
||||
@ -91,11 +91,11 @@ func (tk *Token) Errors(msg string) (err error) {
|
||||
}
|
||||
|
||||
func (tk *Token) ErrorExpectedGot(symbol string) (err error) {
|
||||
err = fmt.Errorf("[%d:%d] expected %q, got %q", tk.row, tk.col, symbol, tk)
|
||||
err = fmt.Errorf("[%d:%d] expected `%s`, got `%s`", tk.row, tk.col, symbol, tk)
|
||||
return
|
||||
}
|
||||
|
||||
func (tk *Token) ErrorExpectedGotString(symbol, got string) (err error) {
|
||||
err = fmt.Errorf("[%d:%d] expected %q, got %q", tk.row, tk.col, symbol, got)
|
||||
err = fmt.Errorf("[%d:%d] expected `%s`, got `%s`", tk.row, tk.col, symbol, got)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user