mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
Fix error position reporting in multiline script (#827)
This commit is contained in:
@@ -1757,6 +1757,17 @@ func TestEval_exposed_error(t *testing.T) {
|
||||
require.Equal(t, 1, fileError.Line)
|
||||
}
|
||||
|
||||
func TestCompile_exposed_error_with_multiline_script(t *testing.T) {
|
||||
_, err := expr.Compile("{\n\ta: 1,\n\tb: #,\n\tc: 3,\n}")
|
||||
require.Error(t, err)
|
||||
|
||||
fileError, ok := err.(*file.Error)
|
||||
require.True(t, ok, "error should be of type *file.Error")
|
||||
require.Equal(t, "unexpected token Operator(\"#\") (3:5)\n | b: #,\n | ....^", fileError.Error())
|
||||
require.Equal(t, 4, fileError.Column)
|
||||
require.Equal(t, 3, fileError.Line)
|
||||
}
|
||||
|
||||
func TestIssue105(t *testing.T) {
|
||||
type A struct {
|
||||
Field string
|
||||
|
||||
+3
-2
@@ -31,12 +31,13 @@ func (e *Error) Bind(source Source) *Error {
|
||||
break
|
||||
}
|
||||
if r == '\n' {
|
||||
lineStart = i
|
||||
lineStart = i + 1
|
||||
e.Line++
|
||||
e.Column = 0
|
||||
} else {
|
||||
e.Column++
|
||||
}
|
||||
runeCount++
|
||||
e.Column++
|
||||
}
|
||||
|
||||
lineEnd := lineStart + strings.IndexByte(src[lineStart:], '\n')
|
||||
|
||||
Reference in New Issue
Block a user