From 19e090549b933c31aeb057e59825a8c279e26e99 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 10 Feb 2015 10:23:17 +0200 Subject: Implement continuation lines in yarn --- simple.scenario | 3 ++- yarnlib/block_parser.py | 8 ++++++++ yarnlib/block_parser_tests.py | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) 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') -- cgit v1.2.1 From 0185e694afdd4741a4e4f64a9cf0fa2a2aa3990e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 10 Feb 2015 10:23:59 +0200 Subject: Update NEWS --- NEWS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS b/NEWS index 9c3eb04..093c6b8 100644 --- a/NEWS +++ b/NEWS @@ -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 --------------------------------- -- cgit v1.2.1 From 70df4760574d8143186be21a558c100f001a0155 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 10 Feb 2015 10:25:04 +0200 Subject: Update README.yarn --- README.yarn | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1