Commits

Anonymous committed cf020a1

nice re testing

Comments (0)

Files changed (1)

+# -*- coding: utf-8 -*-
+import re
+import unittest
+
+string1 = u"""code:c
+sdfäsdfösdfüsdf
+sdfsdfsdfsdf"""
+string2 = u"""code:c"""
+string3 = u"""code:"""
+string4 = u"""code:
+sdäfsdödsfüsdf
+sdfäsdödsf"""
+string5 = u"""code:c
+sdfösdfösdf
+sdfäsdfäsdf
+:code"""
+string6 = u"""
+code:c
+sdfäsdfäsdf
+sdfösdfösdf"""
+
+# strings = (string1, string2, string3, string4, string5)
+
+type_re = re.compile(r'^(?P<type>\w+):(?P<meta>.*?)\n(?P<content>.*)(\n:(?P<endtype>(?P=type)))?', re.DOTALL | re.UNICODE)
+
+class ReTestClass(unittest.TestCase):
+	def test_1(self):
+		match = type_re.match(string1)
+		if not match:
+			self.fail()
+		if not match.group('type'):
+			self.fail()
+		if not match.group('meta'):
+			self.fail()
+		if not match.group('content'):
+			self.fail()
+		if match.group('endtype'):
+			self.fail()
+
+	def test_2(self):
+		match = type_re.match(string2)
+		if match:
+			self.fail()
+
+	def test_3(self):
+		match = type_re.match(string3)
+		if match:
+			self.fail()
+
+	def test_4(self):
+		match = type_re.match(string4)
+		if not match:
+			self.fail()
+		if not match.group('type'):
+			self.fail()
+		if match.group('meta'):
+			self.fail()
+		if not match.group('content'):
+			self.fail()
+		if match.group('endtype'):
+			self.fail()
+
+	def test_5(self):
+		match = type_re.match(string5)
+		if not match:
+			self.fail()
+		if not match.group('type'):
+			self.fail()
+		if not match.group('meta'):
+			self.fail()
+		if not match.group('content'):
+			self.fail()
+		if not match.group('endtype'):
+			self.fail('we got no endtype')
+
+	def test_6(self):
+		match = type_re.match(string6)
+		if match:
+			self.fail()
+
+
+if __name__ == '__main__': unittest.main()