Package trac ::
Package util ::
Package tests ::
Module presentation
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C)2006-2009 Edgewall Software
4 # Copyright (C) 2006 Christopher Lenz <cmlenz@gmx.de>
5 # All rights reserved.
6 #
7 # This software is licensed as described in the file COPYING, which
8 # you should have received as part of this distribution. The terms
9 # are also available at http://trac.edgewall.org/wiki/TracLicense.
10 #
11 # This software consists of voluntary contributions made by many
12 # individuals. For the exact contribution history, see the revision
13 # history and logs, available at http://trac.edgewall.org/log/.
14
15 import doctest
16 import unittest
17
18 from trac .util import presentation
19
20
22
24 self.assertEqual ('42', presentation .to_json(42))
25 self.assertEqual ('123.456', presentation .to_json(123.456))
26 self.assertEqual ('true', presentation .to_json(True))
27 self.assertEqual ('false', presentation .to_json(False))
28 self.assertEqual ('null', presentation .to_json(None))
29 self.assertEqual ('"String"', presentation .to_json('String'))
30 self.assertEqual (r'"a \" quote"', presentation .to_json('a " quote'))
31 self.assertEqual ('''"a ' single quote"''',
32 presentation .to_json("a ' single quote"))
33 self.assertEqual (r'"\u003cb\u003e\u0026\u003c/b\u003e"',
34 presentation .to_json('<b>&</b>'))
35 self.assertEqual (r'"\n\r\u2028\u2029"',
36 presentation .to_json(u'\x0a\x0d\u2028\u2029'))
37
39 self.assertEqual ('[1,2,[true,false]]',
40 presentation .to_json([1, 2, [True, False]]))
41 self.assertEqual (r'{"one":1,"other":[null,0],'
42 r'''"three":[3,"\u0026\u003c\u003e'"],'''
43 r'"two":2,"\u2028\n":"\u2029\r"}',
44 presentation .to_json({"one": 1, "two": 2,
45 "other": [None, 0],
46 "three": [3, "&<>'"],
47 u"\u2028\x0a": u"\u2029\x0d"}))
48
49
55
56
57 if __name__ == '__main__':
58 unittest.main (defaultTest='suite')
59