@@ -2,6 +2,7 @@ package gojq_test
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"log"
7
8
"os"
@@ -275,6 +276,36 @@ func TestCodeCompile_OptimizeJumps(t *testing.T) {
275
276
}
276
277
}
277
278
279
+ func TestParseErrorTokenOffset (t * testing.T ) {
280
+ testCases := []struct {
281
+ src string
282
+ offset int
283
+ }{
284
+ {src : "^" , offset : 1 },
285
+ {src : " ^" , offset : 2 },
286
+ {src : " ^ " , offset : 2 },
287
+ {src : "👍" , offset : 4 },
288
+ {src : " 👍" , offset : 5 },
289
+ {src : " 👍 " , offset : 5 },
290
+ {src : "test👍" , offset : 8 },
291
+ }
292
+ for _ , tc := range testCases {
293
+ t .Run (tc .src , func (t * testing.T ) {
294
+ _ , err := gojq .Parse (tc .src )
295
+ if err == nil {
296
+ t .Fatal ("expected: error" )
297
+ }
298
+ var pe * gojq.ParseError
299
+ if ! errors .As (err , & pe ) {
300
+ t .Fatalf ("expected: *gojq.ParseError, got %v" , err )
301
+ }
302
+ if pe .Offset != tc .offset {
303
+ t .Fatalf ("expected: %v, got %v" , tc .offset , pe .Offset )
304
+ }
305
+ })
306
+ }
307
+ }
308
+
278
309
func TestCodeRun_Race (t * testing.T ) {
279
310
query , err := gojq .Parse ("range(10)" )
280
311
if err != nil {
0 commit comments