Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revisão | 76f7a4c5a47d8278d7761ea14e1bce1fbcbfd288 (tree) |
---|---|
Hora | 2022-03-02 05:09:36 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
renamed test_9-... to _file.py; to make it uniform
@@ -0,0 +1,22 @@ | ||
1 | +import pytest | |
2 | +from pathlib import Path | |
3 | +import os | |
4 | + | |
5 | +from castle.readers.parser import grammar | |
6 | +import arpeggio | |
7 | + | |
8 | +def parse_file(filename, dir=Path('..')): | |
9 | + path_to_current_test = Path(os.path.realpath(__file__)) | |
10 | + path_to_current_dir = path_to_current_test.parent | |
11 | + with (path_to_current_dir / dir / filename).open() as f: | |
12 | + txt = f.read() | |
13 | + | |
14 | + parser = arpeggio.ParserPython(grammar.peg_grammar, grammar.comment, debug=False) | |
15 | + tree = parser.parse(txt) | |
16 | + | |
17 | + assert tree.position_end == len(txt) , f"Not parsed whole input; Only: >>{regex[tree.position: tree.position_end]}<<; Not: >>{regex[tree.position_end:]}<<." | |
18 | + | |
19 | + print("\nPARSE TREE\n" + tree.tree_str()) | |
20 | + return tree | |
21 | + | |
22 | +def test_grammar(): parse_file("grammar.peg") |
@@ -1,22 +0,0 @@ | ||
1 | -import pytest | |
2 | -from pathlib import Path | |
3 | -import os | |
4 | - | |
5 | -from castle.readers.parser import grammar | |
6 | -import arpeggio | |
7 | - | |
8 | -def parse_file(filename, dir=Path('..')): | |
9 | - path_to_current_test = Path(os.path.realpath(__file__)) | |
10 | - path_to_current_dir = path_to_current_test.parent | |
11 | - with (path_to_current_dir / dir / filename).open() as f: | |
12 | - txt = f.read() | |
13 | - | |
14 | - parser = arpeggio.ParserPython(grammar.peg_grammar, grammar.comment, debug=False) | |
15 | - tree = parser.parse(txt) | |
16 | - | |
17 | - assert tree.position_end == len(txt) , f"Not parsed whole input; Only: >>{regex[tree.position: tree.position_end]}<<; Not: >>{regex[tree.position_end:]}<<." | |
18 | - | |
19 | - print("\nPARSE TREE\n" + tree.tree_str()) | |
20 | - return tree | |
21 | - | |
22 | -def test_grammar(): parse_file("grammar.peg") |