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

Function TestFormat_BasicStatements

pkg/formatter/formatter_test.go:22–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestFormat_BasicStatements(t *testing.T) {
23 tests := []struct {
24 name string
25 input string
26 wantErr bool
27 }{
28 {"simple select", "SELECT id, name FROM users", false},
29 {"select with where", "SELECT * FROM users WHERE id = 1", false},
30 {"insert", "INSERT INTO users (id, name) VALUES (1, 'test')", false},
31 {"update", "UPDATE users SET name = 'new' WHERE id = 1", false},
32 {"delete", "DELETE FROM users WHERE id = 1", false},
33 {"empty string", "", false},
34 {"whitespace only", " ", false},
35 {"invalid SQL", "SELEC BOGUS FROM", true},
36 }
37
38 f := New(Options{IndentSize: 2})
39
40 for _, tt := range tests {
41 t.Run(tt.name, func(t *testing.T) {
42 result, err := f.Format(tt.input)
43 if (err != nil) != tt.wantErr {
44 t.Errorf("Format() error = %v, wantErr %v", err, tt.wantErr)
45 return
46 }
47 if !tt.wantErr && tt.input != "" && tt.input != " " && result == "" {
48 t.Error("Format() returned empty string for valid non-empty SQL")
49 }
50 })
51 }
52}
53
54func TestFormatString(t *testing.T) {
55 result, err := FormatString("SELECT 1")

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
NewFunction · 0.70
ErrorfMethod · 0.65
FormatMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected