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

Function TestConvertStatementToJSON

cmd/gosqlx/internal/output/json_test.go:359–404  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

357}
358
359func TestConvertStatementToJSON(t *testing.T) {
360 // Create a simple SELECT statement
361 sqlQuery := "SELECT id, name FROM users WHERE active = true ORDER BY id LIMIT 10"
362
363 tkz := tokenizer.GetTokenizer()
364 defer tokenizer.PutTokenizer(tkz)
365
366 tokens, err := tkz.Tokenize([]byte(sqlQuery))
367 if err != nil {
368 t.Fatalf("Tokenization failed: %v", err)
369 }
370
371 p := parser.NewParser()
372 astObj, err := p.ParseFromModelTokens(tokens)
373 if err != nil {
374 t.Fatalf("Parsing failed: %v", err)
375 }
376 defer ast.ReleaseAST(astObj)
377
378 if len(astObj.Statements) == 0 {
379 t.Fatal("Expected at least one statement")
380 }
381
382 jsonStmt := convertStatementToJSON(astObj.Statements[0])
383
384 if jsonStmt.Type != "SelectStatement" {
385 t.Errorf("Expected type 'SelectStatement', got '%s'", jsonStmt.Type)
386 }
387
388 if jsonStmt.Details == nil {
389 t.Fatal("Expected details to be present")
390 }
391
392 // Check for expected details
393 if hasWhere, ok := jsonStmt.Details["has_where"].(bool); !ok || !hasWhere {
394 t.Error("Expected has_where to be true")
395 }
396
397 if hasOrderBy, ok := jsonStmt.Details["has_order_by"].(bool); !ok || !hasOrderBy {
398 t.Error("Expected has_order_by to be true")
399 }
400
401 if hasLimit, ok := jsonStmt.Details["has_limit"].(bool); !ok || !hasLimit {
402 t.Error("Expected has_limit to be true")
403 }
404}
405
406// testError is a simple error type for testing
407type testError struct {

Callers

nothing calls this directly

Calls 10

ParseFromModelTokensMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
NewParserFunction · 0.92
ReleaseASTFunction · 0.92
convertStatementToJSONFunction · 0.85
TokenizeMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected