@@ -101,7 +101,8 @@ pub(crate) fn adding_field_with_default(ctx: &mut Linter, parse: &Parse<SourceFi
101101mod test {
102102 use insta:: assert_debug_snapshot;
103103
104- use crate :: { Linter , Rule } ;
104+ use crate :: Rule ;
105+ use crate :: test_utils:: lint;
105106
106107 #[ test]
107108 fn docs_example_ok_post_pg_11 ( ) {
@@ -113,9 +114,7 @@ mod test {
113114ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
114115 "# ;
115116
116- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
117- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
118- let errors = linter. lint ( file, sql) ;
117+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
119118 assert ! ( errors. is_empty( ) ) ;
120119 assert_debug_snapshot ! ( errors) ;
121120 }
@@ -130,9 +129,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET DEFAULT 10;
130129-- remove nullability
131130 "# ;
132131
133- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
134- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
135- let errors = linter. lint ( file, sql) ;
132+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
136133 assert ! ( errors. is_empty( ) ) ;
137134 assert_debug_snapshot ! ( errors) ;
138135 }
@@ -143,9 +140,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET DEFAULT 10;
143140alter table t set logged, add column c integer default uuid();
144141 "# ;
145142
146- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
147- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
148- let errors = linter. lint ( file, sql) ;
143+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
149144 assert ! ( !errors. is_empty( ) ) ;
150145 assert_debug_snapshot ! ( errors) ;
151146 }
@@ -156,9 +151,7 @@ alter table t set logged, add column c integer default uuid();
156151ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
157152 "# ;
158153
159- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
160- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
161- let errors = linter. lint ( file, sql) ;
154+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
162155 assert ! ( !errors. is_empty( ) ) ;
163156 assert_debug_snapshot ! ( errors) ;
164157 }
@@ -170,9 +163,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
170163ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
171164 "# ;
172165
173- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
174- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
175- let errors = linter. lint ( file, sql) ;
166+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
176167 assert ! ( !errors. is_empty( ) ) ;
177168 assert_debug_snapshot ! ( errors) ;
178169 }
@@ -184,9 +175,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
184175ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true;
185176 "# ;
186177
187- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
188- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
189- let errors = linter. lint ( file, sql) ;
178+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
190179 assert ! ( errors. is_empty( ) ) ;
191180 assert_debug_snapshot ! ( errors) ;
192181 }
@@ -198,9 +187,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true;
198187ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
199188 "# ;
200189
201- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
202- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
203- let errors = linter. lint ( file, sql) ;
190+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
204191 assert ! ( errors. is_empty( ) ) ;
205192 assert_debug_snapshot ! ( errors) ;
206193 }
@@ -212,9 +199,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
212199ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-variant';
213200 "# ;
214201
215- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
216- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
217- let errors = linter. lint ( file, sql) ;
202+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
218203 assert ! ( errors. is_empty( ) ) ;
219204 assert_debug_snapshot ! ( errors) ;
220205 }
@@ -226,9 +211,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-varia
226211ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
227212 "# ;
228213
229- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
230- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
231- let errors = linter. lint ( file, sql) ;
214+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
232215 assert ! ( errors. is_empty( ) ) ;
233216 assert_debug_snapshot ! ( errors) ;
234217 }
@@ -240,9 +223,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
240223ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
241224 "# ;
242225
243- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
244- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
245- let errors = linter. lint ( file, sql) ;
226+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
246227 assert ! ( !errors. is_empty( ) ) ;
247228 assert_debug_snapshot ! ( errors) ;
248229 }
@@ -254,9 +235,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
254235ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
255236 "# ;
256237
257- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
258- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
259- let errors = linter. lint ( file, sql) ;
238+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
260239 assert ! ( !errors. is_empty( ) ) ;
261240 assert_debug_snapshot ! ( errors) ;
262241 }
@@ -267,9 +246,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
267246ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
268247 "# ;
269248
270- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
271- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
272- let errors = linter. lint ( file, sql) ;
249+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
273250 assert ! ( errors. is_empty( ) ) ;
274251 assert_debug_snapshot ! ( errors) ;
275252 }
@@ -281,9 +258,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
281258alter table account_metadata add column blah integer default 2 + 2;
282259 "# ;
283260
284- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
285- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
286- let errors = linter. lint ( file, sql) ;
261+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
287262 assert_debug_snapshot ! ( errors) ;
288263 }
289264
@@ -294,9 +269,7 @@ ALTER TABLE foo
294269ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED;
295270 "# ;
296271
297- let file = squawk_syntax:: SourceFile :: parse ( sql) ;
298- let mut linter = Linter :: from ( [ Rule :: AddingFieldWithDefault ] ) ;
299- let errors = linter. lint ( file, sql) ;
272+ let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
300273 assert ! ( !errors. is_empty( ) ) ;
301274 assert_debug_snapshot ! ( errors) ;
302275 }
0 commit comments