Ensure the library can correctly scan strings.
(t *testing.T)
| 204 | |
| 205 | // Ensure the library can correctly scan strings. |
| 206 | func 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 | } |
nothing calls this directly
no test coverage detected