コード例 #1
0
    def testEncodeSymbols(self):
        s = "\u273f\u2661\u273f"  # ✿♡✿
        encoded = ujson.dumps(s)
        encoded_json = json.dumps(s)
        self.assertEqual(len(encoded), len(s) * 6 + 2)  # 6 characters + quotes
        self.assertEqual(encoded, encoded_json)
        decoded = ujson.loads(encoded)
        self.assertEqual(s, decoded)

        # ujson outputs an UTF-8 encoded str object
        encoded = ujson.dumps(s, ensure_ascii=False)
        # json outputs an unicode object
        encoded_json = json.dumps(s, ensure_ascii=False)
        self.assertEqual(len(encoded), len(s) + 2)  # original length + quotes
        self.assertEqual(encoded, encoded_json)
        decoded = ujson.loads(encoded)
        self.assertEqual(s, decoded)
コード例 #2
0
    def testEncodeUnicodeBMP(self):
        s = "\U0001f42e\U0001f42e\U0001F42D\U0001F42D"  # 🐮🐮🐭🐭
        encoded = ujson.dumps(s)
        encoded_json = json.dumps(s)

        if len(s) == 4:
            self.assertEqual(len(encoded), len(s) * 12 + 2)
        else:
            self.assertEqual(len(encoded), len(s) * 6 + 2)

        self.assertEqual(encoded, encoded_json)
        decoded = ujson.loads(encoded)
        self.assertEqual(s, decoded)

        # ujson outputs an UTF-8 encoded str object
        encoded = ujson.dumps(s, ensure_ascii=False)
        # json outputs an unicode object
        encoded_json = json.dumps(s, ensure_ascii=False)
        self.assertEqual(len(encoded), len(s) + 2)  # original length + quotes
        self.assertEqual(encoded, encoded_json)
        decoded = ujson.loads(encoded)
        self.assertEqual(s, decoded)
コード例 #3
0
 def test_ReadArrayOfSymbols(self):
     self.assertEqual([True, False, None],
                      ujson.loads(" [ true, false,null] "))
コード例 #4
0
 def test_ReadNull(self):
     self.assertEqual(None, ujson.loads("null"))
コード例 #5
0
 def test_ReadFalse(self):
     self.assertEqual(False, ujson.loads("false"))
コード例 #6
0
 def test_ReadTrue(self):
     self.assertEqual(True, ujson.loads("true"))
コード例 #7
0
    def test_decodeFloatingPointAdditionalTests(self):
        self.assertAlmostEqual(-1.1234567893, ujson.loads("-1.1234567893"))
        self.assertAlmostEqual(-1.234567893, ujson.loads("-1.234567893"))
        self.assertAlmostEqual(-1.34567893, ujson.loads("-1.34567893"))
        self.assertAlmostEqual(-1.4567893, ujson.loads("-1.4567893"))
        self.assertAlmostEqual(-1.567893, ujson.loads("-1.567893"))
        self.assertAlmostEqual(-1.67893, ujson.loads("-1.67893"))
        self.assertAlmostEqual(-1.7894, ujson.loads("-1.7894"))
        self.assertAlmostEqual(-1.893, ujson.loads("-1.893"))
        self.assertAlmostEqual(-1.3, ujson.loads("-1.3"))

        self.assertAlmostEqual(1.1234567893, ujson.loads("1.1234567893"))
        self.assertAlmostEqual(1.234567893, ujson.loads("1.234567893"))
        self.assertAlmostEqual(1.34567893, ujson.loads("1.34567893"))
        self.assertAlmostEqual(1.4567893, ujson.loads("1.4567893"))
        self.assertAlmostEqual(1.567893, ujson.loads("1.567893"))
        self.assertAlmostEqual(1.67893, ujson.loads("1.67893"))
        self.assertAlmostEqual(1.7894, ujson.loads("1.7894"))
        self.assertAlmostEqual(1.893, ujson.loads("1.893"))
        self.assertAlmostEqual(1.3, ujson.loads("1.3"))