metaheader 1.3beta3 → 1.3beta4
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.
- checksums.yaml +4 -4
- data/lib/metaheader.rb +16 -3
- data/lib/metaheader/version.rb +1 -1
- data/test/test_multiline.rb +193 -0
- data/test/test_parser.rb +0 -135
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b110cd1fab31d12091a47b6d9b77cdb001b5c14
|
4
|
+
data.tar.gz: 483baa10662faaf8ccd83c93a5fae63e9ce83ab7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9b0cbfc3b61abd41cc545a0825d56995f5362c701170c6b709911a44d56c4c2205b4e849712207dabb2e9de8f1d5ab4d50592b1982c95a5aa5853c7a54c523b
|
7
|
+
data.tar.gz: cc5133876cdeb62d1ebce9808411e7e43883c084bc6645d6ae4836622cf5b875d5243a17fa0009eda156e29970d75e6e80bec899965cd45556820093401211cf
|
data/lib/metaheader.rb
CHANGED
@@ -227,6 +227,7 @@ private
|
|
227
227
|
|
228
228
|
@last_tag = Tag.new match[:key].freeze, value
|
229
229
|
@line_breaks = 0
|
230
|
+
@block_indent = nil
|
230
231
|
|
231
232
|
# disable implicit values with the alternate syntax
|
232
233
|
register @last_tag unless match[:alt] && match[:value].nil?
|
@@ -236,10 +237,12 @@ private
|
|
236
237
|
end
|
237
238
|
|
238
239
|
def register(tag)
|
240
|
+
return if has? tag
|
239
241
|
key = tag.name.downcase.gsub(/[^\w]/, '_').to_sym
|
240
242
|
@data[key] = tag
|
241
243
|
end
|
242
244
|
|
245
|
+
# handle multiline tags
|
243
246
|
def append(line)
|
244
247
|
prefix = line.rstrip
|
245
248
|
if prefix == @last_prefix.rstrip
|
@@ -248,9 +251,19 @@ private
|
|
248
251
|
return true # add the line break later
|
249
252
|
elsif line.start_with? @last_prefix
|
250
253
|
mline = line[@last_prefix.size..-1]
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
+
|
255
|
+
if @block_indent
|
256
|
+
if mline.start_with? @block_indent
|
257
|
+
stripped = mline[@block_indent.size..-1]
|
258
|
+
else
|
259
|
+
return
|
260
|
+
end
|
261
|
+
else
|
262
|
+
stripped = mline.lstrip
|
263
|
+
indent_level = mline.index stripped
|
264
|
+
return if indent_level < 1
|
265
|
+
@block_indent = mline[0, indent_level]
|
266
|
+
end
|
254
267
|
else
|
255
268
|
return
|
256
269
|
end
|
data/lib/metaheader/version.rb
CHANGED
@@ -0,0 +1,193 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
|
3
|
+
class TestMultiline < MiniTest::Test
|
4
|
+
def test_multiline
|
5
|
+
mh = MetaHeader.new <<-IN
|
6
|
+
@test Lorem
|
7
|
+
Ipsum
|
8
|
+
IN
|
9
|
+
|
10
|
+
assert_equal "Lorem\nIpsum", mh[:test]
|
11
|
+
assert_equal 1, mh.size
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_variant
|
15
|
+
mh = MetaHeader.new <<-IN
|
16
|
+
@test
|
17
|
+
Lorem
|
18
|
+
Ipsum
|
19
|
+
IN
|
20
|
+
|
21
|
+
assert_equal "Lorem\nIpsum", mh[:test]
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_trailing_space
|
25
|
+
mh = MetaHeader.new <<-IN
|
26
|
+
@hello\x20
|
27
|
+
test\x20
|
28
|
+
@world\x20\x20
|
29
|
+
test\x20
|
30
|
+
IN
|
31
|
+
|
32
|
+
assert_equal 'test ', mh[:hello]
|
33
|
+
assert_equal 'test ', mh[:world]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_prefix
|
37
|
+
mh = MetaHeader.new <<-IN
|
38
|
+
-- @test Lorem
|
39
|
+
-- Ipsum
|
40
|
+
IN
|
41
|
+
|
42
|
+
assert_equal "Lorem\nIpsum", mh[:test]
|
43
|
+
assert_equal 1, mh.size
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_no_indent
|
47
|
+
mh = MetaHeader.new <<-IN
|
48
|
+
@test Lorem
|
49
|
+
Ipsum
|
50
|
+
Test
|
51
|
+
IN
|
52
|
+
|
53
|
+
assert_equal 1, mh.size
|
54
|
+
assert_equal "Lorem", mh[:test]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lose_indent
|
58
|
+
mh = MetaHeader.new <<-IN
|
59
|
+
@test
|
60
|
+
Hello
|
61
|
+
|
62
|
+
World
|
63
|
+
@chunky bacon
|
64
|
+
|
65
|
+
@foo
|
66
|
+
IN
|
67
|
+
|
68
|
+
assert_equal "Hello\n\nWorld", mh[:test]
|
69
|
+
assert_equal 'bacon', mh[:chunky]
|
70
|
+
assert_nil mh[:foo]
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_fewer_indent
|
74
|
+
mh = MetaHeader.new <<-IN
|
75
|
+
@test Lorem
|
76
|
+
Ipsum
|
77
|
+
Hello
|
78
|
+
World
|
79
|
+
IN
|
80
|
+
|
81
|
+
assert_equal 1, mh.size
|
82
|
+
assert_equal "Lorem\nIpsum", mh[:test]
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_extra_indent
|
86
|
+
mh = MetaHeader.new <<-IN
|
87
|
+
@test Lorem
|
88
|
+
Ipsum
|
89
|
+
Hello
|
90
|
+
World
|
91
|
+
IN
|
92
|
+
|
93
|
+
assert_equal 1, mh.size
|
94
|
+
assert_equal "Lorem\nIpsum\n Hello\nWorld", mh[:test]
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_do_not_reuse_indent
|
98
|
+
mh = MetaHeader.new <<-IN
|
99
|
+
@a
|
100
|
+
Lorem
|
101
|
+
Ipsum
|
102
|
+
@b
|
103
|
+
\tHello
|
104
|
+
\tWorld
|
105
|
+
IN
|
106
|
+
|
107
|
+
assert_equal 2, mh.size
|
108
|
+
assert_equal "Lorem\nIpsum", mh[:a]
|
109
|
+
assert_equal "Hello\nWorld", mh[:b]
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_sub_alternate_syntax
|
113
|
+
mh = MetaHeader.new <<-IN
|
114
|
+
@test Lorem
|
115
|
+
Ipsum:
|
116
|
+
Dolor: sit amet
|
117
|
+
IN
|
118
|
+
|
119
|
+
assert_equal "Lorem\nIpsum:\nDolor: sit amet", mh[:test]
|
120
|
+
assert_equal 1, mh.size
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_explicit_boolean
|
124
|
+
mh = MetaHeader.new <<-IN
|
125
|
+
@test true
|
126
|
+
test
|
127
|
+
IN
|
128
|
+
|
129
|
+
assert_equal "true\ntest", mh[:test]
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_empty_line_prefix
|
133
|
+
mh = MetaHeader.new <<-IN
|
134
|
+
--@test
|
135
|
+
-- Hello
|
136
|
+
--
|
137
|
+
-- World
|
138
|
+
--
|
139
|
+
--@chunky
|
140
|
+
-- bacon
|
141
|
+
IN
|
142
|
+
|
143
|
+
assert_equal "Hello\n\nWorld", mh[:test]
|
144
|
+
assert_equal 'bacon', mh[:chunky]
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_empty_line_prefix_with_space
|
148
|
+
mh = MetaHeader.new <<-IN
|
149
|
+
-- @test
|
150
|
+
-- Hello
|
151
|
+
--
|
152
|
+
-- World
|
153
|
+
IN
|
154
|
+
|
155
|
+
assert_equal "Hello\n\nWorld", mh[:test]
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_empty_line
|
159
|
+
mh = MetaHeader.new <<-IN
|
160
|
+
@test
|
161
|
+
Hello
|
162
|
+
|
163
|
+
World
|
164
|
+
@chunky bacon
|
165
|
+
|
166
|
+
@foo
|
167
|
+
IN
|
168
|
+
|
169
|
+
assert_equal "Hello\n\nWorld", mh[:test]
|
170
|
+
assert_equal 'bacon', mh[:chunky]
|
171
|
+
assert_nil mh[:foo]
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_break_at_empty_line
|
175
|
+
mh = MetaHeader.new <<-IN
|
176
|
+
-- @hello world
|
177
|
+
|
178
|
+
@chunky bacon
|
179
|
+
IN
|
180
|
+
|
181
|
+
assert_equal 'world', mh[:hello]
|
182
|
+
assert_nil mh[:chunky]
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_alternate_syntax
|
186
|
+
mh = MetaHeader.new <<-IN
|
187
|
+
-- Hello:
|
188
|
+
-- World
|
189
|
+
IN
|
190
|
+
|
191
|
+
assert_equal 'World', mh[:hello]
|
192
|
+
end
|
193
|
+
end
|
data/test/test_parser.rb
CHANGED
@@ -124,141 +124,6 @@ class TestParser < MiniTest::Test
|
|
124
124
|
refute_nil mh[:second]
|
125
125
|
end
|
126
126
|
|
127
|
-
def test_multiline
|
128
|
-
mh = MetaHeader.new <<-IN
|
129
|
-
@test Lorem
|
130
|
-
Ipsum
|
131
|
-
IN
|
132
|
-
|
133
|
-
assert_equal "Lorem\nIpsum", mh[:test]
|
134
|
-
assert_equal 1, mh.size
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_multiline_variant
|
138
|
-
mh = MetaHeader.new <<-IN
|
139
|
-
@test
|
140
|
-
Lorem
|
141
|
-
Ipsum
|
142
|
-
IN
|
143
|
-
|
144
|
-
assert_equal "Lorem\nIpsum", mh[:test]
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_multiline_trailing_space
|
148
|
-
mh = MetaHeader.new <<-IN
|
149
|
-
@hello\x20
|
150
|
-
test\x20
|
151
|
-
@world\x20\x20
|
152
|
-
test\x20
|
153
|
-
IN
|
154
|
-
|
155
|
-
assert_equal 'test ', mh[:hello]
|
156
|
-
assert_equal 'test ', mh[:world]
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_multiline_prefix
|
160
|
-
mh = MetaHeader.new <<-IN
|
161
|
-
-- @test Lorem
|
162
|
-
-- Ipsum
|
163
|
-
IN
|
164
|
-
|
165
|
-
assert_equal "Lorem\nIpsum", mh[:test]
|
166
|
-
assert_equal 1, mh.size
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_multiline_wrong_indent
|
170
|
-
mh = MetaHeader.new <<-IN
|
171
|
-
@test Lorem
|
172
|
-
Ipsum
|
173
|
-
Test
|
174
|
-
IN
|
175
|
-
|
176
|
-
assert_equal 1, mh.size
|
177
|
-
assert_equal "Lorem", mh[:test]
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_multiline_sub_alternate_syntax
|
181
|
-
mh = MetaHeader.new <<-IN
|
182
|
-
@test Lorem
|
183
|
-
Ipsum:
|
184
|
-
Dolor: sit amet
|
185
|
-
IN
|
186
|
-
|
187
|
-
assert_equal "Lorem\nIpsum:\nDolor: sit amet", mh[:test]
|
188
|
-
assert_equal 1, mh.size
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_multiline_explicit_boolean
|
192
|
-
mh = MetaHeader.new <<-IN
|
193
|
-
@test true
|
194
|
-
test
|
195
|
-
IN
|
196
|
-
|
197
|
-
assert_equal "true\ntest", mh[:test]
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_multiline_empty_line_prefix
|
201
|
-
mh = MetaHeader.new <<-IN
|
202
|
-
--@test
|
203
|
-
-- Hello
|
204
|
-
--
|
205
|
-
-- World
|
206
|
-
--
|
207
|
-
--@chunky
|
208
|
-
-- bacon
|
209
|
-
IN
|
210
|
-
|
211
|
-
assert_equal "Hello\n\nWorld", mh[:test]
|
212
|
-
assert_equal 'bacon', mh[:chunky]
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_multiline_empty_line_space_prefix
|
216
|
-
mh = MetaHeader.new <<-IN
|
217
|
-
-- @test
|
218
|
-
-- Hello
|
219
|
-
--
|
220
|
-
-- World
|
221
|
-
IN
|
222
|
-
|
223
|
-
assert_equal "Hello\n\nWorld", mh[:test]
|
224
|
-
end
|
225
|
-
|
226
|
-
def test_multiline_empty_line
|
227
|
-
mh = MetaHeader.new <<-IN
|
228
|
-
@test
|
229
|
-
Hello
|
230
|
-
|
231
|
-
World
|
232
|
-
@chunky bacon
|
233
|
-
|
234
|
-
@foo
|
235
|
-
IN
|
236
|
-
|
237
|
-
assert_equal "Hello\n\nWorld", mh[:test]
|
238
|
-
assert_equal 'bacon', mh[:chunky]
|
239
|
-
assert_nil mh[:foo]
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_multiline_break_at_empty_line
|
243
|
-
mh = MetaHeader.new <<-IN
|
244
|
-
-- @hello world
|
245
|
-
|
246
|
-
@chunky bacon
|
247
|
-
IN
|
248
|
-
|
249
|
-
assert_equal 'world', mh[:hello]
|
250
|
-
assert_nil mh[:chunky]
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_multiline_alternate_syntax
|
254
|
-
mh = MetaHeader.new <<-IN
|
255
|
-
-- Hello:
|
256
|
-
-- World
|
257
|
-
IN
|
258
|
-
|
259
|
-
assert_equal 'World', mh[:hello]
|
260
|
-
end
|
261
|
-
|
262
127
|
def test_read_file
|
263
128
|
path = File.expand_path '../input/basic_tag', __FILE__
|
264
129
|
mh = MetaHeader.from_file path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metaheader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cfillion
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- test/helper.rb
|
102
102
|
- test/input/basic_tag
|
103
103
|
- test/input/custom_parser
|
104
|
+
- test/test_multiline.rb
|
104
105
|
- test/test_parser.rb
|
105
106
|
- test/test_validator.rb
|
106
107
|
homepage: https://github.com/cfillion/metaheader
|
@@ -131,5 +132,6 @@ test_files:
|
|
131
132
|
- test/helper.rb
|
132
133
|
- test/input/basic_tag
|
133
134
|
- test/input/custom_parser
|
135
|
+
- test/test_multiline.rb
|
134
136
|
- test/test_parser.rb
|
135
137
|
- test/test_validator.rb
|