kyanite 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/0 start all Tests.bat +23 -0
- data/History.txt +4 -0
- data/License.txt +21 -0
- data/Manifest.txt +88 -0
- data/PostInstall.txt +4 -0
- data/README.txt +48 -0
- data/Rakefile.rb +79 -0
- data/init.rb +2 -0
- data/lib/kyanite.rb +39 -0
- data/lib/kyanite/array.rb +5 -0
- data/lib/kyanite/array/array.rb +172 -0
- data/lib/kyanite/array/array2.rb +140 -0
- data/lib/kyanite/array/matrix2.rb +120 -0
- data/lib/kyanite/array_of_enumerables.rb +2 -0
- data/lib/kyanite/array_of_numerics.rb +2 -0
- data/lib/kyanite/array_of_strings.rb +2 -0
- data/lib/kyanite/basics.rb +60 -0
- data/lib/kyanite/dictionary.rb +116 -0
- data/lib/kyanite/enumerable.rb +7 -0
- data/lib/kyanite/enumerable/enumerable_enumerables.rb +70 -0
- data/lib/kyanite/enumerable/enumerable_numerics.rb +171 -0
- data/lib/kyanite/enumerable/enumerable_strings.rb +58 -0
- data/lib/kyanite/enumerable/structure.rb +170 -0
- data/lib/kyanite/general.rb +8 -0
- data/lib/kyanite/general/callerutils.rb +128 -0
- data/lib/kyanite/general/classutils.rb +246 -0
- data/lib/kyanite/general/kernel.rb +105 -0
- data/lib/kyanite/general/nil.rb +64 -0
- data/lib/kyanite/general/object.rb +86 -0
- data/lib/kyanite/general/true_false.rb +65 -0
- data/lib/kyanite/general/undoable.rb +24 -0
- data/lib/kyanite/hash.rb +170 -0
- data/lib/kyanite/matrix2.rb +2 -0
- data/lib/kyanite/nil.rb +3 -0
- data/lib/kyanite/numeric.rb +4 -0
- data/lib/kyanite/numeric/float.rb +26 -0
- data/lib/kyanite/numeric/integer.rb +34 -0
- data/lib/kyanite/numeric/numeric.rb +45 -0
- data/lib/kyanite/operation.rb +5 -0
- data/lib/kyanite/operation/call_tracker.rb +69 -0
- data/lib/kyanite/operation/rake.rb +101 -0
- data/lib/kyanite/operation/regexp.rb +23 -0
- data/lib/kyanite/operation/unit_test.rb +53 -0
- data/lib/kyanite/optimizer.rb +119 -0
- data/lib/kyanite/rake.rb +2 -0
- data/lib/kyanite/range.rb +54 -0
- data/lib/kyanite/set.rb +219 -0
- data/lib/kyanite/smart_load_path.rb +2 -0
- data/lib/kyanite/string.rb +13 -0
- data/lib/kyanite/string/cast.rb +104 -0
- data/lib/kyanite/string/chars.rb +184 -0
- data/lib/kyanite/string/chars_const.rb +190 -0
- data/lib/kyanite/string/diff.rb +78 -0
- data/lib/kyanite/string/div.rb +19 -0
- data/lib/kyanite/string/include.rb +43 -0
- data/lib/kyanite/string/list.rb +84 -0
- data/lib/kyanite/string/mgsub.rb +35 -0
- data/lib/kyanite/string/nested.rb +253 -0
- data/lib/kyanite/string/random.rb +69 -0
- data/lib/kyanite/string/split.rb +136 -0
- data/lib/kyanite/symbol.rb +19 -0
- data/lib/kyanite/tree.rb +99 -0
- data/lib/kyanite/undoable.rb +2 -0
- data/lib/kyanite/unit_test.rb +2 -0
- data/test/_start_all.rb +17 -0
- data/test/array/test_array.rb +106 -0
- data/test/array/test_matrix2.rb +162 -0
- data/test/enumerable/test_enumerable_enumerables.rb +46 -0
- data/test/enumerable/test_enumerable_numerics.rb +93 -0
- data/test/enumerable/test_enumerable_strings.rb +22 -0
- data/test/enumerable/test_structure.rb +220 -0
- data/test/general/test_classutils.rb +45 -0
- data/test/general/test_nil.rb +44 -0
- data/test/general/test_object.rb +49 -0
- data/test/general/test_true_false.rb +28 -0
- data/test/numeric/test_numeric_integer.rb +28 -0
- data/test/string/test_cast.rb +108 -0
- data/test/string/test_chars.rb +255 -0
- data/test/string/test_diff.rb +95 -0
- data/test/string/test_list.rb +141 -0
- data/test/string/test_nested.rb +361 -0
- data/test/string/test_split.rb +187 -0
- data/test/test_dictionary.rb +128 -0
- data/test/test_hash.rb +59 -0
- data/test/test_optimizer.rb +150 -0
- data/test/test_range.rb +41 -0
- data/test/test_set.rb +210 -0
- data/test/test_tree.rb +94 -0
- metadata +217 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/string/list'
|
7
|
+
require 'kyanite/string/chars'
|
8
|
+
WA_ABBREV = :abbrev unless defined?(WA_ABBREV)
|
9
|
+
|
10
|
+
|
11
|
+
class TestKyaniteStringList < UnitTest
|
12
|
+
|
13
|
+
|
14
|
+
def test_list_with_ohne_block
|
15
|
+
|
16
|
+
array = ['Anna','Birte','Charlie']
|
17
|
+
|
18
|
+
|
19
|
+
# normale Verwendung
|
20
|
+
assert_equal "kisses_from = 'Anna' OR kisses_from = 'Birte' OR kisses_from = 'Charlie'",
|
21
|
+
"kisses_from = ".list_with(array)
|
22
|
+
|
23
|
+
assert_equal "kisses_from='Anna' AND kisses_from='Birte' AND kisses_from='Charlie'",
|
24
|
+
"kisses_from=".list_with(array, :sep => ' AND ')
|
25
|
+
|
26
|
+
assert_equal "kisses_from='Anna' AND kisses_from='Birte'",
|
27
|
+
"kisses_from=".list_with(['Anna','Birte'], :sep => ' AND ')
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
# assert_equal 'kisses_from ="Anna" AND kisses_from ="Birte" AND kisses_from ="Charlie"',
|
33
|
+
# 'kisses_from ='.list_with(array, :pre => '"', :post => '"')
|
34
|
+
|
35
|
+
|
36
|
+
# leeres Array
|
37
|
+
assert_equal "FALSE", "kisses_from = ".list_with(nil)
|
38
|
+
assert_equal "FALSE", "kisses_from = ".list_with('')
|
39
|
+
assert_equal "FALSE", "kisses_from = ".list_with([])
|
40
|
+
assert_equal "FALSE", "kisses_from = ".list_with('', :sep => 'gg')
|
41
|
+
assert_equal "FALSE", "kisses_from = ".list_with('', :pre => 'gg')
|
42
|
+
assert_equal "FALSE", "kisses_from = ".list_with(nil, :post => 'gg')
|
43
|
+
assert_equal "", "kisses_from = ".list_with([], :empty => '')
|
44
|
+
|
45
|
+
# Einzelelement
|
46
|
+
assert_equal "kisses_from = 'Anna'", "kisses_from = ".list_with(['Anna'])
|
47
|
+
assert_equal "kisses_from = 'Anna'", "kisses_from = ".list_with('Anna')
|
48
|
+
assert_equal "kisses_from = 'Anna'", "kisses_from = ".list_with(['Anna'], :sep => ' AND ')
|
49
|
+
assert_equal "kisses_from = <Anna>", "kisses_from = ".list_with(['Anna'], :pre => '<', :post => '>')
|
50
|
+
|
51
|
+
|
52
|
+
array = [:multi, WA_ABBREV]
|
53
|
+
assert_equal "AND worte_from.kat_multi=1 OR worte_from.kat_abbrev=1",
|
54
|
+
'AND ' + 'worte_from.kat_'.list_with(array, :pre => '', :post => '=1', :sep => ' OR ', :empty => 'TRUE' )
|
55
|
+
|
56
|
+
array = [:multi]
|
57
|
+
assert_equal "AND worte_from.kat_multi=1",
|
58
|
+
'AND ' + 'worte_from.kat_'.list_with(array, :pre => '', :post => '=1', :sep => ' OR ', :empty => 'TRUE' )
|
59
|
+
|
60
|
+
array = []
|
61
|
+
assert_equal "AND TRUE",
|
62
|
+
'AND ' + 'worte_from.kat_'.list_with(array, :pre => '', :post => '=1', :sep => ' OR ', :empty => 'TRUE' )
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
def test_list_with_mit_block
|
70
|
+
|
71
|
+
array = ['Anna','Birte','Charlie']
|
72
|
+
|
73
|
+
|
74
|
+
# mit lesendem Block
|
75
|
+
assert_equal "kisses_from = 'anna' OR kisses_from = 'birte' OR kisses_from = 'charlie'",
|
76
|
+
"kisses_from = ".list_with(array) { |e| e.downcase2 }
|
77
|
+
|
78
|
+
# ohne Block: Objekte sind unver�ndert geblieben
|
79
|
+
assert_equal "kisses_from='Anna' AND kisses_from='Birte' AND kisses_from='Charlie'",
|
80
|
+
"kisses_from=".list_with(array, :sep => ' AND ')
|
81
|
+
|
82
|
+
|
83
|
+
# leeres Array
|
84
|
+
assert_equal "FALSE", "kisses_from = ".list_with(nil) { |e| e.downcase2 }
|
85
|
+
assert_equal "FALSE", "kisses_from = ".list_with('') { |e| e.downcase2 }
|
86
|
+
assert_equal "FALSE", "kisses_from = ".list_with([]) { |e| e.downcase2 }
|
87
|
+
assert_equal "FALSE", "kisses_from = ".list_with('', :sep => 'gg') { |e| e.downcase2 }
|
88
|
+
assert_equal "FALSE", "kisses_from = ".list_with('', :pre => 'gg') { |e| e.downcase2 }
|
89
|
+
assert_equal "FALSE", "kisses_from = ".list_with(nil, :post => 'gg') { |e| e.downcase2 }
|
90
|
+
assert_equal "", "kisses_from = ".list_with([], :empty => '') { |e| e.downcase2 }
|
91
|
+
|
92
|
+
# Einzelelement
|
93
|
+
einzelelement = ['Anna']
|
94
|
+
assert_equal "kisses_from = 'anna'", "kisses_from = ".list_with(einzelelement) { |e| e.downcase2 }
|
95
|
+
assert_equal "kisses_from = 'Anna'", "kisses_from = ".list_with(einzelelement)
|
96
|
+
assert_equal "kisses_from = 'anna'", "kisses_from = ".list_with(einzelelement, :sep => ' AND ') { |e| e.downcase2 }
|
97
|
+
assert_equal "kisses_from = 'Anna'", "kisses_from = ".list_with(einzelelement, :sep => ' AND ')
|
98
|
+
assert_equal "kisses_from = <anna>", "kisses_from = ".list_with(einzelelement, :pre => '<', :post => '>') { |e| e.downcase2 }
|
99
|
+
assert_equal "kisses_from = <Anna>", "kisses_from = ".list_with(einzelelement, :pre => '<', :post => '>')
|
100
|
+
einzelelement = 'Anna'
|
101
|
+
assert_equal "kisses_from = 'anna'", "kisses_from = ".list_with(einzelelement) { |e| e.downcase2 }
|
102
|
+
assert_equal "kisses_from = 'Anna'", "kisses_from = ".list_with(einzelelement)
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
end # class
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
@@ -0,0 +1,361 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/string/nested'
|
7
|
+
|
8
|
+
|
9
|
+
class TestKyaniteStringNested < UnitTest
|
10
|
+
|
11
|
+
def test_010_anti
|
12
|
+
test = '()[]<>{}'
|
13
|
+
test.split(//).each do |t|
|
14
|
+
assert_equal t, t.anti.anti
|
15
|
+
assert t != t.anti
|
16
|
+
end
|
17
|
+
assert_equal '</hallo>', '<hallo>'.anti
|
18
|
+
assert_equal '<hallo>', '</hallo>'.anti
|
19
|
+
assert_equal '*', '*'.anti
|
20
|
+
assert_equal '"', '"'.anti
|
21
|
+
assert_equal "'", "'".anti
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_020_index_bracket
|
26
|
+
test = 'Hallo welt wort'
|
27
|
+
assert_equal nil, test.index_bracket(/['"({<\[]/)
|
28
|
+
|
29
|
+
test = 'Hallo(welt)wort'
|
30
|
+
assert_equal 5..10, test.index_bracket(/['"({<\[]/)
|
31
|
+
assert_equal 5..10, test.index_bracket('(')
|
32
|
+
assert_equal nil, test.index_bracket(')')
|
33
|
+
assert_equal nil, test.index_bracket('(',6)
|
34
|
+
|
35
|
+
test = 'Hallo"welt"wort'
|
36
|
+
assert_equal 5..10, test.index_bracket(/['"({<\[]/)
|
37
|
+
assert_equal 5..10, test.index_bracket('"')
|
38
|
+
assert_equal nil, test.index_bracket(')')
|
39
|
+
assert_equal nil, test.index_bracket('(',6)
|
40
|
+
|
41
|
+
test = 'Hallo[welt]wort'
|
42
|
+
assert_equal 5..10, test.index_bracket(/['"({<\[]/)
|
43
|
+
|
44
|
+
test = '(hallo) [welt] wort'
|
45
|
+
assert_equal 0..6, test.index_bracket(/['"({<\[]/)
|
46
|
+
assert_equal 8..13, test.index_bracket(/['"({<\[]/, 1 )
|
47
|
+
|
48
|
+
test = 'Hallo(welt(klammer)bla(blubb)nuff)wort'
|
49
|
+
# see RULER
|
50
|
+
# see test
|
51
|
+
# see test[test.index_bracket('(',11)]
|
52
|
+
assert_equal 5..33, test.index_bracket(/['"({<\[]/)
|
53
|
+
assert_equal 10..18, test.index_bracket('(',6)
|
54
|
+
assert_equal 22..28, test.index_bracket('(',11)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
def test_030_mask_ungeklammert
|
65
|
+
assert_raise(ArgumentError) {result = test.mask(1,0) {|s| s.upcase} }
|
66
|
+
assert_raise(ArgumentError) {result = test.mask(nil,1) {|s| s.upcase} }
|
67
|
+
assert_raise(ArgumentError) {result = test.mask(1,nil) {|s| s.upcase} }
|
68
|
+
|
69
|
+
test = 'hallo'
|
70
|
+
|
71
|
+
result = test.mask {|s| s.upcase}
|
72
|
+
assert_equal 'hallo', result
|
73
|
+
result = test.mask {|s| '-'}
|
74
|
+
assert_equal 'hallo', result
|
75
|
+
result = test.mask {|s| "+#{s}+"}
|
76
|
+
assert_equal 'hallo', result
|
77
|
+
|
78
|
+
result = test.mask(:level_start => 0) {|s| s.upcase}
|
79
|
+
assert_equal 'HALLO', result
|
80
|
+
result = test.mask(:level_start => 0) {|s| '-'}
|
81
|
+
assert_equal '-', result
|
82
|
+
result = test.mask(:level_start => 0) {|s| "+#{s}+"}
|
83
|
+
assert_equal '+hallo+', result
|
84
|
+
|
85
|
+
result = test.mask(:level_start => 0, :level_end => 0) {|s| s.upcase}
|
86
|
+
assert_equal 'HALLO', result
|
87
|
+
result = test.mask(:level_start => 0, :level_end => 0) {|s| '-'}
|
88
|
+
assert_equal '-', result
|
89
|
+
result = test.mask(:level_start => 0, :level_end => 0) {|s| "+#{s}+"}
|
90
|
+
assert_equal '+hallo+', result
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def test_040_mask_eine_klammer
|
95
|
+
test = 'a_level_0(level1)b_level_0'
|
96
|
+
options = { :pattern => /\(/ }
|
97
|
+
|
98
|
+
result = test.mask(options) {|s| s.upcase}
|
99
|
+
assert_equal 'a_level_0(LEVEL1)b_level_0', result
|
100
|
+
result = test.mask(options) {|s| '-'}
|
101
|
+
assert_equal 'a_level_0(-)b_level_0', result
|
102
|
+
result = test.mask(options) {|s| " +#{s}+ "}
|
103
|
+
assert_equal 'a_level_0( +level1+ )b_level_0', result
|
104
|
+
|
105
|
+
result = test.mask( :level_start => 0,
|
106
|
+
:level_end => 0,
|
107
|
+
:pattern => /\(/
|
108
|
+
) {|s| s.upcase}
|
109
|
+
assert_equal 'A_LEVEL_0(level1)B_LEVEL_0', result
|
110
|
+
|
111
|
+
result = test.mask( :level_start => 0,
|
112
|
+
:level_end => 0,
|
113
|
+
:pattern => /\(/
|
114
|
+
) {|s| '-'}
|
115
|
+
assert_equal '-(level1)-', result
|
116
|
+
|
117
|
+
result = test.mask( :level_start => 0,
|
118
|
+
:level_end => 0,
|
119
|
+
:pattern => /\(/
|
120
|
+
) {|s| " +#{s}+ "}
|
121
|
+
assert_equal ' +a_level_0+ (level1) +b_level_0+ ', result
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def test_050_mask_zwei_klammern
|
126
|
+
test = 'r_level_0<a_level_1>s_level_0<b_level_1>t_level_0'
|
127
|
+
|
128
|
+
result = test.mask {|s| s.upcase}
|
129
|
+
assert_equal 'r_level_0<A_LEVEL_1>s_level_0<B_LEVEL_1>t_level_0', result
|
130
|
+
result = test.mask {|s| '-'}
|
131
|
+
assert_equal 'r_level_0<->s_level_0<->t_level_0', result
|
132
|
+
result = test.mask {|s| " +#{s}+ "}
|
133
|
+
assert_equal 'r_level_0< +a_level_1+ >s_level_0< +b_level_1+ >t_level_0', result
|
134
|
+
|
135
|
+
result = test.mask( :level_start => 0,
|
136
|
+
:level_end => 0 ) {|s| s.upcase}
|
137
|
+
assert_equal 'R_LEVEL_0<a_level_1>S_LEVEL_0<b_level_1>T_LEVEL_0', result
|
138
|
+
|
139
|
+
result = test.mask( :level_start => 0,
|
140
|
+
:level_end => 0 ) {|s| '-'}
|
141
|
+
assert_equal '-<a_level_1>-<b_level_1>-', result
|
142
|
+
|
143
|
+
result = test.mask( :level_start => 0,
|
144
|
+
:level_end => 0 ) {|s| " +#{s}+ "}
|
145
|
+
assert_equal ' +r_level_0+ <a_level_1> +s_level_0+ <b_level_1> +t_level_0+ ', result
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def test_060_mask_leer
|
150
|
+
test = ''
|
151
|
+
|
152
|
+
result = test.mask {|s| s.upcase}
|
153
|
+
assert_equal '', result
|
154
|
+
result = test.mask {|s| nil }
|
155
|
+
assert_equal '', result
|
156
|
+
result = test.mask {|s| '-'}
|
157
|
+
assert_equal '', result
|
158
|
+
result = test.mask {|s| s + '+'}
|
159
|
+
assert_equal '', result
|
160
|
+
|
161
|
+
result = test.mask( :level_start => 0,
|
162
|
+
:level_end => 0 ) {|s| s.upcase}
|
163
|
+
assert_equal '', result
|
164
|
+
|
165
|
+
result = test.mask( :level_start => 0,
|
166
|
+
:level_end => 0 ) {|s| nil}
|
167
|
+
assert_equal '', result
|
168
|
+
|
169
|
+
result = test.mask( :level_start => 0,
|
170
|
+
:level_end => 0 ) {|s| '-'}
|
171
|
+
assert_equal '-', result
|
172
|
+
|
173
|
+
result = test.mask( :level_start => 0,
|
174
|
+
:level_end => 0,
|
175
|
+
:skip_empty => true) {|s| '-'}
|
176
|
+
assert_equal '', result
|
177
|
+
|
178
|
+
result = test.mask( :level_start => 0,
|
179
|
+
:level_end => 0 ) {|s| s + '+'}
|
180
|
+
assert_equal '+', result
|
181
|
+
|
182
|
+
result = test.mask( :level_start => 0,
|
183
|
+
:level_end => 0,
|
184
|
+
:skip_empty => true) {|s| s + '+'}
|
185
|
+
assert_equal '', result
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
def test_070_mask_start_mit_level_1
|
190
|
+
options = { :pattern => /\(/ }
|
191
|
+
test = '(level1)level0'
|
192
|
+
|
193
|
+
result = test.mask(options) {|s| s.upcase}
|
194
|
+
assert_equal '(LEVEL1)level0', result
|
195
|
+
result = test.mask(options) {|s| '-'}
|
196
|
+
assert_equal '(-)level0', result
|
197
|
+
result = test.mask(options) {|s| "+#{s}+"}
|
198
|
+
assert_equal '(+level1+)level0', result
|
199
|
+
|
200
|
+
result = test.mask( :level_start => 0,
|
201
|
+
:level_end => 0,
|
202
|
+
:pattern => /\(/
|
203
|
+
) {|s| s.upcase}
|
204
|
+
assert_equal '(level1)LEVEL0', result
|
205
|
+
|
206
|
+
result = test.mask( :level_start => 0,
|
207
|
+
:level_end => 0,
|
208
|
+
:pattern => /\(/
|
209
|
+
) {|s| '-'}
|
210
|
+
assert_equal '-(level1)-', result
|
211
|
+
|
212
|
+
result = test.mask( :level_start => 0,
|
213
|
+
:level_end => 0,
|
214
|
+
:pattern => /\(/,
|
215
|
+
:skip_empty => true) {|s| '-'}
|
216
|
+
assert_equal '(level1)-', result
|
217
|
+
|
218
|
+
result = test.mask( :level_start => 0,
|
219
|
+
:level_end => 0,
|
220
|
+
:pattern => /\(/
|
221
|
+
) {|s| "+#{s}+"}
|
222
|
+
assert_equal '++(level1)+level0+', result
|
223
|
+
|
224
|
+
result = test.mask( :level_start => 0,
|
225
|
+
:level_end => 0,
|
226
|
+
:pattern => /\(/,
|
227
|
+
:skip_empty => true) {|s| "+#{s}+"}
|
228
|
+
assert_equal '(level1)+level0+', result
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
def test_080_mask_end_mit_level_1
|
233
|
+
test = 'level0(level1)'
|
234
|
+
options = { :pattern => /\(/ }
|
235
|
+
|
236
|
+
result = test.mask(options) {|s| s.upcase}
|
237
|
+
assert_equal 'level0(LEVEL1)', result
|
238
|
+
result = test.mask(options) {|s| '-'}
|
239
|
+
assert_equal 'level0(-)', result
|
240
|
+
result = test.mask(options) {|s| "+#{s}+"}
|
241
|
+
assert_equal 'level0(+level1+)', result
|
242
|
+
|
243
|
+
result = test.mask( :level_start => 0,
|
244
|
+
:level_end => 0,
|
245
|
+
:pattern => /\(/
|
246
|
+
) {|s| s.upcase}
|
247
|
+
assert_equal 'LEVEL0(level1)', result
|
248
|
+
|
249
|
+
result = test.mask( :level_start => 0,
|
250
|
+
:level_end => 0,
|
251
|
+
:pattern => /\(/
|
252
|
+
) {|s| '-'}
|
253
|
+
assert_equal '-(level1)-', result
|
254
|
+
|
255
|
+
result = test.mask( :level_start => 0,
|
256
|
+
:level_end => 0,
|
257
|
+
:pattern => /\(/,
|
258
|
+
:skip_empty => true) {|s| '-'}
|
259
|
+
assert_equal '-(level1)', result
|
260
|
+
|
261
|
+
result = test.mask( :level_start => 0,
|
262
|
+
:level_end => 0,
|
263
|
+
:pattern => /\(/
|
264
|
+
) {|s| "+#{s}+"}
|
265
|
+
assert_equal '+level0+(level1)++', result
|
266
|
+
|
267
|
+
result = test.mask( :level_start => 0,
|
268
|
+
:level_end => 0,
|
269
|
+
:pattern => /\(/,
|
270
|
+
:skip_empty => true) {|s| "+#{s}+"}
|
271
|
+
assert_equal '+level0+(level1)', result
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
def test_090_mask_multilevel
|
277
|
+
test = '((((()))))'
|
278
|
+
options = { :pattern => /\(/ }
|
279
|
+
|
280
|
+
result = test.mask(options) {|s| "+#{s}+"}
|
281
|
+
assert_equal '(++(++(++(++(++)++)++)++)++)', result
|
282
|
+
|
283
|
+
result = test.mask( :level_start => 0,
|
284
|
+
:skip_empty => false,
|
285
|
+
:pattern => /\(/
|
286
|
+
) {|s| "+#{s}+"}
|
287
|
+
assert_equal '++(++(++(++(++(++)++)++)++)++)++', result
|
288
|
+
|
289
|
+
result = test.mask( :level_start => 0,
|
290
|
+
:pattern => /\(/,
|
291
|
+
:skip_empty => true) {|s| "+#{s}+"}
|
292
|
+
assert_equal test, result
|
293
|
+
|
294
|
+
result = test.mask( :level_start => 2,
|
295
|
+
:level_end => 4,
|
296
|
+
:pattern => /\(/
|
297
|
+
) {|s| "+#{s}+"}
|
298
|
+
assert_equal '((++(++(++()++)++)++))', result
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
def test_100_mask_with_brackets
|
303
|
+
test = 'level0(lev(el)1)level0'
|
304
|
+
options = {:with_brackets => true}
|
305
|
+
|
306
|
+
result = test.mask( :with_brackets => true,
|
307
|
+
:level_start => 0,
|
308
|
+
:level_end => 0,
|
309
|
+
:pattern => /\(/
|
310
|
+
) {|s| s.tr('()','{}')}
|
311
|
+
assert_equal 'level0{lev(el)1}level0' , result
|
312
|
+
|
313
|
+
result = test.mask( :with_brackets => true,
|
314
|
+
:level_start => 1,
|
315
|
+
:level_end => 1,
|
316
|
+
:pattern => /\(/
|
317
|
+
) {|s| s.tr('()','<>')}
|
318
|
+
assert_equal 'level0(lev<el>1)level0' , result
|
319
|
+
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
end # class
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|