Merge pull request #216 from smikes/215-indented-yaml

candidate fix for #215
This commit is contained in:
Brian Terlson 2015-03-31 11:41:37 -07:00
commit 43acf615b5
2 changed files with 43 additions and 4 deletions

View File

@ -90,7 +90,7 @@ def myFlowList(value):
def myMultiline(lines, value):
# assume no explcit indentor (otherwise have to parse value)
value = []
indent = 1
indent = myLeadingSpaces(lines[0])
while lines:
line = lines.pop(0)
if myIsAllSpaces(line):

View File

@ -58,7 +58,7 @@ class TestMonkeyYAMLParsing(unittest.TestCase):
self.assertEqual(lines, [])
self.assertEqual(value, yaml.load(y))
def test_Multiline_1(self):
def test_Multiline_2(self):
lines = [" foo", " bar"]
value = ">"
y = "\n".join([value] + lines)
@ -66,6 +66,21 @@ class TestMonkeyYAMLParsing(unittest.TestCase):
self.assertEqual(lines, [])
self.assertEqual(value, yaml.load(y))
def test_Multiline_3(self):
lines = [" foo", " bar"]
value = ">"
y = "\n".join([value] + lines)
(lines, value) = monkeyYaml.myMultiline(lines, value)
self.assertEqual(lines, [])
self.assertEqual(value, yaml.load(y))
def test_Multiline_4(self):
lines = [" foo", " bar", " other: 42"]
value = ">"
(lines, value) = monkeyYaml.myMultiline(lines, value)
self.assertEqual(lines, [" other: 42"])
self.assertEqual(value, "foo bar")
def test_myLeading(self):
self.assertEqual(2, monkeyYaml.myLeadingSpaces(" foo"))
self.assertEqual(2, monkeyYaml.myLeadingSpaces(" "))
@ -83,15 +98,39 @@ class TestMonkeyYAMLParsing(unittest.TestCase):
y = "foo:\n - bar\n - baz"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_mulineline_list2(self):
def test_multiline_list2(self):
self.assertEqual(monkeyYaml.myRemoveListHeader(2, " - foo"), "foo")
def test_mulineline_list3(self):
def test_multiline_list3(self):
(lines, value) = monkeyYaml.myMultilineList([" - foo", " - bar", "baz: bletch"], "")
self.assertEqual(lines, ["baz: bletch"])
self.assertEqual(value, ["foo", "bar"])
def test_oneline_indented(self):
y = " foo: bar\n baz: baf\n"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_indentation_215(self):
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))
def test_indentation_215_2(self):
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))
if __name__ == '__main__':
unittest.main()