Esempio n. 1
0
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')
Esempio n. 2
0
def test_even_validates_2():
    p = even.validates(fmap(lambda xs: int(''.join(xs)), many1(character())))
    assert run_parser(p, '2').value == 2
Esempio n. 3
0
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
Esempio n. 4
0
def test_odd_does_validate_5():
    p = odd.validates(fmap(lambda xs: int(''.join(xs)), many1(character())))
    assert run_parser(p, '5').value == 5
Esempio n. 5
0
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')
Esempio n. 6
0
def test_character_raises_ParsingFailed_when_too_few_characters_in_stream(
        runner
):
    p = character(n=5)
    with pytest.raises(ParsingFailed):
        runner(p, '1234')
Esempio n. 7
0
def test_character_can_parse_5_characters(runner):
    p = character(n=5)
    assert runner(p, '12345').value == '12345'
Esempio n. 8
0
def test_character_raises_ParsingFailed_on_empty_string(runner):
    p = character()
    with pytest.raises(ParsingFailed):
        runner(p, '')
Esempio n. 9
0
def test_character_parses_a_single_character(runner, text):
    p = character()
    assert runner(p, text).value == text