From: Chris Lamb Date: Sun, 9 Aug 2009 12:09:26 +0000 (+0100) Subject: Add some simple regression tests for regexes.re_single_line_field X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9812e557a1c49b7e3bf8081ba74e0c4f67ba2d0c;p=dak Add some simple regression tests for regexes.re_single_line_field In particular, check fields that being with a colon (see d7eb2f0). --- 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'))