summaryrefslogtreecommitdiff
path: root/yarnlib/block_parser_tests.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-06-09 11:51:30 +0100
committerLars Wirzenius <liw@liw.fi>2013-06-09 11:51:30 +0100
commit7fdb775486405a334b2f0db4e47eac9c7ed53023 (patch)
treed6c20cd153538933804f6c09732b421fa962e34d /yarnlib/block_parser_tests.py
parentfe8ce17ae1d9a4b1e7a2df1b9588fbe42bec2000 (diff)
downloadcmdtest-7fdb775486405a334b2f0db4e47eac9c7ed53023.tar.gz
Add tests for BlockParser
Diffstat (limited to 'yarnlib/block_parser_tests.py')
-rw-r--r--yarnlib/block_parser_tests.py73
1 files changed, 73 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+#
+# =*= 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')
+