...
1
16
17 package decoder
18
19 import (
20 `testing`
21
22 `github.com/bytedance/sonic/internal/native/types`
23 `github.com/stretchr/testify/assert`
24 )
25
26 func make_err(src string, pos int) SyntaxError {
27 return SyntaxError {
28 Src : src,
29 Pos : pos,
30 Code : types.ERR_INVALID_CHAR,
31 }
32 }
33
34 func TestErrors_Normal(t *testing.T) {
35 println(make_err("this is a very long message with 'hello, world' embedded in the string", 33).Description())
36 }
37
38 func TestErrors_LeftEdge(t *testing.T) {
39 println(make_err("this is a very long message with 'hello, world' embedded in the string", 6).Description())
40 }
41
42 func TestErrors_RightEdge(t *testing.T) {
43 println(make_err("this is a very long message with 'hello, world' embedded in the string", 65).Description())
44 }
45
46 func TestErrors_AfterRightEdge(t *testing.T) {
47 println(make_err("this is a very long message with 'hello, world' embedded in the string", 70).Description())
48 }
49
50 func TestErrors_ShortDescription(t *testing.T) {
51 e := make_err("hello, world", 5)
52 println(e.Description())
53 assert.Equal(t, "Syntax error at index 5: invalid char\n\n\thello, world\n\t.....^......\n", e.Description())
54 assert.Equal(t, `"Syntax error at index 5: invalid char\n\n\thello, world\n\t.....^......\n"`, e.Error())
55 }
56
57 func TestErrors_EmptyDescription(t *testing.T) {
58 println(make_err("", 0).Description())
59 }
60
View as plain text