(t *testing.T)
| 24 | } |
| 25 | |
| 26 | func TestStripFuncResultTextCasts(t *testing.T) { |
| 27 | testCases := []struct { |
| 28 | name string |
| 29 | input string |
| 30 | want string |
| 31 | }{ |
| 32 | { |
| 33 | name: "strips text cast on function result", |
| 34 | input: "current_setting('app.tenant_id', true)::text = tenant_id::text", |
| 35 | want: "current_setting('app.tenant_id', true) = tenant_id::text", |
| 36 | }, |
| 37 | { |
| 38 | name: "strips text cast on parenthesized function result", |
| 39 | input: "(current_setting('app.tenant_id', true))::text = 'x'", |
| 40 | want: "current_setting('app.tenant_id', true) = 'x'", |
| 41 | }, |
| 42 | { |
| 43 | name: "strips character varying cast on function result", |
| 44 | input: "current_user::character varying = 'x'", |
| 45 | want: "current_user::character varying = 'x'", // current_user is a keyword, not a function call |
| 46 | }, |
| 47 | { |
| 48 | name: "strips character varying cast on function call", |
| 49 | input: "lower('X')::character varying = 'x'", |
| 50 | want: "lower('X') = 'x'", |
| 51 | }, |
| 52 | { |
| 53 | name: "keeps non-text cast on function result", |
| 54 | input: "current_setting('app.tenant_id', true)::integer = 1", |
| 55 | want: "current_setting('app.tenant_id', true)::integer = 1", |
| 56 | }, |
| 57 | { |
| 58 | name: "keeps text cast on column", |
| 59 | input: "tenant_id::text = 'x'", |
| 60 | want: "tenant_id::text = 'x'", |
| 61 | }, |
| 62 | { |
| 63 | name: "keeps text cast on literal", |
| 64 | input: "'x'::text = name", |
| 65 | want: "'x'::text = name", |
| 66 | }, |
| 67 | { |
| 68 | name: "strips inner text cast under outer non-text cast", |
| 69 | input: "lower('X')::text::integer = 1", |
| 70 | want: "lower('X')::integer = 1", |
| 71 | }, |
| 72 | { |
| 73 | name: "recurses into NOT", |
| 74 | input: "NOT (lower('X')::text = 'x')", |
| 75 | want: "NOT (lower('X') = 'x')", |
| 76 | }, |
| 77 | { |
| 78 | name: "recurses into AND and OR", |
| 79 | input: "lower('a')::text = 'a' AND (lower('b')::text = 'b' OR tenant_id = 1)", |
| 80 | want: "lower('a') = 'a' AND (lower('b') = 'b' OR tenant_id = 1)", |
| 81 | }, |
| 82 | { |
| 83 | name: "recurses into string concatenation", |
nothing calls this directly
no test coverage detected