1
1
module TestString
2
2
using Compat
3
3
using Compat. Test
4
+ using Compat. Unicode
4
5
using CategoricalArrays
5
6
6
7
@testset " AbstractString operations on values of CategoricalPool{String}" begin
@@ -40,22 +41,35 @@ using CategoricalArrays
40
41
@test sizeof (v1) === 0
41
42
@test sizeof (v2) === 5
42
43
43
- @test nextind (v1, 1 ) === 2
44
+ if VERSION >= v " 0.7.0-DEV.2949"
45
+ @test_throws BoundsError nextind (v1, 1 )
46
+ else
47
+ @test nextind (v1, 1 ) === 2
48
+ end
44
49
@test nextind (v2, 4 ) === 6
45
50
46
51
@test prevind (v1, 1 ) === 0
47
52
@test prevind (v2, 6 ) === 4
48
53
49
- @test endof (v1) === 0
50
- @test endof (v2) === 4
54
+ if VERSION >= v " 0.7.0-DEV.3583"
55
+ @test firstindex (v1) === 1
56
+ @test firstindex (v2) === 1
57
+ end
58
+
59
+ @test lastindex (v1) === 0
60
+ @test lastindex (v2) === 4
51
61
52
62
@test collect (v1) == []
53
63
@test collect (v2) == collect (" café" )
54
64
55
65
@test v2[2 ] === ' a'
56
66
@test v2[4 ] === ' é'
57
67
@test_throws BoundsError v1[1 ]
58
- @test_throws UnicodeError v2[5 ]
68
+ if VERSION >= v " 0.7.0-DEV.2949"
69
+ @test_throws StringIndexError v2[5 ]
70
+ else
71
+ @test_throws UnicodeError v2[5 ]
72
+ end
59
73
60
74
@test codeunit (v2, 2 ) === 0x61
61
75
@test codeunit (v2, 5 ) === 0xa9
@@ -65,9 +79,9 @@ using CategoricalArrays
65
79
@test ascii (v1):: String == " "
66
80
@test_throws ArgumentError ascii (v2)
67
81
68
- @test normalize_string (v1) == " "
69
- @test normalize_string (v2) == " café"
70
- @test normalize_string (v2, :NFKD ) == " café"
82
+ @test Unicode . normalize_string (v1) == " "
83
+ @test Unicode . normalize_string (v2) == " café"
84
+ @test Unicode . normalize_string (v2, :NFKD ) == " café"
71
85
72
86
@test isempty (collect (graphemes (v1)))
73
87
@test collect (graphemes (v2)) == collect (graphemes (" café" ))
@@ -78,11 +92,19 @@ using CategoricalArrays
78
92
@test isvalid (v2, 4 )
79
93
@test ! isvalid (v2, 5 )
80
94
81
- @test_throws BoundsError ind2chr (v1, 0 )
82
- @test ind2chr (v2, 4 ) === 4
95
+ if VERSION >= v " 0.7.0-DEV.2949"
96
+ @test_throws BoundsError length (v1, 0 , 0 )
97
+ @test length (v2, 1 , 4 ) === 4
98
+
99
+ @test_throws BoundsError nextind (v1, 1 , 1 )
100
+ @test nextind (v2, 1 , 2 ) === 3
101
+ else
102
+ @test_throws BoundsError ind2chr (v1, 0 )
103
+ @test ind2chr (v2, 4 ) === 4
83
104
84
- @test_throws BoundsError chr2ind (v1, 1 )
85
- @test chr2ind (v2, 2 ) === 2
105
+ @test_throws BoundsError chr2ind (v1, 1 )
106
+ @test chr2ind (v2, 2 ) === 2
107
+ end
86
108
87
109
@test string (v1) == " "
88
110
@test string (v2) == " café"
@@ -108,20 +130,22 @@ using CategoricalArrays
108
130
@test repeat (v1, 10 ) == " "
109
131
@test repeat (v2, 2 ) == " cafécafé"
110
132
111
- @test ! ismatch (r" fé" , v1)
112
- @test ismatch (r" fé" , v2)
113
-
114
- @test isempty (collect (eachmatch (r" fé" , v1)))
115
- @test first (eachmatch (r" fé" , v2)). offset == 3
133
+ @test isempty (collect (eachmatch (r" af" , v1)))
134
+ @test first (eachmatch (r" af" , v2)). offset == 2
116
135
117
- @test match (r" fé " , v1) === nothing
118
- @test match (r" fé " , v2). offset === 3
119
- @test match (r" fé " , v2, 2 ). offset === 3
120
- @test match (r" fé " , v2, 2 , UInt32 (0 )). offset === 3
136
+ @test match (r" af " , v1) === nothing
137
+ @test match (r" af " , v2). offset === 2
138
+ @test match (r" af " , v2, 2 ). offset === 2
139
+ @test match (r" af " , v2, 2 , UInt32 (0 )). offset === 2
121
140
122
- @test matchall (r" fé" , v1) == []
123
- @test matchall (r" fé" , v2) == [" fé" ]
124
- @test matchall (r" fé" , v2, true ) == [" fé" ]
141
+ @test matchall (r" af" , v1) == []
142
+ @test matchall (r" af" , v2) == [" af" ]
143
+ if VERSION > v " 0.7.0-DEV.3526"
144
+ @test matchall (r" af" , v2, overlap= true ) == [" af" ]
145
+ else
146
+ @test matchall (r" af" , v2, overlap= true ) == [" af" ]
147
+ @test matchall (r" af" , v2, true ) == [" af" ]
148
+ end
125
149
126
150
@test lpad (v1, 1 ) == " "
127
151
@test lpad (v2, 1 ) == " café"
@@ -131,31 +155,23 @@ using CategoricalArrays
131
155
@test rpad (v2, 1 ) == " café"
132
156
@test rpad (v2, 5 ) == " café "
133
157
134
- @test search (v1, " " ) === 1 : 0
135
- @test search (v2, " a" ) === 2 : 2
136
- @test search (v2, ' a' ) === 2
137
- @test search (v2, ' a' , 3 ) === 0
158
+ @test Compat . findfirst ( " " , v1 ) === 1 : 0
159
+ @test Compat . findfirst ( " a" , v2 ) === 2 : 2
160
+ @test Compat . findfirst ( equalto ( ' a' ), v2 ) === 2
161
+ @test Compat . findnext ( equalto ( ' a' ), v2, 3 ) === nothing
138
162
139
- @test searchindex (v1, " " ) === 1
140
- @test searchindex (v2, " a" ) === 2
141
- @test searchindex (v2, ' a' ) === 2
142
- @test searchindex (v2, ' a' , 3 ) === 0
143
-
144
- @test rsearch (v1, " a" ) === 0 : - 1
145
- @test rsearch (v2, " a" ) === 2 : 2
146
- @test rsearch (v2, ' a' ) === 2
147
- @test rsearch (v2, ' a' , 1 ) === 0
148
-
149
- @test rsearchindex (v1, " a" ) === 0
150
- @test rsearchindex (v2, " a" ) === 2
151
- # Methods not defined even for String
152
- # @test rsearchindex(v2, 'a') === 2
153
- # @test rsearchindex(v2, 'a', 1) === 0
163
+ @test Compat. findlast (" a" , v1) === 0 : - 1
164
+ @test Compat. findlast (" a" , v2) === 2 : 2
165
+ @test Compat. findlast (equalto (' a' ), v2) === 2
166
+ @test Compat. findprev (equalto (' a' ), v2, 1 ) === nothing
154
167
155
168
@test ! contains (v1, " a" )
156
169
@test contains (v1, " " )
157
170
@test contains (v2, " fé" )
158
171
172
+ @test ! contains (v1, r" af" )
173
+ @test contains (v2, r" af" )
174
+
159
175
@test startswith (v1, " " )
160
176
@test ! startswith (v1, " a" )
161
177
@test startswith (v2, " caf" )
@@ -167,9 +183,9 @@ using CategoricalArrays
167
183
@test reverse (v1) == " "
168
184
@test reverse (v2) == " éfac"
169
185
170
- @test replace (v1, " a" , " b" ) == " "
171
- @test replace (v2, ' a' , ' b' ) == " cbfé"
172
- @test replace (v2, " ca" , " b" , 1 ) == " bfé"
186
+ @test replace (v1, " a" => " b" ) == " "
187
+ @test replace (v2, ' a' => ' b' ) == " cbfé"
188
+ @test replace (v2, " ca" => " b" , count = 1 ) == " bfé"
173
189
174
190
@test isempty (split (v1))
175
191
@test split (v1, " a" ) == [" " ]
@@ -209,14 +225,16 @@ using CategoricalArrays
209
225
@test join ([v1, " a" ]) == " a"
210
226
@test join ([v1, " a" ], v2) == " caféa"
211
227
212
- @test chop (v1) == " "
228
+ if VERSION >= v " 0.7.0-DEV.3688" # Version known to throw an erro
229
+ @test_throws BoundsError chop (v1) == " "
230
+ end
213
231
@test chop (v2) == " caf"
214
232
215
233
@test chomp (v1) == " "
216
234
@test chomp (v2) == " café"
217
235
218
- @test strwidth (v1) === 0
219
- @test strwidth (v2) === 4
236
+ @test textwidth (v1) === 0
237
+ @test textwidth (v2) === 4
220
238
221
239
@test isascii (v1)
222
240
@test ! isascii (v2)
0 commit comments