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 --- yarnlib/block_parser.py | 8 ++++++++ yarnlib/block_parser_tests.py | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'yarnlib') 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