def test_skip_whitespace(): s = ' hello ' dec = JSONDecoder('fake space', s) assert dec.pos == 0 assert dec.skip_whitespace(0) == 3 assert dec.skip_whitespace(3) == 3 assert dec.skip_whitespace(8) == len(s) dec.close()
def test_skip_whitespace(): s = " hello " dec = JSONDecoder("fake space", s) assert dec.pos == 0 assert dec.skip_whitespace(0) == 3 assert dec.skip_whitespace(3) == 3 assert dec.skip_whitespace(8) == len(s) dec.close()
def test_instatiation_count(self): m = Terminator(self.space) dec = JSONDecoder(self.space, '"abc" "def"') m1 = dec.decode_key_map(dec.skip_whitespace(0), m) m2 = dec.decode_key_map(dec.skip_whitespace(6), m1) m1 = dec.decode_key_map(dec.skip_whitespace(0), m) m2 = dec.decode_key_map(dec.skip_whitespace(6), m1) m1 = dec.decode_key_map(dec.skip_whitespace(0), m) assert m1.instantiation_count == 3 assert m2.instantiation_count == 2 dec.close()
def test_decode_string_caching(self): for s1 in ["abc", u"ä".encode("utf-8")]: s = '"%s" "%s" "%s"' % (s1, s1, s1) dec = JSONDecoder(self.space, s) dec.MIN_SIZE_FOR_STRING_CACHE = 0 assert dec.pos == 0 w_x = dec.decode_string(1) w_y = dec.decode_string(dec.skip_whitespace(dec.pos) + 1) assert w_x is not w_y # check caching w_z = dec.decode_string(dec.skip_whitespace(dec.pos) + 1) assert w_z is w_y dec.close()
def test_decode_key_map(self): m = Terminator(self.space) m_diff = Terminator(self.space) for s1 in ["abc", "1001" * 10, u"ä".encode("utf-8")]: s = ' "%s" "%s" "%s"' % (s1, s1, s1) dec = JSONDecoder(self.space, s) assert dec.pos == 0 m1 = dec.decode_key_map(dec.skip_whitespace(0), m) assert m1.w_key._utf8 == s1 assert m1.key_repr == '"%s"' % s1 # check caching on w_key level m2 = dec.decode_key_map(dec.skip_whitespace(dec.pos), m_diff) assert m1.w_key is m2.w_key # check caching on map level m3 = dec.decode_key_map(dec.skip_whitespace(dec.pos), m_diff) assert m3 is m2 dec.close()