class CharSetTest(unittest.TestCase): def setUp(self): self.cs = CharSet() def test_add(self): self.cs.add('a') self.assertTrue(self.cs.contains('a')) def test_add_invalid(self): self.assertRaises(ValueError, self.cs.add, '-') def test_add_range(self): self.cs.add_range('a', 'c') for c in ['a', 'b', 'c']: self.assertTrue(self.cs.contains(c)) def test_add_invalid_range(self): self.assertRaises(ValueError, self.cs.add_range, 'c', 'a')
def __read_charset(self): """Lukee syötteestä merkkijoukon ja palauttaa sen, kun merkkijoukon avaava '[' on luettu ennen tämän funktion kutsua""" c = self.next_char() negated = False charset = CharSet() if c == '^': negated = True c = self.next_char() while c != ']': self.check_allowed_char(c) c2 = self.peek_char() if c2 == '-': # character range self.next_char() # eat - c2 = self.next_char() self.check_allowed_char(c2) charset.add_range(c, c2) else: charset.add(c) c = self.next_char() if negated: charset.negate() return charset
def setUp(self): self.cs = CharSet()