iniparse 1.1.6 → 1.2.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.
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Tests parsing of multiple lines, in context, using #parse.
4
-
5
- describe 'Parsing a document' do
6
- describe 'when a comment preceeds a single section and option' do
7
- before(:all) do
8
- @doc = IniParse::Parser.new(fixture(:comment_before_section)).parse
9
- end
10
-
11
- it 'should have a comment as the first line' do
12
- @doc.lines.to_a.first.should be_kind_of(IniParse::Lines::Comment)
13
- end
14
-
15
- it 'should have one section' do
16
- @doc.lines.keys.should == ['first_section']
17
- end
18
-
19
- it 'should have one option belonging to `first_section`' do
20
- @doc['first_section']['key'].should == 'value'
21
- end
22
- end
23
-
24
- it 'should allow blank lines to preceed the first section' do
25
- lambda {
26
- @doc = IniParse::Parser.new(fixture(:blank_before_section)).parse
27
- }.should_not raise_error
28
-
29
- @doc.lines.to_a.first.should be_kind_of(IniParse::Lines::Blank)
30
- end
31
-
32
- it 'should allow a blank line to belong to a section' do
33
- lambda {
34
- @doc = IniParse::Parser.new(fixture(:blank_in_section)).parse
35
- }.should_not raise_error
36
-
37
- @doc['first_section'].lines.to_a.first.should be_kind_of(IniParse::Lines::Blank)
38
- end
39
-
40
- it 'should permit comments on their own line' do
41
- lambda {
42
- @doc = IniParse::Parser.new(fixture(:comment_line)).parse
43
- }.should_not raise_error
44
-
45
- line = @doc['first_section'].lines.to_a.first
46
- line.comment.should eql('; block comment ;')
47
- end
48
-
49
- it 'should raise an error if an option preceeds the first section' do
50
- lambda {
51
- IniParse::Parser.new(fixture(:option_before_section)).parse
52
- }.should raise_error(IniParse::NoSectionError)
53
- end
54
-
55
- it 'should raise ParseError if a line could not be parsed' do
56
- lambda { IniParse::Parser.new(fixture(:invalid_line)).parse }.should \
57
- raise_error(IniParse::ParseError)
58
- end
59
-
60
- describe 'when a section name contains "="' do
61
- before(:all) do
62
- @doc = IniParse::Parser.new(fixture(:section_with_equals)).parse
63
- end
64
-
65
- it 'should have two sections' do
66
- @doc.lines.to_a.length.should == 2
67
- end
68
-
69
- it 'should have one section' do
70
- @doc.lines.keys.should == ['first_section = name',
71
- 'another_section = a name']
72
- end
73
-
74
- it 'should have one option belonging to `first_section = name`' do
75
- @doc['first_section = name']['key'].should == 'value'
76
- end
77
-
78
- it 'should have one option belonging to `another_section = a name`' do
79
- @doc['another_section = a name']['another'].should == 'thing'
80
- end
81
- end
82
- end
@@ -1,382 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Tests parsing of individual, out of context, line types using #parse_line.
4
-
5
- describe 'Parsing a line' do
6
- it 'should strip leading whitespace and set the :indent option' do
7
- IniParse::Parser.parse_line(' [section]').should \
8
- be_section_tuple(:any, {:indent => ' '})
9
- end
10
-
11
- it 'should raise an error if the line could not be matched' do
12
- lambda { IniParse::Parser.parse_line('invalid line') }.should \
13
- raise_error(IniParse::ParseError)
14
- end
15
-
16
- it 'should parse using the types set in IniParse::Parser.parse_types' do
17
- begin
18
- # Remove last type.
19
- type = IniParse::Parser.parse_types.pop
20
- type.should_not_receive(:parse)
21
- IniParse::Parser.parse_line('[section]')
22
- ensure
23
- IniParse::Parser.parse_types << type
24
- end
25
- end
26
-
27
- # --
28
- # ==========================================================================
29
- # Option lines.
30
- # ==========================================================================
31
- # ++
32
-
33
- describe 'with "k = v"' do
34
- before(:all) do
35
- @tuple = IniParse::Parser.parse_line('k = v')
36
- end
37
-
38
- it 'should return an option tuple' do
39
- @tuple.should be_option_tuple('k', 'v')
40
- end
41
-
42
- it 'should set no indent, comment, offset or separator' do
43
- @tuple.last[:indent].should be_nil
44
- @tuple.last[:comment].should be_nil
45
- @tuple.last[:comment_offset].should be_nil
46
- @tuple.last[:comment_sep].should be_nil
47
- end
48
- end
49
-
50
- describe 'with "k = a value with spaces"' do
51
- it 'should return an option tuple' do
52
- IniParse::Parser.parse_line('k = a value with spaces').should \
53
- be_option_tuple('k', 'a value with spaces')
54
- end
55
- end
56
-
57
- describe 'with "k = v ; a comment "' do
58
- before(:all) do
59
- @tuple = IniParse::Parser.parse_line('k = v ; a comment')
60
- end
61
-
62
- it 'should return an option tuple' do
63
- @tuple.should be_option_tuple('k', 'v')
64
- end
65
-
66
- it 'should set the comment to "a comment"' do
67
- @tuple.should be_option_tuple(:any, :any, :comment => 'a comment')
68
- end
69
-
70
- it 'should set the comment separator to ";"' do
71
- @tuple.should be_option_tuple(:any, :any, :comment_sep => ';')
72
- end
73
-
74
- it 'should set the comment offset to 6' do
75
- @tuple.should be_option_tuple(:any, :any, :comment_offset => 6)
76
- end
77
- end
78
-
79
- describe 'with "k = v;w;x y;z"' do
80
- before(:all) do
81
- @tuple = IniParse::Parser.parse_line('k = v;w;x y;z')
82
- end
83
-
84
- it 'should return an option tuple with the correct value' do
85
- @tuple.should be_option_tuple(:any, 'v;w;x y;z')
86
- end
87
-
88
- it 'should not set a comment' do
89
- @tuple.last[:comment].should be_nil
90
- @tuple.last[:comment_offset].should be_nil
91
- @tuple.last[:comment_sep].should be_nil
92
- end
93
- end
94
-
95
- describe 'with "k = v;w ; a comment"' do
96
- before(:all) do
97
- @tuple = IniParse::Parser.parse_line('k = v;w ; a comment')
98
- end
99
-
100
- it 'should return an option tuple with the correct value' do
101
- @tuple.should be_option_tuple(:any, 'v;w')
102
- end
103
-
104
- it 'should set the comment to "a comment"' do
105
- @tuple.should be_option_tuple(:any, :any, :comment => 'a comment')
106
- end
107
-
108
- it 'should set the comment separator to ";"' do
109
- @tuple.should be_option_tuple(:any, :any, :comment_sep => ';')
110
- end
111
-
112
- it 'should set the comment offset to 8' do
113
- @tuple.should be_option_tuple(:any, :any, :comment_offset => 8)
114
- end
115
- end
116
-
117
- describe 'with "key=value"' do
118
- it 'should return an option tuple with the correct key and value' do
119
- IniParse::Parser.parse_line('key=value').should \
120
- be_option_tuple('key', 'value')
121
- end
122
- end
123
-
124
- describe 'with "key= value"' do
125
- it 'should return an option tuple with the correct key and value' do
126
- IniParse::Parser.parse_line('key= value').should \
127
- be_option_tuple('key', 'value')
128
- end
129
- end
130
-
131
- describe 'with "key =value"' do
132
- it 'should return an option tuple with the correct key and value' do
133
- IniParse::Parser.parse_line('key =value').should \
134
- be_option_tuple('key', 'value')
135
- end
136
- end
137
-
138
- describe 'with "key = value"' do
139
- it 'should return an option tuple with the correct key and value' do
140
- IniParse::Parser.parse_line('key = value').should \
141
- be_option_tuple('key', 'value')
142
- end
143
- end
144
-
145
- describe 'with "key ="' do
146
- it 'should return an option tuple with the correct key' do
147
- IniParse::Parser.parse_line('key =').should \
148
- be_option_tuple('key')
149
- end
150
-
151
- it 'should set the option value to nil' do
152
- IniParse::Parser.parse_line('key =').should \
153
- be_option_tuple(:any, nil)
154
- end
155
- end
156
-
157
-
158
- describe 'with "key = EEjDDJJjDJDJD233232=="' do
159
- it 'should include the "equals" in the option value' do
160
- IniParse::Parser.parse_line('key = EEjDDJJjDJDJD233232==').should \
161
- be_option_tuple('key', 'EEjDDJJjDJDJD233232==')
162
- end
163
- end
164
-
165
- describe 'with "key = ==EEjDDJJjDJDJD233232"' do
166
- it 'should include the "equals" in the option value' do
167
- IniParse::Parser.parse_line('key = ==EEjDDJJjDJDJD233232').should \
168
- be_option_tuple('key', '==EEjDDJJjDJDJD233232')
169
- end
170
- end
171
-
172
- describe 'with "key.two = value"' do
173
- it 'should return an option tuple with the correct key' do
174
- IniParse::Parser.parse_line('key.two = value').should \
175
- be_option_tuple('key.two')
176
- end
177
- end
178
-
179
- describe 'with "key/with/slashes = value"' do
180
- it 'should return an option tuple with the correct key' do
181
- IniParse::Parser.parse_line('key/with/slashes = value').should \
182
- be_option_tuple('key/with/slashes', 'value')
183
- end
184
- end
185
-
186
- describe 'with "key_with_underscores = value"' do
187
- it 'should return an option tuple with the correct key' do
188
- IniParse::Parser.parse_line('key_with_underscores = value').should \
189
- be_option_tuple('key_with_underscores', 'value')
190
- end
191
- end
192
-
193
- describe 'with "key-with-dashes = value"' do
194
- it 'should return an option tuple with the correct key' do
195
- IniParse::Parser.parse_line('key-with-dashes = value').should \
196
- be_option_tuple('key-with-dashes', 'value')
197
- end
198
- end
199
-
200
- describe 'with "key with spaces = value"' do
201
- it 'should return an option tuple with the correct key' do
202
- IniParse::Parser.parse_line('key with spaces = value').should \
203
- be_option_tuple('key with spaces', 'value')
204
- end
205
- end
206
-
207
- # --
208
- # ==========================================================================
209
- # Section lines.
210
- # ==========================================================================
211
- # ++
212
-
213
- describe 'with "[section]"' do
214
- before(:all) do
215
- @tuple = IniParse::Parser.parse_line('[section]')
216
- end
217
-
218
- it 'should return a section tuple' do
219
- @tuple.should be_section_tuple('section')
220
- end
221
-
222
- it 'should set no indent, comment, offset or separator' do
223
- @tuple.last[:indent].should be_nil
224
- @tuple.last[:comment].should be_nil
225
- @tuple.last[:comment_offset].should be_nil
226
- @tuple.last[:comment_sep].should be_nil
227
- end
228
- end
229
-
230
- describe 'with "[section with whitespace]"' do
231
- it 'should return a section tuple with the correct key' do
232
- IniParse::Parser.parse_line('[section with whitespace]').should \
233
- be_section_tuple('section with whitespace')
234
- end
235
- end
236
-
237
- describe 'with "[ section with surounding whitespace ]"' do
238
- it 'should return a section tuple with the correct key' do
239
- IniParse::Parser.parse_line('[ section with surounding whitespace ]').should \
240
- be_section_tuple(' section with surounding whitespace ')
241
- end
242
- end
243
-
244
- describe 'with "[section] ; a comment"' do
245
- before(:all) do
246
- @tuple = IniParse::Parser.parse_line('[section] ; a comment')
247
- end
248
-
249
- it 'should return a section tuple' do
250
- @tuple.should be_section_tuple('section')
251
- end
252
-
253
- it 'should set the comment to "a comment"' do
254
- @tuple.should be_section_tuple(:any, :comment => 'a comment')
255
- end
256
-
257
- it 'should set the comment separator to ";"' do
258
- @tuple.should be_section_tuple(:any, :comment_sep => ';')
259
- end
260
-
261
- it 'should set the comment offset to 10' do
262
- @tuple.should be_section_tuple(:any, :comment_offset => 10)
263
- end
264
- end
265
-
266
- describe 'with "[section;with#comment;chars]"' do
267
- before(:all) do
268
- @tuple = IniParse::Parser.parse_line('[section;with#comment;chars]')
269
- end
270
-
271
- it 'should return a section tuple with the correct key' do
272
- @tuple.should be_section_tuple('section;with#comment;chars')
273
- end
274
-
275
- it 'should not set a comment' do
276
- @tuple.last[:indent].should be_nil
277
- @tuple.last[:comment].should be_nil
278
- @tuple.last[:comment_offset].should be_nil
279
- @tuple.last[:comment_sep].should be_nil
280
- end
281
- end
282
-
283
- describe 'with "[section;with#comment;chars] ; a comment"' do
284
- before(:all) do
285
- @tuple = IniParse::Parser.parse_line('[section;with#comment;chars] ; a comment')
286
- end
287
-
288
- it 'should return a section tuple with the correct key' do
289
- @tuple.should be_section_tuple('section;with#comment;chars')
290
- end
291
-
292
- it 'should set the comment to "a comment"' do
293
- @tuple.should be_section_tuple(:any, :comment => 'a comment')
294
- end
295
-
296
- it 'should set the comment separator to ";"' do
297
- @tuple.should be_section_tuple(:any, :comment_sep => ';')
298
- end
299
-
300
- it 'should set the comment offset to 29' do
301
- @tuple.should be_section_tuple(:any, :comment_offset => 29)
302
- end
303
- end
304
-
305
- # --
306
- # ==========================================================================
307
- # Comment lines.
308
- # ==========================================================================
309
- # ++
310
-
311
- describe 'with "; a comment"' do
312
- before(:all) do
313
- @tuple = IniParse::Parser.parse_line('; a comment')
314
- end
315
-
316
- it 'should return a comment tuple with the correct comment' do
317
- @tuple.should be_comment_tuple('a comment')
318
- end
319
-
320
- it 'should set the comment separator to ";"' do
321
- @tuple.should be_comment_tuple(:any, :comment_sep => ';')
322
- end
323
-
324
- it 'should set the comment offset to 0' do
325
- @tuple.should be_comment_tuple(:any, :comment_offset => 0)
326
- end
327
- end
328
-
329
- describe 'with " ; a comment"' do
330
- before(:all) do
331
- @tuple = IniParse::Parser.parse_line(' ; a comment')
332
- end
333
-
334
- it 'should return a comment tuple with the correct comment' do
335
- @tuple.should be_comment_tuple('a comment')
336
- end
337
-
338
- it 'should set the comment separator to ";"' do
339
- @tuple.should be_comment_tuple(:any, :comment_sep => ';')
340
- end
341
-
342
- it 'should set the comment offset to 1' do
343
- @tuple.should be_comment_tuple(:any, :comment_offset => 1)
344
- end
345
- end
346
-
347
- describe 'with ";"' do
348
- before(:all) do
349
- @tuple = IniParse::Parser.parse_line(';')
350
- end
351
-
352
- it 'should return a comment tuple with an empty value' do
353
- @tuple.should be_comment_tuple('')
354
- end
355
-
356
- it 'should set the comment separator to ";"' do
357
- @tuple.should be_comment_tuple(:any, :comment_sep => ';')
358
- end
359
-
360
- it 'should set the comment offset to 0' do
361
- @tuple.should be_comment_tuple(:any, :comment_offset => 0)
362
- end
363
- end
364
-
365
- # --
366
- # ==========================================================================
367
- # Blank lines.
368
- # ==========================================================================
369
- # ++
370
-
371
- describe 'with ""' do
372
- it 'should return a blank tuple' do
373
- IniParse::Parser.parse_line('').should be_blank_tuple
374
- end
375
- end
376
-
377
- describe 'with " "' do
378
- it 'should return a blank tuple' do
379
- IniParse::Parser.parse_line(' ').should be_blank_tuple
380
- end
381
- end
382
- end