From 9812e557a1c49b7e3bf8081ba74e0c4f67ba2d0c Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Sun, 9 Aug 2009 13:09:26 +0100 Subject: [PATCH] Add some simple regression tests for regexes.re_single_line_field In particular, check fields that being with a colon (see d7eb2f0). --- tests/test_regexes.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 tests/test_regexes.py diff --git a/tests/test_regexes.py b/tests/test_regexes.py new file mode 100755 index 00000000..7c43d097 --- /dev/null +++ b/tests/test_regexes.py @@ -0,0 +1,31 @@ +import unittest + +import os, sys +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from daklib import regexes + +class re_single_line_field(unittest.TestCase): + MATCH = regexes.re_single_line_field.match + + def testSimple(self): + self.assertEqual(self.MATCH('Foo: bar').groups(), ('Foo', 'bar')) + + def testLeadingWhitespace(self): + self.assertEqual(self.MATCH(' Foo: bar'), None) + + def testTrailingWhitespace(self): + self.assertEqual(self.MATCH('Foo: bar \n').groups(), ('Foo', 'bar ')) + + def testMiddleWhitespace(self): + self.assertEqual(self.MATCH('Foo: bar').groups(), ('Foo', 'bar')) + self.assertEqual(self.MATCH('Foo : bar').groups(), ('Foo', 'bar')) + self.assertEqual(self.MATCH('Foo \n:\n bar').groups(), ('Foo', 'bar')) + self.assertEqual(self.MATCH('Foo:bar').groups(), ('Foo', 'bar')) + + def testColons(self): + self.assertEqual(self.MATCH('Foo: :').groups(), ('Foo', ':')) + self.assertEqual(self.MATCH('Foo: ::').groups(), ('Foo', '::')) + self.assertEqual(self.MATCH(': ::').groups(), ('', '::')) + self.assertEqual(self.MATCH('Foo::bar').groups(), ('Foo', ':bar')) + self.assertEqual(self.MATCH('Foo: :bar').groups(), ('Foo', ':bar')) -- 2.39.5