summaryrefslogtreecommitdiffstats
path: root/third_party/simplejson/simplejson/tests/test_decode.py
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/simplejson/simplejson/tests/test_decode.py')
-rwxr-xr-xthird_party/simplejson/simplejson/tests/test_decode.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/third_party/simplejson/simplejson/tests/test_decode.py b/third_party/simplejson/simplejson/tests/test_decode.py
new file mode 100755
index 0000000..1cd701d
--- /dev/null
+++ b/third_party/simplejson/simplejson/tests/test_decode.py
@@ -0,0 +1,22 @@
+import decimal
+from unittest import TestCase
+
+import simplejson as json
+
+class TestDecode(TestCase):
+ def test_decimal(self):
+ rval = json.loads('1.1', parse_float=decimal.Decimal)
+ self.assert_(isinstance(rval, decimal.Decimal))
+ self.assertEquals(rval, decimal.Decimal('1.1'))
+
+ def test_float(self):
+ rval = json.loads('1', parse_int=float)
+ self.assert_(isinstance(rval, float))
+ self.assertEquals(rval, 1.0)
+
+ def test_decoder_optimizations(self):
+ # Several optimizations were made that skip over calls to
+ # the whitespace regex, so this test is designed to try and
+ # exercise the uncommon cases. The array cases are already covered.
+ rval = json.loads('{ "key" : "value" , "k":"v" }')
+ self.assertEquals(rval, {"key":"value", "k":"v"})