mirror of https://github.com/tc39/test262.git
Merge pull request #346 from arv/monkey-yaml-confused
monkeyYaml: Add support for line folding
This commit is contained in:
commit
c6ac390868
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue