Debian Codegraph @

printer/printer_test.go

raw symbols SCIP
1 package printer_testscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer_test`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/"
5 "testingscip-go gomod github.com/golang/go/src go1.21.0 testing/"
6
7 "github.com/goccy/go-yaml/lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/"
8 "github.com/goccy/go-yaml/printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/"
9 )
10
11 func Test_Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer_test`/Test_Printer().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
12 yml := `---
13 text: aaaa
14 text2: aaaa
15 bbbb
16 cccc
17 dddd
18 eeee
19 text3: ffff
20 gggg
21 hhhh
22 iiii
23 jjjj
24 bool: true
25 number: 10
26 anchor: &x 1
27 alias: *x
28 `
29 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("print starting from tokens[3]", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
30 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(yml)
31 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
32 actual := "\n" + p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[3], false)
33 expect := `
34 1 | ---
35 > 2 | text: aaaa
36 ^
37 3 | text2: aaaa
38 4 | bbbb
39 5 | cccc
40 6 | dddd
41 7 | eeee
42 8 | `
43 if actual != expect {
44 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected output: expect:[%s]\n actual:[%s]", expect, actual)
45 }
46 })
47 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("print starting from tokens[4]", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
48 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(yml)
49 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
50 actual := "\n" + p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[4], false)
51 expect := `
52 1 | ---
53 2 | text: aaaa
54 > 3 | text2: aaaa
55 4 | bbbb
56 5 | cccc
57 6 | dddd
58 7 | eeee
59 ^
60 `
61 if actual != expect {
62 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected output: expect:[%s]\n actual:[%s]", expect, actual)
63 }
64 })
65 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("print starting from tokens[6]", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
66 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(yml)
67 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
68 actual := "\n" + p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[6], false)
69 expect := `
70 1 | ---
71 2 | text: aaaa
72 > 3 | text2: aaaa
73 4 | bbbb
74 5 | cccc
75 6 | dddd
76 7 | eeee
77 ^
78 8 | text3: ffff
79 9 | gggg
80 10 | hhhh
81 11 | iiii
82 12 | jjjj
83 13 | `
84 if actual != expect {
85 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected output: expect:[%s]\n actual:[%s]", expect, actual)
86 }
87 })
88 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("print error token with document header", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
89 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(`---
90 a:
91 b:
92 c:
93 d: e
94 f: g
95 h: i
96
97 ---
98 `)
99 expect := `
100 3 | b:
101 4 | c:
102 5 | d: e
103 > 6 | f: g
104 ^
105 7 | h: i
106 8 |
107 9 | ---`
108 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
109 actual := "\n" + p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[12], false)
110 if actual != expect {
111 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected output: expect:[%s]\n actual:[%s]", expect, actual)
112 }
113 })
114 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("output with color", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
115 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("token6", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
116 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(yml)
117 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
118 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("\n%s", p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[6], true))
119 })
120 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("token9", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
121 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(yml)
122 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
123 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("\n%s", p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[9], true))
124 })
125 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("token12", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
126 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(yml)
127 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
128 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("\n%s", p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[12], true))
129 })
130 })
131 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("print error message", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
132 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
133 src := "message"
134 msg := p.PrintErrorMessagescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorMessage().(src, false)
135 if msg != src {
136 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("unexpected result")
137 }
138 p.PrintErrorMessagescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorMessage().(src, true)
139 })
140 }
141
142 func TestPrinter_Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer_test`/TestPrinter_Anchor().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
143 expected := `
144 anchor: &x 1
145 alias: *x`
146 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(expected)
147 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
148 got := p.PrintTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintTokens().(tokens)
149 if expected != got {
150 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected output: expect:[%s]\n actual:[%s]", expected, got)
151 }
152 }
153
154 func Test_Printer_Multilinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer_test`/Test_Printer_Multiline().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
155 yml := `
156 text1: 'aaaa
157 bbbb
158 cccc'
159 text2: "ffff
160 gggg
161 hhhh"
162 text3: hello
163 `
164 tc := []struct {
165 token int
166 want string
167 }{
168 {
169 token: 2,
170 want: `
171 > 2 | text1: 'aaaa
172 3 | bbbb
173 4 | cccc'
174 ^
175 5 | text2: "ffff
176 6 | gggg
177 7 | hhhh"`,
178 },
179 {token: 3,
180 want: `
181 2 | text1: 'aaaa
182 3 | bbbb
183 4 | cccc'
184 > 5 | text2: "ffff
185 6 | gggg
186 7 | hhhh"
187 ^
188 8 | text3: hello`,
189 },
190 {token: 5,
191 want: `
192 2 | text1: 'aaaa
193 3 | bbbb
194 4 | cccc'
195 > 5 | text2: "ffff
196 6 | gggg
197 7 | hhhh"
198 ^
199 8 | text3: hello`,
200 },
201 {token: 6,
202 want: `
203 5 | text2: "ffff
204 6 | gggg
205 7 | hhhh"
206 > 8 | text3: hello
207 ^
208 `,
209 },
210 }
211 for _, tt := range tc {
212 name := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("print starting from tokens[%d]", tt.token)
213 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(name, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
214 tokens := lexerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/.Tokenizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/lexer`/Tokenize().(yml)
215 var p printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/.Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#
216 got := "\n" + p.PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tokens[tt.token], false)
217 want := tt.want
218 if got != want {
219 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("PrintErrorToken() got: %s\n want:%s\n", want, got)
220 }
221 })
222 }
223 }