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

Function TestFormatSQLWithDialect_Pagination

pkg/transform/dialect_test.go:85–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestFormatSQLWithDialect_Pagination(t *testing.T) {
86 tests := []struct {
87 name string
88 dialect keywords.SQLDialect
89 limit int
90 offset int
91 want []string
92 reject []string
93 }{
94 {
95 name: "postgresql pagination",
96 dialect: keywords.DialectPostgreSQL,
97 limit: 10,
98 offset: 20,
99 want: []string{"LIMIT 10", "OFFSET 20"},
100 },
101 {
102 name: "oracle pagination",
103 dialect: keywords.DialectOracle,
104 limit: 10,
105 offset: 20,
106 want: []string{"OFFSET 20 ROWS", "FETCH FIRST 10 ROWS ONLY"},
107 reject: []string{"LIMIT"},
108 },
109 {
110 name: "mysql pagination",
111 dialect: keywords.DialectMySQL,
112 limit: 10,
113 offset: 20,
114 want: []string{"LIMIT 10", "OFFSET 20"},
115 },
116 {
117 name: "snowflake pagination",
118 dialect: keywords.DialectSnowflake,
119 limit: 10,
120 offset: 20,
121 want: []string{"LIMIT 10", "OFFSET 20"},
122 },
123 }
124
125 for _, tt := range tests {
126 t.Run(tt.name, func(t *testing.T) {
127 tree, err := ParseSQL("SELECT * FROM users ORDER BY id")
128 if err != nil {
129 t.Fatalf("parse: %v", err)
130 }
131 stmt := tree.Statements[0]
132 if err := Apply(stmt, SetLimit(tt.limit), SetOffset(tt.offset)); err != nil {
133 t.Fatalf("apply: %v", err)
134 }
135
136 got := FormatSQLWithDialect(stmt, tt.dialect)
137 for _, w := range tt.want {
138 if !strings.Contains(got, w) {
139 t.Errorf("expected %q in output, got: %s", w, got)
140 }
141 }
142 for _, r := range tt.reject {

Callers

nothing calls this directly

Calls 8

ParseSQLFunction · 0.85
ApplyFunction · 0.85
SetLimitFunction · 0.85
SetOffsetFunction · 0.85
FormatSQLWithDialectFunction · 0.85
RunMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected