1 #
2 # Copyright (c) 2001 Richard Jones
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # This module is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 #
11 # $Id: test_token.py,v 1.3 2003-10-25 22:53:26 richard Exp $
13 import unittest, time
15 from roundup.token import token_split
17 class TokenTestCase(unittest.TestCase):
18 def testValid(self):
19 l = token_split('hello world')
20 self.assertEqual(l, ['hello', 'world'])
22 def testIgnoreExtraSpace(self):
23 l = token_split('hello world ')
24 self.assertEqual(l, ['hello', 'world'])
26 def testQuoting(self):
27 l = token_split('"hello world"')
28 self.assertEqual(l, ['hello world'])
29 l = token_split("'hello world'")
30 self.assertEqual(l, ['hello world'])
32 def testEmbedQuote(self):
33 l = token_split(r'Roch\'e Compaan')
34 self.assertEqual(l, ["Roch'e", "Compaan"])
35 l = token_split('address="1 2 3"')
36 self.assertEqual(l, ['address=1 2 3'])
38 def testEscaping(self):
39 l = token_split('"Roch\'e" Compaan')
40 self.assertEqual(l, ["Roch'e", "Compaan"])
41 l = token_split(r'hello\ world')
42 self.assertEqual(l, ['hello world'])
43 l = token_split(r'\\')
44 self.assertEqual(l, ['\\'])
45 l = token_split(r'\n')
46 self.assertEqual(l, ['\n'])
48 def testBadQuote(self):
49 self.assertRaises(ValueError, token_split, '"hello world')
50 self.assertRaises(ValueError, token_split, "Roch'e Compaan")
52 def test_suite():
53 suite = unittest.TestSuite()
54 suite.addTest(unittest.makeSuite(TokenTestCase))
55 return suite
57 if __name__ == '__main__':
58 runner = unittest.TextTestRunner()
59 unittest.main(testRunner=runner)
61 # vim: set filetype=python ts=4 sw=4 et si