TestParseSQL verifies that Statement.SQL is set correctly.
(t *testing.T)
| 3388 | |
| 3389 | // TestParseSQL verifies that Statement.SQL is set correctly. |
| 3390 | func TestParseSQL(t *testing.T) { |
| 3391 | testData := []struct { |
| 3392 | in string |
| 3393 | exp []string |
| 3394 | }{ |
| 3395 | {in: ``, exp: nil}, |
| 3396 | {in: `SELECT 1`, exp: []string{`SELECT 1`}}, |
| 3397 | {in: `SELECT 1;`, exp: []string{`SELECT 1`}}, |
| 3398 | {in: `SELECT 1 /* comment */`, exp: []string{`SELECT 1`}}, |
| 3399 | {in: `SELECT 1;SELECT 2`, exp: []string{`SELECT 1`, `SELECT 2`}}, |
| 3400 | {in: `SELECT 1 /* comment */ ;SELECT 2`, exp: []string{`SELECT 1`, `SELECT 2`}}, |
| 3401 | {in: `SELECT 1 /* comment */ ; /* comment */ SELECT 2`, exp: []string{`SELECT 1`, `SELECT 2`}}, |
| 3402 | } |
| 3403 | var p parser.Parser // Verify that the same parser can be reused. |
| 3404 | for _, d := range testData { |
| 3405 | t.Run(d.in, func(t *testing.T) { |
| 3406 | stmts, err := p.Parse(d.in) |
| 3407 | if err != nil { |
| 3408 | t.Fatalf("expected success, but found %s", err) |
| 3409 | } |
| 3410 | var res []string |
| 3411 | for i := range stmts { |
| 3412 | res = append(res, stmts[i].SQL) |
| 3413 | } |
| 3414 | if !reflect.DeepEqual(res, d.exp) { |
| 3415 | t.Errorf("expected \n%v\n, but found %v", res, d.exp) |
| 3416 | } |
| 3417 | }) |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | // TestParseNumPlaceholders verifies that Statement.NumPlaceholders is set |
| 3422 | // correctly. |
nothing calls this directly
no test coverage detected
searching dependent graphs…