MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestTokenizeContext_BasicSuccess

Function TestTokenizeContext_BasicSuccess

pkg/sql/tokenizer/context_test.go:25–65  ·  view source on GitHub ↗

TestTokenizeContext_BasicSuccess verifies that TokenizeContext works for valid SQL

(t *testing.T)

Source from the content-addressed store, hash-verified

23
24// TestTokenizeContext_BasicSuccess verifies that TokenizeContext works for valid SQL
25func 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
68func TestTokenizeContext_CancelledContext(t *testing.T) {

Callers

nothing calls this directly

Calls 7

GetTokenizerFunction · 0.85
PutTokenizerFunction · 0.85
RunMethod · 0.80
TokenizeContextMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected