aboutsummaryrefslogtreecommitdiff
path: root/bin/tests/convert-filenames.bats
blob: d8ea465293cae38d89c1817e755330091014a80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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"
}