-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitchLets.bats
More file actions
executable file
·46 lines (39 loc) · 983 Bytes
/
switchLets.bats
File metadata and controls
executable file
·46 lines (39 loc) · 983 Bytes
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
#!/usr/bin/env bats
#The switchLetters function outputs its argument
#with the first three and the last three characters
#switched. If the number of arguments isn't exactly
#1, it returns a status of 1. Otherwise, it returns
#a status of 1
switchLetters() {
if [ "$#" -ne 1 ]; then
return 1
else
echo "$1" | sed -r 's/(...)(.*)(...)/\3\2\1/'
fi
return 0
}
@test "switchLetters hi there" {
run switchLetters 'hi there'
[ "$output" == "erethhi " ]
[ $status -eq 0 ]
}
@test "switchLetters: goodie" {
run switchLetters 'goodie'
[ "$output" == "diegoo" ]
[ $status -eq 0 ]
}
@test "switchLetters abc 1234f 9 cde" {
run switchLetters 'abc 1234f 9 cde'
[ "$output" == "cde 1234f 9 abc" ]
[ $status -eq 0 ]
}
@test "switchLetters efgh 1234" {
run switchLetters 'efgh 1234'
[ "$output" == "234h 1efg" ]
[ $status -eq 0 ]
}
#test on no arguments; should return 1
@test "switchLetters" {
run switchLetters
[ $status -eq 1 ]
}