aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclyhtsuriva <aimeric@adjutor.xyz>2023-06-18 21:29:21 +0200
committerclyhtsuriva <aimeric@adjutor.xyz>2023-06-18 21:29:21 +0200
commit5a3f7ffdc70538b87a78c367b6fba743d11e5a7d (patch)
treef0c536c30d53b89173cc9bf104522b346cf7ff7e
parent138950d31dc04bc310afd994321ebee750a38bdb (diff)
Add a test for convert-filenames
Using BATS (Bash Automated Testing System) for the tests. More to come soon for other scripts
-rwxr-xr-xbin/tests/convert-filenames.bats68
1 files changed, 68 insertions, 0 deletions
diff --git a/bin/tests/convert-filenames.bats b/bin/tests/convert-filenames.bats
new file mode 100755
index 0000000..d8ea465
--- /dev/null
+++ b/bin/tests/convert-filenames.bats
@@ -0,0 +1,68 @@
+#!/usr/bin/env bats
+
+@test "Test if file exists" {
+ run convert-filenames.sh non_existent_file.txt
+
+ [ "$status" -ne 0 ]
+ [ "${lines[0]}" = "File 'non_existent_file.txt' does not exist." ]
+}
+
+@test "Test already correct file name conversion" {
+ og_file='/tmp/already_correct-filename.test'
+ new_name="$og_file"
+
+ touch "$og_file"
+
+ run convert-filenames.sh "$og_file"
+
+ # Verify the file stayed the same
+ [ "$status" -eq 0 ]
+ [ "$output" = "$new_name" ]
+
+ rm "$new_name"
+}
+
+@test "Test file name conversion with brackets and spaces" {
+ og_file='/tmp/file.name-with(brackets]and spaces.test'
+ new_name='/tmp/file.name-with-brackets-and_spaces.test'
+
+ touch "$og_file"
+
+ run convert-filenames.sh "$og_file"
+
+ # Verify the file has been renamed correctly
+ [ "$status" -eq 0 ]
+ [ "$output" = "$new_name" ]
+
+ rm "$new_name"
+}
+###
+@test "Test file name conversion with consecutive occurrences of characters" {
+ og_file='/tmp/filename_-_with--consecutive__occurrences-.test'
+ new_name='/tmp/filename-with-consecutive_occurrences.test'
+
+ touch "$og_file"
+
+ run convert-filenames.sh "$og_file"
+
+ # Verify the file has been renamed correctly
+ [ "$status" -eq 0 ]
+ [ "$output" = "$new_name" ]
+
+ rm "$new_name"
+}
+
+@test "Test file name conversion with leading special characters and uppercases" {
+ og_file='/tmp/@FileName-w-leaDing-char-aNd-Uppercases'
+ new_name='/tmp/filename-w-leading-char-and-uppercases'
+
+ touch "$og_file"
+
+ run convert-filenames.sh "$og_file"
+
+ # Verify the file has been renamed correctly
+ [ "$status" -eq 0 ]
+ [ "$output" = "$new_name" ]
+
+ rm "$new_name"
+}