From 7fdb775486405a334b2f0db4e47eac9c7ed53023 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 9 Jun 2013 11:51:30 +0100 Subject: Add tests for BlockParser --- yarnlib/__init__.py | 1 + yarnlib/block_parser.py | 21 +++++++++++++ yarnlib/block_parser_tests.py | 73 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 yarnlib/block_parser.py create mode 100644 yarnlib/block_parser_tests.py (limited to 'yarnlib') diff --git a/yarnlib/__init__.py b/yarnlib/__init__.py index 2abc3ad..7b81c66 100644 --- a/yarnlib/__init__.py +++ b/yarnlib/__init__.py @@ -18,3 +18,4 @@ from mdparser import MarkdownParser from elements import Story, StoryStep, Implementation +from block_parser import BlockParser diff --git a/yarnlib/block_parser.py b/yarnlib/block_parser.py new file mode 100644 index 0000000..8fd87d2 --- /dev/null +++ b/yarnlib/block_parser.py @@ -0,0 +1,21 @@ +# Copyright 2013 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# =*= License: GPL-3+ =*= + + +class BlockParser(object): + + pass diff --git a/yarnlib/block_parser_tests.py b/yarnlib/block_parser_tests.py new file mode 100644 index 0000000..1c14a80 --- /dev/null +++ b/yarnlib/block_parser_tests.py @@ -0,0 +1,73 @@ +# Copyright 2013 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# =*= License: GPL-3+ =*= + + +import unittest + +import yarnlib + + +class BlockParserTests(unittest.TestCase): + + def setUp(self): + self.parser = yarnlib.BlockParser() + + def test_is_initially_empty(self): + self.assertEqual(self.parser.stories, []) + self.assertEqual(self.parser.implementations, []) + + def test_parses_simple_elements(self): + self.parser.parse_blocks( + ['STORY foo', 'GIVEN bar', 'WHEN foobar\nTHEN yoyo']) + + self.assertEqual(len(self.parser.stories), 1) + self.assertEqual(len(self.parser.implementations), 0) + + story = self.parser.stories[0] + self.assertEqual(story.name, 'foo') + self.assertEqual(len(story.steps), 3) + self.assertEqual(story.steps[0].what, 'GIVEN') + self.assertEqual(story.steps[0].text, 'bar') + self.assertEqual(story.steps[0].what, 'WHEN') + self.assertEqual(story.steps[0].text, 'foobar') + self.assertEqual(story.steps[0].what, 'THEN') + self.assertEqual(story.steps[0].text, 'yoyo') + + def test_normalises_whitespace(self): + self.parser.parse_code_blocks(['STORY foo bar ']) + self.assertEqual(self.parser.stories[0].name, 'foo bar') + + def test_parses_implements_in_a_block_by_itself(self): + self.parser.parse_code_blocks(['IMPLEMENTS GIVEN foo\ntrue']) + impls = self.parser.implementations + self.assertEqual(len(impls), 1) + self.assertEqual(impls[0].what, 'GIVEN') + self.assertEqual(impls[0].regexp, 'foo') + self.assertEqual(impls[0].shell, 'true') + + def test_parses_two_implements_in_a_code_block(self): + self.parser.parse_code_blocks( + ['IMPLEMENTS GIVEN foo\ntrue\nIMPLEMENTS WHEN bar\ncat /dev/null']) + impls = self.parser.implementations + self.assertEqual(len(impls), 2) + self.assertEqual(impls[0].what, 'GIVEN') + self.assertEqual(impls[0].regexp, 'foo') + self.assertEqual(impls[0].shell, 'true') + self.assertEqual(impls[1].what, 'WHEN') + self.assertEqual(impls[1].regexp, 'bar') + self.assertEqual(impls[1].shell, 'cat /dev/null') + -- cgit v1.2.1