~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to python/simplejson-2.1.1/simplejson/tests/test_scanstring.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import sys
2
 
from unittest import TestCase
3
 
 
4
 
import simplejson as json
5
 
import simplejson.decoder
6
 
 
7
 
class TestScanString(TestCase):
8
 
    def test_py_scanstring(self):
9
 
        self._test_scanstring(simplejson.decoder.py_scanstring)
10
 
 
11
 
    def test_c_scanstring(self):
12
 
        if not simplejson.decoder.c_scanstring:
13
 
            return
14
 
        self._test_scanstring(simplejson.decoder.c_scanstring)
15
 
 
16
 
    def _test_scanstring(self, scanstring):
17
 
        self.assertEquals(
18
 
            scanstring('"z\\ud834\\udd20x"', 1, None, True),
19
 
            (u'z\U0001d120x', 16))
20
 
 
21
 
        if sys.maxunicode == 65535:
22
 
            self.assertEquals(
23
 
                scanstring(u'"z\U0001d120x"', 1, None, True),
24
 
                (u'z\U0001d120x', 6))
25
 
        else:
26
 
            self.assertEquals(
27
 
                scanstring(u'"z\U0001d120x"', 1, None, True),
28
 
                (u'z\U0001d120x', 5))
29
 
 
30
 
        self.assertEquals(
31
 
            scanstring('"\\u007b"', 1, None, True),
32
 
            (u'{', 8))
33
 
 
34
 
        self.assertEquals(
35
 
            scanstring('"A JSON payload should be an object or array, not a string."', 1, None, True),
36
 
            (u'A JSON payload should be an object or array, not a string.', 60))
37
 
 
38
 
        self.assertEquals(
39
 
            scanstring('["Unclosed array"', 2, None, True),
40
 
            (u'Unclosed array', 17))
41
 
 
42
 
        self.assertEquals(
43
 
            scanstring('["extra comma",]', 2, None, True),
44
 
            (u'extra comma', 14))
45
 
 
46
 
        self.assertEquals(
47
 
            scanstring('["double extra comma",,]', 2, None, True),
48
 
            (u'double extra comma', 21))
49
 
 
50
 
        self.assertEquals(
51
 
            scanstring('["Comma after the close"],', 2, None, True),
52
 
            (u'Comma after the close', 24))
53
 
 
54
 
        self.assertEquals(
55
 
            scanstring('["Extra close"]]', 2, None, True),
56
 
            (u'Extra close', 14))
57
 
 
58
 
        self.assertEquals(
59
 
            scanstring('{"Extra comma": true,}', 2, None, True),
60
 
            (u'Extra comma', 14))
61
 
 
62
 
        self.assertEquals(
63
 
            scanstring('{"Extra value after close": true} "misplaced quoted value"', 2, None, True),
64
 
            (u'Extra value after close', 26))
65
 
 
66
 
        self.assertEquals(
67
 
            scanstring('{"Illegal expression": 1 + 2}', 2, None, True),
68
 
            (u'Illegal expression', 21))
69
 
 
70
 
        self.assertEquals(
71
 
            scanstring('{"Illegal invocation": alert()}', 2, None, True),
72
 
            (u'Illegal invocation', 21))
73
 
 
74
 
        self.assertEquals(
75
 
            scanstring('{"Numbers cannot have leading zeroes": 013}', 2, None, True),
76
 
            (u'Numbers cannot have leading zeroes', 37))
77
 
 
78
 
        self.assertEquals(
79
 
            scanstring('{"Numbers cannot be hex": 0x14}', 2, None, True),
80
 
            (u'Numbers cannot be hex', 24))
81
 
 
82
 
        self.assertEquals(
83
 
            scanstring('[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]', 21, None, True),
84
 
            (u'Too deep', 30))
85
 
 
86
 
        self.assertEquals(
87
 
            scanstring('{"Missing colon" null}', 2, None, True),
88
 
            (u'Missing colon', 16))
89
 
 
90
 
        self.assertEquals(
91
 
            scanstring('{"Double colon":: null}', 2, None, True),
92
 
            (u'Double colon', 15))
93
 
 
94
 
        self.assertEquals(
95
 
            scanstring('{"Comma instead of colon", null}', 2, None, True),
96
 
            (u'Comma instead of colon', 25))
97
 
 
98
 
        self.assertEquals(
99
 
            scanstring('["Colon instead of comma": false]', 2, None, True),
100
 
            (u'Colon instead of comma', 25))
101
 
 
102
 
        self.assertEquals(
103
 
            scanstring('["Bad value", truth]', 2, None, True),
104
 
            (u'Bad value', 12))
105
 
 
106
 
    def test_issue3623(self):
107
 
        self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
108
 
                          "xxx")
109
 
        self.assertRaises(UnicodeDecodeError,
110
 
                          json.encoder.encode_basestring_ascii, "xx\xff")
111
 
 
112
 
    def test_overflow(self):
113
 
        # Python 2.5 does not have maxsize
114
 
        maxsize = getattr(sys, 'maxsize', sys.maxint)
115
 
        self.assertRaises(OverflowError, json.decoder.scanstring, "xxx",
116
 
                          maxsize + 1)
117