From 2bd060daaf3b73af6461c0601088c274d947b302 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 27 Oct 2015 20:39:39 +0200 Subject: Implement EXAMLE blocks --- simple.scenario | 6 ++++++ yarnlib/block_parser.py | 5 +++++ yarnlib/block_parser_tests.py | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/simple.scenario b/simple.scenario index 9391cf1..5beed80 100644 --- a/simple.scenario +++ b/simple.scenario @@ -17,6 +17,12 @@ The following is the actual test in this scenario: We also support some non-ASCII text: älämölö. +We can have code examples: + + EXAMPLE this is a code example + This is NOT a scenario! + This is just ignored. + And the implementations follow. IMPLEMENTS GIVEN a clean slate diff --git a/yarnlib/block_parser.py b/yarnlib/block_parser.py index db99b31..df95fb2 100644 --- a/yarnlib/block_parser.py +++ b/yarnlib/block_parser.py @@ -44,6 +44,7 @@ class BlockParser(object): 'AND': self.parse_and, '...': self.parse_continuation, 'IMPLEMENTS': self.parse_implementing, + 'EXAMPLE': self.parse_example, } def parse_blocks(self, blocks): @@ -148,3 +149,7 @@ class BlockParser(object): self.implementations.append(implementation) return blocks + def parse_example(self, line, blocks): + if blocks: + del blocks[0] + return blocks diff --git a/yarnlib/block_parser_tests.py b/yarnlib/block_parser_tests.py index 689a197..ead8a31 100644 --- a/yarnlib/block_parser_tests.py +++ b/yarnlib/block_parser_tests.py @@ -30,6 +30,10 @@ class BlockParserTests(unittest.TestCase): self.assertEqual(self.parser.scenarios, []) self.assertEqual(self.parser.implementations, []) + def test_skips_examples(self): + self.parser.parse_blocks(['EXAMPLE foo', 'bar']) + self.assertEqual(len(self.parser.scenarios), 0) + def test_parses_simple_elements(self): self.parser.parse_blocks( ['SCENARIO foo', 'ASSUMING something', 'GIVEN bar', -- cgit v1.2.1