yamlr 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,393 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'minitest/unit'
5
+ $: << 'lib' << 'test'
6
+ require 'yamlr/reader/format'
7
+ require 'yamlr/defaults'
8
+ MiniTest::Unit.autorun
9
+
10
+ class TestReaderFormat < MiniTest::Unit::TestCase
11
+ def setup
12
+ @format = Yamlr::Reader::Format
13
+ @opt = {}
14
+ Yamlr::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
+ def test_format_symbolize_keys_number_in_string
45
+ opt1 = @opt.merge({:symbolize_keys => true})
46
+ opt2 = @opt.merge({:int => true, :symbolize_keys => true})
47
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
48
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
49
+ act1 = @format.format(phs1)
50
+ act2 = @format.format(phs2)
51
+ exp1 = "1".to_sym
52
+ exp2 = "1".to_sym
53
+ assert_equal exp1, act1[:key]
54
+ assert_equal exp2, act2[:key]
55
+ end
56
+
57
+ #def test_format_sym_str_nested
58
+ #end
59
+
60
+ def test_format_sym_str
61
+ opt1 = @opt.merge({:sym_str => true})
62
+ opt2 = @opt.merge({:int => true, :sym_str => true})
63
+ opt3 = opt1
64
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
65
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
66
+ phs3 = @phs.merge({:key => "awesome", :val => "awesome", :opt => opt3})
67
+ act1 = @format.format(phs1)
68
+ act2 = @format.format(phs2)
69
+ act3 = @format.format(phs3)
70
+ exp1 = :"1"
71
+ exp2 = 1
72
+ exp3 = "awesome".to_sym
73
+ exp4 = :"1"
74
+ exp5 = 1
75
+ exp6 = "awesome".to_sym
76
+ assert_equal exp1, act1[:key]
77
+ assert_equal exp2, act2[:key]
78
+ assert_equal exp3, act3[:key]
79
+ assert_equal exp4, act1[:val]
80
+ assert_equal exp5, act2[:val]
81
+ assert_equal exp6, act3[:val]
82
+ end
83
+
84
+ def test_format_sym_str_keys
85
+ opt1 = @opt.merge({:sym_str_keys => true})
86
+ opt2 = @opt.merge({:int => true, :sym_str_keys => true})
87
+ opt3 = opt1
88
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
89
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
90
+ phs3 = @phs.merge({:key => "awesome", :val => "awesome", :opt => opt3})
91
+ act1 = @format.format(phs1)
92
+ act2 = @format.format(phs2)
93
+ act3 = @format.format(phs3)
94
+ exp1 = :"1"
95
+ exp2 = 1
96
+ exp3 = "awesome".to_sym
97
+ exp4 = "1"
98
+ exp5 = 1
99
+ exp6 = "awesome"
100
+ assert_equal exp1, act1[:key]
101
+ assert_equal exp2, act2[:key]
102
+ assert_equal exp3, act3[:key]
103
+ assert_equal exp4, act1[:val]
104
+ assert_equal exp5, act2[:val]
105
+ assert_equal exp6, act3[:val]
106
+ end
107
+
108
+ def test_format_sym_str_vals
109
+ opt1 = @opt.merge({:sym_str_vals => true})
110
+ opt2 = @opt.merge({:int => true, :sym_str_vals => true})
111
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
112
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
113
+ phs3 = @phs.merge({:key => "awesome", :val => "awesome", :opt => opt1})
114
+ act1 = @format.format(phs1)
115
+ act2 = @format.format(phs2)
116
+ act3 = @format.format(phs3)
117
+ assert_equal "1", act1[:key]
118
+ assert_equal 1, act2[:key]
119
+ assert_equal "awesome", act3[:key]
120
+ assert_equal :"1", act1[:val]
121
+ assert_equal 1, act2[:val]
122
+ assert_equal "awesome".to_sym, act3[:val]
123
+ end
124
+
125
+ #
126
+ # strip different things
127
+ #
128
+ def test_strip
129
+ key = " awesome "
130
+ val = " awesome "
131
+ opt1 = {:strip => true}
132
+ opt2 = @opt.clone
133
+ act_phs1 = @phs.merge({:key => key, :val => val, :opt => opt1})
134
+ act_phs2 = @phs.merge({:key => key, :val => val, :opt => opt2})
135
+ exp_key1 = "awesome"
136
+ exp_val1 = "awesome"
137
+ exp_key2 = key
138
+ exp_val2 = val
139
+ @format.format(act_phs1)
140
+ @format.format(act_phs2)
141
+ assert_equal exp_key1, act_phs1[:key]
142
+ assert_equal exp_val1, act_phs1[:val]
143
+ assert_equal exp_key2, act_phs2[:key]
144
+ assert_equal exp_val2, act_phs2[:val]
145
+ end
146
+
147
+ def test_strip_keys
148
+ key = " awesome "
149
+ opt1 = {:strip_keys => true}
150
+ opt2 = @opt.clone
151
+ act_phs1 = @phs.merge({:key => key, :opt => opt1})
152
+ act_phs2 = @phs.merge({:key => key, :opt => opt2})
153
+ exp_key1 = "awesome"
154
+ exp_key2 = key
155
+ @format.format(act_phs1)
156
+ @format.format(act_phs2)
157
+ assert_equal exp_key1, act_phs1[:key]
158
+ assert_equal exp_key2, act_phs2[:key]
159
+ end
160
+
161
+ def test_strip_vals
162
+ val = " awesome "
163
+ opt1 = {:strip_vals => true}
164
+ opt2 = @opt.clone
165
+ act_phs1 = @phs.merge({:val => val, :opt => opt1})
166
+ act_phs2 = @phs.merge({:val => val, :opt => opt2})
167
+ exp_val1 = "awesome"
168
+ exp_val2 = val
169
+ @format.format(act_phs1)
170
+ @format.format(act_phs2)
171
+ assert_equal exp_val1, act_phs1[:val]
172
+ assert_equal exp_val2, act_phs2[:val]
173
+ end
174
+
175
+ #
176
+ # convert true, false in strings
177
+ #
178
+ def test_true_keys
179
+ opt1 = @opt.clone
180
+ opt2 = @opt.merge({:auto_true_keys => true})
181
+ opt3 = @opt.merge({:auto_true => true})
182
+ opt4 = @opt.clone
183
+ opt5 = @opt.merge({:auto_true_keys => true})
184
+ opt6 = @opt.merge({:auto_true => true})
185
+ act_phs1 = @phs.merge({:key => "true", :opt => opt1})
186
+ act_phs2 = @phs.merge({:key => "true", :opt => opt2})
187
+ act_phs3 = @phs.merge({:key => "true", :opt => opt3})
188
+ act_phs4 = @phs.merge({:key => "false", :opt => opt4})
189
+ act_phs5 = @phs.merge({:key => "false", :opt => opt5})
190
+ act_phs6 = @phs.merge({:key => "false", :opt => opt6})
191
+ @format.key_to_true(act_phs1)
192
+ @format.key_to_true(act_phs2)
193
+ @format.key_to_true(act_phs3)
194
+ @format.key_to_true(act_phs4)
195
+ @format.key_to_true(act_phs5)
196
+ @format.key_to_true(act_phs6)
197
+ assert_equal "true", act_phs1[:key]
198
+ assert_equal true, act_phs2[:key]
199
+ assert_equal true, act_phs3[:key]
200
+ assert_equal "false", act_phs4[:key]
201
+ assert_equal false, act_phs5[:key]
202
+ assert_equal false, act_phs6[:key]
203
+ end
204
+
205
+ def test_true_vals
206
+ opt1 = @opt.clone
207
+ opt2 = @opt.merge({:auto_true_vals => true})
208
+ opt3 = @opt.merge({:auto_true => true})
209
+ opt4 = @opt.clone
210
+ opt5 = @opt.merge({:auto_true_vals => true})
211
+ opt6 = @opt.merge({:auto_true => true})
212
+ act_phs1 = @phs.merge({:val => "true", :opt => opt1})
213
+ act_phs2 = @phs.merge({:val => "true", :opt => opt2})
214
+ act_phs3 = @phs.merge({:val => "true", :opt => opt3})
215
+ act_phs4 = @phs.merge({:val => "false", :opt => opt4})
216
+ act_phs5 = @phs.merge({:val => "false", :opt => opt5})
217
+ act_phs6 = @phs.merge({:val => "false", :opt => opt6})
218
+ @format.val_to_true(act_phs1)
219
+ @format.val_to_true(act_phs2)
220
+ @format.val_to_true(act_phs3)
221
+ @format.val_to_true(act_phs4)
222
+ @format.val_to_true(act_phs5)
223
+ @format.val_to_true(act_phs6)
224
+ assert_equal "true", act_phs1[:val]
225
+ assert_equal true, act_phs2[:val]
226
+ assert_equal true, act_phs3[:val]
227
+ assert_equal "false", act_phs4[:val]
228
+ assert_equal false, act_phs5[:val]
229
+ assert_equal false, act_phs6[:val]
230
+ end
231
+
232
+ #
233
+ # symbolize key
234
+ #
235
+ def test_key_to_sym
236
+ exp_key1 = "awesome"
237
+ exp_key2 = "awesome".to_sym
238
+ opt1 = @opt.clone
239
+ opt2 = @opt.merge({:auto_sym_keys => true})
240
+ opt3 = @opt.merge({:symbolize => true})
241
+ opt4 = @opt.merge({:symbolize_keys => true})
242
+ act_phs1 = @phs.merge({:key => "awesome", :opt => opt1})
243
+ act_phs2 = @phs.merge({:key => "awesome", :opt => opt2})
244
+ act_phs3 = @phs.merge({:key => "awesome", :opt => opt3})
245
+ act_phs4 = @phs.merge({:key => "awesome", :opt => opt4})
246
+ @format.key_to_sym(act_phs1)
247
+ @format.key_to_sym(act_phs2)
248
+ @format.key_to_sym(act_phs3)
249
+ @format.key_to_sym(act_phs4)
250
+ assert_equal exp_key1, act_phs1[:key]
251
+ assert_equal exp_key1, act_phs2[:key]
252
+ assert_equal exp_key2, act_phs3[:key]
253
+ assert_equal exp_key2, act_phs4[:key]
254
+ end
255
+
256
+ def test_key_to_sym_number_in_string
257
+ exp_key1 = "411"
258
+ exp_key2 = "411".to_sym
259
+ opt1 = @opt.clone
260
+ opt2 = @opt.merge({:auto_sym_keys => true})
261
+ opt3 = @opt.merge({:symbolize => true})
262
+ opt4 = @opt.merge({:symbolize_keys => true})
263
+ act_phs1 = @phs.merge({:key => "411", :opt => opt1})
264
+ act_phs2 = @phs.merge({:key => "411", :opt => opt2})
265
+ act_phs3 = @phs.merge({:key => "411", :opt => opt3})
266
+ act_phs4 = @phs.merge({:key => "411", :opt => opt4})
267
+ @format.key_to_sym(act_phs1)
268
+ @format.key_to_sym(act_phs2)
269
+ @format.key_to_sym(act_phs3)
270
+ @format.key_to_sym(act_phs4)
271
+ assert_equal exp_key1, act_phs1[:key]
272
+ assert_equal exp_key1, act_phs2[:key]
273
+ assert_equal exp_key2, act_phs3[:key]
274
+ assert_equal exp_key2, act_phs4[:key]
275
+ end
276
+
277
+ #
278
+ # symbolize val
279
+ #
280
+ def test_val_to_sym
281
+ exp_val1 = "awesome"
282
+ exp_val2 = "awesome".to_sym
283
+ opt1 = @opt.clone
284
+ opt2 = @opt.merge({:auto_sym_vals => true})
285
+ opt3 = @opt.merge({:symbolize => true})
286
+ opt4 = @opt.merge({:symbolize_vals => true})
287
+ act_phs1 = @phs.merge({:val => "awesome", :opt => opt1})
288
+ act_phs2 = @phs.merge({:val => "awesome", :opt => opt2})
289
+ act_phs3 = @phs.merge({:val => "awesome", :opt => opt3})
290
+ act_phs4 = @phs.merge({:val => "awesome", :opt => opt4})
291
+ @format.val_to_sym(act_phs1)
292
+ @format.val_to_sym(act_phs2)
293
+ @format.val_to_sym(act_phs3)
294
+ @format.val_to_sym(act_phs4)
295
+ assert_equal exp_val1, act_phs1[:val]
296
+ assert_equal exp_val1, act_phs2[:val]
297
+ assert_equal exp_val2, act_phs3[:val]
298
+ assert_equal exp_val2, act_phs4[:val]
299
+ end
300
+
301
+ def test_val_to_sym_number_in_string
302
+ exp_val1 = "411"
303
+ exp_val2 = "411".to_sym
304
+ opt1 = @opt.clone
305
+ opt2 = @opt.merge({:auto_sym_vals => true})
306
+ opt3 = @opt.merge({:symbolize => true})
307
+ opt4 = @opt.merge({:symbolize_vals => true})
308
+ act_phs1 = @phs.merge({:val => "411", :opt => opt1})
309
+ act_phs2 = @phs.merge({:val => "411", :opt => opt2})
310
+ act_phs3 = @phs.merge({:val => "411", :opt => opt3})
311
+ act_phs4 = @phs.merge({:val => "411", :opt => opt4})
312
+ @format.val_to_sym(act_phs1)
313
+ @format.val_to_sym(act_phs2)
314
+ @format.val_to_sym(act_phs3)
315
+ @format.val_to_sym(act_phs4)
316
+ assert_equal exp_val1, act_phs1[:val]
317
+ assert_equal exp_val1, act_phs2[:val]
318
+ assert_equal exp_val2, act_phs3[:val]
319
+ assert_equal exp_val2, act_phs4[:val]
320
+ end
321
+
322
+ # key is parsed as string, try to_i
323
+ #
324
+ def test_key_to_int_string
325
+ opt1 = @opt.clone
326
+ opt2 = @opt.merge({:int => true})
327
+ opt3 = @opt.merge({:int_keys => true})
328
+ opt4 = @opt.merge({:int => true})
329
+ opt5 = @opt.merge({:int_keys => true})
330
+ act_phs1 = @phs.merge({:key => "411", :opt => opt1})
331
+ act_phs2 = @phs.merge({:key => "411", :opt => opt2})
332
+ act_phs3 = @phs.merge({:key => "411", :opt => opt3})
333
+ act_phs4 = @phs.merge({:key => "411".to_sym, :opt => opt4})
334
+ act_phs5 = @phs.merge({:key => "411".to_sym, :opt => opt5})
335
+ @format.key_to_int(act_phs1)
336
+ @format.key_to_int(act_phs2)
337
+ @format.key_to_int(act_phs3)
338
+ @format.key_to_int(act_phs4)
339
+ @format.key_to_int(act_phs5)
340
+ assert_equal "411", act_phs1[:key]
341
+ assert_equal 411, act_phs2[:key]
342
+ assert_equal 411, act_phs3[:key]
343
+ assert_equal 411, act_phs4[:key]
344
+ assert_equal 411, act_phs5[:key]
345
+ end
346
+
347
+ # val is parsed as string, try to_i
348
+ #
349
+ def test_val_to_int
350
+ opt1 = @opt.clone
351
+ opt2 = @opt.merge({:int => true})
352
+ opt3 = @opt.merge({:int_vals => true})
353
+ opt4 = @opt.merge({:int => true})
354
+ opt5 = @opt.merge({:int_vals => true})
355
+ act_phs1 = @phs.merge({:val => "411", :opt => opt1})
356
+ act_phs2 = @phs.merge({:val => "411", :opt => opt2})
357
+ act_phs3 = @phs.merge({:val => "411", :opt => opt3})
358
+ act_phs4 = @phs.merge({:val => "411".to_sym, :opt => opt4})
359
+ act_phs5 = @phs.merge({:val => "411".to_sym, :opt => opt5})
360
+ @format.val_to_int(act_phs1)
361
+ @format.val_to_int(act_phs2)
362
+ @format.val_to_int(act_phs3)
363
+ @format.val_to_int(act_phs4)
364
+ @format.val_to_int(act_phs5)
365
+ assert_equal "411", act_phs1[:val]
366
+ assert_equal 411, act_phs2[:val]
367
+ assert_equal 411, act_phs3[:val]
368
+ assert_equal 411, act_phs4[:val]
369
+ assert_equal 411, act_phs5[:val]
370
+ end
371
+
372
+ #
373
+ # returns Int if String is convertable
374
+ #
375
+ def test_string_to_int
376
+ str1 = ""
377
+ str2 = "awesome"
378
+ str3 = "123awesome"
379
+ str4 = "123"
380
+ exp1 = ""
381
+ exp2 = "awesome"
382
+ exp3 = "123awesome"
383
+ exp4 = 123
384
+ act1 = @format.string_to_int(str1)
385
+ act2 = @format.string_to_int(str2)
386
+ act3 = @format.string_to_int(str3)
387
+ act4 = @format.string_to_int(str4)
388
+ assert_equal exp1, act1
389
+ assert_equal exp2, act2
390
+ assert_equal exp3, act3
391
+ assert_equal exp4, act4
392
+ end
393
+ end
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'minitest/unit'
5
+ $: << 'lib' << 'test'
6
+ require 'yamlr/reader/node'
7
+ require 'yamlr/reader/parser'
8
+ require 'yamlr/indicators'
9
+ MiniTest::Unit.autorun
10
+
11
+ class TestReaderParser < MiniTest::Unit::TestCase
12
+ def setup
13
+ @parser = Yamlr::Reader::Parser
14
+ @opt = Yamlr::Indicators.options
15
+ end
16
+
17
+ def test_parser_module
18
+ assert_kind_of Module, @parser
19
+ end
20
+
21
+ def test_parse_raise_indenterror
22
+ lin1 = " 7:7"
23
+ spc1 = 1
24
+ idt1 = 2
25
+ num1 = 88
26
+ assert_raises(Yamlr::Reader::Parser::IndentError) {
27
+ @parser.check_indent(lin1, spc1, idt1, num1)
28
+ }
29
+ end
30
+
31
+ def test_check_indent_no_raise_indenterror
32
+ lin1 = " 7:7"
33
+ spc1 = 2
34
+ idt1 = 2
35
+ num1 = 88
36
+ assert_nil @parser.check_indent(lin1, spc1, idt1, num1)
37
+ end
38
+
39
+ def test_parse_comment
40
+ line = "#dude"
41
+ phs = @parser.parse(line, @opt, 77)
42
+ exp_msg = "com".to_sym
43
+ exp_spc = 0
44
+ exp_key = ""
45
+ exp_val = "dude"
46
+ exp_ask = nil
47
+ exp_asv = nil
48
+ exp_opt = @opt
49
+ assert_equal exp_msg, phs[:msg]
50
+ assert_equal exp_spc, phs[:spc]
51
+ assert_equal exp_key, phs[:key]
52
+ assert_equal exp_val, phs[:val]
53
+ assert_equal exp_ask, phs[:ask]
54
+ assert_equal exp_asv, phs[:asv]
55
+ assert_equal exp_opt, phs[:opt]
56
+ end
57
+
58
+ # parsed line => [msg, spc, key, val, ask, asv, opt]
59
+ def test_results_to_hash
60
+ results = [1, " ", "3", "4", 5, 6]
61
+ phs = @parser.results_to_hash(results, 7)
62
+ exp_msg = 1
63
+ exp_spc = 2
64
+ exp_key = "3"
65
+ exp_val = "4"
66
+ exp_ask = 5
67
+ exp_asv = 6
68
+ exp_opt = 7
69
+ assert_equal exp_msg, phs[:msg]
70
+ assert_equal exp_spc, phs[:spc]
71
+ assert_equal exp_key, phs[:key]
72
+ assert_equal exp_val, phs[:val]
73
+ assert_equal exp_ask, phs[:ask]
74
+ assert_equal exp_asv, phs[:asv]
75
+ assert_equal exp_opt, phs[:opt]
76
+ end
77
+
78
+ def test_parse_line_malformed
79
+ line = "awesome"
80
+ phs = @parser.parse_line(line, @opt)
81
+ assert_equal :mal, phs[0]
82
+ assert_equal "awesome", phs[3]
83
+ end
84
+
85
+ def test_parse_line_blank
86
+ line1 = " "
87
+ line2 = ""
88
+ exp_phs1 = @parser.parse_line(line1, @opt)
89
+ exp_phs2 = @parser.parse_line(line2, @opt)
90
+ assert_equal :bla, exp_phs1[0]
91
+ assert_equal :bla, exp_phs2[0]
92
+ end
93
+
94
+ def test_parse_line_comment
95
+ line1 = " #awesome"
96
+ line2 = "# dude"
97
+ line3 = "###beer"
98
+ line4 = " # camaro"
99
+ exp_phs1 = @parser.parse_line(line1, @opt)
100
+ exp_phs2 = @parser.parse_line(line2, @opt)
101
+ exp_phs3 = @parser.parse_line(line3, @opt)
102
+ exp_phs4 = @parser.parse_line(line4, @opt)
103
+ assert_equal :com, exp_phs1[0]
104
+ assert_equal :com, exp_phs2[0]
105
+ assert_equal :com, exp_phs3[0]
106
+ assert_equal :com, exp_phs4[0]
107
+ assert_equal "awesome", exp_phs1.flatten[3]
108
+ assert_equal "dude", exp_phs2.flatten[3]
109
+ assert_equal "##beer", exp_phs3.flatten[3]
110
+ assert_equal "camaro", exp_phs4.flatten[3]
111
+ end
112
+
113
+ def test_parse_line_array
114
+ line1 = "- awesome"
115
+ line2 = " -dude"
116
+ line3 = " -- beer"
117
+ line4 = " - #camaro"
118
+ exp_phs1 = @parser.parse_line(line1, @opt)
119
+ exp_phs2 = @parser.parse_line(line2, @opt)
120
+ exp_phs3 = @parser.parse_line(line3, @opt)
121
+ exp_phs4 = @parser.parse_line(line4, @opt)
122
+ assert_equal :arr, exp_phs1[0]
123
+ assert_equal :arr, exp_phs2[0]
124
+ assert_equal :arr, exp_phs3[0]
125
+ assert_equal :arr, exp_phs4[0]
126
+ assert_equal "", exp_phs1.flatten[1]
127
+ assert_equal " ", exp_phs2.flatten[1]
128
+ assert_equal " ", exp_phs3.flatten[1]
129
+ assert_equal " ", exp_phs4.flatten[1]
130
+ assert_equal "awesome", exp_phs1.flatten[3]
131
+ assert_equal "dude", exp_phs2.flatten[3]
132
+ assert_equal "- beer", exp_phs3.flatten[3]
133
+ assert_equal "#camaro", exp_phs4.flatten[3]
134
+ end
135
+
136
+ def test_parse_line_hashkey
137
+ line1 = "awesome:"
138
+ line2 = " dude :"
139
+ line3 = " :beer:"
140
+ line4 = ' "camaro":'
141
+ exp_phs1 = @parser.parse_line(line1, @opt)
142
+ exp_phs2 = @parser.parse_line(line2, @opt)
143
+ exp_phs3 = @parser.parse_line(line3, @opt)
144
+ exp_phs4 = @parser.parse_line(line4, @opt)
145
+ assert_equal :hky, exp_phs1[0]
146
+ assert_equal :mal, exp_phs2[0]
147
+ assert_equal :hky, exp_phs3[0]
148
+ assert_equal :hky, exp_phs4[0]
149
+ assert_equal "", exp_phs1.flatten[1]
150
+ assert_equal " ", exp_phs3.flatten[1]
151
+ assert_equal " ", exp_phs4.flatten[1]
152
+ assert_equal "awesome", exp_phs1.flatten[2]
153
+ assert_equal ":beer", exp_phs3.flatten[2]
154
+ assert_equal '"camaro"', exp_phs4.flatten[2]
155
+ assert_equal nil, exp_phs1.flatten[4]
156
+ assert_equal true, exp_phs3.flatten[4]
157
+ assert_equal nil, exp_phs4.flatten[4]
158
+ end
159
+
160
+ def test_parse_line_hashpair
161
+ line1 = "awesome:dude"
162
+ line2 = " :dude::fekja"
163
+ line3 = " :beer:coke"
164
+ line4 = ' "camaro"::firebird'
165
+ exp_phs1 = @parser.parse_line(line1, @opt)
166
+ exp_phs2 = @parser.parse_line(line2, @opt)
167
+ exp_phs3 = @parser.parse_line(line3, @opt)
168
+ exp_phs4 = @parser.parse_line(line4, @opt)
169
+ assert_equal :hpr, exp_phs1[0]
170
+ assert_equal :hpr, exp_phs2[0]
171
+ assert_equal :hpr, exp_phs3[0]
172
+ assert_equal :hpr, exp_phs4[0]
173
+ assert_equal "", exp_phs1.flatten[1]
174
+ assert_equal " ", exp_phs2.flatten[1]
175
+ assert_equal " ", exp_phs3.flatten[1]
176
+ assert_equal " ", exp_phs4.flatten[1]
177
+ assert_equal "awesome", exp_phs1.flatten[2]
178
+ assert_equal ":dude", exp_phs2.flatten[2]
179
+ assert_equal ":beer", exp_phs3.flatten[2]
180
+ assert_equal '"camaro"', exp_phs4.flatten[2]
181
+ assert_equal nil, exp_phs1.flatten[4]
182
+ assert_equal true, exp_phs2.flatten[4]
183
+ assert_equal true, exp_phs3.flatten[4]
184
+ assert_equal nil, exp_phs4.flatten[4]
185
+ assert_equal nil, exp_phs1.flatten[5]
186
+ assert_equal true, exp_phs2.flatten[5]
187
+ assert_equal nil, exp_phs3.flatten[5]
188
+ assert_equal true, exp_phs4.flatten[5]
189
+ end
190
+ end