-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstring-tests.ark
More file actions
109 lines (91 loc) · 4.64 KB
/
string-tests.ark
File metadata and controls
109 lines (91 loc) · 4.64 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(import std.String)
(import std.Testing)
(test:suite string {
(test:eq (builtin__string:find "abcd" "a") (string:find "abcd" "a"))
(test:eq (builtin__string:find "abcd" "e") (string:find "abcd" "e"))
(test:eq (builtin__string:find "aaacd" "a" 1) (string:findAfter "aaacd" "a" 1))
(test:eq (builtin__string:removeAt "abcd" 1) (string:removeAt "abcd" 1))
(test:eq (builtin__string:setAt "abcd" 1 "z") (string:setAt "abcd" 1 "z"))
(test:expect (string:contains? "hello, world" "h"))
(test:expect (string:contains? "hello, world" "hello"))
(test:expect (string:contains? "hello, world" "world"))
(test:expect (string:contains? "hello, world" ","))
(test:expect (not (string:contains? "hello, world" "!")))
(test:expect (string:containsAnyOf? "Hello, world" ["world" "one"]))
(test:expect (string:containsAnyOf? "Hello, world" string:punctuation))
(test:expect (not (string:containsAnyOf? "Hello, world" [])))
(test:expect (not (string:containsAnyOf? "Hello, world" ["nice" "cool"])))
(test:eq (string:emptyOrWhitespace? "") true)
(test:eq (string:emptyOrWhitespace? " ") true)
(test:eq (string:emptyOrWhitespace? " ") true)
(test:eq (string:emptyOrWhitespace? "\t") true)
(test:eq (string:emptyOrWhitespace? "\n") true)
(test:eq (string:emptyOrWhitespace? "\r") true)
(test:eq (string:emptyOrWhitespace? " \t\r\n") true)
(test:eq (string:emptyOrWhitespace? " \t a") false)
(test:eq (string:emptyOrWhitespace? "a") false)
(test:eq (string:emptyOrWhitespace? "a ") false)
(test:eq (string:emptyOrWhitespace? " a ") false)
(test:eq (builtin__string:ord "a") (string:ord "a"))
(test:eq (builtin__string:chr 65) (string:chr 65))
(test:eq 3 (string:count "the three truths" "th"))
(test:eq 0 (string:count "the three truths" "thz"))
(test:eq 2 (string:count "ababababab" "abab"))
(test:eq "abcdefghijklmnopqrstuvwxyz" (string:toLower "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(test:eq "abcdefghijklmnopqrstuvwxyz" (string:toLower "abcdefghijklmnopqrstuvwxyz"))
(test:eq "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (string:toUpper "abcdefghijklmnopqrstuvwxyz"))
(test:eq "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (string:toUpper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(test:eq "hello world" (string:reverse "dlrow olleh"))
(test:eq "" (string:reverse ""))
(test:eq "a" (string:reverse "a"))
(test:eq "" (string:repeat "" 5))
(test:eq "a" (string:repeat "a" 1))
(test:eq "aaaaa" (string:repeat "a" 5))
(test:eq "hello" (string:slice "hello world" 0 5))
(test:eq "hello world" (string:slice "hello world" 0 100))
(test:eq "h" (string:slice "hello world" 0 1))
(test:eq "ello" (string:slice "hello world" 1 4))
(test:eq ["a" "bc" "def"] (string:split "a,bc,def" ","))
(test:eq ["a" "bc" "def"] (string:split "a-;-bc-;-def" "-;-"))
(test:eq ["abcdef"] (string:split "abcdef" ";;;;"))
(test:eq ["a"] (string:split "a" ","))
(test:eq [""] (string:split "" ","))
(test:eq "hello world" (string:replace "hello world" "coucou" "not"))
(test:eq "not world" (string:replace "hello world" "hello" "not"))
(test:eq "not not " (string:replace "hello hello " "hello" "not"))
(test:eq "hello worldworldABC" (string:replace "hello worldABC" "ABC" "worldABC"))
(test:eq "hello;3.14;true;world" (string:join ["hello" 3.14 true "world"] ";"))
(test:eq "hello" (string:join ["hello"] ";"))
(test:eq "" (string:join [] ";;"))
(test:eq "abc" (string:lstrip "abc"))
(test:eq "abc" (string:lstrip " \t\n\rabc"))
(test:eq "abc \t\n\r" (string:lstrip "abc \t\n\r"))
(test:eq "" (string:lstrip ""))
(test:eq "" (string:lstrip " \t\n\r"))
(test:eq "abc" (string:rstrip "abc"))
(test:eq "abc" (string:rstrip "abc \t\n\r"))
(test:eq " \t\n\rabc" (string:rstrip " \t\n\rabc"))
(test:eq "" (string:rstrip ""))
(test:eq "" (string:rstrip " \t\n\r"))
(test:eq "abc" (string:strip "\t\n\r abc \t\n\r"))
(test:eq "" (string:strip "\t\n\r "))
(test:eq "abc" (string:strip "abc"))
(test:eq "" (string:strip ""))
(test:eq "abc" (string:strip " \t\n\rabc"))
(test:eq "abc" (string:strip "abc \t\n\r"))
(test:eq "" (string:stripMargin ""))
(test:eq " hello" (string:stripMargin " hello"))
(test:eq "hello" (string:stripMargin " |hello"))
(test:eq "hello\nabc"
(string:stripMargin " |hello
|abc"))
(test:eq "hello\nabc\nd"
(string:stripMargin "hello
|abc
|d"))
(test:eq "hello\n\nabc\nd"
(string:stripMargin "hello
|
|abc
|d"))
})