def test_odd_and_even_neither_validate_2_nor_5(): p = (odd & even).validates( fmap(lambda xs: int(''.join(xs)), many1(character()))) with pytest.raises(ParsingFailed): run_parser(p, '2') with pytest.raises(ParsingFailed): run_parser(p, '5')
def test_even_validates_2(): p = even.validates(fmap(lambda xs: int(''.join(xs)), many1(character()))) assert run_parser(p, '2').value == 2
def test_odd_or_even_validates_2_and_5(): p = (odd | even).validates( fmap(lambda xs: int(''.join(xs)), many1(character()))) assert run_parser(p, '2').value == 2 assert run_parser(p, '5').value == 5
def test_odd_does_validate_5(): p = odd.validates(fmap(lambda xs: int(''.join(xs)), many1(character()))) assert run_parser(p, '5').value == 5
def test_even_does_not_validate_5(): p = even.validates(fmap(lambda xs: int(''.join(xs)), many1(character()))) with pytest.raises(ParsingFailed): run_parser(p, '3')
def test_character_raises_ParsingFailed_when_too_few_characters_in_stream( runner ): p = character(n=5) with pytest.raises(ParsingFailed): runner(p, '1234')
def test_character_can_parse_5_characters(runner): p = character(n=5) assert runner(p, '12345').value == '12345'
def test_character_raises_ParsingFailed_on_empty_string(runner): p = character() with pytest.raises(ParsingFailed): runner(p, '')
def test_character_parses_a_single_character(runner, text): p = character() assert runner(p, text).value == text