def test_read_everything(self): text = """ [ [ "Jon Snow" , "Lord Varys" , "The "Little Finger"" ] , [ ] ] , 20.14, fAlSe, 'X' , [ -2 , 0 , 1 , 4 ] """ reader = tc.Reader(text) self.assertTrue(deep_equals(reader.next("String[][]"), [["Jon Snow", "Lord Varys", 'The "Little Finger"'], []])) reader.next() self.assertEqual(reader.next("double"), 20.14) reader.next() self.assertEqual(reader.next("boolean"), False) reader.next() self.assertEqual(reader.next("char"), 'X') reader.next() self.assertEqual(reader.next("int[]"), [-2, 0, 1, 4])
def check(self, value, type): self.assertTrue(deep_equals(tc.Reader(tc.write(value, type)).next(type), value))
def test_deep_equals(self): self.assertTrue(deep_equals([], [])) self.assertTrue(deep_equals([123], [123])) self.assertFalse(deep_equals([123], [123, 456])) self.assertTrue(deep_equals([[123], [1, 2, 3]], [[123], [1, 2, 3]]))
def test_read_array_2d(self): reader = tc.Reader('[ ["abc", "def"], ["foo", "bar"] ]') arr = reader.next("String[][]") self.assertTrue(deep_equals(arr, [["abc", "def"], ["foo", "bar"]]))
def test_read_array(self): reader = tc.Reader("[2, 3, 1, 4, 6, 5]") arr = reader.next("int[]") self.assertTrue(deep_equals(arr, [2, 3, 1, 4, 6, 5]))
def check(self, value, type): self.assertTrue( deep_equals(tc.Reader(tc.write(value, type)).next(type), value))