1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
"""Tests for Hassil parser"""
from hassil.parser import ParseChunk, ParseType, next_chunk
def test_word():
text = "test"
assert next_chunk(text) == ParseChunk(
text="test",
parse_type=ParseType.WORD,
start_index=0,
end_index=len(text),
)
def test_group():
text = "(test test2)"
assert next_chunk(text) == ParseChunk(
text="(test test2)",
parse_type=ParseType.GROUP,
start_index=0,
end_index=len(text),
)
def test_optional():
text = "[test test2]"
assert next_chunk(text) == ParseChunk(
text="[test test2]",
parse_type=ParseType.OPT,
start_index=0,
end_index=len(text),
)
def test_list_reference():
text = "{test}"
assert next_chunk(text) == ParseChunk(
text="{test}",
parse_type=ParseType.LIST,
start_index=0,
end_index=len(text),
)
def test_rule_reference():
text = "<test>"
assert next_chunk(text) == ParseChunk(
text="<test>",
parse_type=ParseType.RULE,
start_index=0,
end_index=len(text),
)
|