-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_test.sh
executable file
·39 lines (30 loc) · 1.07 KB
/
string_test.sh
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
#!/usr/bin/env import
set -euo pipefail
import "[email protected]"
source "./string.sh"
# string_lower
assert_equal "$(echo AaBbCc123 | string_lower)" "aabbcc123"
# string_upper
assert_equal "$(echo AaBbCc123 | string_upper)" "AABBCC123"
# string_sub
assert_equal "$(echo aabbcc | string_sub b d)" "aadbcc"
assert_equal "$(echo aabbcc | string_sub b '/')" "aa/bcc"
# string_gsub
assert_equal "$(echo aabbcc | string_gsub b '/')" "aa//cc"
# string_includes
assert_exit 0 string_includes "abc" "a"
assert_exit 0 string_includes "abc" "b"
assert_exit 0 string_includes "abc" "ab"
assert_exit 0 string_includes "abc" "bc"
assert_exit 1 string_includes "abc" "d"
# string_starts_with
assert_exit 0 string_starts_with "abc" "a"
assert_exit 1 string_starts_with "abc" "b"
assert_exit 0 string_starts_with "/home/me/foo.txt" "/home/me"
assert_exit 1 string_starts_with "/root/foo.txt" "/home/me"
# string_ends_with
assert_exit 1 string_ends_with "abc" "a"
assert_exit 1 string_ends_with "abc" "b"
assert_exit 0 string_ends_with "abc" "c"
assert_exit 0 string_ends_with "abc" "bc"
echo "Tests passed!"