iniparse 1.1.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/README.rdoc +16 -0
- data/Rakefile +1 -1
- data/iniparse.gemspec +8 -21
- data/lib/iniparse.rb +1 -1
- data/lib/iniparse/line_collection.rb +4 -2
- data/lib/iniparse/lines.rb +24 -1
- data/lib/iniparse/parser.rb +4 -3
- metadata +16 -47
- data/spec/document_spec.rb +0 -88
- data/spec/fixture_spec.rb +0 -166
- data/spec/fixtures/openttd.ini +0 -397
- data/spec/fixtures/race07.ini +0 -133
- data/spec/fixtures/smb.ini +0 -102
- data/spec/generator/method_missing_spec.rb +0 -104
- data/spec/generator/with_section_blocks_spec.rb +0 -322
- data/spec/generator/without_section_blocks_spec.rb +0 -136
- data/spec/iniparse_spec.rb +0 -21
- data/spec/line_collection_spec.rb +0 -214
- data/spec/lines_spec.rb +0 -407
- data/spec/parser/document_parsing_spec.rb +0 -82
- data/spec/parser/line_parsing_spec.rb +0 -382
- data/spec/spec_fixtures.rb +0 -62
- data/spec/spec_helper.rb +0 -168
- data/spec/spec_helper_spec.rb +0 -201
data/spec/spec_fixtures.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
module IniParse
|
2
|
-
module Test
|
3
|
-
class Fixtures
|
4
|
-
@@fixtures = {}
|
5
|
-
|
6
|
-
def self.[](fix)
|
7
|
-
if @@fixtures.has_key?(fix)
|
8
|
-
@@fixtures[fix]
|
9
|
-
else
|
10
|
-
@@fixtures[fix] = File.read(
|
11
|
-
File.join(File.expand_path('fixtures', File.dirname(__FILE__)), fix)
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.[]=(fix, val)
|
17
|
-
@@fixtures[fix] = val
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
IniParse::Test::Fixtures[:comment_before_section] = <<-FIX.gsub(/^ /, '')
|
24
|
-
; This is a comment
|
25
|
-
[first_section]
|
26
|
-
key = value
|
27
|
-
FIX
|
28
|
-
|
29
|
-
IniParse::Test::Fixtures[:blank_before_section] = <<-FIX.gsub(/^ /, '')
|
30
|
-
|
31
|
-
[first_section]
|
32
|
-
key = value
|
33
|
-
FIX
|
34
|
-
|
35
|
-
IniParse::Test::Fixtures[:blank_in_section] = <<-FIX.gsub(/^ /, '')
|
36
|
-
[first_section]
|
37
|
-
|
38
|
-
key = value
|
39
|
-
FIX
|
40
|
-
|
41
|
-
IniParse::Test::Fixtures[:option_before_section] = <<-FIX.gsub(/^ /, '')
|
42
|
-
key = value
|
43
|
-
[first_section]
|
44
|
-
FIX
|
45
|
-
|
46
|
-
IniParse::Test::Fixtures[:invalid_line] = <<-FIX.gsub(/^ /, '')
|
47
|
-
this line is not valid
|
48
|
-
FIX
|
49
|
-
|
50
|
-
IniParse::Test::Fixtures[:section_with_equals] = <<-FIX.gsub(/^ /, '')
|
51
|
-
[first_section = name]
|
52
|
-
key = value
|
53
|
-
[another_section = a name]
|
54
|
-
another = thing
|
55
|
-
FIX
|
56
|
-
|
57
|
-
IniParse::Test::Fixtures[:comment_line] = <<-FIX.gsub(/^ /, '')
|
58
|
-
[first_section]
|
59
|
-
; block comment ;
|
60
|
-
; with more lines ;
|
61
|
-
key = value
|
62
|
-
FIX
|
data/spec/spec_helper.rb
DELETED
@@ -1,168 +0,0 @@
|
|
1
|
-
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
require 'iniparse'
|
7
|
-
require File.join(File.dirname(__FILE__), 'spec_fixtures')
|
8
|
-
|
9
|
-
module IniParse
|
10
|
-
module Test
|
11
|
-
module Helpers
|
12
|
-
# Taken from Merb Core's spec helper.
|
13
|
-
# Merb is licenced using the MIT License and is copyright
|
14
|
-
# Engine Yard Inc.
|
15
|
-
class BeKindOf
|
16
|
-
def initialize(expected) # + args
|
17
|
-
@expected = expected
|
18
|
-
end
|
19
|
-
|
20
|
-
def matches?(target)
|
21
|
-
@target = target
|
22
|
-
@target.kind_of?(@expected)
|
23
|
-
end
|
24
|
-
|
25
|
-
def failure_message
|
26
|
-
"expected #{@expected} but got #{@target.class}"
|
27
|
-
end
|
28
|
-
|
29
|
-
def negative_failure_message
|
30
|
-
"expected #{@expected} to not be #{@target.class}"
|
31
|
-
end
|
32
|
-
|
33
|
-
def description
|
34
|
-
"be_kind_of #{@target}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Used to match line tuples returned by Parser.parse_line.
|
39
|
-
class BeLineTuple
|
40
|
-
def initialize(type, value_keys = [], *expected)
|
41
|
-
@expected_type = type
|
42
|
-
@value_keys = value_keys
|
43
|
-
|
44
|
-
if expected.nil?
|
45
|
-
@expected_opts = {}
|
46
|
-
@expected_values = []
|
47
|
-
else
|
48
|
-
@expected_opts = expected.pop
|
49
|
-
@expected_values = expected
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def matches?(tuple)
|
54
|
-
@tuple = tuple
|
55
|
-
|
56
|
-
@failure_message = catch(:fail) do
|
57
|
-
tuple?
|
58
|
-
correct_type?
|
59
|
-
correct_values?
|
60
|
-
correct_opts?
|
61
|
-
true
|
62
|
-
end
|
63
|
-
|
64
|
-
@failure_message == true
|
65
|
-
end
|
66
|
-
|
67
|
-
def failure_message
|
68
|
-
"expected #{@expected_type} tuple #{@failure_message}"
|
69
|
-
end
|
70
|
-
|
71
|
-
def negative_failure_message
|
72
|
-
"expected #{@tuple.inspect} to not be #{@expected_type} tuple"
|
73
|
-
end
|
74
|
-
|
75
|
-
def description
|
76
|
-
"be_#{@expected_type}_tuple #{@tuple}"
|
77
|
-
end
|
78
|
-
|
79
|
-
#######
|
80
|
-
private
|
81
|
-
#######
|
82
|
-
|
83
|
-
# Matchers.
|
84
|
-
|
85
|
-
def tuple?
|
86
|
-
throw :fail, "but was #{@tuple.class}" unless @tuple.kind_of?(Array)
|
87
|
-
end
|
88
|
-
|
89
|
-
def correct_type?
|
90
|
-
throw :fail, "but was #{type} tuple" unless type == @expected_type
|
91
|
-
end
|
92
|
-
|
93
|
-
def correct_values?
|
94
|
-
# Make sure the values match.
|
95
|
-
@value_keys.each_with_index do |key, i|
|
96
|
-
if @expected_values[i] != :any && values[i] != @expected_values[i]
|
97
|
-
throw :fail, 'with %s value of "%s" but was "%s"' % [
|
98
|
-
key, values[i], @expected_values[i]
|
99
|
-
]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def correct_opts?
|
105
|
-
if(! @expected_opts.nil?)
|
106
|
-
if (! @expected_opts.empty?) && opts.empty?
|
107
|
-
throw :fail, 'with options but there were none'
|
108
|
-
end
|
109
|
-
|
110
|
-
@expected_opts.each do |key, value|
|
111
|
-
unless opts.has_key?(key)
|
112
|
-
throw :fail, 'with option "%s", but key was not present' % key
|
113
|
-
end
|
114
|
-
|
115
|
-
unless opts[key] == value
|
116
|
-
throw :fail, 'with option "%s" => "%s" but was "%s"' % [
|
117
|
-
key, value, opts[key]
|
118
|
-
]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Tuple values, etc.
|
125
|
-
|
126
|
-
def type
|
127
|
-
@type ||= @tuple.first
|
128
|
-
end
|
129
|
-
|
130
|
-
def values
|
131
|
-
@values ||= @tuple.length < 3 ? [] : @tuple[1..-2]
|
132
|
-
end
|
133
|
-
|
134
|
-
def opts
|
135
|
-
@opts ||= @tuple.last
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def be_kind_of(expected) # + args
|
140
|
-
BeKindOf.new(expected)
|
141
|
-
end
|
142
|
-
|
143
|
-
def be_section_tuple(key = :any, opts = {})
|
144
|
-
BeLineTuple.new(:section, [:key], key, opts)
|
145
|
-
end
|
146
|
-
|
147
|
-
def be_option_tuple(key = :any, value = :any, opts = {})
|
148
|
-
BeLineTuple.new(:option, [:key, :value], key, value, opts)
|
149
|
-
end
|
150
|
-
|
151
|
-
def be_blank_tuple
|
152
|
-
BeLineTuple.new(:blank)
|
153
|
-
end
|
154
|
-
|
155
|
-
def be_comment_tuple(comment = :any, opts = {})
|
156
|
-
BeLineTuple.new(:comment, [:comment], comment, opts)
|
157
|
-
end
|
158
|
-
|
159
|
-
def fixture(fix)
|
160
|
-
IniParse::Test::Fixtures[fix]
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
RSpec.configure do |config|
|
167
|
-
config.include(IniParse::Test::Helpers)
|
168
|
-
end
|
data/spec/spec_helper_spec.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# --
|
4
|
-
# ============================================================================
|
5
|
-
# Empty array.
|
6
|
-
# ============================================================================
|
7
|
-
# ++
|
8
|
-
|
9
|
-
describe 'An empty array' do
|
10
|
-
it 'should not pass be_section_tuple' do
|
11
|
-
[].should_not be_section_tuple
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should not pass be_option_tuple' do
|
15
|
-
[].should_not be_option_tuple
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should not pass be_blank_tuple' do
|
19
|
-
[].should_not be_blank_tuple
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should not pass be_comment_tuple' do
|
23
|
-
[].should_not be_comment_tuple
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# --
|
28
|
-
# ============================================================================
|
29
|
-
# Section tuple.
|
30
|
-
# ============================================================================
|
31
|
-
# ++
|
32
|
-
|
33
|
-
describe 'Line tuple [:section, "key", {:opt => "val"}]' do
|
34
|
-
before(:all) { @tuple = [:section, "key", {:opt => "val"}] }
|
35
|
-
|
36
|
-
it 'should pass be_section_tuple' do
|
37
|
-
@tuple.should be_section_tuple
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should pass be_section_tuple("key")' do
|
41
|
-
@tuple.should be_section_tuple("key")
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should fail be_section_tuple("invalid")' do
|
45
|
-
@tuple.should_not be_section_tuple("invalid")
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should pass be_section_tuple("key", {:opt => "val"})' do
|
49
|
-
@tuple.should be_section_tuple("key", {:opt => "val"})
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should not pass be_section_tuple("key", {:invalid => "val"})' do
|
53
|
-
@tuple.should_not be_section_tuple("key", {:invalid => "val"})
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should not pass be_section_tuple("key", {:opt => "invalid"})' do
|
57
|
-
@tuple.should_not be_section_tuple("key", {:opt => "invalid"})
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should fail be_option_tuple' do
|
61
|
-
@tuple.should_not be_option_tuple
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should fail be_blank_tuple' do
|
65
|
-
@tuple.should_not be_blank_tuple
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should fail be_comment_tuple' do
|
69
|
-
@tuple.should_not be_comment_tuple
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# --
|
74
|
-
# ============================================================================
|
75
|
-
# Option tuple.
|
76
|
-
# ============================================================================
|
77
|
-
# ++
|
78
|
-
|
79
|
-
describe 'Line tuple [:option, "key", "val", {:opt => "val"}]' do
|
80
|
-
before(:all) { @tuple = [:option, "key", "val", {:opt => "val"}] }
|
81
|
-
|
82
|
-
it 'should fail be_section_tuple' do
|
83
|
-
@tuple.should_not be_section_tuple
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should pass be_option_tuple' do
|
87
|
-
@tuple.should be_option_tuple
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should pass be_option_tuple("key")' do
|
91
|
-
@tuple.should be_option_tuple("key")
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should fail be_option_tuple("invalid")' do
|
95
|
-
@tuple.should_not be_option_tuple("invalid")
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should pass be_option_tuple("key", "val")' do
|
99
|
-
@tuple.should be_option_tuple("key", "val")
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should pass be_option_tuple(:any, "val")' do
|
103
|
-
@tuple.should be_option_tuple(:any, "val")
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should fail be_option_tuple("key", "invalid")' do
|
107
|
-
@tuple.should_not be_option_tuple("key", "invalid")
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should pass be_option_tuple("key", "val", { :opt => "val" })' do
|
111
|
-
@tuple.should be_option_tuple("key", "val", { :opt => "val" })
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'should fail be_option_tuple("key", "val", { :invalid => "val" })' do
|
115
|
-
@tuple.should_not be_option_tuple("key", "val", { :invalid => "val" })
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'should fail be_option_tuple("key", "val", { :opt => "invalid" })' do
|
119
|
-
@tuple.should_not be_option_tuple("key", "val", { :opt => "invalid" })
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should fail be_blank_tuple' do
|
123
|
-
@tuple.should_not be_blank_tuple
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'should fail be_comment_tuple' do
|
127
|
-
@tuple.should_not be_comment_tuple
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# --
|
132
|
-
# ============================================================================
|
133
|
-
# Blank tuple.
|
134
|
-
# ============================================================================
|
135
|
-
# ++
|
136
|
-
|
137
|
-
describe 'Line tuple [:blank]' do
|
138
|
-
before(:all) { @tuple = [:blank] }
|
139
|
-
|
140
|
-
it 'should fail be_section_tuple' do
|
141
|
-
@tuple.should_not be_section_tuple
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'should fail be_option_tuple' do
|
145
|
-
@tuple.should_not be_option_tuple
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should pass be_blank_tuple' do
|
149
|
-
@tuple.should be_blank_tuple
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'should fail be_comment_tuple' do
|
153
|
-
@tuple.should_not be_comment_tuple
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
# --
|
158
|
-
# ============================================================================
|
159
|
-
# Coment tuple.
|
160
|
-
# ============================================================================
|
161
|
-
# ++
|
162
|
-
|
163
|
-
describe 'Line tuple [:comment, "A comment", {:opt => "val"}]' do
|
164
|
-
before(:all) { @tuple = [:comment, "A comment", {:opt => "val"}] }
|
165
|
-
|
166
|
-
it 'should fail be_section_tuple' do
|
167
|
-
@tuple.should_not be_section_tuple
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'should fail be_option_tuple' do
|
171
|
-
@tuple.should_not be_option_tuple
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'should fail be_blank_tuple' do
|
175
|
-
@tuple.should_not be_blank_tuple
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should pass be_comment_tuple' do
|
179
|
-
@tuple.should be_comment_tuple
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'should pass be_comment_tuple("A comment")' do
|
183
|
-
@tuple.should be_comment_tuple("A comment")
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'should fail be_comment_tuple("Invalid")' do
|
187
|
-
@tuple.should_not be_comment_tuple("Invalid")
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'should pass be_comment_tuple("A comment", {:opt => "val"})' do
|
191
|
-
@tuple.should be_comment_tuple("A comment", {:opt => "val"})
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'should fail be_comment_tuple("A comment", {:invalid => "val"})' do
|
195
|
-
@tuple.should_not be_comment_tuple("A comment", {:invalid => "val"})
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'should fail be_comment_tuple("A comment", {:opt => "invalid"})' do
|
199
|
-
@tuple.should_not be_comment_tuple("A comment", {:opt => "invalid"})
|
200
|
-
end
|
201
|
-
end
|