turkish_support 1.1.3 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +2 -9
- data/lib/turkish_support/constants.rb +32 -50
- data/lib/turkish_support/helpers.rb +12 -35
- data/lib/turkish_support/string_methods.rb +30 -34
- data/lib/turkish_support/version.rb +1 -1
- data/spec/helpers_spec.rb +37 -134
- data/spec/string_spec.rb +101 -282
- data/turkish_support.gemspec +5 -5
- metadata +16 -11
data/spec/string_spec.rb
CHANGED
@@ -5,44 +5,29 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
5
5
|
describe String do
|
6
6
|
let(:downcased_turkish_alphabet) { 'abcçdefgğhıijklmnoöprsştuüvyz' }
|
7
7
|
let(:upcased_turkish_alphabet) { 'ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ' }
|
8
|
-
let(:downcased_english_alphabet) {
|
9
|
-
let(:upcased_english_alphabet) {
|
8
|
+
let(:downcased_english_alphabet) { ('a'..'z').to_a.join }
|
9
|
+
let(:upcased_english_alphabet) { ('A'..'Z').to_a.join }
|
10
10
|
let(:turkish_words) { %w[çamur ıhlamur insan ördek şahika ümraniye] }
|
11
11
|
|
12
12
|
describe '#[]' do
|
13
13
|
context 'with non-destructive version' do
|
14
14
|
it 'does not change the original value of the string' do
|
15
15
|
word = turkish_words.sample
|
16
|
-
|
17
|
-
expect { word[/\w+/] }
|
18
|
-
.to_not change { word }
|
16
|
+
expect { word[/\w+/] }.to_not(change { word })
|
19
17
|
end
|
20
18
|
|
21
19
|
it 'is able to capture Turkish characters' do
|
22
|
-
expect(turkish_words
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
expect(turkish_words
|
27
|
-
.all? { |w| w[/[a-z]+/] == w }
|
28
|
-
).to eq(true)
|
29
|
-
|
30
|
-
expect(turkish_words
|
31
|
-
.map(&:upcase)
|
32
|
-
.all? { |w| w[/[a-z]+/i] == w }
|
33
|
-
).to eq(true)
|
20
|
+
expect(turkish_words.all? { |w| w[/\w+/] == w }).to eq(true)
|
21
|
+
expect(turkish_words.all? { |w| w[/[a-z]+/] == w }).to eq(true)
|
22
|
+
expect(turkish_words.map(&:upcase).all? { |w| w[/[a-z]+/i] == w }).to eq(true)
|
34
23
|
end
|
35
24
|
end
|
36
25
|
|
37
26
|
context 'with destructive version' do
|
38
27
|
it 'changes the original value of the string' do
|
39
28
|
word = turkish_words.sample
|
40
|
-
|
41
|
-
expect
|
42
|
-
.to change { word }
|
43
|
-
|
44
|
-
expect(word)
|
45
|
-
.to eq('new value')
|
29
|
+
expect { word[/\w+/] = 'new value' }.to(change { word })
|
30
|
+
expect(word).to eq('new value')
|
46
31
|
end
|
47
32
|
end
|
48
33
|
end
|
@@ -50,24 +35,13 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
50
35
|
describe '#index' do
|
51
36
|
it 'does not change the original value of the string' do
|
52
37
|
word = turkish_words.sample
|
53
|
-
|
54
|
-
expect { word.index(/\w+/) }
|
55
|
-
.to_not change { word }
|
38
|
+
expect { word.index(/\w+/) }.to_not(change { word })
|
56
39
|
end
|
57
40
|
|
58
41
|
it 'is able to capture Turkish characters' do
|
59
|
-
expect(turkish_words
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
expect(turkish_words
|
64
|
-
.all? { |w| w.index(/[a-z]+/).zero? }
|
65
|
-
).to eq(true)
|
66
|
-
|
67
|
-
expect(turkish_words
|
68
|
-
.map(&:upcase)
|
69
|
-
.all? { |w| w.index(/[a-z]+/i).zero? }
|
70
|
-
).to eq(true)
|
42
|
+
expect(turkish_words.all? { |w| w.index(/\w+/).zero? }).to(eq(true))
|
43
|
+
expect(turkish_words.all? { |w| w.index(/[a-z]+/).zero? }).to eq(true)
|
44
|
+
expect(turkish_words.map(&:upcase).all? { |w| w.index(/[a-z]+/i).zero? }).to eq(true)
|
71
45
|
end
|
72
46
|
|
73
47
|
it 'begins to search from the right position' do
|
@@ -78,25 +52,13 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
78
52
|
describe '#rindex' do
|
79
53
|
it 'does not change the original value of the string' do
|
80
54
|
word = turkish_words.sample
|
81
|
-
expect { word.rindex(/\w+/) }.to_not
|
55
|
+
expect { word.rindex(/\w+/) }.to_not(change { word })
|
82
56
|
end
|
83
57
|
|
84
58
|
it 'is able to capture Turkish characters' do
|
85
|
-
expect(turkish_words
|
86
|
-
|
87
|
-
|
88
|
-
).to eq(true)
|
89
|
-
|
90
|
-
expect(turkish_words
|
91
|
-
.map(&:reverse)
|
92
|
-
.all? { |w| w.rindex(/[a-z]+/) == w.size - 1 }
|
93
|
-
).to eq(true)
|
94
|
-
|
95
|
-
expect(turkish_words
|
96
|
-
.map(&:upcase)
|
97
|
-
.map(&:reverse)
|
98
|
-
.all? { |w| w.rindex(/[a-z]+/i) == w.size - 1 }
|
99
|
-
).to eq(true)
|
59
|
+
expect(turkish_words.map(&:reverse).all? { |w| w.rindex(/\w+/) == w.size - 1 }).to(eq(true))
|
60
|
+
expect(turkish_words.map(&:reverse).all? { |w| w.rindex(/[a-z]+/) == w.size - 1 }).to eq(true)
|
61
|
+
expect(turkish_words.map { |w| w.upcase.reverse }.all? { |w| w.rindex(/[a-z]+/i) == w.size - 1 }).to(eq(true))
|
100
62
|
end
|
101
63
|
|
102
64
|
it 'finishes the searching to the right position' do
|
@@ -110,11 +72,11 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
110
72
|
let(:two_words) { "#{word1} #{word2}" }
|
111
73
|
|
112
74
|
it 'does not change the original value of the string' do
|
113
|
-
expect { two_words.partition(/\W+/) }.to_not
|
75
|
+
expect { two_words.partition(/\W+/) }.to_not(change { two_words })
|
114
76
|
end
|
115
77
|
|
116
78
|
it 'is able to capture Turkish characters' do
|
117
|
-
expect(two_words.partition(/\W+/)).to
|
79
|
+
expect(two_words.partition(/\W+/)).to(eq([word1, ' ', word2]))
|
118
80
|
end
|
119
81
|
end
|
120
82
|
|
@@ -125,12 +87,11 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
125
87
|
let(:three_words) { "#{word1} #{word2} #{word3}" }
|
126
88
|
|
127
89
|
it 'does not change the original value of the string' do
|
128
|
-
expect { three_words.rpartition(/\W+/) }.to_not
|
90
|
+
expect { three_words.rpartition(/\W+/) }.to_not(change { three_words })
|
129
91
|
end
|
130
92
|
|
131
93
|
it 'is able to capture Turkish characters' do
|
132
|
-
expect(three_words.rpartition(/\W+/))
|
133
|
-
.to eq(["#{word1} #{word2}", ' ', word3])
|
94
|
+
expect(three_words.rpartition(/\W+/)).to(eq(["#{word1} #{word2}", ' ', word3]))
|
134
95
|
end
|
135
96
|
end
|
136
97
|
|
@@ -138,90 +99,54 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
138
99
|
context 'with non-destructive version' do
|
139
100
|
it 'does not change the original value of the string' do
|
140
101
|
sentence = turkish_words * ' '
|
141
|
-
expect { sentence.slice(/\w+/) }.to_not
|
102
|
+
expect { sentence.slice(/\w+/) }.to_not(change { sentence })
|
142
103
|
end
|
143
104
|
|
144
105
|
it 'is able to capture Turkish characters' do
|
145
|
-
expect(turkish_words
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
expect(turkish_words
|
150
|
-
.all? { |w| w.slice(/[a-z]+/) == w }
|
151
|
-
).to eq(true)
|
152
|
-
|
153
|
-
expect(turkish_words
|
154
|
-
.map(&:upcase)
|
155
|
-
.all? { |w| w.slice(/[a-z]+/i) == w }
|
156
|
-
).to eq(true)
|
106
|
+
expect(turkish_words.all? { |w| w.slice(/\w+/) == w }).to(eq(true))
|
107
|
+
expect(turkish_words.all? { |w| w.slice(/[a-z]+/) == w }).to eq(true)
|
108
|
+
expect(turkish_words.map(&:upcase).all? { |w| w.slice(/[a-z]+/i) == w }).to eq(true)
|
157
109
|
end
|
158
110
|
end
|
159
111
|
|
160
112
|
context 'with destructive version' do
|
161
113
|
it 'changes the original value of the string' do
|
162
114
|
sentence = turkish_words * ' '
|
163
|
-
|
164
|
-
expect
|
165
|
-
expect(sentence).to eq(' ' + turkish_words[1..-1] * ' ')
|
115
|
+
expect { sentence.slice!(/\w+/) }.to(change { sentence })
|
116
|
+
expect(sentence).to eq(" #{turkish_words[1..] * ' '}")
|
166
117
|
end
|
167
118
|
end
|
168
119
|
end
|
169
120
|
|
170
121
|
describe '#split' do
|
171
122
|
it 'is able to capture Turkish characters' do
|
172
|
-
expect(turkish_words
|
173
|
-
|
174
|
-
|
175
|
-
.join
|
176
|
-
.strip
|
177
|
-
.empty?
|
178
|
-
).to eq(true)
|
179
|
-
|
180
|
-
expect(turkish_words
|
181
|
-
.join(' ')
|
182
|
-
.split(/[a-z]+/)
|
183
|
-
.join
|
184
|
-
.strip
|
185
|
-
.empty?
|
186
|
-
).to eq(true)
|
187
|
-
|
188
|
-
expect(turkish_words
|
189
|
-
.join(' ')
|
190
|
-
.upcase
|
191
|
-
.split(/[a-z]+/i)
|
192
|
-
.join
|
193
|
-
.strip
|
194
|
-
.empty?
|
195
|
-
).to eq(true)
|
123
|
+
expect(turkish_words.join(' ').split(/\w+/).join.strip.empty?).to(eq(true))
|
124
|
+
expect(turkish_words.join(' ').split(/[a-z]+/).join.strip.empty?).to(eq(true))
|
125
|
+
expect(turkish_words.join(' ').upcase.split(/[a-z]+/i).join.strip.empty?).to(eq(true))
|
196
126
|
end
|
197
127
|
end
|
198
128
|
|
199
129
|
describe '#upcase' do
|
200
130
|
context 'with non-destructive version' do
|
201
131
|
it 'does not change the original value of the string' do
|
202
|
-
expect { downcased_turkish_alphabet.upcase }
|
203
|
-
.to_not change { downcased_turkish_alphabet }
|
132
|
+
expect { downcased_turkish_alphabet.upcase }.to_not(change { downcased_turkish_alphabet })
|
204
133
|
end
|
205
134
|
|
206
135
|
it 'upcases all of Turkish characters' do
|
207
136
|
upcased_string = downcased_turkish_alphabet.upcase
|
208
|
-
|
209
|
-
expect(upcased_string).to eq(upcased_turkish_alphabet)
|
137
|
+
expect(upcased_string).to(eq(upcased_turkish_alphabet))
|
210
138
|
end
|
211
139
|
|
212
140
|
it 'upcases English characters except i as I' do
|
213
141
|
upcased_string = downcased_english_alphabet.upcase
|
214
|
-
|
215
|
-
expect(upcased_string).to eq(upcased_english_alphabet.tr('I', 'İ'))
|
142
|
+
expect(upcased_string).to(eq(upcased_english_alphabet.tr('I', 'İ')))
|
216
143
|
end
|
217
144
|
end
|
218
145
|
|
219
146
|
context 'with destructive version' do
|
220
147
|
it 'changes the original value of the string' do
|
221
|
-
expect { downcased_turkish_alphabet.upcase! }
|
222
|
-
|
223
|
-
|
224
|
-
expect(downcased_turkish_alphabet).to eq(upcased_turkish_alphabet)
|
148
|
+
expect { downcased_turkish_alphabet.upcase! }.to(change { downcased_turkish_alphabet })
|
149
|
+
expect(downcased_turkish_alphabet).to(eq(upcased_turkish_alphabet))
|
225
150
|
end
|
226
151
|
end
|
227
152
|
end
|
@@ -229,30 +154,24 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
229
154
|
describe '#downcase' do
|
230
155
|
context 'with non-destructive version' do
|
231
156
|
it 'does not change the original value of the string' do
|
232
|
-
expect { upcased_turkish_alphabet.downcase }
|
233
|
-
.to_not change { upcased_turkish_alphabet }
|
157
|
+
expect { upcased_turkish_alphabet.downcase }.to_not(change { upcased_turkish_alphabet })
|
234
158
|
end
|
235
159
|
|
236
160
|
it 'downcases all of Turkish characters' do
|
237
161
|
downcased_string = upcased_turkish_alphabet.downcase
|
238
|
-
|
239
|
-
expect(downcased_string)
|
240
|
-
.to eq(downcased_turkish_alphabet)
|
162
|
+
expect(downcased_string).to(eq(downcased_turkish_alphabet))
|
241
163
|
end
|
242
164
|
|
243
165
|
it 'downcases English characters except I as ı' do
|
244
166
|
downcased_string = upcased_english_alphabet.downcase
|
245
|
-
expect(downcased_string)
|
246
|
-
.to eq(downcased_english_alphabet.tr('i', 'ı'))
|
167
|
+
expect(downcased_string).to(eq(downcased_english_alphabet.tr('i', 'ı')))
|
247
168
|
end
|
248
169
|
end
|
249
170
|
|
250
171
|
context 'with destructive version' do
|
251
172
|
it 'changes the original value of the string' do
|
252
|
-
expect { upcased_turkish_alphabet.downcase! }
|
253
|
-
|
254
|
-
expect(upcased_turkish_alphabet)
|
255
|
-
.to eq(downcased_turkish_alphabet)
|
173
|
+
expect { upcased_turkish_alphabet.downcase! }.to(change { upcased_turkish_alphabet })
|
174
|
+
expect(upcased_turkish_alphabet).to(eq(downcased_turkish_alphabet))
|
256
175
|
end
|
257
176
|
end
|
258
177
|
end
|
@@ -261,41 +180,29 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
261
180
|
context 'with non-destructive version' do
|
262
181
|
it 'does not change the original value of the string' do
|
263
182
|
turkish_word = turkish_words.sample
|
264
|
-
|
265
|
-
expect { turkish_word.capitalize }.to_not change { turkish_word }
|
183
|
+
expect { turkish_word.capitalize }.to_not(change { turkish_word })
|
266
184
|
end
|
267
185
|
|
268
186
|
it 'capitalizes the leading first Turkish character' do
|
269
|
-
|
270
|
-
capitalized_words
|
271
|
-
|
272
|
-
expect(capitalized_words)
|
273
|
-
.to eq(%w[Çamur Ihlamur İnsan Ördek Şahika Ümraniye])
|
187
|
+
capitalized_words = turkish_words.map(&:capitalize)
|
188
|
+
expect(capitalized_words).to(eq(%w[Çamur Ihlamur İnsan Ördek Şahika Ümraniye]))
|
274
189
|
end
|
275
190
|
|
276
191
|
it 'capitalizes the first character of a string and downcase others' do
|
277
|
-
expect('türkÇE desteĞİ'.capitalize)
|
278
|
-
.to eq('Türkçe desteği')
|
192
|
+
expect('türkÇE desteĞİ'.capitalize).to(eq('Türkçe desteği'))
|
279
193
|
end
|
280
194
|
|
281
195
|
it 'capitalizes the first character of an English string' do
|
282
196
|
english_word = 'spy'
|
283
|
-
|
284
|
-
|
285
|
-
expect(capitalized_string)
|
286
|
-
.to eq('Spy')
|
197
|
+
expect(english_word.capitalize).to(eq('Spy'))
|
287
198
|
end
|
288
199
|
end
|
289
200
|
|
290
201
|
context 'with destructive version' do
|
291
202
|
it 'changes the original value of the string' do
|
292
203
|
turkish_word = 'çamur'
|
293
|
-
|
294
|
-
expect
|
295
|
-
.to change { turkish_word }
|
296
|
-
|
297
|
-
expect(turkish_word)
|
298
|
-
.to eq('Çamur')
|
204
|
+
expect { turkish_word.capitalize! }.to(change { turkish_word })
|
205
|
+
expect(turkish_word).to eq('Çamur')
|
299
206
|
end
|
300
207
|
end
|
301
208
|
end
|
@@ -304,13 +211,11 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
304
211
|
it 'compares Turkish characters correctly' do
|
305
212
|
result = downcased_turkish_alphabet.casecmp(upcased_turkish_alphabet)
|
306
213
|
|
307
|
-
expect(result.zero?)
|
308
|
-
.to eq(true)
|
214
|
+
expect(result.zero?).to(eq(true))
|
309
215
|
end
|
310
216
|
|
311
217
|
it 'compares Turkish characters correctly' do
|
312
|
-
expect('sıtkı'.casecmp('SıTKI')
|
313
|
-
.to eq(true)
|
218
|
+
expect('sıtkı'.casecmp('SıTKI')&.zero?).to(eq(true))
|
314
219
|
end
|
315
220
|
end
|
316
221
|
|
@@ -318,56 +223,41 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
318
223
|
context 'with non-destructive version' do
|
319
224
|
it 'does not change the original value of the string' do
|
320
225
|
word = 'mERHABA çAMUR iSMETOĞULLARI'
|
321
|
-
|
322
|
-
expect { word.titleize }
|
323
|
-
.to_not change { word }
|
226
|
+
expect { word.titleize }.to_not(change { word })
|
324
227
|
end
|
325
228
|
|
326
229
|
it 'upcases first character of all words' do
|
327
230
|
titleized = 'merhaba çamur ismet'.titleize
|
328
|
-
|
329
|
-
expect(titleized)
|
330
|
-
.to eq('Merhaba Çamur İsmet')
|
231
|
+
expect(titleized).to(eq('Merhaba Çamur İsmet'))
|
331
232
|
end
|
332
233
|
|
333
234
|
it 'no problem with words that consist of special chars only' do
|
334
235
|
titleized = '(( merhaba çamur ismet'.titleize
|
335
|
-
|
336
|
-
expect(titleized)
|
337
|
-
.to eq('(( Merhaba Çamur İsmet')
|
236
|
+
expect(titleized).to(eq('(( Merhaba Çamur İsmet'))
|
338
237
|
end
|
339
238
|
|
340
239
|
it 'downcases characters other than first characters of all words' do
|
341
240
|
titleized = 'mERHABA çAMUR iSMETOĞULLARI'.titleize
|
342
|
-
|
343
|
-
expect(titleized)
|
344
|
-
.to eq('Merhaba Çamur İsmetoğulları')
|
241
|
+
expect(titleized).to(eq('Merhaba Çamur İsmetoğulları'))
|
345
242
|
end
|
346
243
|
|
347
244
|
it 'support strings that include paranthesis, quotes, etc.' do
|
348
245
|
titleized = "rUBY roCkS... (really! 'tRUSt' ME)".titleize
|
349
|
-
|
350
|
-
expect(titleized)
|
351
|
-
.to eq("Ruby Rocks... (Really! 'Trust' Me)")
|
246
|
+
expect(titleized).to(eq("Ruby Rocks... (Really! 'Trust' Me)"))
|
352
247
|
end
|
353
248
|
|
354
249
|
it 'does not capitalize conjuctions when false passed' do
|
355
|
-
titleized = 'kerem VE aslı VeYa leyla İlE mecnun'.titleize(false)
|
356
|
-
|
357
|
-
expect(titleized)
|
358
|
-
.to eq('Kerem ve Aslı veya Leyla ile Mecnun')
|
250
|
+
titleized = 'kerem VE aslı VeYa leyla İlE mecnun'.titleize(conjuction: false)
|
251
|
+
expect(titleized).to eq('Kerem ve Aslı veya Leyla ile Mecnun')
|
359
252
|
end
|
360
253
|
end
|
361
254
|
|
362
255
|
context 'with destructive version' do
|
363
256
|
it 'changes the original value of the string' do
|
364
257
|
word = 'mERHABA çAMUR iSMETOĞULLARI'
|
258
|
+
expect { word.titleize! }.to(change { word })
|
365
259
|
|
366
|
-
expect
|
367
|
-
.to change { word }
|
368
|
-
|
369
|
-
expect(word)
|
370
|
-
.to eq('Merhaba Çamur İsmetoğulları')
|
260
|
+
expect(word).to(eq('Merhaba Çamur İsmetoğulları'))
|
371
261
|
end
|
372
262
|
end
|
373
263
|
end
|
@@ -376,52 +266,40 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
376
266
|
context 'with non-destructive version' do
|
377
267
|
it 'does not change the original value of the string' do
|
378
268
|
word = 'mErHaba çamur ismetoğullarI'
|
379
|
-
|
380
|
-
expect { word.swapcase }
|
381
|
-
.to_not change { word }
|
269
|
+
expect { word.swapcase }.to_not(change { word })
|
382
270
|
end
|
383
271
|
|
384
272
|
it 'swaps characters correctly' do
|
385
273
|
word = 'mErHaba çamur ismetoğullarI'.swapcase
|
386
|
-
|
387
|
-
expect(word)
|
388
|
-
.to eq('MeRhABA ÇAMUR İSMETOĞULLARı')
|
274
|
+
expect(word).to(eq('MeRhABA ÇAMUR İSMETOĞULLARı'))
|
389
275
|
end
|
390
276
|
end
|
391
277
|
|
392
278
|
context 'with destructive version' do
|
393
279
|
it 'changes the original value of the string' do
|
394
280
|
word = 'mErHaba çamur ismetoğullarI'
|
395
|
-
|
396
|
-
expect
|
397
|
-
.to change { word }
|
398
|
-
expect(word)
|
399
|
-
.to eq('MeRhABA ÇAMUR İSMETOĞULLARı')
|
281
|
+
expect { word.swapcase! }.to(change { word })
|
282
|
+
expect(word).to(eq('MeRhABA ÇAMUR İSMETOĞULLARı'))
|
400
283
|
end
|
401
284
|
end
|
402
285
|
end
|
403
286
|
|
404
287
|
describe '#match' do
|
405
288
|
it "matches Turkish characters when regex include '\\w'" do
|
406
|
-
expect('Aşağı'.match(/\w+/).to_s)
|
407
|
-
|
408
|
-
|
409
|
-
expect('Aşağı Ayrancı'.match(/^\w+\s\w+$/).to_s)
|
410
|
-
.to eq('Aşağı Ayrancı')
|
289
|
+
expect('Aşağı'.match(/\w+/).to_s).to(eq('Aşağı'))
|
290
|
+
expect('Aşağı Ayrancı'.match(/^\w+\s\w+$/).to_s).to(eq('Aşağı Ayrancı'))
|
411
291
|
end
|
412
292
|
|
413
293
|
it 'matches Turkish characters when regex include lowercase range' do
|
414
|
-
expect('aüvvağğ öövvaağ'.match(/^[a-z]+\s[a-z]+$/).to_s)
|
415
|
-
.to eq('aüvvağğ öövvaağ')
|
294
|
+
expect('aüvvağğ öövvaağ'.match(/^[a-z]+\s[a-z]+$/).to_s).to(eq('aüvvağğ öövvaağ'))
|
416
295
|
end
|
417
296
|
|
418
297
|
it 'matches Turkish characters when regex include uppercase range' do
|
419
|
-
expect('BAĞCIlar'.match(/[A-Z]+/).to_s)
|
420
|
-
.to eq('BAĞCI')
|
298
|
+
expect('BAĞCIlar'.match(/[A-Z]+/).to_s).to(eq('BAĞCI'))
|
421
299
|
end
|
422
300
|
|
423
301
|
it "doesn't match Turkish characters when regex include '\\W'" do
|
424
|
-
expect('Aşağı Ayrancı'.match(/\W+/).to_s).to
|
302
|
+
expect('Aşağı Ayrancı'.match(/\W+/).to_s).to(eq(' '))
|
425
303
|
end
|
426
304
|
end
|
427
305
|
|
@@ -431,59 +309,15 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
431
309
|
end
|
432
310
|
|
433
311
|
it 'matches Turkish characters when regex include lowercase range' do
|
434
|
-
expect(turkish_words
|
435
|
-
.join(' ')
|
436
|
-
.scan(/^[a-z\s]+$/)
|
437
|
-
).to eq([turkish_words.join(' ')])
|
312
|
+
expect(turkish_words.join(' ').scan(/^[a-z\s]+$/)).to(eq([turkish_words.join(' ')]))
|
438
313
|
end
|
439
314
|
|
440
315
|
it 'matches Turkish characters when regex include uppercase range' do
|
441
|
-
expect(turkish_words
|
442
|
-
.join(' ')
|
443
|
-
.upcase
|
444
|
-
.scan(/^[A-Z\s]+$/)
|
445
|
-
).to eq([turkish_words.join(' ').upcase])
|
316
|
+
expect(turkish_words.join(' ').upcase.scan(/^[A-Z\s]+$/)).to(eq([turkish_words.join(' ').upcase]))
|
446
317
|
end
|
447
318
|
|
448
319
|
it "matches Turkish characters when regex include '\\w'" do
|
449
|
-
expect(turkish_words
|
450
|
-
.join(' ')
|
451
|
-
.scan(/\W+/)
|
452
|
-
.map(&:strip)
|
453
|
-
.all?(&:empty?)
|
454
|
-
).to eq(true)
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
describe '#=~' do
|
459
|
-
tr_chars = ALPHA[:tr_lower] + ALPHA[:tr_upper]
|
460
|
-
|
461
|
-
it "matches Turkish characters when regex include '\\w'" do
|
462
|
-
expect(tr_chars
|
463
|
-
.split(//)
|
464
|
-
.all? { |ch| (ch =~ /\w/).zero? }
|
465
|
-
).to eq(true)
|
466
|
-
end
|
467
|
-
|
468
|
-
it 'matches Turkish characters when regex include lowercase range' do
|
469
|
-
expect(ALPHA[:tr_lower]
|
470
|
-
.split(//)
|
471
|
-
.all? { |ch| (ch =~ /[a-z]/).zero? }
|
472
|
-
).to eq(true)
|
473
|
-
end
|
474
|
-
|
475
|
-
it 'matches Turkish characters when regex include uppercase range' do
|
476
|
-
expect(ALPHA[:tr_upper]
|
477
|
-
.split(//)
|
478
|
-
.all? { |ch| (ch =~ /[A-Z]/).zero? }
|
479
|
-
).to eq(true)
|
480
|
-
end
|
481
|
-
|
482
|
-
it "doesn't match Turkish characters when regex include '\\W'" do
|
483
|
-
expect(tr_chars
|
484
|
-
.split(//)
|
485
|
-
.all? { |ch| (ch =~ /\W/).nil? }
|
486
|
-
).to eq(true)
|
320
|
+
expect(turkish_words.join(' ').scan(/\W+/).map(&:strip).all?(&:empty?)).to(eq(true))
|
487
321
|
end
|
488
322
|
end
|
489
323
|
|
@@ -491,28 +325,20 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
491
325
|
context 'non-destructive version' do
|
492
326
|
it 'does not affect the object' do
|
493
327
|
word = 'ağapaşa ağa'
|
494
|
-
|
495
|
-
expect { word.sub(/\w+/, 'bey') }.to_not change { word }
|
328
|
+
expect { word.sub(/\w+/, 'bey') }.to_not(change { word })
|
496
329
|
end
|
497
330
|
|
498
331
|
it 'matches Turkish characters, and replaces them' do
|
499
|
-
expect('ağapaşa ağa'.sub(/\w+/, 'bey')).to
|
500
|
-
|
501
|
-
expect('
|
502
|
-
.to eq('ağapaşabeyağa şapka')
|
503
|
-
|
504
|
-
expect('ağapaşaağa'.sub(/[a-h]+/, 'bey')).to eq('beypaşaağa')
|
332
|
+
expect('ağapaşa ağa'.sub(/\w+/, 'bey')).to(eq('bey ağa'))
|
333
|
+
expect('ağapaşa ağa şapka'.sub(/\W+/, 'bey')).to(eq('ağapaşabeyağa şapka'))
|
334
|
+
expect('ağapaşaağa'.sub(/[a-h]+/, 'bey')).to(eq('beypaşaağa'))
|
505
335
|
end
|
506
336
|
end
|
507
337
|
|
508
338
|
context 'destructive version' do
|
509
339
|
it 'affects the object' do
|
510
340
|
word = 'ağapaşa ağa'
|
511
|
-
|
512
|
-
expect { word.sub!(/\w+/, 'bey') }
|
513
|
-
.to change { word }
|
514
|
-
.from('ağapaşa ağa')
|
515
|
-
.to('bey ağa')
|
341
|
+
expect { word.sub!(/\w+/, 'bey') }.to(change { word }.from('ağapaşa ağa').to('bey ağa'))
|
516
342
|
end
|
517
343
|
end
|
518
344
|
end
|
@@ -521,74 +347,67 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
521
347
|
context 'non-destructive version' do
|
522
348
|
it 'does not affect the object' do
|
523
349
|
word = 'ağapaşa ağa'
|
524
|
-
|
525
|
-
expect { word.gsub(/\w+/, 'bey') }.to_not change { word }
|
350
|
+
expect { word.gsub(/\w+/, 'bey') }.to_not(change { word })
|
526
351
|
end
|
527
352
|
|
528
353
|
it 'matches Turkish characters, and replaces them' do
|
529
|
-
expect('ağapaşa ağa'.gsub(/\w+/, 'bey')).to
|
530
|
-
|
531
|
-
expect('
|
532
|
-
.to eq('ağapaşabeyağabeyşapka')
|
533
|
-
|
534
|
-
expect('ağapaşaağa'.gsub(/[a-h]+/, 'bey')).to eq('beypbeyşbey')
|
354
|
+
expect('ağapaşa ağa'.gsub(/\w+/, 'bey')).to(eq('bey bey'))
|
355
|
+
expect('ağapaşa ağa şapka'.gsub(/\W+/, 'bey')).to(eq('ağapaşabeyağabeyşapka'))
|
356
|
+
expect('ağapaşaağa'.gsub(/[a-h]+/, 'bey')).to(eq('beypbeyşbey'))
|
535
357
|
end
|
536
358
|
end
|
537
359
|
|
538
360
|
context 'destructive version' do
|
539
361
|
it 'affects the object' do
|
540
362
|
word = 'ağapaşa ağa'
|
541
|
-
expect { word.gsub!(/\w+/, 'bey') }
|
542
|
-
.to change { word }
|
543
|
-
.from('ağapaşa ağa')
|
544
|
-
.to('bey bey')
|
363
|
+
expect { word.gsub!(/\w+/, 'bey') }.to(change { word }.from('ağapaşa ağa').to('bey bey'))
|
545
364
|
end
|
546
365
|
end
|
547
366
|
end
|
548
367
|
|
549
|
-
describe
|
368
|
+
describe '#<=>' do
|
550
369
|
let(:sorted_equal_length_strings) { %w[Cahit Çağla Ömer Sıtkı Şakir] }
|
551
370
|
let(:sorted_different_length_strings) { %w[c ca falan om saki sıt] }
|
552
|
-
context
|
553
|
-
it
|
371
|
+
context 'with equal length strings' do
|
372
|
+
it 'works for smaller test' do
|
554
373
|
0.upto(sorted_equal_length_strings.length - 2) do |i|
|
555
|
-
expect(sorted_equal_length_strings[i] <=> sorted_equal_length_strings[i+1]).to
|
374
|
+
expect(sorted_equal_length_strings[i] <=> sorted_equal_length_strings[i + 1]).to(eq(-1))
|
556
375
|
end
|
557
376
|
end
|
558
377
|
|
559
|
-
it
|
560
|
-
(sorted_equal_length_strings.length-1).downto(1) do |i|
|
561
|
-
expect(sorted_equal_length_strings[i] <=> sorted_equal_length_strings[i-1]).to
|
378
|
+
it 'works for bigger test' do
|
379
|
+
(sorted_equal_length_strings.length - 1).downto(1) do |i|
|
380
|
+
expect(sorted_equal_length_strings[i] <=> sorted_equal_length_strings[i - 1]).to(eq(1))
|
562
381
|
end
|
563
382
|
end
|
564
383
|
|
565
|
-
it
|
566
|
-
sorted_equal_length_strings.each do |str|
|
567
|
-
expect(str <=> str).to eq(0)
|
384
|
+
it 'works for equals test' do
|
385
|
+
sorted_equal_length_strings.each do |str|
|
386
|
+
expect(str <=> str).to eq(0) # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
|
568
387
|
end
|
569
388
|
end
|
570
389
|
end
|
571
390
|
|
572
|
-
context
|
573
|
-
it
|
391
|
+
context 'with different length strings' do
|
392
|
+
it 'works for smaller test' do
|
574
393
|
0.upto(sorted_different_length_strings.length - 2) do |i|
|
575
|
-
expect(sorted_different_length_strings[i] <=> sorted_different_length_strings[i+1]).to eq(-1)
|
394
|
+
expect(sorted_different_length_strings[i] <=> sorted_different_length_strings[i + 1]).to eq(-1)
|
576
395
|
end
|
577
396
|
end
|
578
397
|
|
579
|
-
it
|
580
|
-
(sorted_different_length_strings.length-1).downto(1) do |i|
|
581
|
-
expect(sorted_different_length_strings[i] <=> sorted_different_length_strings[i-1]).to eq(1)
|
398
|
+
it 'works for bigger test' do
|
399
|
+
(sorted_different_length_strings.length - 1).downto(1) do |i|
|
400
|
+
expect(sorted_different_length_strings[i] <=> sorted_different_length_strings[i - 1]).to eq(1)
|
582
401
|
end
|
583
402
|
end
|
584
403
|
end
|
585
404
|
|
586
|
-
context
|
587
|
-
it
|
588
|
-
expect(
|
589
|
-
expect(
|
590
|
-
expect(
|
591
|
-
expect(
|
405
|
+
context 'invalid comparisons' do
|
406
|
+
it 'returns nil' do
|
407
|
+
expect('a' <=> 3.5).to eq(nil)
|
408
|
+
expect('a' <=> true).to eq(nil)
|
409
|
+
expect('a' <=> Object.new).to eq(nil)
|
410
|
+
expect('a' <=> 1).to eq(nil)
|
592
411
|
end
|
593
412
|
end
|
594
413
|
end
|