From 2915fe8527d06c2cb1a4780eeac37ef743c02d9f Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Sun, 31 Jan 2016 13:16:12 -0500 Subject: [PATCH] Update test harness to support new negative format --- tools/packaging/monkeyYaml.py | 25 ++++++++++++++++--------- tools/packaging/test/test_monkeyYaml.py | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/tools/packaging/monkeyYaml.py b/tools/packaging/monkeyYaml.py index b017e55b56..21c3fa42ee 100644 --- a/tools/packaging/monkeyYaml.py +++ b/tools/packaging/monkeyYaml.py @@ -14,12 +14,16 @@ mYamlListPattern = re.compile(r"^\[(.*)\]$") mYamlMultilineList = re.compile(r"^ *- (.*)$") def load(str): + return myReadDict(str.splitlines())[1] + +def myReadDict(lines, indent=""): dict = None key = None emptyLines = 0 - - lines = str.splitlines() while lines: + if not lines[0].startswith(indent): + break + line = lines.pop(0) if myIsAllSpaces(line): emptyLines += 1 @@ -31,7 +35,7 @@ def load(str): dict = {} key = result.group(1).strip() value = result.group(2).strip() - (lines, value) = myReadValue(lines, value) + (lines, value) = myReadValue(lines, value, indent) dict[key] = value else: if dict and key and key in dict: @@ -40,17 +44,20 @@ def load(str): else: raise Exception("monkeyYaml is confused at " + line) emptyLines = 0 - return dict + return lines, dict -def myReadValue(lines, value): +def myReadValue(lines, value, indent): if value == ">" or value == "|": (lines, value) = myMultiline(lines, value) value = value + "\n" return (lines, value) - if lines and not value and myMaybeList(lines[0]): - return myMultilineList(lines, value) - else: - return lines, myReadOneLine(value) + if lines and not value: + if myMaybeList(lines[0]): + return myMultilineList(lines, value) + indentMatch = re.match("(" + indent + r"\s+)", lines[0]) + if indentMatch: + return myReadDict(lines, indentMatch.group(1)) + return lines, myReadOneLine(value) def myMaybeList(value): return mYamlMultilineList.match(value) diff --git a/tools/packaging/test/test_monkeyYaml.py b/tools/packaging/test/test_monkeyYaml.py index df6667105d..92d4e6139b 100644 --- a/tools/packaging/test/test_monkeyYaml.py +++ b/tools/packaging/test/test_monkeyYaml.py @@ -182,6 +182,27 @@ description: ggg jjj 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))