From 4e6b73d830a35e40ac2c31b41056f5df308a85fb Mon Sep 17 00:00:00 2001 From: "Shahar \"Dawn\" Or" Date: Tue, 14 Oct 2025 11:40:54 +0700 Subject: [PATCH] chore: 1-expr tests empty-list-concat Co-authored-by: Wes Gray --- bin/tests/data/empty_list_concat.nix | 16 ------- bin/tests/empty_list_concat.rs | 23 +++++++++ bin/tests/main.rs | 48 ------------------- ...636e6d87461d7e091b87b44fb8b5959b31b1a.snap | 9 ++++ ...a2193f00467aabdd6230c1019702fdabe53bb.snap | 5 ++ ...0dbc9e4479628a5b7250418efeb5911e743b2.snap | 9 ++++ ...d62ca22410c59471e767d80ea85a3f7fcc1ef.snap | 9 ++++ ...d5d6851ad340d059d1012ed809a04a21a00a9.snap | 9 ++++ ...636e6d87461d7e091b87b44fb8b5959b31b1a.snap | 11 +++++ ...a2193f00467aabdd6230c1019702fdabe53bb.snap | 5 ++ ...0dbc9e4479628a5b7250418efeb5911e743b2.snap | 18 +++++++ ...d62ca22410c59471e767d80ea85a3f7fcc1ef.snap | 11 +++++ ...d5d6851ad340d059d1012ed809a04a21a00a9.snap | 11 +++++ .../main__empty_list_concat_fix.snap | 27 ----------- .../main__empty_list_concat_lint.snap | 39 --------------- flake-parts/statix.nix | 1 - 16 files changed, 120 insertions(+), 131 deletions(-) delete mode 100644 bin/tests/data/empty_list_concat.nix create mode 100644 bin/tests/empty_list_concat.rs delete mode 100644 bin/tests/main.rs create mode 100644 bin/tests/snapshots/empty_list_concat__fix_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap create mode 100644 bin/tests/snapshots/empty_list_concat__fix_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap create mode 100644 bin/tests/snapshots/empty_list_concat__fix_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap create mode 100644 bin/tests/snapshots/empty_list_concat__fix_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap create mode 100644 bin/tests/snapshots/empty_list_concat__fix_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap create mode 100644 bin/tests/snapshots/empty_list_concat__lint_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap create mode 100644 bin/tests/snapshots/empty_list_concat__lint_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap create mode 100644 bin/tests/snapshots/empty_list_concat__lint_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap create mode 100644 bin/tests/snapshots/empty_list_concat__lint_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap create mode 100644 bin/tests/snapshots/empty_list_concat__lint_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap delete mode 100644 bin/tests/snapshots/main__empty_list_concat_fix.snap delete mode 100644 bin/tests/snapshots/main__empty_list_concat_lint.snap diff --git a/bin/tests/data/empty_list_concat.nix b/bin/tests/data/empty_list_concat.nix deleted file mode 100644 index b71030d..0000000 --- a/bin/tests/data/empty_list_concat.nix +++ /dev/null @@ -1,16 +0,0 @@ -[ - # no match - ([1 2] ++ [3 4]) - - # unnecessary left - ([] ++ [1 2 3]) - - # unnecessary right - ([1 2 3] ++ []) - - # collapses to a single array - ([] ++ []) - - # multiple empties - ([] ++ [] ++ []) -] \ No newline at end of file diff --git a/bin/tests/empty_list_concat.rs b/bin/tests/empty_list_concat.rs new file mode 100644 index 0000000..7913317 --- /dev/null +++ b/bin/tests/empty_list_concat.rs @@ -0,0 +1,23 @@ +mod _utils; + +use macros::generate_tests; + +generate_tests! { + rule: empty_list_concat, + expressions: [ + // no match + "[1 2] ++ [3 4]", + + // unnecessary left + "[] ++ [1 2 3]", + + // unnecessary right + "[1 2 3] ++ []", + + // collapses to a single array + "[] ++ []", + + // multiple empties + "[] ++ [] ++ []", + ], +} diff --git a/bin/tests/main.rs b/bin/tests/main.rs deleted file mode 100644 index 3a06bb1..0000000 --- a/bin/tests/main.rs +++ /dev/null @@ -1,48 +0,0 @@ -mod util { - #[macro_export] - macro_rules! test_lint { - ($tname:ident, $($tail:tt)*) => { - test_lint!($tname); - test_lint!($($tail)*); - }; - ($tname:ident, $($tail:tt)*) => { - test_lint!($tname); - test_lint!($($tail)*); - }; - ($tname:ident) => { - paste::paste! { - #[test] - fn [<$tname _lint>](){ - let file_path = concat!("tests/data/", stringify!($tname), ".nix"); - test_cli(concat!(stringify!($tname), "_lint"), file_path, &["check"]); - } - - #[test] - fn [<$tname _fix>](){ - let file_path = concat!("tests/data/", stringify!($tname), ".nix"); - test_cli(concat!(stringify!($tname), "_fix"), file_path, &["fix", "--dry-run"]); - } - } - - }; - } -} - -fn test_cli(test_name: &str, file_path: &str, args: &[&str]) { - let output = std::process::Command::new("cargo") - .arg("run") - .arg("--") - .args(args) - .arg(file_path) - .output() - .expect("command runs successfully"); - - let stdout = strip_ansi_escapes::strip(output.stdout).unwrap(); - let stdout = String::from_utf8(stdout).unwrap(); - - insta::assert_snapshot!(test_name, &stdout); -} - -test_lint! { - empty_list_concat -} diff --git a/bin/tests/snapshots/empty_list_concat__fix_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap b/bin/tests/snapshots/empty_list_concat__fix_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap new file mode 100644 index 0000000..4988226 --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__fix_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[1 2 3] ++ []\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-[1 2 3] ++ [] ++[1 2 3] diff --git a/bin/tests/snapshots/empty_list_concat__fix_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap b/bin/tests/snapshots/empty_list_concat__fix_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap new file mode 100644 index 0000000..31ecf52 --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__fix_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap @@ -0,0 +1,5 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[1 2] ++ [3 4]\"" +--- + diff --git a/bin/tests/snapshots/empty_list_concat__fix_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap b/bin/tests/snapshots/empty_list_concat__fix_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap new file mode 100644 index 0000000..cd57712 --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__fix_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[] ++ [] ++ []\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-[] ++ [] ++ [] ++[] diff --git a/bin/tests/snapshots/empty_list_concat__fix_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap b/bin/tests/snapshots/empty_list_concat__fix_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap new file mode 100644 index 0000000..a55c3f6 --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__fix_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[] ++ [1 2 3]\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-[] ++ [1 2 3] ++[1 2 3] diff --git a/bin/tests/snapshots/empty_list_concat__fix_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap b/bin/tests/snapshots/empty_list_concat__fix_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap new file mode 100644 index 0000000..7e2813b --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__fix_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[] ++ []\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-[] ++ [] ++[] diff --git a/bin/tests/snapshots/empty_list_concat__lint_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap b/bin/tests/snapshots/empty_list_concat__lint_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap new file mode 100644 index 0000000..67a94ae --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__lint_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[1 2 3] ++ []\"" +--- +[W23] Warning: Unnecessary concatenation with empty list + ╭─[:1:1] + │ + 1 │ [1 2 3] ++ [] + · ──────┬────── + · ╰──────── Concatenation with the empty list, [], is a no-op +───╯ diff --git a/bin/tests/snapshots/empty_list_concat__lint_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap b/bin/tests/snapshots/empty_list_concat__lint_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap new file mode 100644 index 0000000..31ecf52 --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__lint_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap @@ -0,0 +1,5 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[1 2] ++ [3 4]\"" +--- + diff --git a/bin/tests/snapshots/empty_list_concat__lint_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap b/bin/tests/snapshots/empty_list_concat__lint_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap new file mode 100644 index 0000000..64b6704 --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__lint_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap @@ -0,0 +1,18 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[] ++ [] ++ []\"" +--- +[W23] Warning: Unnecessary concatenation with empty list + ╭─[:1:1] + │ + 1 │ [] ++ [] ++ [] + · ───────┬────── + · ╰──────── Concatenation with the empty list, [], is a no-op +───╯ +[W23] Warning: Unnecessary concatenation with empty list + ╭─[:1:7] + │ + 1 │ [] ++ [] ++ [] + · ────┬─── + · ╰───── Concatenation with the empty list, [], is a no-op +───╯ diff --git a/bin/tests/snapshots/empty_list_concat__lint_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap b/bin/tests/snapshots/empty_list_concat__lint_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap new file mode 100644 index 0000000..bf89acc --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__lint_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[] ++ [1 2 3]\"" +--- +[W23] Warning: Unnecessary concatenation with empty list + ╭─[:1:1] + │ + 1 │ [] ++ [1 2 3] + · ──────┬────── + · ╰──────── Concatenation with the empty list, [], is a no-op +───╯ diff --git a/bin/tests/snapshots/empty_list_concat__lint_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap b/bin/tests/snapshots/empty_list_concat__lint_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap new file mode 100644 index 0000000..47457b3 --- /dev/null +++ b/bin/tests/snapshots/empty_list_concat__lint_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/empty_list_concat.rs +expression: "\"[] ++ []\"" +--- +[W23] Warning: Unnecessary concatenation with empty list + ╭─[:1:1] + │ + 1 │ [] ++ [] + · ────┬─── + · ╰───── Concatenation with the empty list, [], is a no-op +───╯ diff --git a/bin/tests/snapshots/main__empty_list_concat_fix.snap b/bin/tests/snapshots/main__empty_list_concat_fix.snap deleted file mode 100644 index 204bbe8..0000000 --- a/bin/tests/snapshots/main__empty_list_concat_fix.snap +++ /dev/null @@ -1,27 +0,0 @@ ---- -source: bin/tests/main.rs -expression: "&stdout" ---- ---- tests/data/empty_list_concat.nix -+++ tests/data/empty_list_concat.nix [fixed] -@@ -2,15 +2,15 @@ - # no match - ([1 2] ++ [3 4]) - - # unnecessary left -- ([] ++ [1 2 3]) -+ [1 2 3] - - # unnecessary right -- ([1 2 3] ++ []) -+ [1 2 3] - - # collapses to a single array -- ([] ++ []) -+ [] - - # multiple empties -- ([] ++ [] ++ []) -+ [] - ] -\ No newline at end of file diff --git a/bin/tests/snapshots/main__empty_list_concat_lint.snap b/bin/tests/snapshots/main__empty_list_concat_lint.snap deleted file mode 100644 index 6b8667a..0000000 --- a/bin/tests/snapshots/main__empty_list_concat_lint.snap +++ /dev/null @@ -1,39 +0,0 @@ ---- -source: bin/tests/main.rs -expression: "&stdout" ---- -[W23] Warning: Unnecessary concatenation with empty list - ╭─[tests/data/empty_list_concat.nix:6:4] - │ - 6 │ ([] ++ [1 2 3]) - · ──────┬────── - · ╰──────── Concatenation with the empty list, [], is a no-op -───╯ -[W23] Warning: Unnecessary concatenation with empty list - ╭─[tests/data/empty_list_concat.nix:9:4] - │ - 9 │ ([1 2 3] ++ []) - · ──────┬────── - · ╰──────── Concatenation with the empty list, [], is a no-op -───╯ -[W23] Warning: Unnecessary concatenation with empty list - ╭─[tests/data/empty_list_concat.nix:12:4] - │ - 12 │ ([] ++ []) - · ────┬─── - · ╰───── Concatenation with the empty list, [], is a no-op -────╯ -[W23] Warning: Unnecessary concatenation with empty list - ╭─[tests/data/empty_list_concat.nix:15:4] - │ - 15 │ ([] ++ [] ++ []) - · ───────┬────── - · ╰──────── Concatenation with the empty list, [], is a no-op -────╯ -[W23] Warning: Unnecessary concatenation with empty list - ╭─[tests/data/empty_list_concat.nix:15:10] - │ - 15 │ ([] ++ [] ++ []) - · ────┬─── - · ╰───── Concatenation with the empty list, [], is a no-op -────╯ diff --git a/flake-parts/statix.nix b/flake-parts/statix.nix index 20a7808..624476f 100644 --- a/flake-parts/statix.nix +++ b/flake-parts/statix.nix @@ -24,7 +24,6 @@ ] ) root) (root + "/Cargo.lock") - (root + "/bin/tests/data") ]; }; cargoLock.lockFile = root + "/Cargo.lock"; -- 2.51.2