MCPcopy
hub / github.com/sqldef/sqldef / TestNormalizeCheckExpr

Function TestNormalizeCheckExpr

schema/generator_test.go:187–326  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

185}
186
187func TestNormalizeCheckExpr(t *testing.T) {
188 tests := []struct {
189 name string
190 input string
191 expected string
192 }{
193 {
194 name: "Remove ::text cast from string literal",
195 input: "status = 'active'::text",
196 expected: "status = 'active'",
197 },
198 {
199 name: "Remove ::text cast from ARRAY elements",
200 input: "status = ANY (ARRAY['active'::text, 'pending'::text])",
201 expected: "status = ANY (ARRAY['active', 'pending'])",
202 },
203 {
204 name: "Remove ::character varying cast",
205 input: "name = 'test'::character varying",
206 expected: "name = 'test'",
207 },
208 {
209 name: "Remove ::character varying(255) cast",
210 input: "name = 'test'::character varying(255)",
211 expected: "name = 'test'",
212 },
213 {
214 name: "Remove double parentheses",
215 input: "((status = 'active'))",
216 expected: "(status = 'active')",
217 },
218 {
219 name: "Handle AND expression with casts",
220 input: "status = 'active'::text and name = 'test'::text",
221 expected: "status = 'active' and name = 'test'",
222 },
223 {
224 name: "Handle OR expression with casts",
225 input: "status = 'active'::text or status = 'pending'::text",
226 expected: "status in ('active', 'pending')",
227 },
228 {
229 name: "Handle NOT expression with cast",
230 input: "not status = 'inactive'::text",
231 expected: "not status = 'inactive'",
232 },
233 {
234 name: "Handle complex comparison with casts",
235 input: "status = ANY (ARRAY['active'::text, 'pending'::text, 'processing'::text])",
236 expected: "status = ANY (ARRAY['active', 'pending', 'processing'])",
237 },
238 {
239 name: "Handle IS NULL with cast",
240 input: "status::text is null",
241 expected: "status is null",
242 },
243 {
244 name: "Handle BETWEEN with casts",

Callers

nothing calls this directly

Calls 3

ParseDDLFunction · 0.92
StringFunction · 0.92
normalizeCheckExprFunction · 0.85

Tested by

no test coverage detected