diff options
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | README.yarn | 4 | ||||
-rw-r--r-- | simple.scenario | 3 | ||||
-rw-r--r-- | yarnlib/block_parser.py | 8 | ||||
-rw-r--r-- | yarnlib/block_parser_tests.py | 8 |
5 files changed, 27 insertions, 2 deletions
@@ -3,6 +3,12 @@ NEWS for cmdtest This file summarizes changes between releases of cmdtest. +Version 0.14, released UNRELEASED +--------------------------------- + +* Yarn now supports continuation lines: start a line with `...` and it + continues the previous line. + Version 0.12, released 2014-03-28 --------------------------------- diff --git a/README.yarn b/README.yarn index 5f1c7a2..843fac8 100644 --- a/README.yarn +++ b/README.yarn @@ -99,7 +99,9 @@ A test document is written in [Markdown][markdown], with block quoted code blocks being interpreted specially. Each block must follow the syntax defined here. -* Every step in a scenario is one line, and starts with a keyword. +* Every step in a scenario is one logical line, and starts with a + keyword. A step can be continued on the next physical line by + starting the next line with `...` (three dots, followed by a space). * Each implementation (IMPLEMENTS) starts as a new block, and continues until there is a block that starts with another diff --git a/simple.scenario b/simple.scenario index 8061e47..a244d88 100644 --- a/simple.scenario +++ b/simple.scenario @@ -9,7 +9,8 @@ the scenario test runner itself. The following is the actual test in this scenario: GIVEN a clean slate - WHEN nothing happens + WHEN nothing + ... happens THEN everything is OK AND not all is well FINALLY cleanup diff --git a/yarnlib/block_parser.py b/yarnlib/block_parser.py index 64dc990..db99b31 100644 --- a/yarnlib/block_parser.py +++ b/yarnlib/block_parser.py @@ -42,6 +42,7 @@ class BlockParser(object): 'THEN': self.parse_then, 'FINALLY': self.parse_finally, 'AND': self.parse_and, + '...': self.parse_continuation, 'IMPLEMENTS': self.parse_implementing, } @@ -113,6 +114,13 @@ class BlockParser(object): assert step.what in self.line_parsers return self.line_parsers[step.what](line, blocks) + def parse_continuation(self, line, blocks): + scenario = self.scenarios[-1] + step = scenario.steps[-1] + text = '%s %s' % (step.text, line) + del scenario.steps[-1] + return self.line_parsers[step.what](text, blocks) + def parse_implementing(self, line, blocks): words = line.split() if len(words) < 2: diff --git a/yarnlib/block_parser_tests.py b/yarnlib/block_parser_tests.py index 78754b5..689a197 100644 --- a/yarnlib/block_parser_tests.py +++ b/yarnlib/block_parser_tests.py @@ -54,6 +54,14 @@ class BlockParserTests(unittest.TestCase): self.assertEqual(scenario.steps[5].what, 'FINALLY') self.assertEqual(scenario.steps[5].text, 'yeehaa') + def test_handles_continuation_line(self): + self.parser.parse_blocks(['SCENARIO foo', 'GIVEN foo', '... and bar']) + scenario = self.parser.scenarios[0] + self.assertEqual(len(self.parser.scenarios), 1) + self.assertEqual(scenario.name, 'foo') + self.assertEqual(scenario.steps[0].what, 'GIVEN') + self.assertEqual(scenario.steps[0].text, 'foo and bar') + def test_normalises_whitespace(self): self.parser.parse_blocks(['SCENARIO foo bar ']) self.assertEqual(self.parser.scenarios[0].name, 'foo bar') |