turkish_support 2.0.1 → 2.1.0
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/.reek.yml +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +8 -5
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -2
- data/README.md +50 -64
- data/Rakefile +8 -0
- data/lib/turkish_support.rb +32 -2
- data/lib/turkish_support/array_methods.rb +6 -9
- data/lib/turkish_support/constants.rb +26 -34
- data/lib/turkish_support/string_methods.rb +30 -48
- data/lib/turkish_support/version.rb +3 -1
- data/spec/array_spec.rb +57 -86
- data/spec/spec_helper.rb +3 -1
- data/spec/string_spec.rb +89 -37
- data/spec/turkish_support_spec.rb +2 -1
- data/turkish_support.gemspec +9 -2
- metadata +60 -11
- data/lib/turkish_support/helpers.rb +0 -90
- data/spec/helpers_spec.rb +0 -165
@@ -1,74 +1,56 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: false
|
2
2
|
|
3
3
|
module TurkishSupport
|
4
4
|
refine String do # rubocop:disable Metrics/BlockLength
|
5
|
-
|
5
|
+
REGEX_METHODS.each do |meth|
|
6
6
|
define_method meth do |*args|
|
7
|
-
|
7
|
+
if args[0].is_a?(Regexp) || %i[match scan].include?(meth)
|
8
|
+
args[0] = TurkishRegexps::TrRegexp.new(args[0]).translate
|
9
|
+
end
|
8
10
|
|
9
|
-
args[0] = translate_regexp(args[0]) if REGEX_REQUIRED_METHODS.include?(meth) || args[0].is_a?(Regexp)
|
10
11
|
instance_exec { super(*args) }
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
define_method(meth) { super(:turkic) }
|
16
|
-
end
|
15
|
+
CASE_METHODS.each { define_method(_1) { super(:turkic) } }
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
# capitalize all words and returns a copy of the string
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
def titleize
|
21
|
+
downcase.gsub(/\b\S/u).each { _1.upcase }
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
word.chr + (word.length > 1 ? word[1..].capitalize : '')
|
26
|
-
else
|
27
|
-
word.capitalize
|
28
|
-
end
|
29
|
-
end.join(' ')
|
24
|
+
# capitalize all words in place
|
25
|
+
# @return [String]
|
26
|
+
def titleize!
|
27
|
+
replace(titleize)
|
30
28
|
end
|
31
29
|
|
32
|
-
def
|
33
|
-
|
30
|
+
def casecmp(other) # :nodoc:
|
31
|
+
upcase.instance_exec { super(other.upcase) }
|
34
32
|
end
|
35
33
|
|
36
|
-
def
|
37
|
-
|
34
|
+
def <=>(other) # :nodoc:
|
35
|
+
return nil unless other.is_a? String
|
38
36
|
|
39
|
-
|
40
|
-
if tr_char?(c)
|
41
|
-
tr_lower?(c) ? c.upcase : c.downcase
|
42
|
-
else
|
43
|
-
c.instance_exec { super }
|
44
|
-
end
|
45
|
-
end.join
|
37
|
+
TurkishRanges::TrText.new(to_s) <=> TurkishRanges::TrText.new(other)
|
46
38
|
end
|
47
39
|
|
48
|
-
def
|
49
|
-
|
40
|
+
def >(other) # :nodoc:
|
41
|
+
(self <=> other) == 1
|
50
42
|
end
|
51
43
|
|
52
|
-
def
|
53
|
-
|
44
|
+
def <(other) # :nodoc:
|
45
|
+
(self <=> other) == -1
|
54
46
|
end
|
55
47
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
each_char.with_index do |ch, i|
|
60
|
-
position1 = ASCII_ALPHABET[ch]
|
61
|
-
position2 = ASCII_ALPHABET[other[i]]
|
62
|
-
|
63
|
-
return (position2.nil? ? 0 : -1) if position1.nil?
|
64
|
-
return 1 if position2.nil?
|
65
|
-
return (position1 < position2 ? -1 : 1) if position1 != position2
|
66
|
-
end
|
67
|
-
|
68
|
-
return 0 if length == other.length
|
69
|
-
return -1 if length < other.length
|
48
|
+
def >=(other) # :nodoc:
|
49
|
+
(self <=> other) != -1
|
50
|
+
end
|
70
51
|
|
71
|
-
|
52
|
+
def <=(other) # :nodoc:
|
53
|
+
(self <=> other) != 1
|
72
54
|
end
|
73
55
|
end
|
74
56
|
end
|
data/spec/array_spec.rb
CHANGED
@@ -1,103 +1,74 @@
|
|
1
|
-
|
2
|
-
using TurkishSupport
|
1
|
+
# frozen_string_literal: false
|
3
2
|
|
4
|
-
|
5
|
-
describe Array do
|
6
|
-
describe '#sort' do
|
7
|
-
|
8
|
-
let(:samples) {
|
9
|
-
[
|
10
|
-
{
|
11
|
-
mixed: %w[ bağcılar bahçelievler şimdi çüNKÜ olmalı üç\ kere düş ılık duy ],
|
12
|
-
sorted: %w[ bağcılar bahçelievler çüNKÜ duy düş ılık olmalı şimdi üç\ kere ]
|
13
|
-
},
|
14
|
-
{
|
15
|
-
mixed: %w[ iki Üç dört ılık İğne iyne Ul ],
|
16
|
-
sorted: %w[ İğne Ul Üç dört ılık iki iyne ]
|
17
|
-
},
|
18
|
-
{
|
19
|
-
mixed: %w[ Sıtkı1\ Bağdat Sıtkı\ Bağdat a 3s 2\ b ab\ ],
|
20
|
-
sorted: %w[ 2\ b 3s Sıtkı\ Bağdat Sıtkı1\ Bağdat a ab\ ]
|
21
|
-
}
|
22
|
-
]
|
23
|
-
}
|
3
|
+
using TurkishSupport
|
24
4
|
|
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
|
-
}
|
5
|
+
describe 'Array' do
|
6
|
+
describe '#sort' do
|
7
|
+
let(:samples) do
|
8
|
+
[{ mixed: %w[bağcılar bahçelievler şimdi çüNKÜ olmalı üç\ kere düş ılık duy],
|
9
|
+
sorted: %w[bağcılar bahçelievler çüNKÜ duy düş ılık olmalı şimdi üç\ kere] },
|
10
|
+
{ mixed: %w[iki Üç dört ılık İğne iyne Ul],
|
11
|
+
sorted: %w[İğne Ul Üç dört ılık iki iyne] },
|
12
|
+
{ mixed: %w[Sıtkı1\ Bağdat Sıtkı\ Bağdat a 3s 2\ b ab\ ],
|
13
|
+
sorted: %w[2\ b 3s Sıtkı\ Bağdat Sıtkı1\ Bağdat a ab\ ] }]
|
14
|
+
end
|
15
|
+
let(:block_samples) do
|
16
|
+
[{ mixed: %w[ağa aça aşa aöa aüa aua afa aba],
|
17
|
+
sorted: { "a[1]<=>b[1]": %w[aba aça afa ağa aöa aşa aua aüa],
|
18
|
+
"b[1]<=>a[1]": %w[aüa aua aşa aöa ağa afa aça aba] } },
|
19
|
+
{ mixed: %w[iki Üç dört ılık İğne iyne Ul],
|
20
|
+
sorted: { "a.length<=>b.length": %w[Üç Ul iki dört ılık İğne iyne],
|
21
|
+
"b.length<=>a.length": %w[dört ılık İğne iyne iki Üç Ul] } },
|
22
|
+
{ mixed: [['Şakir', 2], ['İsmet', 0], ['Zeliha', 1]],
|
23
|
+
sorted: { "a[1]<=>b[1]": [['İsmet', 0], ['Zeliha', 1], ['Şakir', 2]],
|
24
|
+
"b[0]<=>a[0]": [['Zeliha', 1], ['Şakir', 2], ['İsmet', 0]] } }]
|
25
|
+
end
|
50
26
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
27
|
+
context 'nondestructive version' do
|
28
|
+
context 'no block given' do
|
29
|
+
it 'does not change the original value of the array' do
|
30
|
+
samples.each do |sample|
|
31
|
+
expect { sample[:mixed].sort }.to_not(change { sample[:mixed] })
|
57
32
|
end
|
33
|
+
end
|
58
34
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
35
|
+
it 'sorts array in alphabetical order' do
|
36
|
+
samples.each do |sample|
|
37
|
+
expect(sample[:mixed].sort).to eq(sample[:sorted])
|
63
38
|
end
|
64
39
|
end
|
40
|
+
end
|
65
41
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
sample
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
expect(sample[:mixed].sort {|a, b| b.length <=> a.length})
|
80
|
-
.to eq(sample[:sorted][:"b.length<=>a.length"])
|
81
|
-
end
|
42
|
+
context 'block given' do
|
43
|
+
it 'sorts array for random conditions' do
|
44
|
+
sample = block_samples.first
|
45
|
+
expect(sample[:mixed].sort { |a, b| a[1] <=> b[1] })
|
46
|
+
.to eq(sample[:sorted][:"a[1]<=>b[1]"])
|
47
|
+
expect(sample[:mixed].sort { |a, b| b[1] <=> a[1] })
|
48
|
+
.to eq(sample[:sorted][:"b[1]<=>a[1]"])
|
49
|
+
sample = block_samples[1]
|
50
|
+
expect(sample[:mixed].sort { |a, b| a.length <=> b.length })
|
51
|
+
.to eq(sample[:sorted][:"a.length<=>b.length"])
|
52
|
+
expect(sample[:mixed].sort { |a, b| b.length <=> a.length })
|
53
|
+
.to eq(sample[:sorted][:"b.length<=>a.length"])
|
54
|
+
end
|
82
55
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
56
|
+
it 'sorts nested arrays' do
|
57
|
+
sample = block_samples[2]
|
58
|
+
expect(sample[:mixed].sort { |a, b| a[1] <=> b[1] })
|
59
|
+
.to eq(sample[:sorted][:"a[1]<=>b[1]"])
|
60
|
+
expect(sample[:mixed].sort { |a, b| b[0] <=> a[0] })
|
61
|
+
.to eq(sample[:sorted][:"b[0]<=>a[0]"])
|
90
62
|
end
|
91
63
|
end
|
64
|
+
end
|
92
65
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
66
|
+
context 'with destructive version' do
|
67
|
+
it 'changes the original value of the array' do
|
68
|
+
samples.each do |sample|
|
69
|
+
expect { sample[:mixed].sort! }.to(change { sample[:mixed] })
|
98
70
|
end
|
99
71
|
end
|
100
|
-
|
101
72
|
end
|
102
73
|
end
|
103
74
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/string_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
2
3
|
using TurkishSupport
|
3
4
|
|
4
5
|
module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
@@ -13,19 +14,21 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
13
14
|
context 'with non-destructive version' do
|
14
15
|
it 'does not change the original value of the string' do
|
15
16
|
word = turkish_words.sample
|
17
|
+
|
16
18
|
expect { word[/\w+/] }.to_not(change { word })
|
17
19
|
end
|
18
20
|
|
19
21
|
it 'is able to capture Turkish characters' do
|
20
|
-
expect(turkish_words.all? { |w| w[/\w+/] == w }).to
|
21
|
-
expect(turkish_words.all? { |w| w[/[a-z]+/] == w }).to
|
22
|
-
expect(turkish_words.map(&:upcase).all? { |w| w[/[a-z]+/i] == w }).to
|
22
|
+
expect(turkish_words.all? { |w| w[/\w+/] == w }).to be true
|
23
|
+
expect(turkish_words.all? { |w| w[/[a-z]+/] == w }).to be true
|
24
|
+
expect(turkish_words.map(&:upcase).all? { |w| w[/[a-z]+/i] == w }).to be true
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
context 'with destructive version' do
|
27
29
|
it 'changes the original value of the string' do
|
28
30
|
word = turkish_words.sample
|
31
|
+
|
29
32
|
expect { word[/\w+/] = 'new value' }.to(change { word })
|
30
33
|
expect(word).to eq('new value')
|
31
34
|
end
|
@@ -35,34 +38,36 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
35
38
|
describe '#index' do
|
36
39
|
it 'does not change the original value of the string' do
|
37
40
|
word = turkish_words.sample
|
41
|
+
|
38
42
|
expect { word.index(/\w+/) }.to_not(change { word })
|
39
43
|
end
|
40
44
|
|
41
45
|
it 'is able to capture Turkish characters' do
|
42
|
-
expect(turkish_words.all? { |w| w.index(/\w+/).zero? }).to
|
43
|
-
expect(turkish_words.all? { |w| w.index(/[a-z]+/).zero? }).to
|
44
|
-
expect(turkish_words.map(&:upcase).all? { |w| w.index(/[a-z]+/i).zero? }).to
|
46
|
+
expect(turkish_words.all? { |w| w.index(/\w+/).zero? }).to be true
|
47
|
+
expect(turkish_words.all? { |w| w.index(/[a-z]+/).zero? }).to be true
|
48
|
+
expect(turkish_words.map(&:upcase).all? { |w| w.index(/[a-z]+/i).zero? }).to be true
|
45
49
|
end
|
46
50
|
|
47
51
|
it 'begins to search from the right position' do
|
48
|
-
expect('şç-!+*/-ğüı'.index(/\w+/, 2)).to
|
52
|
+
expect('şç-!+*/-ğüı'.index(/\w+/, 2)).to be 8
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
52
56
|
describe '#rindex' do
|
53
57
|
it 'does not change the original value of the string' do
|
54
58
|
word = turkish_words.sample
|
59
|
+
|
55
60
|
expect { word.rindex(/\w+/) }.to_not(change { word })
|
56
61
|
end
|
57
62
|
|
58
63
|
it 'is able to capture Turkish characters' do
|
59
|
-
expect(turkish_words.map(&:reverse).all? { |w| w.rindex(/\w+/) == w.size - 1 }).to
|
60
|
-
expect(turkish_words.map(&:reverse).all? { |w| w.rindex(/[a-z]+/) == w.size - 1 }).to
|
61
|
-
expect(turkish_words.map { |w| w.upcase.reverse }.all? { |w| w.rindex(/[a-z]+/i) == w.size - 1 }).to
|
64
|
+
expect(turkish_words.map(&:reverse).all? { |w| w.rindex(/\w+/) == w.size - 1 }).to be true
|
65
|
+
expect(turkish_words.map(&:reverse).all? { |w| w.rindex(/[a-z]+/) == w.size - 1 }).to be true
|
66
|
+
expect(turkish_words.map { |w| w.upcase.reverse }.all? { |w| w.rindex(/[a-z]+/i) == w.size - 1 }).to be true
|
62
67
|
end
|
63
68
|
|
64
69
|
it 'finishes the searching to the right position' do
|
65
|
-
expect('şç-!+*/-ğüı'.rindex(/\w+/, 7)).to
|
70
|
+
expect('şç-!+*/-ğüı'.rindex(/\w+/, 7)).to be 1
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
@@ -99,19 +104,21 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
99
104
|
context 'with non-destructive version' do
|
100
105
|
it 'does not change the original value of the string' do
|
101
106
|
sentence = turkish_words * ' '
|
107
|
+
|
102
108
|
expect { sentence.slice(/\w+/) }.to_not(change { sentence })
|
103
109
|
end
|
104
110
|
|
105
111
|
it 'is able to capture Turkish characters' do
|
106
|
-
expect(turkish_words.all? { |w| w.slice(/\w+/) == w }).to
|
107
|
-
expect(turkish_words.all? { |w| w.slice(/[a-z]+/) == w }).to
|
108
|
-
expect(turkish_words.map(&:upcase).all? { |w| w.slice(/[a-z]+/i) == w }).to
|
112
|
+
expect(turkish_words.all? { |w| w.slice(/\w+/) == w }).to be true
|
113
|
+
expect(turkish_words.all? { |w| w.slice(/[a-z]+/) == w }).to be true
|
114
|
+
expect(turkish_words.map(&:upcase).all? { |w| w.slice(/[a-z]+/i) == w }).to be true
|
109
115
|
end
|
110
116
|
end
|
111
117
|
|
112
118
|
context 'with destructive version' do
|
113
119
|
it 'changes the original value of the string' do
|
114
120
|
sentence = turkish_words * ' '
|
121
|
+
|
115
122
|
expect { sentence.slice!(/\w+/) }.to(change { sentence })
|
116
123
|
expect(sentence).to eq(" #{turkish_words[1..] * ' '}")
|
117
124
|
end
|
@@ -120,9 +127,9 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
120
127
|
|
121
128
|
describe '#split' do
|
122
129
|
it 'is able to capture Turkish characters' do
|
123
|
-
expect(turkish_words.join(' ').split(/\w+/).join.strip.empty?).to
|
124
|
-
expect(turkish_words.join(' ').split(/[a-z]+/).join.strip.empty?).to
|
125
|
-
expect(turkish_words.join(' ').upcase.split(/[a-z]+/i).join.strip.empty?).to
|
130
|
+
expect(turkish_words.join(' ').split(/\w+/).join.strip.empty?).to be true
|
131
|
+
expect(turkish_words.join(' ').split(/[a-z]+/).join.strip.empty?).to be true
|
132
|
+
expect(turkish_words.join(' ').upcase.split(/[a-z]+/i).join.strip.empty?).to be true
|
126
133
|
end
|
127
134
|
end
|
128
135
|
|
@@ -134,12 +141,14 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
134
141
|
|
135
142
|
it 'upcases all of Turkish characters' do
|
136
143
|
upcased_string = downcased_turkish_alphabet.upcase
|
144
|
+
|
137
145
|
expect(upcased_string).to(eq(upcased_turkish_alphabet))
|
138
146
|
end
|
139
147
|
|
140
148
|
it 'upcases English characters except i as I' do
|
141
149
|
upcased_string = downcased_english_alphabet.upcase
|
142
|
-
|
150
|
+
|
151
|
+
expect(upcased_string).to eq upcased_english_alphabet.tr('I', 'İ')
|
143
152
|
end
|
144
153
|
end
|
145
154
|
|
@@ -159,12 +168,12 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
159
168
|
|
160
169
|
it 'downcases all of Turkish characters' do
|
161
170
|
downcased_string = upcased_turkish_alphabet.downcase
|
162
|
-
expect(downcased_string).to
|
171
|
+
expect(downcased_string).to eq downcased_turkish_alphabet
|
163
172
|
end
|
164
173
|
|
165
174
|
it 'downcases English characters except I as ı' do
|
166
175
|
downcased_string = upcased_english_alphabet.downcase
|
167
|
-
expect(downcased_string).to
|
176
|
+
expect(downcased_string).to eq downcased_english_alphabet.tr('i', 'ı')
|
168
177
|
end
|
169
178
|
end
|
170
179
|
|
@@ -180,27 +189,31 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
180
189
|
context 'with non-destructive version' do
|
181
190
|
it 'does not change the original value of the string' do
|
182
191
|
turkish_word = turkish_words.sample
|
192
|
+
|
183
193
|
expect { turkish_word.capitalize }.to_not(change { turkish_word })
|
184
194
|
end
|
185
195
|
|
186
196
|
it 'capitalizes the leading first Turkish character' do
|
187
197
|
capitalized_words = turkish_words.map(&:capitalize)
|
188
|
-
|
198
|
+
|
199
|
+
expect(capitalized_words).to eq %w[Çamur Ihlamur İnsan Ördek Şahika Ümraniye]
|
189
200
|
end
|
190
201
|
|
191
202
|
it 'capitalizes the first character of a string and downcase others' do
|
192
|
-
expect('türkÇE desteĞİ'.capitalize).to
|
203
|
+
expect('türkÇE desteĞİ'.capitalize).to eq 'Türkçe desteği'
|
193
204
|
end
|
194
205
|
|
195
206
|
it 'capitalizes the first character of an English string' do
|
196
207
|
english_word = 'spy'
|
197
|
-
|
208
|
+
|
209
|
+
expect(english_word.capitalize).to eq 'Spy'
|
198
210
|
end
|
199
211
|
end
|
200
212
|
|
201
213
|
context 'with destructive version' do
|
202
214
|
it 'changes the original value of the string' do
|
203
215
|
turkish_word = 'çamur'
|
216
|
+
|
204
217
|
expect { turkish_word.capitalize! }.to(change { turkish_word })
|
205
218
|
expect(turkish_word).to eq('Çamur')
|
206
219
|
end
|
@@ -211,11 +224,11 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
211
224
|
it 'compares Turkish characters correctly' do
|
212
225
|
result = downcased_turkish_alphabet.casecmp(upcased_turkish_alphabet)
|
213
226
|
|
214
|
-
expect(result.zero?).to
|
227
|
+
expect(result.zero?).to be true
|
215
228
|
end
|
216
229
|
|
217
230
|
it 'compares Turkish characters correctly' do
|
218
|
-
expect('sıtkı'.casecmp('SıTKI')&.zero?).to
|
231
|
+
expect('sıtkı'.casecmp('SıTKI')&.zero?).to be true
|
219
232
|
end
|
220
233
|
end
|
221
234
|
|
@@ -223,40 +236,40 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
223
236
|
context 'with non-destructive version' do
|
224
237
|
it 'does not change the original value of the string' do
|
225
238
|
word = 'mERHABA çAMUR iSMETOĞULLARI'
|
239
|
+
|
226
240
|
expect { word.titleize }.to_not(change { word })
|
227
241
|
end
|
228
242
|
|
229
243
|
it 'upcases first character of all words' do
|
230
244
|
titleized = 'merhaba çamur ismet'.titleize
|
245
|
+
|
231
246
|
expect(titleized).to(eq('Merhaba Çamur İsmet'))
|
232
247
|
end
|
233
248
|
|
234
249
|
it 'no problem with words that consist of special chars only' do
|
235
250
|
titleized = '(( merhaba çamur ismet'.titleize
|
251
|
+
|
236
252
|
expect(titleized).to(eq('(( Merhaba Çamur İsmet'))
|
237
253
|
end
|
238
254
|
|
239
255
|
it 'downcases characters other than first characters of all words' do
|
240
256
|
titleized = 'mERHABA çAMUR iSMETOĞULLARI'.titleize
|
257
|
+
|
241
258
|
expect(titleized).to(eq('Merhaba Çamur İsmetoğulları'))
|
242
259
|
end
|
243
260
|
|
244
261
|
it 'support strings that include paranthesis, quotes, etc.' do
|
245
262
|
titleized = "rUBY roCkS... (really! 'tRUSt' ME)".titleize
|
246
|
-
expect(titleized).to(eq("Ruby Rocks... (Really! 'Trust' Me)"))
|
247
|
-
end
|
248
263
|
|
249
|
-
|
250
|
-
titleized = 'kerem VE aslı VeYa leyla İlE mecnun'.titleize(conjuction: false)
|
251
|
-
expect(titleized).to eq('Kerem ve Aslı veya Leyla ile Mecnun')
|
264
|
+
expect(titleized).to(eq("Ruby Rocks... (Really! 'Trust' Me)"))
|
252
265
|
end
|
253
266
|
end
|
254
267
|
|
255
268
|
context 'with destructive version' do
|
256
269
|
it 'changes the original value of the string' do
|
257
270
|
word = 'mERHABA çAMUR iSMETOĞULLARI'
|
258
|
-
expect { word.titleize! }.to(change { word })
|
259
271
|
|
272
|
+
expect { word.titleize! }.to(change { word })
|
260
273
|
expect(word).to(eq('Merhaba Çamur İsmetoğulları'))
|
261
274
|
end
|
262
275
|
end
|
@@ -266,11 +279,13 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
266
279
|
context 'with non-destructive version' do
|
267
280
|
it 'does not change the original value of the string' do
|
268
281
|
word = 'mErHaba çamur ismetoğullarI'
|
282
|
+
|
269
283
|
expect { word.swapcase }.to_not(change { word })
|
270
284
|
end
|
271
285
|
|
272
286
|
it 'swaps characters correctly' do
|
273
287
|
word = 'mErHaba çamur ismetoğullarI'.swapcase
|
288
|
+
|
274
289
|
expect(word).to(eq('MeRhABA ÇAMUR İSMETOĞULLARı'))
|
275
290
|
end
|
276
291
|
end
|
@@ -278,6 +293,7 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
278
293
|
context 'with destructive version' do
|
279
294
|
it 'changes the original value of the string' do
|
280
295
|
word = 'mErHaba çamur ismetoğullarI'
|
296
|
+
|
281
297
|
expect { word.swapcase! }.to(change { word })
|
282
298
|
expect(word).to(eq('MeRhABA ÇAMUR İSMETOĞULLARı'))
|
283
299
|
end
|
@@ -317,7 +333,7 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
317
333
|
end
|
318
334
|
|
319
335
|
it "matches Turkish characters when regex include '\\w'" do
|
320
|
-
expect(turkish_words.join(' ').scan(/\W+/).map(&:strip).all?(&:empty?)).to
|
336
|
+
expect(turkish_words.join(' ').scan(/\W+/).map(&:strip).all?(&:empty?)).to be true
|
321
337
|
end
|
322
338
|
end
|
323
339
|
|
@@ -325,6 +341,7 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
325
341
|
context 'non-destructive version' do
|
326
342
|
it 'does not affect the object' do
|
327
343
|
word = 'ağapaşa ağa'
|
344
|
+
|
328
345
|
expect { word.sub(/\w+/, 'bey') }.to_not(change { word })
|
329
346
|
end
|
330
347
|
|
@@ -338,6 +355,7 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
338
355
|
context 'destructive version' do
|
339
356
|
it 'affects the object' do
|
340
357
|
word = 'ağapaşa ağa'
|
358
|
+
|
341
359
|
expect { word.sub!(/\w+/, 'bey') }.to(change { word }.from('ağapaşa ağa').to('bey ağa'))
|
342
360
|
end
|
343
361
|
end
|
@@ -347,6 +365,7 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
347
365
|
context 'non-destructive version' do
|
348
366
|
it 'does not affect the object' do
|
349
367
|
word = 'ağapaşa ağa'
|
368
|
+
|
350
369
|
expect { word.gsub(/\w+/, 'bey') }.to_not(change { word })
|
351
370
|
end
|
352
371
|
|
@@ -360,11 +379,44 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
360
379
|
context 'destructive version' do
|
361
380
|
it 'affects the object' do
|
362
381
|
word = 'ağapaşa ağa'
|
382
|
+
|
363
383
|
expect { word.gsub!(/\w+/, 'bey') }.to(change { word }.from('ağapaşa ağa').to('bey bey'))
|
364
384
|
end
|
365
385
|
end
|
366
386
|
end
|
367
387
|
|
388
|
+
describe '#>' do
|
389
|
+
it 'should compares turkish cars correctly' do
|
390
|
+
expect('d' > 'ç').to be true
|
391
|
+
expect('ağa' > 'aga').to be true
|
392
|
+
expect('ğ' > 'h').to be false
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
describe '#>=' do
|
397
|
+
it 'should compares turkish cars correctly' do
|
398
|
+
expect('d' >= 'ç').to be true
|
399
|
+
expect('aha' >= 'ağa').to be true
|
400
|
+
expect('ğ.' >= 'ğ').to be true
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe '#<' do
|
405
|
+
it 'should compares turkish cars correctly' do
|
406
|
+
expect('d' < 'ç').to be false
|
407
|
+
expect('ağa' < 'aga').to be false
|
408
|
+
expect('ğ' < 'h').to be true
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
describe '#<=' do
|
413
|
+
it 'should compares turkish cars correctly' do
|
414
|
+
expect('d' <= 'ç').to be false
|
415
|
+
expect('aha' <= 'ağa').to be false
|
416
|
+
expect('ğ.' <= 'ğ').to be false
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
368
420
|
describe '#<=>' do
|
369
421
|
let(:sorted_equal_length_strings) { %w[Cahit Çağla Ömer Sıtkı Şakir] }
|
370
422
|
let(:sorted_different_length_strings) { %w[c ca falan om saki sıt] }
|
@@ -404,10 +456,10 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
404
456
|
|
405
457
|
context 'invalid comparisons' do
|
406
458
|
it 'returns nil' do
|
407
|
-
expect('a' <=> 3.5).to
|
408
|
-
expect('a' <=> true).to
|
409
|
-
expect('a' <=> Object.new).to
|
410
|
-
expect('a' <=> 1).to
|
459
|
+
expect('a' <=> 3.5).to be nil
|
460
|
+
expect('a' <=> true).to be nil
|
461
|
+
expect('a' <=> Object.new).to be nil
|
462
|
+
expect('a' <=> 1).to be nil
|
411
463
|
end
|
412
464
|
end
|
413
465
|
end
|