Skip to content
Snippets Groups Projects
Commit c6ac3908 authored by Brian Terlson's avatar Brian Terlson
Browse files

Merge pull request #346 from arv/monkey-yaml-confused

monkeyYaml: Add support for line folding
parents 1e80bf22 37b1d7a7
No related branches found
No related tags found
No related merge requests found
...@@ -15,13 +15,17 @@ mYamlMultilineList = re.compile(r"^ *- (.*)$") ...@@ -15,13 +15,17 @@ mYamlMultilineList = re.compile(r"^ *- (.*)$")
def load(str): def load(str):
dict = None dict = None
key = None
emptyLines = 0
lines = str.splitlines() lines = str.splitlines()
while lines: while lines:
line = lines.pop(0) line = lines.pop(0)
if myIsAllSpaces(line): if myIsAllSpaces(line):
emptyLines += 1
continue continue
result = mYamlKV.match(line) result = mYamlKV.match(line)
if result: if result:
if not dict: if not dict:
dict = {} dict = {}
...@@ -30,7 +34,12 @@ def load(str): ...@@ -30,7 +34,12 @@ def load(str):
(lines, value) = myReadValue(lines, value) (lines, value) = myReadValue(lines, value)
dict[key] = value dict[key] = value
else: else:
raise Exception("monkeyYaml is confused at " + line) if dict and key and key in dict:
c = " " if emptyLines == 0 else "\n" * emptyLines
dict[key] += c + line.strip()
else:
raise Exception("monkeyYaml is confused at " + line)
emptyLines = 0
return dict return dict
def myReadValue(lines, value): def myReadValue(lines, value):
......
...@@ -111,30 +111,75 @@ class TestMonkeyYAMLParsing(unittest.TestCase): ...@@ -111,30 +111,75 @@ class TestMonkeyYAMLParsing(unittest.TestCase):
self.assertEqual(monkeyYaml.load(y), yaml.load(y)) self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_oneline_indented(self): def test_oneline_indented(self):
y = " foo: bar\n baz: baf\n" y = " foo: bar\n baz: baf\n"
self.assertEqual(monkeyYaml.load(y), yaml.load(y)) self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_indentation_215(self): def test_indentation_215(self):
self.maxDiff = None self.maxDiff = None
y = """ y = """
description: > description: >
The method should exist on the Array prototype, and it should be writable The method should exist on the Array prototype, and it should be writable
and configurable, but not enumerable. and configurable, but not enumerable.
includes: [propertyHelper.js] includes: [propertyHelper.js]
es6id: 22.1.3.13 es6id: 22.1.3.13
""" """
self.assertEqual(monkeyYaml.load(y), yaml.load(y)) self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_indentation_215_2(self): def test_indentation_215_2(self):
self.maxDiff = None self.maxDiff = None
y = """ y = """
description: > description: >
The method should exist The method should exist
includes: [propertyHelper.js] includes: [propertyHelper.js]
es6id: 22.1.3.13 es6id: 22.1.3.13
""" """
self.assertEqual(monkeyYaml.load(y), yaml.load(y)) self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding(self):
self.maxDiff = None
y = """
description: aaa
bbb
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding_2(self):
self.maxDiff = None
y = """
description: ccc
ddd
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding_3(self):
self.maxDiff = None
y = """
description: eee
fff
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding_4(self):
self.maxDiff = None
y = """
description: ggg
hhh
iii
jjj
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment