Trees Indices Help
Trac
Package trac :: Package util :: Package tests :: Module presentation

Source Code for Module trac.util.tests.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 
21 - class ToJsonTestCase (unittest.TestCase):
22
23 - def test_simple_types (self):
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
38 - def test_compound_types (self):
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
50 - def suite ():
51 suite = unittest.TestSuite() 52 suite .addTest(doctest.DocTestSuite(presentation )) 53 suite .addTest(unittest.makeSuite(ToJsonTestCase )) 54 return suite
55 56 57 if __name__ == '__main__': 58 unittest.main (defaultTest='suite') 59

Trees Indices Help
Trac
Generated by Epydoc 3.0.1 on Mon Feb 13 23:37:31 2023 http://epydoc.sourceforge.net

AltStyle によって変換されたページ (->オリジナル) /