From 37b1d7a7a89b9d5c51674cf873f82a212beb0bb9 Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Wed, 1 Jul 2015 10:19:33 -0400 Subject: [PATCH] monkeyYaml: Add support for line folding Fixes #345 --- tools/packaging/monkeyYaml.py | 11 ++++- tools/packaging/test/test_monkeyYaml.py | 61 +++++++++++++++++++++---- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/tools/packaging/monkeyYaml.py b/tools/packaging/monkeyYaml.py index 85e1ae1940..26ac194b4e 100644 --- a/tools/packaging/monkeyYaml.py +++ b/tools/packaging/monkeyYaml.py @@ -15,13 +15,17 @@ mYamlMultilineList = re.compile(r"^ *- (.*)$") def load(str): dict = None + key = None + emptyLines = 0 lines = str.splitlines() while lines: line = lines.pop(0) if myIsAllSpaces(line): + emptyLines += 1 continue result = mYamlKV.match(line) + if result: if not dict: dict = {} @@ -30,7 +34,12 @@ def load(str): (lines, value) = myReadValue(lines, value) dict[key] = value 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 def myReadValue(lines, value): diff --git a/tools/packaging/test/test_monkeyYaml.py b/tools/packaging/test/test_monkeyYaml.py index c0800e35a7..cd0accf54b 100644 --- a/tools/packaging/test/test_monkeyYaml.py +++ b/tools/packaging/test/test_monkeyYaml.py @@ -111,30 +111,75 @@ class TestMonkeyYAMLParsing(unittest.TestCase): self.assertEqual(monkeyYaml.load(y), yaml.load(y)) def test_oneline_indented(self): - y = " foo: bar\n baz: baf\n" - self.assertEqual(monkeyYaml.load(y), yaml.load(y)) + y = " foo: bar\n baz: baf\n" + self.assertEqual(monkeyYaml.load(y), yaml.load(y)) def test_indentation_215(self): - self.maxDiff = None - y = """ + self.maxDiff = None + y = """ description: > The method should exist on the Array prototype, and it should be writable and configurable, but not enumerable. includes: [propertyHelper.js] 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): - self.maxDiff = None - y = """ + self.maxDiff = None + y = """ description: > The method should exist includes: [propertyHelper.js] 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__': unittest.main()