awesome-cheeba 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,345 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'minitest/unit'
5
+ $: << 'lib' << 'test'
6
+ require 'cheeba/reader/builder'
7
+ MiniTest::Unit.autorun
8
+
9
+ class TestReaderBuilder < MiniTest::Unit::TestCase
10
+ def setup
11
+ @builder = Cheeba::Reader::Builder
12
+ @phash = { :msg => nil,
13
+ :spc => nil,
14
+ :key => nil,
15
+ :val => nil,
16
+ :ask => false,
17
+ :asv => false,
18
+ :opt => {:indent => 2}}
19
+ @dcs = @phash.merge({:msg => :dcs})
20
+ @dct = @phash.merge({:msg => :dct})
21
+ @hpr = @phash.merge({:msg => :hpr})
22
+ @hky = @phash.merge({:msg => :hky})
23
+ @arr = @phash.merge({:msg => :arr})
24
+ @mal = @phash.merge({:msg => :mal})
25
+ end
26
+
27
+ ##
28
+ # build
29
+ #
30
+ def test_build_module
31
+ assert_kind_of Module, @builder
32
+ end
33
+
34
+ def test_build_array_raise_rootnodeerror
35
+ hsh = {1 =>{"k1" => "awesome"}, :lst => {1 => "k1"}, :adr => [1,"k1"]}
36
+ val = "dude"
37
+ phs = @arr.merge({:val => val, :spc => 0})
38
+ assert_raises(Cheeba::Reader::Builder::RootNodeError) {@builder.build(hsh, phs)}
39
+ end
40
+
41
+ def test_build_array_with_zero_indent
42
+ hsh = {}
43
+ val = "awesome"
44
+ phs = @arr.merge({:val => val, :spc => 0})
45
+ @builder.build(hsh, phs)
46
+ assert_equal(["awesome"], hsh[1])
47
+ end
48
+
49
+ def test_build_array_into_hashkey
50
+ hsh = {:adr => [1, "k1"], 1 => {"k1" => {}}, :lst =>{}}
51
+ exp = {"k1" => ["awesome"]}
52
+ val = "awesome"
53
+ phs = @arr.merge({:val => val, :spc => 2})
54
+ @builder.build(hsh, phs)
55
+ assert_equal exp, hsh[1]
56
+ end
57
+
58
+ def test_build_add_blank
59
+ hsh = {:adr => [1], 1 => {}, :lst => {}}
60
+ exp_lst1 = {1 => "#BLANK"}
61
+ exp_lst2 = {1 => "#BLANK", 2 => "#BLANK"}
62
+ @builder.build(hsh, {:msg => :bla})
63
+ assert_equal exp_lst1, hsh[:lst]
64
+ @builder.build(hsh, {:msg => :bla})
65
+ assert_equal exp_lst2, hsh[:lst]
66
+ end
67
+
68
+ def test_build_malformed
69
+ hsh = {:adr => [1], 1 => {}, :lst => {}}
70
+ exp_lst1 = {1 => "#BLANK"}
71
+ exp_lst2 = {1 => "#BLANK", 2 => "#BLANK"}
72
+ @builder.build(hsh, {:msg => :bla})
73
+ assert_equal exp_lst1, hsh[:lst]
74
+ @builder.build(hsh, {:msg => :bla})
75
+ assert_equal exp_lst2, hsh[:lst]
76
+ end
77
+
78
+ def test_build_array_into_array
79
+ hsh = {:adr => [1, "k1"], 1 => {"k1" => [1,2]}, :lst =>{}}
80
+ val = "awesome"
81
+ phs = @arr.merge({:val => val, :spc => 4})
82
+ @builder.build(hsh, phs)
83
+ exp_hsh = {"k1" => [1,2,["awesome"]]}
84
+ exp_adr = [1, "k1", 2]
85
+ assert_equal exp_hsh, hsh[1]
86
+ assert_equal exp_adr, hsh[:adr]
87
+ end
88
+
89
+ def test_build_hashpair_into_array
90
+ hsh = {:adr => [1, 0], 1 => [["awesome"]], :lst =>{}}
91
+ phs = @hpr.merge({:key => "dude", :val => "fekja", :spc => 2})
92
+ @builder.build(hsh, phs)
93
+ exp_hsh = [["awesome", {"dude" => "fekja"}]]
94
+ exp_adr = [1, 0]
95
+ assert_equal exp_hsh, hsh[1]
96
+ assert_equal exp_adr, hsh[:adr]
97
+ end
98
+
99
+ def test_build_hashkey_into_array
100
+ hsh = {:adr => [1, 0], 1 => [["awesome"]], :lst =>{}}
101
+ phs = @hky.merge({:key => "dude", :spc => 2})
102
+ @builder.build(hsh, phs)
103
+ exp_hsh = [["awesome", {"dude" => {}}]]
104
+ exp_adr = [1, 0, 1, "dude"]
105
+ assert_equal exp_hsh, hsh[1]
106
+ assert_equal exp_adr, hsh[:adr]
107
+ end
108
+
109
+ def test_cur
110
+ hsh1 = {:adr => [], :lst => {}, 1=>[7]}
111
+ hsh2 = {:adr => [], :lst => {}, 1=>[7], 2=>[8]}
112
+ exp_hsh1 = [7]
113
+ exp_hsh2 = [8]
114
+ act_hsh1 = @builder.cur(hsh1)
115
+ act_hsh2 = @builder.cur(hsh2)
116
+ assert_equal exp_hsh1, act_hsh1
117
+ assert_equal exp_hsh2, act_hsh2
118
+ end
119
+
120
+ def test_doc_new
121
+ exp1 = {:adr => [1], :lst => {}, 1=>{}}
122
+ exp2 = {:adr => [2], :lst => {}, 1=>{}, 2=>{}}
123
+ hsh = {}
124
+ @builder.doc_new(hsh)
125
+ assert_equal exp1, hsh
126
+ @builder.doc_new(hsh)
127
+ assert_equal exp2, hsh
128
+ end
129
+
130
+ def test_space
131
+ assert_equal 1, @builder.index(2,2)
132
+ assert_equal 1, @builder.index(8,8)
133
+ assert_equal 3, @builder.index(9,3)
134
+ assert_equal 0, @builder.index(4,3)
135
+ assert_equal 0, @builder.index(0,2)
136
+ end
137
+
138
+ def test_to_adr_all_numbers
139
+ adr = [1, 2, 3]
140
+ exp = "[1][2][3]"
141
+ assert exp, @builder.to_adr(adr)
142
+ end
143
+
144
+ ##
145
+ # address object
146
+ #
147
+ def test_adr_obj
148
+ x = "awesome"
149
+ hsh = {1 => [{"k1" => x}]}
150
+ adr = [1, 0, "k1"]
151
+ act = @builder.adr_obj(hsh, adr)
152
+ assert_equal x, act
153
+ end
154
+
155
+ def test_to_adr_all_string
156
+ adr = ["k1", "k2"]
157
+ exp = "['k1']['k2']"
158
+ assert exp, @builder.to_adr(adr)
159
+ end
160
+
161
+ def test_to_adr_mixed
162
+ adr = ["k1", 1, 2, 3, "k2", 4]
163
+ exp = "['k1'][1][2][3]['k2'][4]"
164
+ assert exp, @builder.to_adr(adr)
165
+ end
166
+
167
+ def test_add_to_list
168
+ lst = {}
169
+ exp_lst1 = {1 => "k1"}
170
+ exp_lst2 = {1 => "k1", 2 => "k1,k2"}
171
+ exp_lst3 = {1 => "k1", 2 => "k1,k2", 3 => "string"}
172
+ @builder.add_to_list(lst, ["k1"])
173
+ assert_equal exp_lst1, lst
174
+ @builder.add_to_list(lst, ["k1","k2"])
175
+ assert_equal exp_lst2, lst
176
+ @builder.add_to_list(lst, "string")
177
+ assert_equal exp_lst3, lst
178
+ end
179
+
180
+ def test_update_index_greater_than_before
181
+ # index > length
182
+ idx = 5
183
+ adr = [1,2,3,4,5]
184
+ exp = "gt"
185
+ act = @builder.update(adr, idx)
186
+ assert_equal 5, adr.length
187
+ assert_equal exp, act
188
+ end
189
+
190
+ def test_update_index_same_as_before
191
+ # index == length; remain the same
192
+ idx = 4
193
+ adr = [1,2,3,4,5]
194
+ exp = "eq"
195
+ act = @builder.update(adr, idx)
196
+ assert_equal 5, adr.length
197
+ assert_equal exp, act
198
+ end
199
+
200
+ def test_update_index_less_than_before
201
+ # remain the same because 0 is the doc
202
+ idx = 3
203
+ adr = [1,2,3,4,5]
204
+ exp_msg = "lt"
205
+ exp_adr = [1,2,3,4]
206
+ act = @builder.update(adr, idx)
207
+ assert_equal 4, adr.length
208
+ assert_equal exp_msg, act
209
+ assert_equal exp_adr, adr
210
+ end
211
+
212
+ def test_update_zero_index
213
+ idx = 0
214
+ adr = [1,2,3,4,5]
215
+ exp_msg = "lt"
216
+ exp_adr = [1]
217
+ act = @builder.update(adr, idx)
218
+ assert_equal 1, adr.length
219
+ assert_equal exp_msg, act
220
+ assert_equal exp_adr, adr
221
+ end
222
+
223
+ def test_blank_line
224
+ hsh = {:lst => {}}
225
+ exp_lst1 = {1=>"#BLANK"}
226
+ exp_lst2 = {1=>"#BLANK",2=>"#BLANK"}
227
+ @builder.blank(hsh[:lst])
228
+ assert_equal exp_lst1, hsh[:lst]
229
+ @builder.blank(hsh[:lst])
230
+ assert_equal exp_lst2, hsh[:lst]
231
+ end
232
+
233
+ def test_doc_start
234
+ hsh = {}
235
+ exp_lst1 = {1=>"#DOC_START"}
236
+ exp_lst2 = {1=>"#DOC_START",2=>"#DOC_START"}
237
+ @builder.doc_start(hsh)
238
+ assert_equal exp_lst1, hsh[:lst]
239
+ @builder.doc_start(hsh)
240
+ assert_equal exp_lst2, hsh[:lst]
241
+ end
242
+
243
+ def test_doc_term
244
+ hsh = {:adr => [], :lst => {}}
245
+ exp_lst1 = {1 => "#DOC_TERM"}
246
+ exp_lst2 = {1 => "#DOC_TERM", 2 => "#DOC_TERM"}
247
+ @builder.doc_term(hsh)
248
+ assert_equal exp_lst1, hsh[:lst]
249
+ @builder.doc_term(hsh)
250
+ assert_equal exp_lst2, hsh[:lst]
251
+ end
252
+
253
+ def test_hashkey_into_hash
254
+ las = {}
255
+ adr = []
256
+ @builder.hsh_key(las, adr, "k1")
257
+ exp_las = {"k1" => {}}
258
+ exp_adr = ["k1"]
259
+ assert_equal exp_las, las
260
+ assert_equal exp_adr, adr
261
+ end
262
+
263
+ def test_hashkey_into_array
264
+ las = []
265
+ adr = []
266
+ @builder.hsh_key(las, adr, "k1")
267
+ exp_las = [{"k1" => {}}]
268
+ exp_adr = [0,"k1"]
269
+ assert_equal exp_las, las
270
+ assert_equal exp_adr, adr
271
+ end
272
+
273
+ def test_hashpair_into_hash
274
+ las = {}
275
+ exp1 = {"k1" => "awesome"}
276
+ exp2 = {"k1" => "awesome", "k2" => "dude"}
277
+ @builder.hsh_pair(las, "k1", "awesome")
278
+ assert_equal exp1, las
279
+ @builder.hsh_pair(las, "k2", "dude")
280
+ assert_equal exp2, las
281
+ end
282
+
283
+ def test_hashpair_into_array
284
+ las = []
285
+ exp1 = [{"k1" => "awesome"}]
286
+ exp2 = [{"k1" => "awesome"}, {"k2" => "dude"}]
287
+ @builder.hsh_pair(las, "k1", "awesome")
288
+ assert_equal exp1, las
289
+ @builder.hsh_pair(las, "k2", "dude")
290
+ assert_equal exp2, las
291
+ end
292
+
293
+ def test_comment
294
+ lst = {}
295
+ exp = {1 => "#COMMENT: awesome"}
296
+ @builder.comment(lst, "awesome")
297
+ assert_equal exp, lst
298
+ exp = {1 => "#COMMENT: awesome", 2 => "#COMMENT: dude"}
299
+ @builder.comment(lst, "dude")
300
+ assert_equal exp, lst
301
+ end
302
+
303
+ def test_array_into_hash
304
+ las = {}
305
+ adr = []
306
+ exp_las = {}
307
+ exp_adr = []
308
+ val = "awesome"
309
+ @builder.array_new(las, adr, val)
310
+ assert_equal exp_las, las
311
+ assert_equal exp_adr, adr
312
+ end
313
+
314
+ def test_array_into_array
315
+ las = [3]
316
+ adr = []
317
+ val = "awesome"
318
+ exp_las = [3,["awesome"]]
319
+ exp_adr = [1]
320
+ @builder.array_new(las, adr, val)
321
+ assert_equal exp_las, las
322
+ assert_equal exp_adr, adr
323
+ end
324
+
325
+ def test_add_value_to_array
326
+ las = []
327
+ adr = []
328
+ @builder.array_val(las, 1)
329
+ assert_equal [], adr
330
+ assert_equal [1], las
331
+ @builder.array_val(las, 2)
332
+ assert_equal [], adr
333
+ assert_equal [1,2], las
334
+ end
335
+
336
+ def test_malformed
337
+ lst = {}
338
+ exp = {1 => "#MALFORMED: string1"}
339
+ @builder.malformed(lst, "string1")
340
+ assert_equal exp, lst
341
+ exp = {1 => "#MALFORMED: string1", 2 => "#MALFORMED: string2"}
342
+ @builder.malformed(lst, "string2")
343
+ assert_equal exp, lst
344
+ end
345
+ end
@@ -0,0 +1,316 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'minitest/unit'
5
+ $: << 'lib' << 'test'
6
+ require 'cheeba/reader/format'
7
+ require 'cheeba/defaults'
8
+ MiniTest::Unit.autorun
9
+
10
+ class TestReaderFormat < MiniTest::Unit::TestCase
11
+ def setup
12
+ @format = Cheeba::Reader::Format
13
+ @opt = {}
14
+ Cheeba::Defaults.options.each_key {|k| @opt[k] = false}
15
+ @phs = { :msg => nil,
16
+ :spc => nil,
17
+ :key => nil,
18
+ :val => nil,
19
+ :ask => nil,
20
+ :asv => nil,
21
+ :opt => @opt}
22
+ end
23
+
24
+ #
25
+ # parsed_hash => formatted_hash
26
+ #
27
+ def test_format_basic
28
+ phs = @phs.merge({:key => "1", :val => "1", :opt => @opt})
29
+ act = @format.format(phs)
30
+ assert_equal Hash, act.class
31
+ end
32
+
33
+ def test_adjust_options
34
+ phs1 = {:opt => {:auto_sym => true}}
35
+ phs2 = {:opt => {:auto_sym => false}}
36
+ @format.adjust_options(phs1)
37
+ @format.adjust_options(phs2)
38
+ assert phs1[:opt][:auto_sym_keys]
39
+ assert phs1[:opt][:auto_sym_vals]
40
+ assert !phs2[:opt][:auto_sym_keys]
41
+ assert !phs2[:opt][:auto_sym_vals]
42
+ end
43
+
44
+ #
45
+ # strip different things
46
+ #
47
+ def test_strip
48
+ key = " awesome "
49
+ val = " awesome "
50
+ opt1 = {:strip => true}
51
+ opt2 = @opt.clone
52
+ act_phs1 = @phs.merge({:key => key, :val => val, :opt => opt1})
53
+ act_phs2 = @phs.merge({:key => key, :val => val, :opt => opt2})
54
+ exp_key1 = "awesome"
55
+ exp_val1 = "awesome"
56
+ exp_key2 = key
57
+ exp_val2 = val
58
+ @format.format(act_phs1)
59
+ @format.format(act_phs2)
60
+ assert_equal exp_key1, act_phs1[:key]
61
+ assert_equal exp_val1, act_phs1[:val]
62
+ assert_equal exp_key2, act_phs2[:key]
63
+ assert_equal exp_val2, act_phs2[:val]
64
+ end
65
+
66
+ def test_strip_keys
67
+ key = " awesome "
68
+ opt1 = {:strip_keys => true}
69
+ opt2 = @opt.clone
70
+ act_phs1 = @phs.merge({:key => key, :opt => opt1})
71
+ act_phs2 = @phs.merge({:key => key, :opt => opt2})
72
+ exp_key1 = "awesome"
73
+ exp_key2 = key
74
+ @format.format(act_phs1)
75
+ @format.format(act_phs2)
76
+ assert_equal exp_key1, act_phs1[:key]
77
+ assert_equal exp_key2, act_phs2[:key]
78
+ end
79
+
80
+ def test_strip_vals
81
+ val = " awesome "
82
+ opt1 = {:strip_vals => true}
83
+ opt2 = @opt.clone
84
+ act_phs1 = @phs.merge({:val => val, :opt => opt1})
85
+ act_phs2 = @phs.merge({:val => val, :opt => opt2})
86
+ exp_val1 = "awesome"
87
+ exp_val2 = val
88
+ @format.format(act_phs1)
89
+ @format.format(act_phs2)
90
+ assert_equal exp_val1, act_phs1[:val]
91
+ assert_equal exp_val2, act_phs2[:val]
92
+ end
93
+
94
+ #
95
+ # convert true, false in strings
96
+ #
97
+ def test_true_keys
98
+ opt1 = @opt.clone
99
+ opt2 = @opt.merge({:auto_true_keys => true})
100
+ opt3 = @opt.merge({:auto_true => true})
101
+ opt4 = @opt.clone
102
+ opt5 = @opt.merge({:auto_true_keys => true})
103
+ opt6 = @opt.merge({:auto_true => true})
104
+ act_phs1 = @phs.merge({:key => "true", :opt => opt1})
105
+ act_phs2 = @phs.merge({:key => "true", :opt => opt2})
106
+ act_phs3 = @phs.merge({:key => "true", :opt => opt3})
107
+ act_phs4 = @phs.merge({:key => "false", :opt => opt4})
108
+ act_phs5 = @phs.merge({:key => "false", :opt => opt5})
109
+ act_phs6 = @phs.merge({:key => "false", :opt => opt6})
110
+ @format.key_to_true(act_phs1)
111
+ @format.key_to_true(act_phs2)
112
+ @format.key_to_true(act_phs3)
113
+ @format.key_to_true(act_phs4)
114
+ @format.key_to_true(act_phs5)
115
+ @format.key_to_true(act_phs6)
116
+ assert_equal "true", act_phs1[:key]
117
+ assert_equal true, act_phs2[:key]
118
+ assert_equal true, act_phs3[:key]
119
+ assert_equal "false", act_phs4[:key]
120
+ assert_equal false, act_phs5[:key]
121
+ assert_equal false, act_phs6[:key]
122
+ end
123
+
124
+ def test_true_vals
125
+ opt1 = @opt.clone
126
+ opt2 = @opt.merge({:auto_true_vals => true})
127
+ opt3 = @opt.merge({:auto_true => true})
128
+ opt4 = @opt.clone
129
+ opt5 = @opt.merge({:auto_true_vals => true})
130
+ opt6 = @opt.merge({:auto_true => true})
131
+ act_phs1 = @phs.merge({:val => "true", :opt => opt1})
132
+ act_phs2 = @phs.merge({:val => "true", :opt => opt2})
133
+ act_phs3 = @phs.merge({:val => "true", :opt => opt3})
134
+ act_phs4 = @phs.merge({:val => "false", :opt => opt4})
135
+ act_phs5 = @phs.merge({:val => "false", :opt => opt5})
136
+ act_phs6 = @phs.merge({:val => "false", :opt => opt6})
137
+ @format.val_to_true(act_phs1)
138
+ @format.val_to_true(act_phs2)
139
+ @format.val_to_true(act_phs3)
140
+ @format.val_to_true(act_phs4)
141
+ @format.val_to_true(act_phs5)
142
+ @format.val_to_true(act_phs6)
143
+ assert_equal "true", act_phs1[:val]
144
+ assert_equal true, act_phs2[:val]
145
+ assert_equal true, act_phs3[:val]
146
+ assert_equal "false", act_phs4[:val]
147
+ assert_equal false, act_phs5[:val]
148
+ assert_equal false, act_phs6[:val]
149
+ end
150
+
151
+ #
152
+ # symbolize key
153
+ #
154
+ def test_key_to_sym
155
+ exp_key1 = "awesome"
156
+ exp_key2 = "awesome".to_sym
157
+ opt1 = @opt.clone
158
+ opt2 = @opt.merge({:auto_sym_keys => true})
159
+ opt3 = @opt.merge({:symbolize => true})
160
+ opt4 = @opt.merge({:symbolize_keys => true})
161
+ act_phs1 = @phs.merge({:key => "awesome", :opt => opt1})
162
+ act_phs2 = @phs.merge({:key => "awesome", :opt => opt2})
163
+ act_phs3 = @phs.merge({:key => "awesome", :opt => opt3})
164
+ act_phs4 = @phs.merge({:key => "awesome", :opt => opt4})
165
+ @format.key_to_sym(act_phs1)
166
+ @format.key_to_sym(act_phs2)
167
+ @format.key_to_sym(act_phs3)
168
+ @format.key_to_sym(act_phs4)
169
+ assert_equal exp_key1, act_phs1[:key]
170
+ assert_equal exp_key1, act_phs2[:key]
171
+ assert_equal exp_key2, act_phs3[:key]
172
+ assert_equal exp_key2, act_phs4[:key]
173
+ end
174
+
175
+ def test_key_to_sym_number_in_string
176
+ exp_key1 = "411"
177
+ exp_key2 = "411".to_sym
178
+ opt1 = @opt.clone
179
+ opt2 = @opt.merge({:auto_sym_keys => true})
180
+ opt3 = @opt.merge({:symbolize => true})
181
+ opt4 = @opt.merge({:symbolize_keys => true})
182
+ act_phs1 = @phs.merge({:key => "411", :opt => opt1})
183
+ act_phs2 = @phs.merge({:key => "411", :opt => opt2})
184
+ act_phs3 = @phs.merge({:key => "411", :opt => opt3})
185
+ act_phs4 = @phs.merge({:key => "411", :opt => opt4})
186
+ @format.key_to_sym(act_phs1)
187
+ @format.key_to_sym(act_phs2)
188
+ @format.key_to_sym(act_phs3)
189
+ @format.key_to_sym(act_phs4)
190
+ assert_equal exp_key1, act_phs1[:key]
191
+ assert_equal exp_key1, act_phs2[:key]
192
+ assert_equal exp_key2, act_phs3[:key]
193
+ assert_equal exp_key2, act_phs4[:key]
194
+ end
195
+
196
+ #
197
+ # symbolize val
198
+ #
199
+ def test_val_to_sym
200
+ exp_val1 = "awesome"
201
+ exp_val2 = "awesome".to_sym
202
+ opt1 = @opt.clone
203
+ opt2 = @opt.merge({:auto_sym_vals => true})
204
+ opt3 = @opt.merge({:symbolize => true})
205
+ opt4 = @opt.merge({:symbolize_vals => true})
206
+ act_phs1 = @phs.merge({:val => "awesome", :opt => opt1})
207
+ act_phs2 = @phs.merge({:val => "awesome", :opt => opt2})
208
+ act_phs3 = @phs.merge({:val => "awesome", :opt => opt3})
209
+ act_phs4 = @phs.merge({:val => "awesome", :opt => opt4})
210
+ @format.val_to_sym(act_phs1)
211
+ @format.val_to_sym(act_phs2)
212
+ @format.val_to_sym(act_phs3)
213
+ @format.val_to_sym(act_phs4)
214
+ assert_equal exp_val1, act_phs1[:val]
215
+ assert_equal exp_val1, act_phs2[:val]
216
+ assert_equal exp_val2, act_phs3[:val]
217
+ assert_equal exp_val2, act_phs4[:val]
218
+ end
219
+
220
+ def test_val_to_sym_number_in_string
221
+ exp_val1 = "411"
222
+ exp_val2 = "411".to_sym
223
+ opt1 = @opt.clone
224
+ opt2 = @opt.merge({:auto_sym_vals => true})
225
+ opt3 = @opt.merge({:symbolize => true})
226
+ opt4 = @opt.merge({:symbolize_vals => true})
227
+ act_phs1 = @phs.merge({:val => "411", :opt => opt1})
228
+ act_phs2 = @phs.merge({:val => "411", :opt => opt2})
229
+ act_phs3 = @phs.merge({:val => "411", :opt => opt3})
230
+ act_phs4 = @phs.merge({:val => "411", :opt => opt4})
231
+ @format.val_to_sym(act_phs1)
232
+ @format.val_to_sym(act_phs2)
233
+ @format.val_to_sym(act_phs3)
234
+ @format.val_to_sym(act_phs4)
235
+ assert_equal exp_val1, act_phs1[:val]
236
+ assert_equal exp_val1, act_phs2[:val]
237
+ assert_equal exp_val2, act_phs3[:val]
238
+ assert_equal exp_val2, act_phs4[:val]
239
+ end
240
+
241
+ #
242
+ # key is parsed as string, try to_i
243
+ #
244
+ def test_key_to_int_string
245
+ exp_key1 = "411"
246
+ exp_key2 = 411
247
+ exp_key3 = "411".to_sym
248
+ opt1 = @opt.clone
249
+ opt2 = @opt.merge({:int => true})
250
+ opt3 = @opt.merge({:int_keys => true})
251
+ opt4 = @opt.merge({:int => true})
252
+ opt5 = @opt.merge({:int_keys => true})
253
+ act_phs1 = @phs.merge({:key => "411", :opt => opt1})
254
+ act_phs2 = @phs.merge({:key => "411", :opt => opt2})
255
+ act_phs3 = @phs.merge({:key => "411", :opt => opt3})
256
+ act_phs4 = @phs.merge({:key => "411".to_sym, :opt => opt4})
257
+ act_phs5 = @phs.merge({:key => "411".to_sym, :opt => opt5})
258
+ @format.key_to_int(act_phs1)
259
+ @format.key_to_int(act_phs2)
260
+ @format.key_to_int(act_phs3)
261
+ @format.key_to_int(act_phs4)
262
+ @format.key_to_int(act_phs5)
263
+ assert_equal exp_key1, act_phs1[:key]
264
+ assert_equal exp_key2, act_phs2[:key]
265
+ assert_equal exp_key2, act_phs3[:key]
266
+ assert_equal exp_key3, act_phs4[:key]
267
+ assert_equal exp_key3, act_phs5[:key]
268
+ end
269
+
270
+ #
271
+ # val is parsed as string, try to_i
272
+ #
273
+ def test_val_to_int
274
+ exp_val1 = "411"
275
+ exp_val2 = 411
276
+ exp_val3 = "411".to_sym
277
+ opt1 = @opt.clone
278
+ opt2 = @opt.merge({:int => true})
279
+ opt3 = @opt.merge({:int_vals => true})
280
+ opt4 = @opt.merge({:int => true})
281
+ opt5 = @opt.merge({:int_vals => true})
282
+ act_phs1 = @phs.merge({:val => "411", :opt => opt1})
283
+ act_phs2 = @phs.merge({:val => "411", :opt => opt2})
284
+ act_phs3 = @phs.merge({:val => "411", :opt => opt3})
285
+ act_phs4 = @phs.merge({:val => "411".to_sym, :opt => opt4})
286
+ act_phs5 = @phs.merge({:val => "411".to_sym, :opt => opt5})
287
+ @format.val_to_int(act_phs1)
288
+ @format.val_to_int(act_phs2)
289
+ @format.val_to_int(act_phs3)
290
+ @format.val_to_int(act_phs4)
291
+ @format.val_to_int(act_phs5)
292
+ assert_equal exp_val1, act_phs1[:val]
293
+ assert_equal exp_val2, act_phs2[:val]
294
+ assert_equal exp_val2, act_phs3[:val]
295
+ assert_equal exp_val3, act_phs4[:val]
296
+ assert_equal exp_val3, act_phs5[:val]
297
+ end
298
+
299
+ #
300
+ # returns Int if String is convertable
301
+ #
302
+ def test_string_to_int
303
+ str1 = ""
304
+ str2 = "awesome"
305
+ str3 = "123awesome"
306
+ str4 = "123"
307
+ exp1 = ""
308
+ exp2 = "awesome"
309
+ exp3 = "123awesome"
310
+ exp4 = 123
311
+ act1 = @format.string_to_int(str1)
312
+ act2 = @format.string_to_int(str2)
313
+ act3 = @format.string_to_int(str3)
314
+ act4 = @format.string_to_int(str4)
315
+ end
316
+ end