-
Notifications
You must be signed in to change notification settings - Fork 1
create lalr grammar tests #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6dee609
4a0a8a4
4d65e78
348b81b
f53f8d2
6946c24
bc291d7
47d9e40
d8b05e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,7 @@ cython_debug/ | |
|
|
||
| # project folders | ||
| .idea | ||
| .vscode/settings.json | ||
| build | ||
| dist | ||
| pyjapt.egg-info | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import pytest | ||
|
|
||
| from pyjapt import Grammar | ||
|
|
||
|
|
||
| def grammar(): | ||
| g = Grammar() | ||
|
|
||
| S = g.add_non_terminal("S", True) | ||
| (A,) = g.add_non_terminals("A") | ||
|
|
||
| g.add_terminals("a b c d") | ||
|
|
||
| S %= "A a" | ||
| S %= "b A c" | ||
| S %= "d c" | ||
| S %= "b d a" | ||
| A %= "d" | ||
|
|
||
| return g | ||
|
|
||
|
|
||
| def test_slr(): | ||
| g = grammar() | ||
| parser = g.get_parser("slr") | ||
| assert parser.has_conflicts | ||
|
|
||
|
|
||
| @pytest.mark.lalr1 | ||
| def test_lalr(): | ||
|
||
| g = grammar() | ||
| parser = g.get_parser("lalr1") | ||
| assert not parser.has_conflicts | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from pyjapt import Grammar | ||
|
|
||
|
|
||
| def grammar(): | ||
| g = Grammar() | ||
|
|
||
| S = g.add_non_terminal("S", True) | ||
| A, B = g.add_non_terminals("A B") | ||
|
|
||
| g.add_terminals("a b c d") | ||
|
|
||
| S %= "A a" | ||
| S %= "b A c" | ||
| S %= "B c" | ||
| S %= "b B a" | ||
| A %= "d" | ||
| B %= "d" | ||
|
|
||
| return g | ||
|
|
||
|
|
||
| def test_lalr(): | ||
|
||
| g = grammar() | ||
| parser = g.get_parser("lalr1") | ||
| assert parser.has_conflicts | ||
|
|
||
|
|
||
| def test_lr1(): | ||
|
||
| g = grammar() | ||
| parser = g.get_parser("lr1") | ||
| assert not parser.has_conflicts | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing pytest marker for SLR test. Similar to the pattern in test_arithmetic_grammar.py, this test function should have the @pytest.mark.slr decorator to allow selective test execution. You'll also need to import pytest at the top of the file.