TestTokenizeContext_BasicSuccess verifies that TokenizeContext works for valid SQL
(t *testing.T)
| 23 | |
| 24 | // TestTokenizeContext_BasicSuccess verifies that TokenizeContext works for valid SQL |
| 25 | func TestTokenizeContext_BasicSuccess(t *testing.T) { |
| 26 | tests := []struct { |
| 27 | name string |
| 28 | input string |
| 29 | }{ |
| 30 | { |
| 31 | name: "simple select", |
| 32 | input: "SELECT * FROM users", |
| 33 | }, |
| 34 | { |
| 35 | name: "complex query with joins", |
| 36 | input: "SELECT u.name, o.total FROM users u JOIN orders o ON u.id = o.user_id WHERE u.active = true", |
| 37 | }, |
| 38 | { |
| 39 | name: "insert statement", |
| 40 | input: "INSERT INTO users (name, email) VALUES ('John', 'john@example.com')", |
| 41 | }, |
| 42 | } |
| 43 | |
| 44 | for _, tt := range tests { |
| 45 | t.Run(tt.name, func(t *testing.T) { |
| 46 | ctx := context.Background() |
| 47 | tkz := GetTokenizer() |
| 48 | defer PutTokenizer(tkz) |
| 49 | |
| 50 | tokens, err := tkz.TokenizeContext(ctx, []byte(tt.input)) |
| 51 | if err != nil { |
| 52 | t.Fatalf("TokenizeContext() error = %v", err) |
| 53 | } |
| 54 | |
| 55 | if len(tokens) == 0 { |
| 56 | t.Error("Expected tokens but got none") |
| 57 | } |
| 58 | |
| 59 | // Verify last token is EOF (TokenTypeEOF = 0) |
| 60 | if tokens[len(tokens)-1].Token.Type != 0 { |
| 61 | t.Errorf("Expected last token to be EOF (0), got %d", tokens[len(tokens)-1].Token.Type) |
| 62 | } |
| 63 | }) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // TestTokenizeContext_CancelledContext verifies that cancellation is detected |
| 68 | func TestTokenizeContext_CancelledContext(t *testing.T) { |
nothing calls this directly
no test coverage detected