TestParseNumPlaceholders verifies that Statement.NumPlaceholders is set correctly.
(t *testing.T)
| 3421 | // TestParseNumPlaceholders verifies that Statement.NumPlaceholders is set |
| 3422 | // correctly. |
| 3423 | func TestParseNumPlaceholders(t *testing.T) { |
| 3424 | testData := []struct { |
| 3425 | in string |
| 3426 | exp []int |
| 3427 | }{ |
| 3428 | {in: ``, exp: nil}, |
| 3429 | |
| 3430 | {in: `SELECT 1`, exp: []int{0}}, |
| 3431 | {in: `SELECT $1`, exp: []int{1}}, |
| 3432 | {in: `SELECT $1 + $1`, exp: []int{1}}, |
| 3433 | {in: `SELECT $1 + $2`, exp: []int{2}}, |
| 3434 | {in: `SELECT $1 + $2 + $1 + $2`, exp: []int{2}}, |
| 3435 | {in: `SELECT $2`, exp: []int{2}}, |
| 3436 | {in: `SELECT $1, $1 + $2, $1 + $2 + $3`, exp: []int{3}}, |
| 3437 | |
| 3438 | {in: `SELECT $1; SELECT $1`, exp: []int{1, 1}}, |
| 3439 | {in: `SELECT $1; SELECT $1 + $2 + $3; SELECT $1 + $2`, exp: []int{1, 3, 2}}, |
| 3440 | } |
| 3441 | |
| 3442 | var p parser.Parser // Verify that the same parser can be reused. |
| 3443 | for _, d := range testData { |
| 3444 | t.Run(d.in, func(t *testing.T) { |
| 3445 | stmts, err := p.Parse(d.in) |
| 3446 | if err != nil { |
| 3447 | t.Fatalf("expected success, but found %s", err) |
| 3448 | } |
| 3449 | var res []int |
| 3450 | for i := range stmts { |
| 3451 | res = append(res, stmts[i].NumPlaceholders) |
| 3452 | } |
| 3453 | if !reflect.DeepEqual(res, d.exp) { |
| 3454 | t.Errorf("expected \n%v\n, but found %v", res, d.exp) |
| 3455 | } |
| 3456 | }) |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | func TestParseOne(t *testing.T) { |
| 3461 | _, err := parser.ParseOne("SELECT 1; SELECT 2") |
nothing calls this directly
no test coverage detected
searching dependent graphs…