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