From 9299b020375e8694ed4879c500bae57820387aa5 Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Wed, 29 Jan 2025 20:20:43 -0500 Subject: [PATCH] tests: refactor names to not prefix with test_ ``` fastmod --fixed-strings 'fn test_' 'fn ' --extensions rs ``` ideally we'd have a lint --- cli/src/config.rs | 12 +- cli/src/reporter.rs | 20 +- linter/src/lib.rs | 8 +- linter/src/rules/adding_field_with_default.rs | 28 +- .../rules/adding_foreign_key_constraint.rs | 8 +- linter/src/rules/adding_not_null_field.rs | 8 +- .../rules/adding_primary_key_constraint.rs | 4 +- linter/src/rules/adding_required_field.rs | 10 +- linter/src/rules/ban_char_field.rs | 4 +- ...oncurrent_index_creation_in_transaction.rs | 6 +- linter/src/rules/ban_drop_column.rs | 2 +- linter/src/rules/ban_drop_database.rs | 2 +- linter/src/rules/ban_drop_not_null.rs | 2 +- linter/src/rules/ban_drop_table.rs | 2 +- linter/src/rules/changing_column_type.rs | 2 +- .../src/rules/constraint_missing_not_valid.rs | 8 +- .../src/rules/disallow_unique_constraint.rs | 12 +- linter/src/rules/prefer_big_int.rs | 6 +- linter/src/rules/prefer_bigint_over_int.rs | 4 +- .../src/rules/prefer_bigint_over_smallint.rs | 4 +- linter/src/rules/prefer_identity.rs | 4 +- linter/src/rules/prefer_robust_stmts.rs | 12 +- linter/src/rules/prefer_text_field.rs | 6 +- linter/src/rules/prefer_timestamptz.rs | 4 +- linter/src/rules/renaming_column.rs | 2 +- linter/src/rules/renaming_table.rs | 2 +- .../require_concurrent_index_creation.rs | 6 +- .../require_concurrent_index_deletion.rs | 2 +- ...es__adding_field_that_is_not_nullable.snap | 2 +- ...ld_that_is_not_nullable_in_version_11.snap | 2 +- ...aint__test_rules__plain_primary_key-2.snap | 2 +- ...est_rules__regression_with_indexing_2.snap | 5 - ...ith_assume_in_transaction_but_outside.snap | 1 - ...rop_table__test_rules__ban_drop_table.snap | 1 - linter/src/rules/transaction_nesting.rs | 16 +- linter/src/versions.rs | 6 +- parser/src/parse.rs | 250 +++++++++--------- ...se__tests__parse_sql_query_json_works.snap | 139 ++++++++++ templates/new_rule.rs.template | 2 +- 39 files changed, 374 insertions(+), 242 deletions(-) delete mode 100644 linter/src/rules/snapshots/squawk_linter__rules__ban_char_field__test_rules__regression_with_indexing_2.snap create mode 100644 parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json_works.snap diff --git a/cli/src/config.rs b/cli/src/config.rs index 2a4d61e8..1fcbbe12 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -104,7 +104,7 @@ mod test_config { use super::*; #[test] - fn test_load_cfg_full() { + fn load_cfg_full() { let squawk_toml = NamedTempFile::new().expect("generate tempFile"); let file = r#" pg_version = "19.1" @@ -117,7 +117,7 @@ assume_in_transaction = true assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf()))); } #[test] - fn test_load_pg_version() { + fn load_pg_version() { let squawk_toml = NamedTempFile::new().expect("generate tempFile"); let file = r#" pg_version = "19.1" @@ -127,7 +127,7 @@ pg_version = "19.1" assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf()))); } #[test] - fn test_load_excluded_rules() { + fn load_excluded_rules() { let squawk_toml = NamedTempFile::new().expect("generate tempFile"); let file = r#" excluded_rules = ["require-concurrent-index-creation"] @@ -137,7 +137,7 @@ excluded_rules = ["require-concurrent-index-creation"] assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf()))); } #[test] - fn test_load_excluded_paths() { + fn load_excluded_paths() { let squawk_toml = NamedTempFile::new().expect("generate tempFile"); let file = r#" excluded_paths = ["example.sql"] @@ -147,7 +147,7 @@ excluded_paths = ["example.sql"] assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf()))); } #[test] - fn test_load_assume_in_transaction() { + fn load_assume_in_transaction() { let squawk_toml = NamedTempFile::new().expect("generate tempFile"); let file = r" assume_in_transaction = false @@ -157,7 +157,7 @@ assume_in_transaction = false assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf()))); } #[test] - fn test_load_fail_on_violations() { + fn load_fail_on_violations() { let squawk_toml = NamedTempFile::new().expect("generate tempFile"); let file = r" [upload_to_github] diff --git a/cli/src/reporter.rs b/cli/src/reporter.rs index c8894b96..f20cb229 100644 --- a/cli/src/reporter.rs +++ b/cli/src/reporter.rs @@ -556,7 +556,7 @@ mod test_github_comment { /// Most cases, hopefully, will be a single migration for a given PR, but /// let's check the case of multiple migrations #[test] - fn test_generating_comment_multiple_files() { + fn generating_comment_multiple_files() { let violations = vec![ViolationContent { filename: "alpha.sql".into(), sql: r" @@ -588,7 +588,7 @@ SELECT 1; /// Even when we don't have violations we still want to output the SQL for /// easy human reading. #[test] - fn test_generating_comment_no_violations() { + fn generating_comment_no_violations() { let violations = vec![ ViolationContent { filename: "alpha.sql".into(), @@ -623,7 +623,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10; /// Ideally the logic won't leave a comment when there are no migrations but /// better safe than sorry #[test] - fn test_generating_no_violations_no_files() { + fn generating_no_violations_no_files() { let violations = vec![]; let body = get_comment_body(&violations, "0.2.3"); @@ -642,7 +642,7 @@ mod test_check_files { use super::process_violations; #[test] - fn test_check_files_invalid_syntax() { + fn check_files_invalid_syntax() { let sql = r" select \; "; @@ -672,7 +672,7 @@ mod test_reporter { } #[test] - fn test_display_violations_gcc() { + fn display_violations_gcc() { let sql = r#" ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL; ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL; @@ -698,7 +698,7 @@ SELECT 1; } #[test] - fn test_display_violations_tty() { + fn display_violations_tty() { let sql = r#" ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL; ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL; @@ -719,7 +719,7 @@ SELECT 1; assert_display_snapshot!(strip_ansi_codes(&String::from_utf8_lossy(&buff))); } #[test] - fn test_display_no_violations_tty() { + fn display_no_violations_tty() { let mut buff = Vec::new(); let res = print_violations( @@ -734,7 +734,7 @@ SELECT 1; } #[test] - fn test_display_violations_json() { + fn display_violations_json() { let sql = r#" ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL; ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL; @@ -757,7 +757,7 @@ SELECT 1; } #[test] - fn test_span_offsets() { + fn span_offsets() { let sql = r#" ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL; @@ -773,7 +773,7 @@ SELECT 1; /// `pretty_violations` was slicing the SQL improperly, trimming off the first /// letter. #[test] - fn test_trimming_sql_newlines() { + fn trimming_sql_newlines() { let sql = r#"ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;"#; let violations = lint_sql(sql); diff --git a/linter/src/lib.rs b/linter/src/lib.rs index e73f3115..174edeb2 100644 --- a/linter/src/lib.rs +++ b/linter/src/lib.rs @@ -425,7 +425,7 @@ mod test_rules { } /// Ensure we handle both serializing and deserializing `RuleViolationKind` #[test] - fn test_parsing_rule_kind() { + fn parsing_rule_kind() { let rule_names = RULES.iter().map(|r| r.name.clone()); for rule in rule_names { let rule_str = rule.to_string(); @@ -435,19 +435,19 @@ mod test_rules { } /// Ensure rule names don't change #[test] - fn test_rule_names_debug_snap() { + fn rule_names_debug_snap() { let rule_names: Vec = RULES.iter().map(|r| r.name.to_string()).collect(); assert_debug_snapshot!(rule_names); } #[test] - fn test_rule_names_display_snap() { + fn rule_names_display_snap() { let rule_names: Vec = RULES.iter().map(|r| r.name.to_string()).collect(); assert_display_snapshot!(rule_names.join("\n")); } /// Ensure we stort the resulting violations by where they occur in the file. #[test] - fn test_check_rules_orderin() { + fn check_rules_orderin() { let sql = r#" ALTER TABLE "table_name" RENAME COLUMN "column_name" TO "new_column_name"; CREATE INDEX "field_name_idx" ON "table_name" ("field_name"); diff --git a/linter/src/rules/adding_field_with_default.rs b/linter/src/rules/adding_field_with_default.rs index 19cfec31..42106c34 100644 --- a/linter/src/rules/adding_field_with_default.rs +++ b/linter/src/rules/adding_field_with_default.rs @@ -131,7 +131,7 @@ mod test_rules { /// -- remove nullability /// ``` #[test] - fn test_docs_example_bad() { + fn docs_example_bad() { let bad_sql = r#" -- instead of ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10; @@ -139,7 +139,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10; assert_debug_snapshot!(lint_sql(bad_sql, None)); } #[test] - fn test_docs_example_ok() { + fn docs_example_ok() { let ok_sql = r#" -- use ALTER TABLE "core_recipe" ADD COLUMN "foo" integer; @@ -151,7 +151,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET DEFAULT 10; } #[test] - fn test_default_integer_ok() { + fn default_integer_ok() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10; @@ -162,7 +162,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10; } #[test] - fn test_default_uuid_err() { + fn default_uuid_err() { let bad_sql = r#" -- VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid(); @@ -173,7 +173,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid(); } #[test] - fn test_default_volatile_func_err() { + fn default_volatile_func_err() { let bad_sql = r#" -- VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random(); @@ -182,7 +182,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random(); assert_debug_snapshot!(lint_sql(bad_sql, pg_version_11)); } #[test] - fn test_default_bool_ok() { + fn default_bool_ok() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true; @@ -191,7 +191,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true; assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11)); } #[test] - fn test_default_str_ok() { + fn default_str_ok() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str'; @@ -200,7 +200,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str'; assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11)); } #[test] - fn test_default_enum_ok() { + fn default_enum_ok() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-variant'; @@ -209,7 +209,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-varia assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11)); } #[test] - fn test_default_jsonb_ok() { + fn default_jsonb_ok() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb; @@ -218,7 +218,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb; assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11)); } #[test] - fn test_default_arbitrary_func_err() { + fn default_arbitrary_func_err() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb(); @@ -227,7 +227,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb(); assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11)); } #[test] - fn test_default_random_with_args_err() { + fn default_random_with_args_err() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123); @@ -236,7 +236,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123); assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11)); } #[test] - fn test_default_now_func_ok() { + fn default_now_func_ok() { let ok_sql = r#" -- NON-VOLATILE ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(); @@ -245,7 +245,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(); assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11)); } #[test] - fn test_add_numbers_ok() { + fn add_numbers_ok() { // This should be okay, but we don't handle expressions like this at the moment. let ok_sql = r" alter table account_metadata add column blah integer default 2 + 2; @@ -255,7 +255,7 @@ alter table account_metadata add column blah integer default 2 + 2; } #[test] - fn test_generated_stored() { + fn generated_stored() { let bad_sql = r" ALTER TABLE foo ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED; diff --git a/linter/src/rules/adding_foreign_key_constraint.rs b/linter/src/rules/adding_foreign_key_constraint.rs index 6fb9d16f..1c73a330 100644 --- a/linter/src/rules/adding_foreign_key_constraint.rs +++ b/linter/src/rules/adding_foreign_key_constraint.rs @@ -85,7 +85,7 @@ mod test_rules { } #[test] - fn test_create_table_with_foreign_key_constraint() { + fn create_table_with_foreign_key_constraint() { let sql = r#" BEGIN; CREATE TABLE email ( @@ -104,7 +104,7 @@ COMMIT; assert_eq!(violations.len(), 0); } #[test] - fn test_add_foreign_key_constraint_not_valid_validate() { + fn add_foreign_key_constraint_not_valid_validate() { let sql = r#" BEGIN; ALTER TABLE "email" ADD COLUMN "user_id" INT; @@ -117,7 +117,7 @@ COMMIT; assert_eq!(violations.len(), 0); } #[test] - fn test_add_foreign_key_constraint_lock() { + fn add_foreign_key_constraint_lock() { let sql = r#" BEGIN; ALTER TABLE "email" ADD COLUMN "user_id" INT; @@ -133,7 +133,7 @@ COMMIT; ); } #[test] - fn test_add_column_references_lock() { + fn add_column_references_lock() { let sql = r#" BEGIN; ALTER TABLE "emails" ADD COLUMN "user_id" INT REFERENCES "user" ("id"); diff --git a/linter/src/rules/adding_not_null_field.rs b/linter/src/rules/adding_not_null_field.rs index 796204ba..afaf012c 100644 --- a/linter/src/rules/adding_not_null_field.rs +++ b/linter/src/rules/adding_not_null_field.rs @@ -63,7 +63,7 @@ mod test_rules { use insta::assert_debug_snapshot; #[test] - fn test_set_not_null() { + fn set_not_null() { let sql = r#" ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET NOT NULL; "#; @@ -71,7 +71,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET NOT NULL; } #[test] - fn test_adding_field_that_is_not_nullable() { + fn adding_field_that_is_not_nullable() { let ok_sql = r#" BEGIN; -- This will cause a table rewrite for Postgres versions before 11, but that is handled by @@ -84,7 +84,7 @@ COMMIT; } #[test] - fn test_adding_field_that_is_not_nullable_without_default() { + fn adding_field_that_is_not_nullable_without_default() { let ok_sql = r#" -- This won't work if the table is populated, but that error is caught by adding-required-field. ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL; @@ -93,7 +93,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL; } #[test] - fn test_adding_field_that_is_not_nullable_in_version_11() { + fn adding_field_that_is_not_nullable_in_version_11() { let ok_sql = r#" BEGIN; -- diff --git a/linter/src/rules/adding_primary_key_constraint.rs b/linter/src/rules/adding_primary_key_constraint.rs index 8b12e6d5..6804a54f 100644 --- a/linter/src/rules/adding_primary_key_constraint.rs +++ b/linter/src/rules/adding_primary_key_constraint.rs @@ -75,7 +75,7 @@ mod test_rules { } #[test] - fn test_serial_primary_key() { + fn serial_primary_key() { let bad_sql = r" ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY; "; @@ -86,7 +86,7 @@ ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY; } #[test] - fn test_plain_primary_key() { + fn plain_primary_key() { let bad_sql = r" ALTER TABLE items ADD PRIMARY KEY (id); "; diff --git a/linter/src/rules/adding_required_field.rs b/linter/src/rules/adding_required_field.rs index 1748c7bf..e667b458 100644 --- a/linter/src/rules/adding_required_field.rs +++ b/linter/src/rules/adding_required_field.rs @@ -75,7 +75,7 @@ mod test_rules { } #[test] - fn test_nullable() { + fn nullable() { let ok_sql = r#" ALTER TABLE "recipe" ADD COLUMN "public" boolean; "#; @@ -83,7 +83,7 @@ ALTER TABLE "recipe" ADD COLUMN "public" boolean; } #[test] - fn test_not_null_with_default() { + fn not_null_with_default() { let ok_sql = r#" ALTER TABLE "recipe" ADD COLUMN "public" boolean NOT NULL DEFAULT true; "#; @@ -91,14 +91,14 @@ ALTER TABLE "recipe" ADD COLUMN "public" boolean NOT NULL DEFAULT true; } #[test] - fn test_not_null_without_default() { + fn not_null_without_default() { let bad_sql = r#" ALTER TABLE "recipe" ADD COLUMN "public" boolean NOT NULL; "#; assert_debug_snapshot!(lint_sql(bad_sql)); } #[test] - fn test_generated_stored_not_null() { + fn generated_stored_not_null() { let ok_sql = r" ALTER TABLE foo ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED NOT NULL; @@ -106,7 +106,7 @@ ALTER TABLE "recipe" ADD COLUMN "public" boolean NOT NULL; assert_debug_snapshot!(lint_sql(ok_sql)); } #[test] - fn test_generated_stored() { + fn generated_stored() { let ok_sql = r" ALTER TABLE foo ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED ; diff --git a/linter/src/rules/ban_char_field.rs b/linter/src/rules/ban_char_field.rs index a6e73edb..dd796bd8 100644 --- a/linter/src/rules/ban_char_field.rs +++ b/linter/src/rules/ban_char_field.rs @@ -49,7 +49,7 @@ mod test_rules { } #[test] - fn test_creating_table_with_char_errors() { + fn creating_table_with_char_errors() { let sql = r#" BEGIN; CREATE TABLE "core_bar" ( @@ -65,7 +65,7 @@ COMMIT; } #[test] - fn test_creating_table_with_var_char_and_text_okay() { + fn creating_table_with_var_char_and_text_okay() { let sql = r#" BEGIN; CREATE TABLE "core_bar" ( diff --git a/linter/src/rules/ban_concurrent_index_creation_in_transaction.rs b/linter/src/rules/ban_concurrent_index_creation_in_transaction.rs index a79c3fa7..25885ef1 100644 --- a/linter/src/rules/ban_concurrent_index_creation_in_transaction.rs +++ b/linter/src/rules/ban_concurrent_index_creation_in_transaction.rs @@ -73,7 +73,7 @@ mod test_rules { } #[test] - fn test_adding_index_concurrently_in_transaction() { + fn adding_index_concurrently_in_transaction() { let bad_sql = r#" -- instead of BEGIN; @@ -91,7 +91,7 @@ mod test_rules { } #[test] - fn test_adding_index_concurrently_in_transaction_with_assume_in_transaction() { + fn adding_index_concurrently_in_transaction_with_assume_in_transaction() { let bad_sql = r#" -- instead of CREATE UNIQUE INDEX CONCURRENTLY "field_name_idx" ON "table_name" ("field_name"); @@ -108,7 +108,7 @@ mod test_rules { } #[test] - fn test_adding_index_concurrently_in_transaction_with_assume_in_transaction_but_outside() { + fn adding_index_concurrently_in_transaction_with_assume_in_transaction_but_outside() { let ok_sql = r#" -- the following will work too COMMIT; diff --git a/linter/src/rules/ban_drop_column.rs b/linter/src/rules/ban_drop_column.rs index 59b2c4a8..78fd8983 100644 --- a/linter/src/rules/ban_drop_column.rs +++ b/linter/src/rules/ban_drop_column.rs @@ -45,7 +45,7 @@ mod test_rules { } #[test] - fn test_drop_column() { + fn drop_column() { let sql = r#" ALTER TABLE "bar_tbl" DROP COLUMN "foo_col" CASCADE; "#; diff --git a/linter/src/rules/ban_drop_database.rs b/linter/src/rules/ban_drop_database.rs index 5b2ea89c..15cd88e9 100644 --- a/linter/src/rules/ban_drop_database.rs +++ b/linter/src/rules/ban_drop_database.rs @@ -41,7 +41,7 @@ mod test_rules { } #[test] - fn test_ban_drop_database() { + fn ban_drop_database() { let sql = r#" DROP DATABASE "table_name"; DROP DATABASE IF EXISTS "table_name"; diff --git a/linter/src/rules/ban_drop_not_null.rs b/linter/src/rules/ban_drop_not_null.rs index 7c249150..e89c9217 100644 --- a/linter/src/rules/ban_drop_not_null.rs +++ b/linter/src/rules/ban_drop_not_null.rs @@ -42,7 +42,7 @@ mod test_rules { } #[test] - fn test_ban_drop_not_null() { + fn ban_drop_not_null() { let bad_sql = r#" ALTER TABLE "bar_tbl" ALTER COLUMN "foo_col" DROP NOT NULL; "#; diff --git a/linter/src/rules/ban_drop_table.rs b/linter/src/rules/ban_drop_table.rs index b4b7fdb4..ed7466fe 100644 --- a/linter/src/rules/ban_drop_table.rs +++ b/linter/src/rules/ban_drop_table.rs @@ -40,7 +40,7 @@ mod test_rules { } #[test] - fn test_ban_drop_table() { + fn ban_drop_table() { let sql = r#" DROP TABLE "table_name"; DROP TABLE IF EXISTS "table_name"; diff --git a/linter/src/rules/changing_column_type.rs b/linter/src/rules/changing_column_type.rs index 26235feb..43ef516d 100644 --- a/linter/src/rules/changing_column_type.rs +++ b/linter/src/rules/changing_column_type.rs @@ -44,7 +44,7 @@ mod test_rules { } #[test] - fn test_changing_field_type() { + fn changing_field_type() { let bad_sql = r#" BEGIN; -- diff --git a/linter/src/rules/constraint_missing_not_valid.rs b/linter/src/rules/constraint_missing_not_valid.rs index c146e4ec..0fa41724 100644 --- a/linter/src/rules/constraint_missing_not_valid.rs +++ b/linter/src/rules/constraint_missing_not_valid.rs @@ -127,7 +127,7 @@ mod test_rules { } #[test] - fn test_ensure_ignored_when_new_table() { + fn ensure_ignored_when_new_table() { let sql = r#" BEGIN; CREATE TABLE "core_foo" ( @@ -142,7 +142,7 @@ COMMIT; } #[test] - fn test_ensure_ignored_when_new_table_with_assume_in_transaction() { + fn ensure_ignored_when_new_table_with_assume_in_transaction() { let sql = r#" CREATE TABLE "core_foo" ( "id" serial NOT NULL PRIMARY KEY, @@ -223,7 +223,7 @@ COMMIT; /// ALTER TABLE distributors VALIDATE CONSTRAINT distfk; /// ``` #[test] - fn test_adding_foreign_key() { + fn adding_foreign_key() { let bad_sql = r" -- instead of ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address); @@ -249,7 +249,7 @@ ALTER TABLE distributors VALIDATE CONSTRAINT distfk; /// ALTER TABLE accounts VALIDATE CONSTRAINT positive_balance; /// ``` #[test] - fn test_adding_check_constraint() { + fn adding_check_constraint() { let bad_sql = r#" -- instead of ALTER TABLE "accounts" ADD CONSTRAINT "positive_balance" CHECK ("balance" >= 0); diff --git a/linter/src/rules/disallow_unique_constraint.rs b/linter/src/rules/disallow_unique_constraint.rs index 13199b6d..4d122eac 100644 --- a/linter/src/rules/disallow_unique_constraint.rs +++ b/linter/src/rules/disallow_unique_constraint.rs @@ -96,7 +96,7 @@ mod test_rules { /// ADD CONSTRAINT distributors_pkey PRIMARY KEY USING INDEX dist_id_temp_idx; /// ``` #[test] - fn test_adding_unique_constraint() { + fn adding_unique_constraint() { let bad_sql = r" ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name); "; @@ -119,7 +119,7 @@ ADD CONSTRAINT distributors_pkey PRIMARY KEY USING INDEX dist_id_temp_idx; /// Creating a UNIQUE constraint from an existing index should be considered /// safe #[test] - fn test_unique_constraint_ok() { + fn unique_constraint_ok() { let sql = r#" CREATE UNIQUE INDEX CONCURRENTLY "legacy_questiongrouppg_mongo_id_1f8f47d9_uniq_idx" ON "legacy_questiongrouppg" ("mongo_id"); @@ -130,7 +130,7 @@ ALTER TABLE "legacy_questiongrouppg" ADD CONSTRAINT "legacy_questiongrouppg_mong /// Creating a UNIQUE constraint in the same transaction as the table is create is OK. #[test] - fn test_unique_constraint_after_create_table() { + fn unique_constraint_after_create_table() { let sql = r" BEGIN; CREATE TABLE products ( @@ -145,7 +145,7 @@ COMMIT; /// Creating a UNIQUE constraint in the same transaction as the table is create is OK. #[test] - fn test_unique_constraint_after_create_table_with_assume_in_transaction() { + fn unique_constraint_after_create_table_with_assume_in_transaction() { let sql = r" CREATE TABLE products ( id bigint generated by default as identity primary key, @@ -156,14 +156,14 @@ ALTER TABLE products ADD CONSTRAINT sku_constraint UNIQUE (sku); assert_eq!(lint_sql_assuming_in_transaction(sql), vec![]); } #[test] - fn test_unique_constraint_inline_add_column() { + fn unique_constraint_inline_add_column() { let sql = r" ALTER TABLE foo ADD COLUMN bar text CONSTRAINT foo_bar_unique UNIQUE; "; assert_debug_snapshot!(lint_sql(sql)); } #[test] - fn test_unique_constraint_inline_add_column_unique() { + fn unique_constraint_inline_add_column_unique() { let sql = r" ALTER TABLE foo ADD COLUMN bar text UNIQUE; "; diff --git a/linter/src/rules/prefer_big_int.rs b/linter/src/rules/prefer_big_int.rs index 752f2c03..64941a03 100644 --- a/linter/src/rules/prefer_big_int.rs +++ b/linter/src/rules/prefer_big_int.rs @@ -64,7 +64,7 @@ mod test_rules { } #[test] - fn test_create_table_ok() { + fn create_table_ok() { let ok_sql = r" create table users ( id bigint @@ -82,7 +82,7 @@ create table users ( assert_eq!(lint_sql(ok_sql), vec![]); } #[test] - fn test_create_table_bad() { + fn create_table_bad() { let bad_sql = r" create table users ( id smallint @@ -127,7 +127,7 @@ create table users ( assert_debug_snapshot!(res); } #[test] - fn test_create_table_many_errors() { + fn create_table_many_errors() { let bad_sql = r" create table users ( foo integer, diff --git a/linter/src/rules/prefer_bigint_over_int.rs b/linter/src/rules/prefer_bigint_over_int.rs index 8482e7d8..2dad3f65 100644 --- a/linter/src/rules/prefer_bigint_over_int.rs +++ b/linter/src/rules/prefer_bigint_over_int.rs @@ -56,7 +56,7 @@ mod test_rules { } #[test] - fn test_create_table_ok() { + fn create_table_ok() { let ok_sql = r" create table users ( id bigint @@ -86,7 +86,7 @@ create table users ( assert_eq!(lint_sql(ok_sql), vec![]); } #[test] - fn test_create_table_bad() { + fn create_table_bad() { let bad_sql = r" create table users ( id integer diff --git a/linter/src/rules/prefer_bigint_over_smallint.rs b/linter/src/rules/prefer_bigint_over_smallint.rs index 99ffb2dc..ecbab033 100644 --- a/linter/src/rules/prefer_bigint_over_smallint.rs +++ b/linter/src/rules/prefer_bigint_over_smallint.rs @@ -62,7 +62,7 @@ mod test_rules { } #[test] - fn test_create_table_ok() { + fn create_table_ok() { let ok_sql = r" create table users ( id bigint @@ -92,7 +92,7 @@ create table users ( assert_eq!(lint_sql(ok_sql), vec![]); } #[test] - fn test_create_table_bad() { + fn create_table_bad() { let bad_sql = r" create table users ( id smallint diff --git a/linter/src/rules/prefer_identity.rs b/linter/src/rules/prefer_identity.rs index 3d971569..638ec614 100644 --- a/linter/src/rules/prefer_identity.rs +++ b/linter/src/rules/prefer_identity.rs @@ -61,7 +61,7 @@ mod test_rules { } #[test] - fn test_prefer_identity_bad() { + fn prefer_identity_bad() { let bad_sql = r" create table users ( id serial @@ -102,7 +102,7 @@ create table users ( assert_debug_snapshot!(res); } #[test] - fn test_prefer_identity_ok() { + fn prefer_identity_ok() { let ok_sql = r" create table users ( id bigint generated by default as identity primary key diff --git a/linter/src/rules/prefer_robust_stmts.rs b/linter/src/rules/prefer_robust_stmts.rs index c8dcc5c4..7a92564b 100644 --- a/linter/src/rules/prefer_robust_stmts.rs +++ b/linter/src/rules/prefer_robust_stmts.rs @@ -203,7 +203,7 @@ ALTER TABLE "app_email" ADD CONSTRAINT "email_uniq" UNIQUE USING INDEX "email_id /// If the statement is in a transaction, or it has a guard like IF NOT /// EXISTS, then it is considered valid by the `prefer-robust-stmt` rule. #[test] - fn test_prefer_robust_stmt_okay_cases() { + fn prefer_robust_stmt_okay_cases() { let sql = r#" BEGIN; ALTER TABLE "core_foo" ADD COLUMN "answer_id" integer NULL; @@ -270,7 +270,7 @@ ALTER TABLE "core_foo" DROP CONSTRAINT IF EXISTS "core_foo_idx"; /// If the statement is in a transaction, or it has a guard like IF NOT /// EXISTS, then it is considered valid by the `prefer-robust-stmt` rule. #[test] - fn test_prefer_robust_stmt_okay_cases_with_assume_in_transaction() { + fn prefer_robust_stmt_okay_cases_with_assume_in_transaction() { let sql = r#" ALTER TABLE "core_foo" ADD COLUMN "answer_id" integer NULL; "#; @@ -293,7 +293,7 @@ DROP TYPE foo; } #[test] - fn test_create_index_concurrently_unnamed() { + fn create_index_concurrently_unnamed() { let bad_sql = r#" CREATE INDEX CONCURRENTLY ON "table_name" ("field_name"); "#; @@ -341,7 +341,7 @@ ALTER TABLE IF EXISTS test DISABLE ROW LEVEL SECURITY; } #[test] - fn test_ignore_single_stmts() { + fn ignore_single_stmts() { let bad_sql = r#" CREATE INDEX CONCURRENTLY ON "table_name" ("field_name"); "#; @@ -369,7 +369,7 @@ ALTER TABLE IF EXISTS test DISABLE ROW LEVEL SECURITY; } #[test] - fn test_start_transaction() { + fn start_transaction() { let sql = r#" START TRANSACTION; @@ -386,7 +386,7 @@ COMMIT;"#; } #[test] - fn test_prefer_robust_stmt_failure_cases() { + fn prefer_robust_stmt_failure_cases() { let sql = r#" ALTER TABLE "core_foo" ADD COLUMN "answer_id" integer NULL; "#; diff --git a/linter/src/rules/prefer_text_field.rs b/linter/src/rules/prefer_text_field.rs index 1bae329c..570c1930 100644 --- a/linter/src/rules/prefer_text_field.rs +++ b/linter/src/rules/prefer_text_field.rs @@ -54,7 +54,7 @@ mod test_rules { /// Changing a column of varchar(255) to varchar(1000) requires an ACCESS /// EXCLUSIVE lock #[test] - fn test_increasing_varchar_size() { + fn increasing_varchar_size() { let sql = r#" BEGIN; -- @@ -85,7 +85,7 @@ COMMIT; } #[test] - fn test_prefer_text_field() { + fn prefer_text_field() { let bad_sql = r#" BEGIN; -- @@ -135,7 +135,7 @@ COMMIT;"#; } #[test] - fn test_adding_column_non_text() { + fn adding_column_non_text() { let bad_sql = r#" BEGIN; ALTER TABLE "foo_table" ADD COLUMN "foo_column" varchar(256) NULL; diff --git a/linter/src/rules/prefer_timestamptz.rs b/linter/src/rules/prefer_timestamptz.rs index f1309339..5686c6fd 100644 --- a/linter/src/rules/prefer_timestamptz.rs +++ b/linter/src/rules/prefer_timestamptz.rs @@ -46,7 +46,7 @@ mod test_rules { } #[test] - fn test_create_with_timestamp() { + fn create_with_timestamp() { let bad_sql = r" create table app.users ( @@ -80,7 +80,7 @@ create table app.accounts } #[test] - fn test_alter_table() { + fn alter_table() { let bad_sql = r" alter table app.users alter column created_ts type timestamp; diff --git a/linter/src/rules/renaming_column.rs b/linter/src/rules/renaming_column.rs index 46769c6f..c8812ce7 100644 --- a/linter/src/rules/renaming_column.rs +++ b/linter/src/rules/renaming_column.rs @@ -43,7 +43,7 @@ mod test_rules { } #[test] - fn test_renaming_column() { + fn renaming_column() { let sql = r#" ALTER TABLE "table_name" RENAME COLUMN "column_name" TO "new_column_name"; "#; diff --git a/linter/src/rules/renaming_table.rs b/linter/src/rules/renaming_table.rs index a4e9921d..3456f1f9 100644 --- a/linter/src/rules/renaming_table.rs +++ b/linter/src/rules/renaming_table.rs @@ -43,7 +43,7 @@ mod test_rules { } #[test] - fn test_renaming_table() { + fn renaming_table() { let sql = r#" ALTER TABLE "table_name" RENAME TO "new_table_name"; "#; diff --git a/linter/src/rules/require_concurrent_index_creation.rs b/linter/src/rules/require_concurrent_index_creation.rs index 474082c3..150e9672 100644 --- a/linter/src/rules/require_concurrent_index_creation.rs +++ b/linter/src/rules/require_concurrent_index_creation.rs @@ -61,7 +61,7 @@ mod test_rules { } #[test] - fn test_ensure_ignored_when_new_table() { + fn ensure_ignored_when_new_table() { let sql = r#" BEGIN; CREATE TABLE "core_foo" ( @@ -76,7 +76,7 @@ COMMIT; } #[test] - fn test_ensure_ignored_when_new_table_with_assume_in_transaction() { + fn ensure_ignored_when_new_table_with_assume_in_transaction() { let sql = r#" CREATE TABLE "core_foo" ( "id" serial NOT NULL PRIMARY KEY, @@ -95,7 +95,7 @@ CREATE INDEX "core_foo_tenant_id_4d397ef9" ON "core_foo" ("tenant_id"); /// CREATE INDEX CONCURRENTLY "field_name_idx" ON "table_name" ("field_name"); /// ``` #[test] - fn test_adding_index_non_concurrently() { + fn adding_index_non_concurrently() { let bad_sql = r#" -- instead of CREATE INDEX "field_name_idx" ON "table_name" ("field_name"); diff --git a/linter/src/rules/require_concurrent_index_deletion.rs b/linter/src/rules/require_concurrent_index_deletion.rs index 76be97a1..b964b539 100644 --- a/linter/src/rules/require_concurrent_index_deletion.rs +++ b/linter/src/rules/require_concurrent_index_deletion.rs @@ -44,7 +44,7 @@ mod test_rules { } #[test] - fn test_drop_index_concurrently() { + fn drop_index_concurrently() { let bad_sql = r#" -- instead of DROP INDEX IF EXISTS "field_name_idx"; diff --git a/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable.snap b/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable.snap index 19bfc769..c832477c 100644 --- a/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable.snap +++ b/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable.snap @@ -1,5 +1,5 @@ --- source: linter/src/rules/adding_not_null_field.rs -expression: "lint_sql(bad_sql, None)" +expression: "lint_sql(ok_sql, None)" --- [] diff --git a/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable_in_version_11.snap b/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable_in_version_11.snap index 08b76ab3..c2b259d9 100644 --- a/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable_in_version_11.snap +++ b/linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test_rules__adding_field_that_is_not_nullable_in_version_11.snap @@ -1,5 +1,5 @@ --- source: linter/src/rules/adding_not_null_field.rs -expression: "lint_sql(ok_sql, Some(Version::from_str(\"11.0.0\").unwrap()))" +expression: "lint_sql(ok_sql, Some(Version::from_str(\"11.0.0\").unwrap()),)" --- [] diff --git a/linter/src/rules/snapshots/squawk_linter__rules__adding_primary_key_constraint__test_rules__plain_primary_key-2.snap b/linter/src/rules/snapshots/squawk_linter__rules__adding_primary_key_constraint__test_rules__plain_primary_key-2.snap index a1b5fc8a..e4a99056 100644 --- a/linter/src/rules/snapshots/squawk_linter__rules__adding_primary_key_constraint__test_rules__plain_primary_key-2.snap +++ b/linter/src/rules/snapshots/squawk_linter__rules__adding_primary_key_constraint__test_rules__plain_primary_key-2.snap @@ -1,5 +1,5 @@ --- source: linter/src/rules/adding_primary_key_constraint.rs -expression: lint_sql(ok_sql) +expression: "lint_sql(ok_sql,)" --- [] diff --git a/linter/src/rules/snapshots/squawk_linter__rules__ban_char_field__test_rules__regression_with_indexing_2.snap b/linter/src/rules/snapshots/squawk_linter__rules__ban_char_field__test_rules__regression_with_indexing_2.snap deleted file mode 100644 index 2cc2d49c..00000000 --- a/linter/src/rules/snapshots/squawk_linter__rules__ban_char_field__test_rules__regression_with_indexing_2.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: linter/src/rules/ban_char_field.rs -expression: lint_sql(sql) ---- -[] diff --git a/linter/src/rules/snapshots/squawk_linter__rules__ban_concurrent_index_creation_in_transaction__test_rules__adding_index_concurrently_in_transaction_with_assume_in_transaction_but_outside.snap b/linter/src/rules/snapshots/squawk_linter__rules__ban_concurrent_index_creation_in_transaction__test_rules__adding_index_concurrently_in_transaction_with_assume_in_transaction_but_outside.snap index 7b120670..ae384db7 100644 --- a/linter/src/rules/snapshots/squawk_linter__rules__ban_concurrent_index_creation_in_transaction__test_rules__adding_index_concurrently_in_transaction_with_assume_in_transaction_but_outside.snap +++ b/linter/src/rules/snapshots/squawk_linter__rules__ban_concurrent_index_creation_in_transaction__test_rules__adding_index_concurrently_in_transaction_with_assume_in_transaction_but_outside.snap @@ -1,6 +1,5 @@ --- source: linter/src/rules/ban_concurrent_index_creation_in_transaction.rs expression: lint_sql_assuming_in_transaction(ok_sql) - --- [] diff --git a/linter/src/rules/snapshots/squawk_linter__rules__ban_drop_table__test_rules__ban_drop_table.snap b/linter/src/rules/snapshots/squawk_linter__rules__ban_drop_table__test_rules__ban_drop_table.snap index 53e9ea14..214dfed6 100644 --- a/linter/src/rules/snapshots/squawk_linter__rules__ban_drop_table__test_rules__ban_drop_table.snap +++ b/linter/src/rules/snapshots/squawk_linter__rules__ban_drop_table__test_rules__ban_drop_table.snap @@ -1,7 +1,6 @@ --- source: linter/src/rules/ban_drop_table.rs expression: lint_sql(sql) - --- [ RuleViolation { diff --git a/linter/src/rules/transaction_nesting.rs b/linter/src/rules/transaction_nesting.rs index 3b1d5aec..2851bff8 100644 --- a/linter/src/rules/transaction_nesting.rs +++ b/linter/src/rules/transaction_nesting.rs @@ -94,7 +94,7 @@ mod test_rules { } #[test] - fn test_no_nesting() { + fn no_nesting() { let ok_sql = r" BEGIN; SELECT 1; @@ -104,7 +104,7 @@ COMMIT; } #[test] - fn test_no_nesting_repeated() { + fn no_nesting_repeated() { let ok_sql = r" BEGIN; SELECT 1; @@ -119,7 +119,7 @@ COMMIT; } #[test] - fn test_no_nesting_with_assume_in_transaction() { + fn no_nesting_with_assume_in_transaction() { let ok_sql = r" SELECT 1; "; @@ -127,7 +127,7 @@ SELECT 1; } #[test] - fn test_begin_repeated() { + fn begin_repeated() { let bad_sql = r" BEGIN; BEGIN; @@ -138,7 +138,7 @@ COMMIT; } #[test] - fn test_begin_with_assume_in_transaction() { + fn begin_with_assume_in_transaction() { let bad_sql = r" BEGIN; SELECT 1; @@ -147,7 +147,7 @@ SELECT 1; } #[test] - fn test_commit_repeated() { + fn commit_repeated() { let bad_sql = r" BEGIN; SELECT 1; @@ -158,7 +158,7 @@ COMMIT; } #[test] - fn test_commit_with_assume_in_transaction() { + fn commit_with_assume_in_transaction() { let bad_sql = r" SELECT 1; COMMIT; @@ -167,7 +167,7 @@ COMMIT; } #[test] - fn test_rollback_with_assume_in_transaction() { + fn rollback_with_assume_in_transaction() { let bad_sql = r" SELECT 1; -- Not sure why rollback would be used in a migration, but test for completeness diff --git a/linter/src/versions.rs b/linter/src/versions.rs index 9a81456f..2e3b1c35 100644 --- a/linter/src/versions.rs +++ b/linter/src/versions.rs @@ -114,11 +114,11 @@ mod test_pg_version { use super::*; #[test] - fn test_eq() { + fn eq() { assert_eq!(Version::new(10, None, None), Version::new(10, None, None)); } #[test] - fn test_gt() { + fn gt() { assert!(Version::new(10, Some(1), None) > Version::new(10, None, None)); assert!(Version::new(10, None, Some(1)) > Version::new(10, None, None)); assert!(Version::new(10, None, Some(1)) > Version::new(9, None, None)); @@ -126,7 +126,7 @@ mod test_pg_version { assert!(!(Version::new(10, None, None) > Version::new(10, None, None))); } #[test] - fn test_parse() { + fn parse() { assert_eq!( Version::from_str("10.1"), Ok(Version::new(10, Some(1), None)) diff --git a/parser/src/parse.rs b/parser/src/parse.rs index 9a624a2a..fc620c5a 100644 --- a/parser/src/parse.rs +++ b/parser/src/parse.rs @@ -60,14 +60,14 @@ mod tests { use insta::assert_debug_snapshot; #[test] - fn test_parse_sql_query_json() { + fn parse_sql_query_json_works() { let sql = r"ALTER TABLE table_c ADD column c boolean GENERATED ALWAYS AS (p IS NOT NULL) STORED NOT NULL;"; let res = parse_sql_query_json(sql); assert_debug_snapshot!(res); } #[test] - fn test_span_with_indent() { + fn span_with_indent() { // NOTE: the span information for these starts at 0 even though the SQL // is offset. let sql = r" SELECT 1;"; @@ -75,7 +75,7 @@ mod tests { assert_debug_snapshot!(res); } #[test] - fn test_span_with_new_line_and_indent() { + fn span_with_new_line_and_indent() { let sql = r" SELECT 1;"; let res = parse_sql_query(sql); @@ -83,7 +83,7 @@ mod tests { } #[test] - fn test_adding_index_non_concurrently() { + fn adding_index_non_concurrently() { let sql = r#" -- instead of CREATE INDEX "field_name_idx" ON "table_name" ("field_name"); @@ -105,14 +105,14 @@ mod tests { } #[test] - fn test_error_paths() { + fn error_paths() { let sql = r"lsakdjf;asdlfkjasd;lfj"; let res = parse_sql_query(sql).unwrap_err(); assert_debug_snapshot!(res); } #[test] - fn test_migration() { + fn migration() { let sql = r#" BEGIN; CREATE INDEX "table_name_field_name_idx" ON "table_name" ("field_name"); @@ -124,41 +124,41 @@ COMMIT; } #[test] - fn test_select_string_literal() { + fn select_string_literal() { let sql = r"SELECT 'some string';"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_select_one() { + fn select_one() { let sql = r"SELECT 1;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_sql_create_index_concurrently() { + fn parse_sql_create_index_concurrently() { let sql = r#"CREATE INDEX CONCURRENTLY "table_name_idx" ON "table_name" ("table_field");"#; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_insert_stmt() { + fn parsing_insert_stmt() { let sql = r"INSERT INTO table_name VALUES (1, 2, 3);"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_update_stmt() { + fn parsing_update_stmt() { let sql = r"UPDATE table_name SET foo = 'bar' WHERE buzz > 10;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_create_table() { + fn parsing_create_table() { let sql = r#" BEGIN; CREATE TABLE "core_foo" ( @@ -180,7 +180,7 @@ COMMIT; } #[test] - fn test_parsing_create_table_using_like() { + fn parsing_create_table_using_like() { let sql = r"CREATE TABLE core_bar (LIKE core_foo INCLUDING DEFAULTS INCLUDING CONSTRAINTS);"; let res = parse_sql_query(sql); @@ -188,13 +188,13 @@ COMMIT; } #[test] - fn test_parse_sql_create_index() { + fn parse_sql_create_index() { let sql = r#"CREATE INDEX "table_name_idx" ON "table_name" ("table_field");"#; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_sql_create_unique_index_safe() { + fn parse_sql_create_unique_index_safe() { let sql = r#" ALTER TABLE "legacy_questiongrouppg" ADD CONSTRAINT "legacy_questiongrouppg_mongo_id_1f8f47d9_uniq" UNIQUE @@ -204,21 +204,21 @@ ALTER TABLE "legacy_questiongrouppg" assert_debug_snapshot!(res); } #[test] - fn test_parse_delete_stmt() { + fn parse_delete_stmt() { let sql = r#"DELETE FROM "table_name";"#; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_delete_stmt_2() { + fn parse_delete_stmt_2() { let sql = r#"DELETE FROM "table_name" WHERE account_age > 10;"#; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_set_operations_stmt() { + fn parse_set_operations_stmt() { let sql = r#"SELECT * from "table_name" UNION SELECT * from "table_foo";"#; let res = parse_sql_query(sql).unwrap(); assert_debug_snapshot!(res); @@ -229,133 +229,133 @@ ALTER TABLE "legacy_questiongrouppg" } #[test] - fn test_parse_set_operations_stmt_2() { + fn parse_set_operations_stmt_2() { let sql = r#"SELECT * from "table_name" UNION ALL SELECT * from "table_foo";"#; let res = parse_sql_query(sql).unwrap(); assert_debug_snapshot!(res); } #[test] - fn test_parse_create_schema_stmt() { + fn parse_create_schema_stmt() { let sql = r"CREATE SCHEMA schema_name;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_replica_identity_stmt() { + fn parse_replica_identity_stmt() { let sql = "ALTER TABLE aa REPLICA IDENTITY FULL;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_alter_table_set_list() { + fn parse_alter_table_set_list() { let sql = "ALTER TABLE table_name SET (autovacuum_vacuum_scale_factor = 0.0);"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_alter_collation_stmt() { + fn parse_alter_collation_stmt() { let sql = "ALTER COLLATION name RENAME TO new_name;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parse_alter_domain_stmt() { + fn parse_alter_domain_stmt() { let sql = "ALTER DOMAIN zipcode SET NOT NULL;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_grant_stmt() { + fn parsing_grant_stmt() { let sql = "GRANT INSERT ON films TO PUBLIC;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_grant_role() { + fn parsing_grant_role() { let sql = "GRANT admins TO joe;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_default_privileges_stmt() { + fn alter_default_privileges_stmt() { let sql = "ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_copy_stmt() { + fn parsing_copy_stmt() { let sql = "COPY country FROM '/usr1/proj/bray/sql/country_data';"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_variable_set_stmt() { + fn parsing_variable_set_stmt() { let sql = "set session my.vars.id = '1';"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_variable_show_stmt() { + fn parsing_variable_show_stmt() { let sql = "SHOW name"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_create_table_space_stmt() { + fn parsing_create_table_space_stmt() { let sql = "CREATE TABLESPACE dbspace LOCATION '/data/dbs';"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_parsing_drop_table_space_stmt() { + fn parsing_drop_table_space_stmt() { let sql = "DROP TABLESPACE dbspace;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_table_space_stmt() { + fn alter_table_space_stmt() { let sql = "ALTER TABLESPACE index_space RENAME TO fast_raid;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_create_extension() { + fn create_extension() { let sql = "CREATE EXTENSION hstore;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_table_extension() { + fn alter_table_extension() { let sql = "ALTER EXTENSION hstore UPDATE TO '2.0';"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_drop_extension() { + fn drop_extension() { let sql = "DROP EXTENSION hstore;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_extension_contents_stmt() { + fn alter_extension_contents_stmt() { let sql = "ALTER EXTENSION hstore SET SCHEMA utils;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); @@ -366,35 +366,35 @@ ALTER TABLE "legacy_questiongrouppg" } #[test] - fn test_create_foreign_data_wrapper() { + fn create_foreign_data_wrapper() { let sql = "CREATE FOREIGN DATA WRAPPER dummy;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_foreign_data_wrapper() { + fn alter_foreign_data_wrapper() { let sql = "ALTER FOREIGN DATA WRAPPER dbi OPTIONS (ADD foo '1', DROP 'bar');"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_create_foreign_server_stmt() { + fn create_foreign_server_stmt() { let sql = "CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foo', dbname 'foodb', port '5432');"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_foreign_server_stmt() { + fn alter_foreign_server_stmt() { let sql = "ALTER SERVER foo OPTIONS (host 'foo', dbname 'foodb');"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_create_foriegn_table_stmt() { + fn create_foriegn_table_stmt() { let sql = r" CREATE FOREIGN TABLE films ( code char(5) NOT NULL, @@ -411,28 +411,28 @@ SERVER film_server; } #[test] - fn test_create_user_mapping_stmt() { + fn create_user_mapping_stmt() { let sql = "CREATE USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'secret');"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_user_mapping_stmt() { + fn alter_user_mapping_stmt() { let sql = "ALTER USER MAPPING FOR bob SERVER foo OPTIONS (SET password 'public');"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_drop_user_mapping_stmt() { + fn drop_user_mapping_stmt() { let sql = "DROP USER MAPPING IF EXISTS FOR bob SERVER foo;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_import_foreign_schema_stmt() { + fn import_foreign_schema_stmt() { let sql = r" IMPORT FOREIGN SCHEMA foreign_films FROM SERVER film_server INTO films; @@ -442,14 +442,14 @@ IMPORT FOREIGN SCHEMA foreign_films } #[test] - fn test_create_policy_stmt() { + fn create_policy_stmt() { let sql = "CREATE POLICY name ON table_name FOR ALL;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_alter_policy_stmt() { + fn alter_policy_stmt() { let sql = "ALTER POLICY name ON table_name RENAME TO new_name;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); @@ -460,14 +460,14 @@ IMPORT FOREIGN SCHEMA foreign_films } #[test] - fn test_create_access_method_stmt() { + fn create_access_method_stmt() { let sql = "CREATE ACCESS METHOD heptree TYPE INDEX HANDLER heptree_handler;"; let res = parse_sql_query(sql); assert_debug_snapshot!(res); } #[test] - fn test_create_trigger_stmt() { + fn create_trigger_stmt() { let sql = r" CREATE TRIGGER check_update BEFORE UPDATE ON accounts @@ -479,7 +479,7 @@ CREATE TRIGGER check_update } #[test] - fn test_create_event_trigger_stmt() { + fn create_event_trigger_stmt() { let sql = r" CREATE EVENT TRIGGER abort_ddl ON ddl_command_start EXECUTE PROCEDURE abort_any_command(); @@ -489,7 +489,7 @@ CREATE EVENT TRIGGER abort_ddl ON ddl_command_start } #[test] - fn test_alter_event_trigger_stmt() { + fn alter_event_trigger_stmt() { let sql = r" ALTER EVENT TRIGGER name DISABLE; "; @@ -499,7 +499,7 @@ ALTER EVENT TRIGGER name DISABLE; /// Postgres >=11 feature not supported in libpg_query #[test] - fn test_create_procedure_stmt() { + fn create_procedure_stmt() { let sql = r" CREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL @@ -515,7 +515,7 @@ CALL insert_data(1, 2); } #[test] - fn test_create_function_stmt() { + fn create_function_stmt() { let sql = r" CREATE FUNCTION populate() RETURNS integer AS $$ DECLARE @@ -530,7 +530,7 @@ $$ LANGUAGE plpgsql; } #[test] - fn test_create_plang_stmt() { + fn create_plang_stmt() { let sql = r" CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler @@ -541,7 +541,7 @@ CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql } #[test] - fn test_create_role_stmt() { + fn create_role_stmt() { let sql = r" CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' @@ -552,7 +552,7 @@ CREATE ROLE miriam } #[test] - fn test_alter_role_stmt() { + fn alter_role_stmt() { let sql = r" ALTER ROLE miriam CREATEROLE CREATEDB; "; @@ -561,7 +561,7 @@ ALTER ROLE miriam CREATEROLE CREATEDB; } #[test] - fn test_alter_role_set_stmt() { + fn alter_role_set_stmt() { let sql = r" ALTER ROLE worker_bee SET maintenance_work_mem = 100000; "; @@ -570,7 +570,7 @@ ALTER ROLE worker_bee SET maintenance_work_mem = 100000; } #[test] - fn test_drop_role_set_stmt() { + fn drop_role_set_stmt() { let sql = r" DROP ROLE jonathan; "; @@ -579,7 +579,7 @@ DROP ROLE jonathan; } #[test] - fn test_create_sequence_stmt() { + fn create_sequence_stmt() { let sql = r" CREATE SEQUENCE serial START 101; "; @@ -588,7 +588,7 @@ CREATE SEQUENCE serial START 101; } #[test] - fn test_alter_sequence_stmt() { + fn alter_sequence_stmt() { let sql = r" ALTER SEQUENCE serial RESTART WITH 105; "; @@ -597,7 +597,7 @@ ALTER SEQUENCE serial RESTART WITH 105; } #[test] - fn test_define_stmt() { + fn define_stmt() { let sql = r" CREATE AGGREGATE sum (complex) ( @@ -637,7 +637,7 @@ CREATE TYPE box ( } #[test] - fn test_create_domain_stmt() { + fn create_domain_stmt() { let sql = r" CREATE DOMAIN us_postal_code AS TEXT CHECK( @@ -650,7 +650,7 @@ OR VALUE ~ '^\d{5}-\d{4}$' } #[test] - fn test_create_op_class_stmt() { + fn create_op_class_stmt() { let sql = r" CREATE OPERATOR CLASS gist__int_ops DEFAULT FOR TYPE _int4 USING gist AS @@ -672,7 +672,7 @@ CREATE OPERATOR CLASS gist__int_ops } #[test] - fn test_alter_op_class_stmt() { + fn alter_op_class_stmt() { let sql = r" ALTER OPERATOR CLASS name USING index_method RENAME TO new_name; ALTER OPERATOR CLASS name USING index_method @@ -685,7 +685,7 @@ ALTER OPERATOR CLASS name USING index_method } #[test] - fn test_alter_op_family_stmt() { + fn alter_op_family_stmt() { let sql = r" ALTER OPERATOR FAMILY integer_ops USING btree ADD @@ -710,7 +710,7 @@ ALTER OPERATOR FAMILY integer_ops USING btree ADD } #[test] - fn test_truncate_stmt() { + fn truncate_stmt() { let sql = r" TRUNCATE bigtable, fattable, bar RESTART IDENTITY; TRUNCATE foo CASCADE; @@ -720,7 +720,7 @@ TRUNCATE foo CASCADE; } #[test] - fn test_comment_on_stmt() { + fn comment_on_stmt() { let sql = r" COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance'; "; @@ -729,7 +729,7 @@ COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample varianc } #[test] - fn test_security_label_stmt() { + fn security_label_stmt() { let sql = r" SECURITY LABEL FOR selinux ON TABLE mytable IS 'system_u:object_r:sepgsql_table_t:s0'; "; @@ -738,7 +738,7 @@ SECURITY LABEL FOR selinux ON TABLE mytable IS 'system_u:object_r:sepgsql_table_ } #[test] - fn test_declare_cursor_stmt() { + fn declare_cursor_stmt() { let sql = r" DECLARE curs2 CURSOR FOR SELECT * FROM tenk1; @@ -748,7 +748,7 @@ DECLARE } #[test] - fn test_close_portal_stmt() { + fn close_portal_stmt() { let sql = r" CLOSE curs1; "; @@ -757,7 +757,7 @@ CLOSE curs1; } #[test] - fn test_fetch_stmt() { + fn fetch_stmt() { let sql = r" FETCH FORWARD 5 FROM foo; "; @@ -766,7 +766,7 @@ FETCH FORWARD 5 FROM foo; } #[test] - fn test_create_stats_stmt() { + fn create_stats_stmt() { let sql = r" CREATE STATISTICS s1 (dependencies) ON a, b FROM t1; "; @@ -775,7 +775,7 @@ CREATE STATISTICS s1 (dependencies) ON a, b FROM t1; } #[test] - fn test_explain_stmt() { + fn explain_stmt() { let sql = r" EXPLAIN ANALYZE SELECT * FROM t1 WHERE (a = 1) AND (b = 0); "; @@ -784,7 +784,7 @@ EXPLAIN ANALYZE SELECT * FROM t1 WHERE (a = 1) AND (b = 0); } #[test] - fn test_alter_function_stmt() { + fn alter_function_stmt() { let sql = r" ALTER FUNCTION sqrt(integer) RENAME TO square_root; ALTER FUNCTION sqrt(integer) OWNER TO joe; @@ -797,7 +797,7 @@ ALTER FUNCTION check_password(text) RESET search_path; } #[test] - fn test_do_stmt() { + fn do_stmt() { let sql = r" DO $$DECLARE r record; BEGIN @@ -813,7 +813,7 @@ END$$; } #[test] - fn test_alter_object_depends_stmt() { + fn alter_object_depends_stmt() { let sql = r" ALTER TRIGGER name ON table_name DEPENDS ON EXTENSION extension_name; @@ -825,7 +825,7 @@ ALTER FUNCTION sqrt(integer) } #[test] - fn test_alter_operator_stmt() { + fn alter_operator_stmt() { let sql = r" ALTER OPERATOR @@ (text, text) OWNER TO joe; ALTER OPERATOR @@ (text, text) SET SCHEMA bar; @@ -836,7 +836,7 @@ ALTER OPERATOR && (_int4, _int4) SET (RESTRICT = _int_contsel, JOIN = _int_contj } #[test] - fn test_rule_stmt() { + fn rule_stmt() { let sql = r#" CREATE RULE "_RETURN" AS ON SELECT TO t1 @@ -850,7 +850,7 @@ CREATE RULE notify_me AS ON UPDATE TO mytable DO ALSO NOTIFY mytable; } #[test] - fn test_notify_stmt() { + fn notify_stmt() { let sql = r" NOTIFY virtual; NOTIFY virtual, 'This is the payload'; @@ -860,7 +860,7 @@ NOTIFY virtual, 'This is the payload'; } #[test] - fn test_listen_stmt() { + fn listen_stmt() { let sql = r" LISTEN virtual; "; @@ -869,7 +869,7 @@ LISTEN virtual; } #[test] - fn test_unlisten_stmt() { + fn unlisten_stmt() { let sql = r" UNLISTEN virtual; "; @@ -878,7 +878,7 @@ UNLISTEN virtual; } #[test] - fn test_composite_type_stmt() { + fn composite_type_stmt() { let sql = r" CREATE TYPE complex AS ( r double precision, @@ -890,7 +890,7 @@ CREATE TYPE complex AS ( } #[test] - fn test_create_enum_stmt() { + fn create_enum_stmt() { let sql = r" CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic'); "; @@ -899,7 +899,7 @@ CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic'); } #[test] - fn test_create_range_stmt() { + fn create_range_stmt() { let sql = r" CREATE TYPE floatrange AS RANGE ( subtype = float8, @@ -911,7 +911,7 @@ CREATE TYPE floatrange AS RANGE ( } #[test] - fn test_alter_enum_stmt() { + fn alter_enum_stmt() { let sql = r" ALTER TYPE colors ADD VALUE 'orange' AFTER 'red'; "; @@ -920,7 +920,7 @@ ALTER TYPE colors ADD VALUE 'orange' AFTER 'red'; } #[test] - fn test_create_view_stmt() { + fn create_view_stmt() { let sql = r" CREATE VIEW vista AS SELECT 'Hello World'; CREATE VIEW comedies AS @@ -933,7 +933,7 @@ CREATE VIEW comedies AS } #[test] - fn test_load_stmt() { + fn load_stmt() { let sql = r" LOAD 'filename'; "; @@ -942,7 +942,7 @@ LOAD 'filename'; } #[test] - fn test_create_database_stmt() { + fn create_database_stmt() { let sql = r" CREATE DATABASE lusiadas; CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; @@ -953,7 +953,7 @@ CREATE DATABASE music ENCODING 'LATIN1' TEMPLATE template0; } #[test] - fn test_alter_database_stmt() { + fn alter_database_stmt() { let sql = r" ALTER DATABASE name RENAME TO new_name; ALTER DATABASE name OWNER TO new_owner; @@ -966,7 +966,7 @@ ALTER DATABASE name RESET ALL; } #[test] - fn test_alter_database_collation() { + fn alter_database_collation() { let sql = r" ALTER DATABASE pipelines REFRESH COLLATION VERSION; "; @@ -975,7 +975,7 @@ ALTER DATABASE pipelines REFRESH COLLATION VERSION; } #[test] - fn test_drop_database_stmt() { + fn drop_database_stmt() { let sql = r" DROP DATABASE name; DROP DATABASE IF EXISTS name; @@ -985,7 +985,7 @@ DROP DATABASE IF EXISTS name; } #[test] - fn test_alter_system_stmt() { + fn alter_system_stmt() { let sql = r" ALTER SYSTEM SET wal_level = hot_standby; ALTER SYSTEM RESET wal_level; @@ -995,7 +995,7 @@ ALTER SYSTEM RESET wal_level; } #[test] - fn test_cluster_stmt() { + fn cluster_stmt() { let sql = r" CLUSTER employees USING employees_ind; CLUSTER employees; @@ -1006,7 +1006,7 @@ CLUSTER; } #[test] - fn test_vacuum_stmt() { + fn vacuum_stmt() { let sql = r" VACUUM (VERBOSE, ANALYZE) foo; "; @@ -1015,7 +1015,7 @@ VACUUM (VERBOSE, ANALYZE) foo; } #[test] - fn test_create_table_as_stmt() { + fn create_table_as_stmt() { let sql = r" CREATE TABLE films2 AS TABLE films; @@ -1025,7 +1025,7 @@ CREATE TABLE films2 AS } #[test] - fn test_refresh_material_view_stmt() { + fn refresh_material_view_stmt() { let sql = r" REFRESH MATERIALIZED VIEW order_summary; REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA; @@ -1035,7 +1035,7 @@ REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA; } #[test] - fn test_checkpoint() { + fn checkpoint() { let sql = r" CHECKPOINT; "; @@ -1044,7 +1044,7 @@ CHECKPOINT; } #[test] - fn test_discard_stmt() { + fn discard_stmt() { let sql = r" DISCARD PLANS; DISCARD SEQUENCES; @@ -1055,7 +1055,7 @@ DISCARD TEMP; } #[test] - fn test_lock_stmt() { + fn lock_stmt() { let sql = r" LOCK TABLE films IN SHARE MODE; LOCK TABLE films IN SHARE ROW EXCLUSIVE MODE; @@ -1065,7 +1065,7 @@ LOCK TABLE films IN SHARE ROW EXCLUSIVE MODE; } #[test] - fn test_set_constraints() { + fn set_constraints() { let sql = r" SET CONSTRAINTS ALL DEFERRED; SET CONSTRAINTS ALL IMMEDIATE; @@ -1076,7 +1076,7 @@ SET CONSTRAINTS foo IMMEDIATE; } #[test] - fn test_reindex_stmt() { + fn reindex_stmt() { let sql = r" REINDEX INDEX my_index; REINDEX TABLE table_name; @@ -1088,7 +1088,7 @@ REINDEX SYSTEM table_name; } #[test] - fn test_create_conversion_stmt() { + fn create_conversion_stmt() { let sql = r" CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc; "; @@ -1097,7 +1097,7 @@ CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc; } #[test] - fn test_create_cast_stmt() { + fn create_cast_stmt() { let sql = r" CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint) AS ASSIGNMENT; "; @@ -1116,7 +1116,7 @@ CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint) AS ASSIGNMENT; } #[test] - fn test_alter_column_default_with_function() { + fn alter_column_default_with_function() { let sql = r#" ALTER TABLE "table_name" ALTER COLUMN "column_name" SET DEFAULT CURRENT_TIMESTAMP; "#; @@ -1126,7 +1126,7 @@ CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint) AS ASSIGNMENT; } #[test] - fn test_create_transform_stmt() { + fn create_transform_stmt() { let sql = r" CREATE TRANSFORM FOR hstore LANGUAGE plpythonu ( FROM SQL WITH FUNCTION hstore_to_plpython(internal), @@ -1138,7 +1138,7 @@ CREATE TRANSFORM FOR hstore LANGUAGE plpythonu ( } #[test] - fn test_prepare_stmt() { + fn prepare_stmt() { let sql = r" PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO foo VALUES($1, $2, $3, $4); @@ -1148,7 +1148,7 @@ PREPARE fooplan (int, text, bool, numeric) AS } #[test] - fn test_execute_stmt() { + fn execute_stmt() { let sql = r" EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00); "; @@ -1157,7 +1157,7 @@ EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00); } #[test] - fn test_deallocate_stmt() { + fn deallocate_stmt() { let sql = r" DEALLOCATE PREPARE ALL; "; @@ -1166,7 +1166,7 @@ DEALLOCATE PREPARE ALL; } #[test] - fn test_drop_owned_stmt() { + fn drop_owned_stmt() { let sql = r" DROP OWNED BY foo CASCADE; "; @@ -1175,7 +1175,7 @@ DROP OWNED BY foo CASCADE; } #[test] - fn test_reassign_owned_stmt() { + fn reassign_owned_stmt() { let sql = r" REASSIGN OWNED BY old_role TO new_role; "; @@ -1184,7 +1184,7 @@ REASSIGN OWNED BY old_role TO new_role; } #[test] - fn test_alter_ts_dictionary_stmt() { + fn alter_ts_dictionary_stmt() { let sql = r" ALTER TEXT SEARCH DICTIONARY my_dict ( StopWords = newrussian ); "; @@ -1193,7 +1193,7 @@ ALTER TEXT SEARCH DICTIONARY my_dict ( StopWords = newrussian ); } #[test] - fn test_alter_ts_configuration_stmt() { + fn alter_ts_configuration_stmt() { let sql = r" ALTER TEXT SEARCH CONFIGURATION astro_en ADD MAPPING FOR asciiword WITH astrosyn, english_ispell, english_stem; @@ -1203,7 +1203,7 @@ ALTER TEXT SEARCH CONFIGURATION astro_en } #[test] - fn test_create_publication_stmt() { + fn create_publication_stmt() { let sql = r" CREATE PUBLICATION mypublication FOR TABLE users, departments; CREATE PUBLICATION insert_only FOR TABLE mydata @@ -1214,7 +1214,7 @@ CREATE PUBLICATION insert_only FOR TABLE mydata } #[test] - fn test_alter_publication() { + fn alter_publication() { let sql = r" ALTER PUBLICATION noinsert SET (publish = 'update, delete'); ALTER PUBLICATION mypublication ADD TABLE users, departments; @@ -1224,7 +1224,7 @@ ALTER PUBLICATION name RENAME TO new_name assert_debug_snapshot!(res); } #[test] - fn test_parse_func_call() { + fn parse_func_call() { let sql = r" ALTER TABLE foobar ALTER COLUMN value SET DEFAULT TO_JSON(false); "; @@ -1233,7 +1233,7 @@ ALTER TABLE foobar ALTER COLUMN value SET DEFAULT TO_JSON(false); } #[test] - fn test_json_index_operator() { + fn json_index_operator() { let sql = r#" CREATE INDEX CONCURRENTLY IF NOT EXISTS "idx_a_foo_bar" ON "a" ((foo->>'bar')); "#; @@ -1242,7 +1242,7 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS "idx_a_foo_bar" ON "a" ((foo->>'bar')); } #[test] - fn test_create_subscription_stmt() { + fn create_subscription_stmt() { let sql = r" CREATE SUBSCRIPTION mysub CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb' @@ -1253,7 +1253,7 @@ CREATE SUBSCRIPTION mysub } #[test] - fn test_alter_subscription_stmt() { + fn alter_subscription_stmt() { let sql = r" ALTER SUBSCRIPTION mysub SET PUBLICATION insert_only; ALTER SUBSCRIPTION mysub DISABLE; @@ -1263,7 +1263,7 @@ ALTER SUBSCRIPTION mysub DISABLE; } #[test] - fn test_drop_subscription_stmt() { + fn drop_subscription_stmt() { let sql = r" DROP SUBSCRIPTION mysub; "; @@ -1309,7 +1309,7 @@ ALTER TABLE table_c ADD column c boolean GENERATED ALWAYS AS (p IS NOT NULL) STO } #[test] - fn test_parse_create_table_regression() { + fn parse_create_table_regression() { let sql = r" CREATE TABLE example ( a integer, @@ -1323,7 +1323,7 @@ CREATE TABLE example ( } #[test] - fn test_parse_create_table_partition() { + fn parse_create_table_partition() { let sql = r" CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR VALUES FROM ('2006-02-01') TO ('2006-03-01'); @@ -1333,7 +1333,7 @@ CREATE TABLE measurement_y2006m02 PARTITION OF measurement } #[test] - fn test_parse_attach_table_partition() { + fn parse_attach_table_partition() { let sql = r" ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02 FOR VALUES FROM ('2008-02-01') TO ('2008-03-01' ); @@ -1343,7 +1343,7 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02 } #[test] - fn test_parse_detach_table_partition() { + fn parse_detach_table_partition() { let sql = r" ALTER TABLE measurement DETACH PARTITION measurement_y2006m02; @@ -1353,7 +1353,7 @@ ALTER TABLE measurement } #[test] - fn test_drop_index() { + fn drop_index() { let sql = r#" DROP INDEX "email_idx"; DROP INDEX IF EXISTS "email_idx"; diff --git a/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json_works.snap b/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json_works.snap new file mode 100644 index 00000000..60b4810c --- /dev/null +++ b/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json_works.snap @@ -0,0 +1,139 @@ +--- +source: parser/src/parse.rs +expression: res +--- +Ok( + Object({ + "stmts": Array([ + Object({ + "stmt": Object({ + "AlterTableStmt": Object({ + "cmds": Array([ + Object({ + "AlterTableCmd": Object({ + "behavior": String( + "DROP_RESTRICT", + ), + "def": Object({ + "ColumnDef": Object({ + "colname": String( + "c", + ), + "constraints": Array([ + Object({ + "Constraint": Object({ + "contype": String( + "CONSTR_GENERATED", + ), + "generated_when": String( + "a", + ), + "location": Number( + 41, + ), + "raw_expr": Object({ + "NullTest": Object({ + "arg": Object({ + "ColumnRef": Object({ + "fields": Array([ + Object({ + "String": Object({ + "sval": String( + "p", + ), + }), + }), + ]), + "location": Number( + 62, + ), + }), + }), + "location": Number( + 64, + ), + "nulltesttype": String( + "IS_NOT_NULL", + ), + }), + }), + }), + }), + Object({ + "Constraint": Object({ + "contype": String( + "CONSTR_NOTNULL", + ), + "location": Number( + 84, + ), + }), + }), + ]), + "is_local": Bool( + true, + ), + "location": Number( + 31, + ), + "typeName": Object({ + "location": Number( + 33, + ), + "names": Array([ + Object({ + "String": Object({ + "sval": String( + "pg_catalog", + ), + }), + }), + Object({ + "String": Object({ + "sval": String( + "bool", + ), + }), + }), + ]), + "typemod": Number( + -1, + ), + }), + }), + }), + "subtype": String( + "AT_AddColumn", + ), + }), + }), + ]), + "objtype": String( + "OBJECT_TABLE", + ), + "relation": Object({ + "inh": Bool( + true, + ), + "location": Number( + 12, + ), + "relname": String( + "table_c", + ), + "relpersistence": String( + "p", + ), + }), + }), + }), + "stmt_len": Number( + 92, + ), + }), + ]), + "version": Number( + 160001, + ), + }), +) diff --git a/templates/new_rule.rs.template b/templates/new_rule.rs.template index 8d895f29..c57797dd 100644 --- a/templates/new_rule.rs.template +++ b/templates/new_rule.rs.template @@ -27,7 +27,7 @@ mod test_rules { } #[test] - fn test_{{RuleNameSnake}}() { + fn {{RuleNameSnake}}_works() { let ok_sql = r#" SELECT 1; "#;