String token end location off-by-one error (#139)

* String token end location off-by-one error
This commit is contained in:
Dave Cunningham 2017-11-03 21:36:31 -04:00 committed by GitHub
parent d753072f4e
commit b6ee2c2f51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 57 additions and 61 deletions

View File

@ -205,11 +205,11 @@ func TestOneLineError(t *testing.T) {
// TODO(sbarzowski) checking if the whitespace is right is quite unpleasant, what can we do about it?
var minimalErrorTests = []errorFormattingTest{
{"error", `error "x"`, "RUNTIME ERROR: x\n" +
" error:1:1-9 $\n" + // TODO(sbarzowski) if seems we have off-by-one in location
" error:1:1-10 $\n" + // TODO(sbarzowski) if seems we have off-by-one in location
" During evaluation \n" +
""},
{"error_in_func", `local x(n) = if n == 0 then error "x" else x(n - 1); x(3)`, "RUNTIME ERROR: x\n" +
" error_in_func:1:29-37 function <x>\n" +
" error_in_func:1:29-38 function <x>\n" +
" error_in_func:1:44-52 function <x>\n" +
" error_in_func:1:44-52 function <x>\n" +
" error_in_func:1:44-52 function <x>\n" +
@ -217,7 +217,7 @@ var minimalErrorTests = []errorFormattingTest{
" During evaluation \n" +
""},
{"error_in_error", `error (error "x")`, "RUNTIME ERROR: x\n" +
" error_in_error:1:8-16 $\n" +
" error_in_error:1:8-17 $\n" +
" During evaluation \n" +
""},
}

View File

@ -711,15 +711,13 @@ func Lex(fn string, input string) (tokens, error) {
// String literals
case '"':
stringStartLoc := l.prevLocation()
l.resetTokenStart() // Don't include the quotes in the token data
for r = l.next(); ; r = l.next() {
if r == lexEOF {
return nil, l.makeStaticErrorPoint("Unterminated String", stringStartLoc)
}
if r == '"' {
l.backup()
l.emitToken(tokenStringDouble)
_ = l.next()
// Don't include the quotes in the token data
l.emitFullToken(tokenStringDouble, l.input[l.tokenStart+1:l.pos.byteNo-1], "", "")
l.resetTokenStart()
break
}
@ -729,15 +727,13 @@ func Lex(fn string, input string) (tokens, error) {
}
case '\'':
stringStartLoc := l.prevLocation()
l.resetTokenStart() // Don't include the quotes in the token data
for r = l.next(); ; r = l.next() {
if r == lexEOF {
return nil, l.makeStaticErrorPoint("Unterminated String", stringStartLoc)
}
if r == '\'' {
l.backup()
l.emitToken(tokenStringSingle)
r = l.next()
// Don't include the quotes in the token data
l.emitFullToken(tokenStringSingle, l.input[l.tokenStart+1:l.pos.byteNo-1], "", "")
l.resetTokenStart()
break
}

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/arrcomp_if6:1:20-28 $
testdata/arrcomp_if6:1:20-29 $
[x for x in [1] if error "x"]

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/bad_index_string:1:2-13 $
testdata/bad_index_string:1:1-13 $
"xxx"["xxx"]

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/binaryNot2:1:1-6 $
testdata/binaryNot2:1:1-7 $
~"xxx"

View File

@ -1,11 +1,11 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/bitwise_and4:1:5-13 $
testdata/bitwise_and4:1:5-14 $
1 & error "x"
-------------------------------------------------
testdata/bitwise_and4:1:1-13 $
testdata/bitwise_and4:1:1-14 $
1 & error "x"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/bitwise_or10:1:2-11 $
testdata/bitwise_or10:1:1-11 $
"xxx" | 42

View File

@ -1,11 +1,11 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/bitwise_xor7:1:5-13 $
testdata/bitwise_xor7:1:5-14 $
1 ^ error "x"
-------------------------------------------------
testdata/bitwise_xor7:1:1-13 $
testdata/bitwise_xor7:1:1-14 $
1 ^ error "x"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/double_thunk:1:21-31 thunk <y> from <thunk <x> from <$>>
testdata/double_thunk:1:21-32 thunk <y> from <thunk <x> from <$>>
local x = local y = error "xxx"; y; x

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: 42
-------------------------------------------------
testdata/error:1:1-10 $
testdata/error:1:1-11 $
error "42"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/error_from_array:1:2-12 thunk from <$>
testdata/error_from_array:1:2-13 thunk from <$>
[error "xxx"][0]

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
<extvar:errorVar>:1:1-11 $
<extvar:errorVar>:1:1-12 $
error 'xxx'

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Couldn't manifest function in JSON output.
-------------------------------------------------
testdata/function_plus_string:1:1-23 $
testdata/function_plus_string:1:1-24 $
(function() 42) + "xxx"

View File

@ -1,4 +1,4 @@
testdata/import_computed:1:9-16 Computed imports are not allowed
testdata/import_computed:1:8-17 Computed imports are not allowed
import "a" + "b"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: read testdata: is a directory
-------------------------------------------------
testdata/import_failure_directory:3:1-10 $
testdata/import_failure_directory:3:1-11 $
import '.'

View File

@ -1,4 +1,4 @@
testdata/importstr_computed:1:12-19 Computed imports are not allowed
testdata/importstr_computed:1:11-20 Computed imports are not allowed
importstr "a" + "b"

View File

@ -1,4 +1,4 @@
testdata/insuper4:1:2-13 Can't use super outside of an object.
testdata/insuper4:1:1-13 Can't use super outside of an object.
"x" in super

View File

@ -1,11 +1,11 @@
RUNTIME ERROR: should happen
-------------------------------------------------
testdata/lazy_operator2:1:9-29 $
testdata/lazy_operator2:1:9-30 $
true && error "should happen"
-------------------------------------------------
testdata/lazy_operator2:1:1-29 $
testdata/lazy_operator2:1:1-30 $
true && error "should happen"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/native4:1:28-38 thunk from <$>
testdata/native4:1:28-39 thunk from <$>
std.native("jsonToString")(error "xxx")

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Couldn't open import "no chance a file with this name exists": No match locally or in the Jsonnet library paths.
-------------------------------------------------
testdata/nonexistent_import:1:1-50 $
testdata/nonexistent_import:1:1-51 $
importstr 'no chance a file with this name exists'

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Couldn't open import "ąęółńśćźż \" ' \n\n\t\t": No match locally or in the Jsonnet library paths.
-------------------------------------------------
testdata/nonexistent_import_crazy:1:1-45 $
testdata/nonexistent_import_crazy:1:1-46 $
importstr "ąęółńśćźż \" \' \n\n\t\t"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/number_divided_by_string:1:1-10 $
testdata/number_divided_by_string:1:1-11 $
42 / "xxx"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/number_times_string:1:1-10 $
testdata/number_times_string:1:1-11 $
42 * "xxx"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/object_comp_err_elem:1:11-21 object <anonymous>
testdata/object_comp_err_elem:1:11-22 object <anonymous>
{ ["x"]: error "xxx" for x in [1] }

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/object_comp_err_index:1:4-14 $
testdata/object_comp_err_index:1:4-15 $
{ [error "xxx"]: 42 for x in [1] }

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/object_invariant13:1:10-18 object <anonymous>
testdata/object_invariant13:1:10-19 object <anonymous>
{ assert error "x" }

View File

@ -5,7 +5,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
{ x: 5, assert super.x == 5 }
-------------------------------------------------
<std>:969:29-30 thunk from <thunk <ta> from <function <anonymous>>>
<std>:979:29-30 thunk from <thunk <ta> from <function <anonymous>>>
local ta = std.type(a);
@ -13,7 +13,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
<builtin> builtin function <type>
-------------------------------------------------
<std>:971:33-35 thunk from <function <anonymous>>
<std>:981:33-35 thunk from <function <anonymous>>
if !std.primitiveEquals(ta, tb) then
@ -21,7 +21,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
<builtin> builtin function <primitiveEquals>
-------------------------------------------------
<std>:971:12-40 function <anonymous>
<std>:981:12-40 function <anonymous>
if !std.primitiveEquals(ta, tb) then

4
testdata/or4.golden vendored
View File

@ -1,11 +1,11 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/or4:1:10-20 $
testdata/or4:1:10-21 $
false || error "xxx"
-------------------------------------------------
testdata/or4:1:1-20 $
testdata/or4:1:1-21 $
false || error "xxx"

2
testdata/or5.golden vendored
View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected boolean
-------------------------------------------------
testdata/or5:1:2-14 $
testdata/or5:1:1-14 $
"xxx" || true

2
testdata/or6.golden vendored
View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected boolean
-------------------------------------------------
testdata/or6:1:1-14 $
testdata/or6:1:1-15 $
false || "xxx"

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Operator % cannot be used on types number and string.
-------------------------------------------------
<std>:150:13-99 function <anonymous>
<std>:150:13-100 function <anonymous>
error "Operator % cannot be used on types " + std.type(a) + " and " + std.type(b) + ".",

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Operator % cannot be used on types function and number.
-------------------------------------------------
<std>:150:13-99 function <anonymous>
<std>:150:13-100 function <anonymous>
error "Operator % cannot be used on types " + std.type(a) + " and " + std.type(b) + ".",

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/recursive_thunk:1:35-45 function <bar>
testdata/recursive_thunk:1:35-46 function <bar>
local bar(th, x) = if x == 0 then error "xxx" else th;

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/std.filter2:1:12-20 thunk from <$>
testdata/std.filter2:1:12-21 thunk from <$>
std.filter(error "x", [])

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/std.primitiveEquals10:1:21-29 thunk from <$>
testdata/std.primitiveEquals10:1:21-30 thunk from <$>
std.primitiveEquals(error "x", 42)

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/std.primitiveEquals9:1:25-33 thunk from <$>
testdata/std.primitiveEquals9:1:25-34 thunk from <$>
std.primitiveEquals(42, error "x")

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: x
-------------------------------------------------
testdata/std.toString5:1:14-22 thunk from <$>
testdata/std.toString5:1:14-23 thunk from <$>
std.toString(error "x")

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/string_divided_by_number:1:2-11 $
testdata/string_divided_by_number:1:1-11 $
"xxx" / 42

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Index -1 out of bounds, not within [0, 4)
-------------------------------------------------
testdata/string_index_negative:1:2-11 $
testdata/string_index_negative:1:1-11 $
"abcd"[-1]

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Index 4 out of bounds, not within [0, 4)
-------------------------------------------------
testdata/string_index_out_of_bounds:1:2-10 $
testdata/string_index_out_of_bounds:1:1-10 $
"abcd"[4]

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/string_minus_number:1:2-9 $
testdata/string_minus_number:1:1-9 $
"x" - 42

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Couldn't manifest function in JSON output.
-------------------------------------------------
testdata/string_plus_function:1:2-23 $
testdata/string_plus_function:1:1-23 $
"xxx" + (function() 42)

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/string_times_number:1:2-9 $
testdata/string_times_number:1:1-9 $
"x" * 42

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/tailstrict3:1:16-26 function <foo>
testdata/tailstrict3:1:16-27 function <foo>
local foo(x, y=error "xxx")=x;

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: xxx
-------------------------------------------------
testdata/type_error:1:10-20 thunk from <$>
testdata/type_error:1:10-21 thunk from <$>
std.type(error "xxx")

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Unexpected type string, expected number
-------------------------------------------------
testdata/unary_minus4:1:1-6 $
testdata/unary_minus4:1:1-7 $
-"xxx"