MCPcopy
hub / github.com/uber/aresdb / TestScanString

Function TestScanString

query/expr/scanner_test.go:206–233  ·  view source on GitHub ↗

Ensure the library can correctly scan strings.

(t *testing.T)

Source from the content-addressed store, hash-verified

204
205// Ensure the library can correctly scan strings.
206func TestScanString(t *testing.T) {
207 var tests = []struct {
208 in string
209 out string
210 err string
211 }{
212 {in: `""`, out: ``},
213 {in: `"foo bar"`, out: `foo bar`},
214 {in: `'foo bar'`, out: `foo bar`},
215 {in: `"foo\nbar"`, out: "foo\nbar"},
216 {in: `"foo\\bar"`, out: `foo\bar`},
217 {in: `"foo\"bar"`, out: `foo"bar`},
218 {in: `'foo\'bar'`, out: `foo'bar`},
219
220 {in: `"foo` + "\n", out: `foo`, err: "bad string"}, // newline in string
221 {in: `"foo`, out: `foo`, err: "bad string"}, // unclosed quotes
222 {in: `"foo\xbar"`, out: `\x`, err: "bad escape"}, // invalid escape
223 }
224
225 for i, tt := range tests {
226 out, err := expr.ScanString(strings.NewReader(tt.in))
227 if tt.err != errstring(err) {
228 t.Errorf("%d. %s: error: exp=%s, got=%s", i, tt.in, tt.err, err)
229 } else if tt.out != out {
230 t.Errorf("%d. %s: out: exp=%s, got=%s", i, tt.in, tt.out, out)
231 }
232 }
233}

Callers

nothing calls this directly

Calls 3

ScanStringFunction · 0.92
errstringFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected