forked from pixie-lang/pixie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-strings.pxi
More file actions
126 lines (103 loc) · 3.89 KB
/
Copy pathtest-strings.pxi
File metadata and controls
126 lines (103 loc) · 3.89 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(ns pixie.test.test-strings
(require pixie.test :as t)
(require pixie.string :as s))
(t/deftest test-starts-with
(let [s "heyhohuh"]
(t/assert= (s/starts-with s "") true)
(t/assert= (s/starts-with s "hey") true)
(t/assert= (s/starts-with s "heyho") true)
(t/assert= (s/starts-with s s) true)
(t/assert= (s/starts-with s "ho") false)
(t/assert= (s/starts-with s "foo") false)))
(t/deftest test-ends-with
(let [s "heyhohuh"]
(t/assert= (s/ends-with s "") true)
(t/assert= (s/ends-with s "huh") true)
(t/assert= (s/ends-with s "hohuh") true)
(t/assert= (s/ends-with s s) true)
(t/assert= (s/ends-with s "hey") false)
(t/assert= (s/ends-with s "foo") false)))
(t/deftest test-split
(let [s "hey,ho,huh"]
(t/assert= (s/split s ",") ["hey" "ho" "huh"])
(t/assert= (s/split s "h") ["" "ey," "o," "u" ""])))
(t/deftest test-index-of
(let [s "heyhohuh"]
(t/assert= (s/index-of s "hey") 0)
(t/assert= (s/index-of s "ho") 3)
(t/assert= (s/index-of s "foo") -1)
(t/assert= (s/index-of s "h" 2) 3)
(t/assert= (s/index-of s "h" 4) 5)
(t/assert= (s/index-of s "hey" 0) 0)
(t/assert= (s/index-of s "hey" 1) -1)
(t/assert= (s/index-of s "h" 0 0) -1)
(t/assert= (s/index-of s "h" 1 2) -1)))
(t/deftest test-substring
(let [s "heyhohuh"]
(t/assert= (s/substring s 0) s)
(t/assert= (s/substring s 3) (s/substring s 3 (count s)))
(t/assert= (s/substring s 0 0) "")
(t/assert= (s/substring s 0 3) "hey")
(t/assert= (s/substring s 3 5) "ho")
(t/assert= (s/substring s 5 8) "huh")
(t/assert= (s/substring s 3 10000) "hohuh")))
(t/deftest test-upper-case
(t/assert= (s/lower-case "") "")
(t/assert= (s/upper-case "hey") "HEY")
(t/assert= (s/upper-case "hEy") "HEY")
(t/assert= (s/upper-case "HEY") "HEY")
(t/assert= (s/upper-case "hey?!") "HEY?!"))
(t/deftest test-lower-case
(t/assert= (s/lower-case "") "")
(t/assert= (s/lower-case "hey") "hey")
(t/assert= (s/lower-case "hEy") "hey")
(t/assert= (s/lower-case "HEY") "hey")
(t/assert= (s/lower-case "HEY?!") "hey?!"))
(t/deftest test-capitalize
(t/assert= (s/capitalize "timothy") "Timothy")
(t/assert= (s/capitalize "Timothy") "Timothy"))
(t/deftest test-trim
(t/assert= (s/trim "") "")
(t/assert= (s/trim " ") "")
(t/assert= (s/trim " hey ") "hey")
(t/assert= (s/trim " h ey ") "h ey"))
(t/deftest test-triml
(t/assert= (s/triml "") "")
(t/assert= (s/triml " ") "")
(t/assert= (s/triml " hey") "hey")
(t/assert= (s/triml " hey ") "hey ")
(t/assert= (s/triml " h ey ") "h ey "))
(t/deftest test-trimr
(t/assert= (s/trimr "") "")
(t/assert= (s/trimr " ") "")
(t/assert= (s/trimr "hey ") "hey")
(t/assert= (s/trimr " hey ") " hey")
(t/assert= (s/trimr " h ey ") " h ey"))
(t/deftest test-replace
(t/assert= (s/replace "hey,you,there" "," ", ") "hey, you, there")
(t/assert= (s/replace "hey,you,there" "," "") "heyyouthere")
(t/assert= (s/replace "&&&" "&" "&&") "&&&&&&")
(t/assert= (s/replace "oops" "" "WAT") "WAToWAToWATpWATsWAT"))
(t/deftest test-replace-first
(t/assert= (s/replace-first "hey,you,there" "," ", ") "hey, you,there")
(t/assert= (s/replace-first "hey,you,there" "," "") "heyyou,there")
(t/assert= (s/replace-first "&&&" "&" "&&") "&&&&")
(t/assert= (s/replace-first "oops" "" "WAT") "WAToops"))
(t/deftest test-join
(t/assert= (s/join []) "")
(t/assert= (s/join [1]) "1")
(t/assert= (s/join [1 2 3]) "123")
(t/assert= (s/join ", " []) "")
(t/assert= (s/join ", " [1]) "1")
(t/assert= (s/join ", " [1 2 3]) "1, 2, 3"))
(t/deftest test-char-literals
(let [s "hey"]
(t/assert= (nth s 0) \h)
(t/assert= (nth s 0) \o150)
(t/assert= (nth s 0) \u0068)
(t/assert= (nth s 1) \e)
(t/assert= (nth s 1) \o145)
(t/assert= (nth s 1) \u0065)
(t/assert= (nth s 2) \y)
(t/assert= (nth s 2) \o171)
(t/assert= (nth s 2) \u0079)))