Update test harness to support new negative format

This commit is contained in:
Mike Pennisi 2016-01-31 13:16:12 -05:00
parent 7d4b1d28ae
commit 2915fe8527
2 changed files with 37 additions and 9 deletions

View File

@ -14,12 +14,16 @@ mYamlListPattern = re.compile(r"^\[(.*)\]$")
mYamlMultilineList = re.compile(r"^ *- (.*)$") mYamlMultilineList = re.compile(r"^ *- (.*)$")
def load(str): def load(str):
return myReadDict(str.splitlines())[1]
def myReadDict(lines, indent=""):
dict = None dict = None
key = None key = None
emptyLines = 0 emptyLines = 0
lines = str.splitlines()
while lines: while lines:
if not lines[0].startswith(indent):
break
line = lines.pop(0) line = lines.pop(0)
if myIsAllSpaces(line): if myIsAllSpaces(line):
emptyLines += 1 emptyLines += 1
@ -31,7 +35,7 @@ def load(str):
dict = {} dict = {}
key = result.group(1).strip() key = result.group(1).strip()
value = result.group(2).strip() value = result.group(2).strip()
(lines, value) = myReadValue(lines, value) (lines, value) = myReadValue(lines, value, indent)
dict[key] = value dict[key] = value
else: else:
if dict and key and key in dict: if dict and key and key in dict:
@ -40,16 +44,19 @@ def load(str):
else: else:
raise Exception("monkeyYaml is confused at " + line) raise Exception("monkeyYaml is confused at " + line)
emptyLines = 0 emptyLines = 0
return dict return lines, dict
def myReadValue(lines, value): def myReadValue(lines, value, indent):
if value == ">" or value == "|": if value == ">" or value == "|":
(lines, value) = myMultiline(lines, value) (lines, value) = myMultiline(lines, value)
value = value + "\n" value = value + "\n"
return (lines, value) return (lines, value)
if lines and not value and myMaybeList(lines[0]): if lines and not value:
if myMaybeList(lines[0]):
return myMultilineList(lines, value) return myMultilineList(lines, value)
else: indentMatch = re.match("(" + indent + r"\s+)", lines[0])
if indentMatch:
return myReadDict(lines, indentMatch.group(1))
return lines, myReadOneLine(value) return lines, myReadOneLine(value)
def myMaybeList(value): def myMaybeList(value):

View File

@ -182,6 +182,27 @@ description: ggg
jjj jjj
es6id: 19.1.2.1 es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_nested_1(self):
y = """
es61d: 19.1.2.1
negative:
stage: early
type: ReferenceError
description: foo
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_nested_2(self):
y = """
es61d: 19.1.2.1
first:
second_a:
third: 1
second_b: 3
description: foo
""" """
self.assertEqual(monkeyYaml.load(y), yaml.load(y)) self.assertEqual(monkeyYaml.load(y), yaml.load(y))