turkish_support 1.1.3 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ea4d5444e4bb6da4e3b833a0722f6d7f3540e4ce4271500f8807e84c91d72af
4
- data.tar.gz: 63d120ac7d6794356019abb14f0cad1aad6d1af76277209581f821bbd3d56e66
3
+ metadata.gz: 661daa780f4a86533a3e5b3d7607b5d131549c928ab65db35598f93fbf89c103
4
+ data.tar.gz: 6006aa50c352658fbac41af13e40e77c49e09ea9887bb2ac605457f0734f14ad
5
5
  SHA512:
6
- metadata.gz: a8f9d5c9c02da13a3bf45b59e09937702382422d7ae08c63a9e7aab7853052a1e73716c0ba5079fcdf5310b30dd2b4100f35c186ca943513e2a04345da1470c6
7
- data.tar.gz: 2de927b3c9352ce60a2e650da231fe08c76b5ecc7fc04479bf06cf9fe61603988c798d5f675cbcfa302e09c1585cca6512469719781c7f58b311d74488e077da
6
+ metadata.gz: 2b06283e2a0626719a52e3e18e26bc3c4555ecedc2f2e7b05dd998a15953ef0ddf0cbf0b00ce88364941e3c8451467f9d24b6a3ee972f52422e6133e67ff1a30
7
+ data.tar.gz: e1cffa240cec788281aee54e8a1435255f90e4757b945e5768d100d48408168071a3137e1ba1597d1ce46d8383635e2c426b9fdb9371b02fde58edf38aeb5af0
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  todo.txt
19
+ .idea/*
@@ -1,3 +1,5 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
1
3
  StringLiterals:
2
4
  EnforcedStyle: single_quotes
3
5
  Documentation:
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
3
+ - 2.7.0
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2017 Sıtkı Bağdat
1
+ Copyright (c) 2014-2020 Sıtkı Bağdat
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -7,8 +7,8 @@ Turkish character support for core ruby methods. This gem provides support nearl
7
7
 
8
8
  ## Requirements
9
9
 
10
- * Ruby >= 2.2.0
11
- * Rails >= 4.0.0
10
+ * Ruby >= 2.7.0
11
+ * Rails >= 6.0.0
12
12
 
13
13
  __Notice:__ TurkishSupport uses __refinements__ instead of monkey patching.
14
14
 
@@ -20,7 +20,6 @@ __Notice:__ TurkishSupport uses __refinements__ instead of monkey patching.
20
20
  * [String Methods](#string-methods)
21
21
  * [#<=>](#-spaceship)
22
22
  * [#[] and #[]=](#-and-)
23
- * [#=~](#-equal-tilda)
24
23
  * [capitalize](#capitalize-and-capitalize)
25
24
  * [casecmp](#casecmp)
26
25
  * [downcase](#downcase-and-downcase)
@@ -139,12 +138,6 @@ If you want to use original set of the core methods in the same scope, you can u
139
138
  'Çetin'[/[a-ğ]+/i] # => "Çe"
140
139
  ```
141
140
 
142
- ### =~ (equal-tilda)
143
-
144
- ```ruby
145
- 'Bağlarbaşı Çarşı Kalabalık' =~ (/[s-ü]+/i) # => 8
146
- ```
147
-
148
141
  ### capitalize and capitalize!
149
142
 
150
143
  ```ruby
@@ -1,56 +1,38 @@
1
- module TurkishSupportHelpers
2
- ALPHA = {
3
- lower: 'abcçdefgğhıijklmnoöpqrsştuüvwxyz',
4
- upper: 'ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ',
5
- tr_lower: 'çğıiöşü',
6
- tr_upper: 'ÇĞIİÖŞÜ'
7
- }.freeze
1
+ # frozen_string_literal: true
8
2
 
3
+ module TurkishSupportHelpers
4
+ ALPHA = { lower: 'abcçdefgğhıijklmnoöpqrsştuüvwxyz',
5
+ upper: 'ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ',
6
+ tr_lower: 'çğıiöşü',
7
+ tr_upper: 'ÇĞIİÖŞÜ' }.freeze
9
8
  ALPHABET = ALPHA[:upper] + ALPHA[:lower]
10
-
11
- ASCII_ALPHABET = ALPHABET.chars.map.with_index do |ch, i|
12
- # Add 65 to put special chars and numbers in correct order
13
- [ch, i + 65]
14
- end.to_h
15
-
16
- META_CHARS = {
17
- '\w' => '[\p{Latin}\d_]',
18
- '\W' => '[^\p{Latin}\d_]'
19
- }.freeze
20
-
21
- # Regexp required methods
22
- RE_RE_METHS = %i(match scan).freeze
23
-
24
- # Regexp optional methods
25
- RE_OP_METHS = %i(
26
- []
27
- []=
28
- =~
29
- index
30
- rindex
31
- partition
32
- rpartition
33
- slice
34
- slice!
35
- split
36
- sub
37
- sub!
38
- gsub
39
- gsub!
40
- ).freeze
41
-
42
- CASE_RELATED_METHS = %i(
43
- downcase
44
- downcase!
45
- upcase
46
- upcase!
47
- capitalize
48
- capitalize!
49
- ).freeze
9
+ ASCII_ALPHABET = ALPHABET.chars.map.with_index { |ch, i| [ch, i + 65] }.to_h
10
+ META_CHARS = { '\w' => '[\p{Latin}\d_]', '\W' => '[^\p{Latin}\d_]' }.freeze
50
11
 
51
- RANGE_REGEXP = /\[[^\]]*?([#{ALPHABET}]-[#{ALPHABET}])[^\[]*?\]/
12
+ CASE_RELATED_METHS = %i[downcase
13
+ downcase!
14
+ upcase
15
+ upcase!
16
+ capitalize
17
+ capitalize!].freeze
52
18
 
53
- CONJUCTIONS = %w(ve ile veya).freeze
19
+ REGEX_REQUIRED_METHODS = %i[match scan].freeze
20
+ REGEX_OPTIONAL_METHODS = %i[[]
21
+ []=
22
+ index
23
+ rindex
24
+ partition
25
+ rpartition
26
+ slice
27
+ slice!
28
+ split
29
+ sub
30
+ sub!
31
+ gsub
32
+ gsub!].freeze
33
+ REGEX_METHS = REGEX_REQUIRED_METHODS + REGEX_OPTIONAL_METHODS
34
+ RANGE_REGEXP = /\[[^\]]*?([#{ALPHABET}]-[#{ALPHABET}])[^\[]*?\]/.freeze
54
35
 
55
- SPECIAL_CHARS = %q{("'}.freeze
36
+ CONJUCTION = %w[ve ile veya].freeze
37
+ SPECIAL_CHARS = %q{("'}
56
38
  end
@@ -6,7 +6,7 @@ module TurkishSupportHelpers
6
6
 
7
7
  while re.match(RANGE_REGEXP)
8
8
  re.scan(RANGE_REGEXP).flatten.compact.each do |matching|
9
- re.gsub! matching, translate_range(matching, pattern.casefold?)
9
+ re.gsub! matching, translate_range(matching, casefold: pattern.casefold?)
10
10
  end
11
11
  end
12
12
 
@@ -14,38 +14,28 @@ module TurkishSupportHelpers
14
14
  Regexp.new(re.force_encoding('UTF-8'), Regexp::FIXEDENCODING | options)
15
15
  end
16
16
 
17
- def translate_range(range_as_string, casefold = false)
17
+ def translate_range(range_as_string, casefold: false)
18
18
  return '' unless range_as_string
19
19
 
20
- range_as_string.gsub!(/\[\]/, '')
20
+ range_as_string = range_as_string.gsub(/\[\]/, '')
21
21
  first, last = range_as_string.split('-')
22
-
23
22
  expand_range(first, last, casefold)
24
23
  end
25
24
 
26
- def prepare_for(meth, string)
27
- valid_meths = %i[upcase downcase capitalize]
28
- unless valid_meths.include?(meth) && string.is_a?(String)
29
- raise ArgumentError, 'Invalid arguments for method `prepare_for`!'
30
- end
31
-
32
- method("prepare_for_#{meth}").call(string)
25
+ def tr_char?(char)
26
+ tr_lower?(char) || tr_upper?(char)
33
27
  end
34
28
 
35
- def tr_char?(ch)
36
- tr_lower?(ch) || tr_upper?(ch)
29
+ def tr_lower?(char)
30
+ ALPHA[:tr_lower].include? char
37
31
  end
38
32
 
39
- def tr_lower?(ch)
40
- ALPHA[:tr_lower].include? ch
41
- end
42
-
43
- def tr_upper?(ch)
44
- ALPHA[:tr_upper].include? ch
33
+ def tr_upper?(char)
34
+ ALPHA[:tr_upper].include? char
45
35
  end
46
36
 
47
37
  def conjuction?(string)
48
- CONJUCTIONS.include? string
38
+ CONJUCTION.include? string
49
39
  end
50
40
 
51
41
  def start_with_a_special_char?(string)
@@ -54,21 +44,6 @@ module TurkishSupportHelpers
54
44
 
55
45
  private
56
46
 
57
- def prepare_for_upcase(string)
58
- string.tr(ALPHA[:tr_lower], ALPHA[:tr_upper])
59
- end
60
-
61
- def prepare_for_downcase(string)
62
- string.tr(ALPHA[:tr_upper], ALPHA[:tr_lower])
63
- end
64
-
65
- def prepare_for_capitalize(string)
66
- [
67
- prepare_for(:upcase, string.chr).upcase,
68
- prepare_for(:downcase, self[1..-1]).downcase
69
- ].join
70
- end
71
-
72
47
  def expand_range(first, last, casefold)
73
48
  if lower.include?(first) && lower.include?(last)
74
49
  downcase_range(first, last, casefold)
@@ -91,6 +66,7 @@ module TurkishSupportHelpers
91
66
 
92
67
  def lower(first = nil, last = nil)
93
68
  return ALPHA[:lower] if first.nil? || last.nil?
69
+
94
70
  ALPHA[:lower][ALPHA[:lower].index(first)..ALPHA[:lower].index(last)]
95
71
  end
96
72
 
@@ -100,6 +76,7 @@ module TurkishSupportHelpers
100
76
 
101
77
  def upper(first = nil, last = nil)
102
78
  return ALPHA[:upper] if first.nil? || last.nil?
79
+
103
80
  ALPHA[:upper][ALPHA[:upper].index(first)..ALPHA[:upper].index(last)]
104
81
  end
105
82
 
@@ -1,50 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TurkishSupport
2
4
  refine String do # rubocop:disable Metrics/BlockLength
3
- (RE_RE_METHS + RE_OP_METHS).each do |meth|
5
+ REGEX_METHS.each do |meth|
4
6
  define_method meth do |*args|
5
- extend(TurkishSupportHelpers)
6
-
7
- if RE_RE_METHS.include?(meth) || args[0].is_a?(Regexp)
8
- args[0] = translate_regexp(args[0])
9
- end
7
+ extend TurkishSupportHelpers
10
8
 
11
- super(*args)
9
+ args[0] = translate_regexp(args[0]) if REGEX_REQUIRED_METHODS.include?(meth) || args[0].is_a?(Regexp)
10
+ instance_exec { super(*args) }
12
11
  end
13
12
  end
14
13
 
15
14
  CASE_RELATED_METHS.each do |meth|
16
- non_destructive = meth.to_s.chomp('!').to_sym
17
- define_method(meth) do
18
- extend(TurkishSupportHelpers)
19
- str = prepare_for(non_destructive, self).public_send(non_destructive)
20
- return meth.to_s.end_with?('!') ? public_send(:replace, str) : str
21
- end
15
+ define_method(meth) { super(:turkic) }
22
16
  end
23
17
 
24
- def titleize(conjuctions = true) # rubocop:disable Metrics/AbcSize
25
- split.map do |word|
26
- word.downcase!
27
- if conjuction?(word) && !conjuctions
18
+ def titleize(conjuction: true)
19
+ extend TurkishSupportHelpers
20
+
21
+ downcase.split.map do |word|
22
+ if !conjuction && conjuction?(word)
28
23
  word
29
24
  elsif start_with_a_special_char?(word)
30
- word.size > 1 ? word[0] + word[1..-1].capitalize : word.chr
25
+ word.chr + (word.length > 1 ? word[1..].capitalize : '')
31
26
  else
32
27
  word.capitalize
33
28
  end
34
29
  end.join(' ')
35
30
  end
36
31
 
37
- def titleize!(conjuctions = true)
38
- replace(titleize(conjuctions))
32
+ def titleize!(conjuction: true)
33
+ replace(titleize(conjuction: conjuction))
39
34
  end
40
35
 
41
36
  def swapcase
42
- extend(TurkishSupportHelpers)
43
- chars.map do |ch|
44
- if tr_char?(ch)
45
- tr_lower?(ch) ? ch.upcase : ch.downcase
37
+ extend TurkishSupportHelpers
38
+
39
+ chars.map do |c|
40
+ if tr_char?(c)
41
+ tr_lower?(c) ? c.upcase : c.downcase
46
42
  else
47
- ch.public_send(:swapcase)
43
+ c.instance_exec { super }
48
44
  end
49
45
  end.join
50
46
  end
@@ -53,26 +49,26 @@ module TurkishSupport
53
49
  replace(swapcase)
54
50
  end
55
51
 
56
- def casecmp(other_string)
57
- upcase.public_send(:casecmp, other_string.upcase)
52
+ def casecmp(other)
53
+ upcase.instance_exec { super(other.upcase) }
58
54
  end
59
55
 
60
- def <=>(other_string)
61
- return nil unless other_string.is_a? String
56
+ def <=>(other)
57
+ return nil unless other.is_a? String
62
58
 
63
59
  each_char.with_index do |ch, i|
64
60
  position1 = ASCII_ALPHABET[ch]
65
- position2 = ASCII_ALPHABET[other_string[i]]
61
+ position2 = ASCII_ALPHABET[other[i]]
66
62
 
67
63
  return (position2.nil? ? 0 : -1) if position1.nil?
68
64
  return 1 if position2.nil?
69
65
  return (position1 < position2 ? -1 : 1) if position1 != position2
70
66
  end
71
67
 
72
- return 0 if length == other_string.length
73
- return -1 if length < other_string.length
74
- return 1
75
-
68
+ return 0 if length == other.length
69
+ return -1 if length < other.length
70
+
71
+ 1
76
72
  end
77
73
  end
78
74
  end
@@ -1,3 +1,3 @@
1
1
  module TurkishSupport
2
- VERSION = '1.1.3'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'turkish_support/helpers'
3
5
 
@@ -13,176 +15,90 @@ describe 'TurkishSupportHelpers' do
13
15
  let(:tr_specific_lower) { 'çğıiöşü' }
14
16
  let(:tr_specific_upper) { 'ÇĞIİÖŞÜ' }
15
17
  let(:tr_all) { tr_specific_upper + tr_specific_lower }
16
- let(:conjuctions) { %w(ve ile veya) }
17
- let(:turkish_words) { %w(çamur ıhlamur insan ördek şahika ümraniye) }
18
- let(:special_chars) { %w{ ( " ' } }
19
-
20
- describe '#prepare_for' do
21
- context ':upcase' do
22
- it "replaces unsupported lower case letters with their upper cases'" do
23
- expect(prepare_for(:upcase, 'çğıiöşü'))
24
- .to eq('ÇĞIİÖŞÜ')
25
- end
26
- end
27
-
28
- context ':downcase' do
29
- it "replaces unsupported upper case letters with their lower cases'" do
30
- expect(prepare_for(:downcase, 'ÇĞIİÖŞÜ'))
31
- .to eq('çğıiöşü')
32
- end
33
- end
34
-
35
- context ':capitalize' do
36
- it 'replaces unsupported upper case and lower case letters' do
37
- dbl = double
38
- allow(dbl)
39
- .to receive(:prepare_for)
40
- .with(:capitalize, 'çaĞLAyan')
41
- .and_return('Çağlayan')
42
-
43
- expect(dbl.prepare_for(:capitalize, 'çaĞLAyan'))
44
- .to eq('Çağlayan')
45
- end
46
- end
47
-
48
- context 'with invalid parameters' do
49
- it 'raises an error if any parameter is not valid' do
50
- expect { prepare_for(:not_valid, :not_valid) }
51
- .to raise_error ArgumentError,
52
- 'Invalid arguments for method `prepare_for`!'
53
- expect { prepare_for(:swapcase, 'ÇĞ') }
54
- .to raise_error ArgumentError,
55
- 'Invalid arguments for method `prepare_for`!'
56
- expect { prepare_for(:upcase, 123) }
57
- .to raise_error ArgumentError,
58
- 'Invalid arguments for method `prepare_for`!'
59
- end
60
- end
61
- end
18
+ let(:conjuctions) { %w[ve ile veya] }
19
+ let(:turkish_words) { %w[çamur ıhlamur insan ördek şahika ümraniye] }
20
+ let(:special_chars) { %w[( " '] }
62
21
 
63
22
  describe '#tr_lower?' do
64
23
  it 'returns true for any Turkish specific lower case character' do
65
- expect(tr_specific_lower
66
- .chars
67
- .all? { |ch| tr_lower?(ch) })
68
- .to eq(true)
24
+ expect(tr_specific_lower.chars.all? { |ch| tr_lower?(ch) }).to(eq(true))
69
25
  end
70
26
 
71
27
  context 'returns false' do
72
28
  it 'for non-Turkish specific lower case characters' do
73
- expect(downcased_alphabet
74
- .delete(tr_specific_lower)
75
- .chars
76
- .any? { |ch| tr_lower?(ch) }
77
- ).to eq(false)
29
+ expect(downcased_alphabet.delete(tr_specific_lower).chars.any? { |ch| tr_lower?(ch) }).to(eq(false))
78
30
  end
79
31
 
80
32
  it 'for any upper case characters' do
81
- expect(upcased_alphabet
82
- .chars
83
- .any? { |ch| tr_lower?(ch) }
84
- ).to eq(false)
33
+ expect(upcased_alphabet.chars.any? { |ch| tr_lower?(ch) }).to(eq(false))
85
34
  end
86
35
 
87
36
  it 'for non-letter characters' do
88
- expect("\"é1!2'3^+4.,-_"
89
- .chars
90
- .any? { |ch| tr_lower?(ch) }
91
- ).to eq(false)
37
+ expect("\"é1!2'3^+4.,-_".chars.any? { |ch| tr_lower?(ch) }).to(eq(false))
92
38
  end
93
39
  end
94
40
  end
95
41
 
96
42
  describe '#tr_upper?' do
97
43
  it 'returns true for any Turkish specific upper case character' do
98
- expect(tr_specific_upper
99
- .chars
100
- .all? { |ch| tr_upper?(ch) }
101
- ).to eq(true)
44
+ expect(tr_specific_upper.chars.all? { |ch| tr_upper?(ch) }).to(eq(true))
102
45
  end
103
46
 
104
47
  context 'returns false' do
105
48
  it 'for non-Turkish specific upper case characters' do
106
- expect(upcased_alphabet
107
- .delete(tr_specific_upper)
108
- .chars
109
- .any? { |ch| tr_upper?(ch) }
110
- ).to eq(false)
49
+ expect(upcased_alphabet.delete(tr_specific_upper).chars.any? { |ch| tr_upper?(ch) }).to(eq(false))
111
50
  end
112
51
 
113
52
  it 'for any lower case characters' do
114
- expect(downcased_alphabet
115
- .chars
116
- .any? { |ch| tr_upper?(ch) }
117
- ).to eq(false)
53
+ expect(downcased_alphabet.chars.any? { |ch| tr_upper?(ch) }).to(eq(false))
118
54
  end
119
55
 
120
56
  it 'for non-letter characters' do
121
- expect("\"é1!2'3^+4.,-_"
122
- .chars
123
- .any? { |ch| tr_upper?(ch) }
124
- ).to eq(false)
57
+ expect("\"é1!2'3^+4.,-_".chars.any? { |ch| tr_upper?(ch) }).to(eq(false))
125
58
  end
126
59
  end
127
60
  end
128
61
 
129
62
  describe '#tr_char?' do
130
63
  it 'returns true for any Turkish specific character' do
131
- expect(tr_all
132
- .chars
133
- .all? { |ch| tr_char?(ch) }
134
- ).to eq(true)
64
+ expect(tr_all.chars.all? { |ch| tr_char?(ch) }).to(eq(true))
135
65
  end
136
66
 
137
67
  context 'returns false' do
138
68
  it 'for non-Turkish specific characters' do
139
- expect(alphabet.delete(tr_all)
140
- .chars
141
- .any? { |ch| tr_char?(ch) }
142
- ).to eq(false)
69
+ expect(alphabet.delete(tr_all).chars.any? { |ch| tr_char?(ch) }).to(eq(false))
143
70
  end
144
71
 
145
72
  it 'for non-letter characters' do
146
- expect("\"é1!2'3^+4.,-_"
147
- .chars
148
- .any? { |ch| tr_char?(ch) }
149
- ).to eq(false)
73
+ expect("\"é1!2'3^+4.,-_".chars.any? { |ch| tr_char?(ch) }).to(eq(false))
150
74
  end
151
75
  end
152
76
  end
153
77
 
154
78
  describe '#conjuction?' do
155
79
  it 'returns true for any conjuction' do
156
- expect(conjuctions
157
- .all? { |c| conjuction?(c) }
158
- ).to eq(true)
80
+ expect(conjuctions.all? { |c| conjuction?(c) }).to(eq(true))
159
81
  end
160
82
 
161
83
  it 'returns false for any word contains conjuction' do
162
- expect(%w(veda aile veyahut)
163
- .any? { |c| conjuction?(c) }
164
- ).to eq(false)
84
+ expect(%w[veda aile veyahut].any? { |c| conjuction?(c) }).to(eq(false))
165
85
  end
166
86
  end
167
87
 
168
88
  describe '#start_with_a_special_char?' do
169
89
  it 'returns true for all words starts with a special char' do
170
90
  special_words = turkish_words.map { |w| special_chars.sample + w }
171
- expect(special_words
172
- .all? { |word| start_with_a_special_char?(word) }
173
- ).to eq(true)
91
+ expect(special_words.all? { |word| start_with_a_special_char?(word) }).to(eq(true))
174
92
  end
175
93
 
176
94
  it 'returns false any words not starts with a special char' do
177
- expect(turkish_words
178
- .any? { |word| start_with_a_special_char?(word) }
179
- ).to eq(false)
95
+ expect(turkish_words.any? { |word| start_with_a_special_char?(word) }).to(eq(false))
180
96
  end
181
97
  end
182
98
 
183
99
  describe '#translate_range' do
184
100
  it 'translates a complete lower-case range correctly' do
185
- expect(translate_range('a-z')).to eq(downcased_alphabet)
101
+ expect(translate_range('a-z')).to(eq(downcased_alphabet))
186
102
  end
187
103
 
188
104
  it 'translates a complete upper-case range correctly' do
@@ -193,65 +109,52 @@ describe 'TurkishSupportHelpers' do
193
109
  invalid_arguments = %w(1-Z A-9 1-9 a-])
194
110
  expect(invalid_arguments
195
111
  .all? do |arg|
196
- expect { translate_range(arg) }
197
- .to raise_error ArgumentError,
198
- 'Invalid regexp range arguments!'
199
- end
200
- ).to eq(true)
112
+ expect { translate_range(arg) }
113
+ .to raise_error ArgumentError,
114
+ 'Invalid regexp range arguments!'
115
+ end).to eq(true)
201
116
  end
202
117
 
203
118
  it 'raises an error if arguments are not in same case' do
204
119
  expect { translate_range('a-Z') }
205
- .to raise_error ArgumentError,
206
- 'Invalid regexp range arguments!'
120
+ .to(raise_error(ArgumentError, 'Invalid regexp range arguments!'))
207
121
  end
208
122
 
209
123
  it 'translates a partial range correctly' do
210
- expect(translate_range('d-t'))
211
- .to eq('defgğhıijklmnoöpqrsşt')
212
- expect(translate_range('Ç-Ü'))
213
- .to eq('ÇDEFGĞHIİJKLMNOÖPQRSŞTUÜ')
124
+ expect(translate_range('d-t')).to(eq('defgğhıijklmnoöpqrsşt'))
125
+ expect(translate_range('Ç-Ü')).to(eq('ÇDEFGĞHIİJKLMNOÖPQRSŞTUÜ'))
214
126
  end
215
127
 
216
128
  it 'translates a range correctly when casefold option is true' do
217
- expect(translate_range('d-t', true))
218
- .to eq('defgğhıijklmnoöpqrsştĞIİÖŞ')
219
- expect(translate_range('C-U', true))
220
- .to eq('CÇDEFGĞHIİJKLMNOÖPQRSŞTUçğıiöş')
129
+ expect(translate_range('d-t', casefold: true)).to(eq('defgğhıijklmnoöpqrsştĞIİÖŞ'))
130
+ expect(translate_range('C-U', casefold: true)).to(eq('CÇDEFGĞHIİJKLMNOÖPQRSŞTUçğıiöş'))
221
131
  end
222
132
 
223
133
  it 'translates ranges created using Turkish characters' do
224
- expect(translate_range('Ç-Ü', true))
225
- .to eq('ÇDEFGĞHIİJKLMNOÖPQRSŞTUÜçğıiöşü')
226
- expect(translate_range('ç-ü', true))
227
- .to eq('çdefgğhıijklmnoöpqrsştuüÇĞIİÖŞÜ')
134
+ expect(translate_range('Ç-Ü', casefold: true)).to(eq('ÇDEFGĞHIİJKLMNOÖPQRSŞTUÜçğıiöşü'))
135
+ expect(translate_range('ç-ü', casefold: true)).to(eq('çdefgğhıijklmnoöpqrsştuüÇĞIİÖŞÜ'))
228
136
  end
229
137
  end
230
138
 
231
139
  describe '#translate_regexp' do
232
140
  it 'translates simple regexp to include Turkish characters' do
233
- expect(translate_regexp(/\w+\s[a-h]/))
234
- .to eq(/[\p{Latin}\d_]+\s[abcçdefgğh]/)
141
+ expect(translate_regexp(/\w+\s[a-h]/)).to(eq(/[\p{Latin}\d_]+\s[abcçdefgğh]/))
235
142
  end
236
143
 
237
144
  it 'translates simple regexp range created with Turkish characters' do
238
- expect(translate_regexp(/[ç-ş]/))
239
- .to eq(/[çdefgğhıijklmnoöpqrsş]/)
145
+ expect(translate_regexp(/[ç-ş]/)).to(eq(/[çdefgğhıijklmnoöpqrsş]/))
240
146
  end
241
147
 
242
148
  it 'preserves flags' do
243
- expect(translate_regexp(/\w+/mixu))
244
- .to eq(/[\p{Latin}\d_]+/mixu)
149
+ expect(translate_regexp(/\w+/mixu)).to(eq(/[\p{Latin}\d_]+/mixu))
245
150
  end
246
151
 
247
152
  it 'translates many range inside a character class' do
248
- expect(translate_regexp(/[a-ht-üy-z]/))
249
- .to eq(/[abcçdefgğhtuüyz]/)
153
+ expect(translate_regexp(/[a-ht-üy-z]/)).to(eq(/[abcçdefgğhtuüyz]/))
250
154
  end
251
155
 
252
156
  it 'translates many range inside different character class' do
253
- expect(translate_regexp(/[a-ht-üy-z]\s[a-dr-z]/))
254
- .to eq(/[abcçdefgğhtuüyz]\s[abcçdrsştuüvwxyz]/)
157
+ expect(translate_regexp(/[a-ht-üy-z]\s[a-dr-z]/)).to(eq(/[abcçdefgğhtuüyz]\s[abcçdrsştuüvwxyz]/))
255
158
  end
256
159
 
257
160
  it 'does not translate ranges outside character class' do