def test_times_with_then(self): then_digit = letter.times(3) >> digit self.assertEqual(then_digit.parse('xyz1'), '1') self.assertRaises(ParseError, then_digit.parse, 'xy1') self.assertRaises(ParseError, then_digit.parse, 'xyz') self.assertRaises(ParseError, then_digit.parse, 'xyzw')
def test_times_with_min_and_max(self): some_letters = letter.times(2, 4) self.assertEqual(some_letters.parse('xy'), ['x', 'y']) self.assertEqual(some_letters.parse('xyz'), ['x', 'y', 'z']) self.assertEqual(some_letters.parse('xyzw'), ['x', 'y', 'z', 'w']) self.assertRaises(ParseError, some_letters.parse, 'x') self.assertRaises(ParseError, some_letters.parse, 'xyzwv')
def test_times_with_min_and_max_and_then(self): then_digit = letter.times(2, 4) >> digit self.assertEqual(then_digit.parse('xy1'), '1') self.assertEqual(then_digit.parse('xyz1'), '1') self.assertEqual(then_digit.parse('xyzw1'), '1') self.assertRaises(ParseError, then_digit.parse, 'xy') self.assertRaises(ParseError, then_digit.parse, 'xyzw') self.assertRaises(ParseError, then_digit.parse, 'xyzwv1') self.assertRaises(ParseError, then_digit.parse, 'x1')
def test_times(self): three_letters = letter.times(3) self.assertEqual(three_letters.parse('xyz'), ['x', 'y', 'z']) self.assertRaises(ParseError, three_letters.parse, 'xy') self.assertRaises(ParseError, three_letters.parse, 'xyzw')
def test_times_zero(self): zero_letters = letter.times(0) self.assertEqual(zero_letters.parse(''), []) self.assertRaises(ParseError, zero_letters.parse, 'x')