Exemplo n.º 1
0
def test_invalid_token_parser(text: str, parser: Parser):
    stream = CharStream(text)
    production = parser.parse(stream)
    assert str(production) == ''
    assert not production
Exemplo n.º 2
0
def test_valid_not_parser(text, parser):
    parser = NotCharParser(parser)
    stream = CharStream(text)
    produce = parser.parse(stream)
    assert str(produce) == ''
    assert produce
Exemplo n.º 3
0
def test_valid_onemany_parser(text: str, parser: Parser):
    parser = OneManyParser(parser)
    stream = CharStream(text)
    production = parser.parse(stream)
    assert str(production) == text
    assert production
Exemplo n.º 4
0
def test_valid_token_parser(text: str, parser: Parser):
    stream = CharStream(text)
    production = parser.parse(stream)
    assert text.startswith(str(production))
    assert production
Exemplo n.º 5
0
def test_invalid_seq_parser_returns_nothing(text, parsers):
    parser = SeqParser(*parsers)
    stream = CharStream(text)
    production = parser.parse(stream)
    assert str(production) == ''
    assert not production
Exemplo n.º 6
0
def test_valid_zeromany_parser(text, parser):
    parser = ZeroManyParser(parser)
    stream = CharStream(text)
    production = parser.parse(stream)
    assert str(production) == text
    assert production
Exemplo n.º 7
0
def test_is_next_char():
    stream = CharStream('a3')
    assert stream.get(0).value == 'a'
    assert not stream.get(1).value == 'C'
    assert stream.get(1).value == '3'
Exemplo n.º 8
0
def test_stream_length():
    stream = CharStream('abc')
    assert len(stream) == 3
Exemplo n.º 9
0
def test_empty_text_is_eof():
    stream = CharStream()
    assert stream.get().is_eof()
Exemplo n.º 10
0
def test_char_values():
    text = 'i76hj-'
    stream = CharStream(text)
    values = ''.join([stream.get(i).value for i, _ in enumerate(text)])
    assert values == text
Exemplo n.º 11
0
def test_char_column():
    text = 'ab\nc\n\nd'
    stream = CharStream(text)
    lines = [stream.get(i).column for i, _ in enumerate(text)]
    assert lines == [0, 1, 2, 0, 1, 0, 0]
Exemplo n.º 12
0
def test_char_line():
    text = 'ab\nc\n\nd'
    stream = CharStream(text)
    lines = [stream.get(i).line for i, _ in enumerate(text)]
    assert lines == [0, 0, 0, 1, 1, 2, 3]
Exemplo n.º 13
0
def test_char_type(test_input, method):
    stream = CharStream(test_input)
    ch = stream.get()
    assert getattr(ch, method)()
Exemplo n.º 14
0
def test_valid_one_of_parser(text, parsers):
    parser = OneOfParser(*parsers)
    stream = CharStream(text)
    production = parser.parse(stream)
    assert str(production) == text
    assert production
Exemplo n.º 15
0
def test_valid_seq_parser(text, parsers):
    parser = SeqParser(*parsers)
    stream = CharStream(text)
    production = parser.parse(stream)
    assert str(production) == text
    assert production
Exemplo n.º 16
0
def test_valid_optional_parser(text, parser):
    parser = OptionalParser(parser)
    stream = CharStream(text)
    assert parser.parse(stream)
Exemplo n.º 17
0
def test_empty_text_has_zero_length():
    stream = CharStream()
    assert len(stream) == 0