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