Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revision | 7676a5cd2196d35437142b2852f0f268e821bd66 (tree) |
---|---|
Time | 2021-12-10 00:00:05 |
Author | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
AST: peg.Rule() has a 'expr', not a 'value'
@@ -2,6 +2,7 @@ | ||
2 | 2 | |
3 | 3 | all: test demos |
4 | 4 | |
5 | +test: | |
5 | 6 | (cd pytst/; pytest) |
6 | 7 | test-s: |
7 | 8 | (cd pytst/; pytest -s) |
@@ -9,7 +10,6 @@ | ||
9 | 10 | DEMOS:=$(wildcard demo/*demo*.py) |
10 | 11 | demos: |
11 | 12 | for d in ${DEMOS}; do echo "*** $$d ***"; python $$d; done |
12 | -test: | |
13 | 13 | |
14 | 14 | clean: |
15 | 15 | rm -rf {.,castle}/{__pycache__,.pytest_cache}/ |
@@ -37,12 +37,12 @@ | ||
37 | 37 | class Rule(NonTerminal): |
38 | 38 | def __init__(self, *, |
39 | 39 | name: ID, |
40 | - value :Expression, | |
40 | + expr :Expression=None, | |
41 | 41 | **kwargs): |
42 | 42 | ID.validate_or_raise(name) |
43 | 43 | super().__init__(**kwargs) |
44 | 44 | self.name = name |
45 | - self.value = value | |
45 | + self.expr = expr | |
46 | 46 | |
47 | 47 | |
48 | 48 |
@@ -1,22 +1,18 @@ | ||
1 | 1 | import pytest |
2 | 2 | |
3 | -## Notice `test_1_Rules.py` and `test_1_Settings.py` are the same, but for the SUT; in the line below -- Keep it that way!! | |
4 | -from castle.peg import Rule as SUT | |
3 | +from castle.peg import Rule | |
5 | 4 | |
6 | 5 | def test_a_ID(): |
7 | 6 | a_name, a_val = 'aName', 42 |
8 | - s=SUT(name=a_name, value=a_val) | |
7 | + s=Rule(name=a_name, expr=a_val) | |
9 | 8 | assert s.name == a_name, "Remember the ID" |
10 | - assert s.value == a_val, "Remember the value" | |
9 | + assert s.expr == a_val, "Remember the expr" | |
11 | 10 | |
12 | 11 | |
13 | 12 | def test_needID(): |
14 | 13 | with pytest.raises(ValueError): |
15 | - SUT(name=42, value="the name should be an ID, or string") | |
14 | + Rule(name=42) # The name should be an ID, or string | |
16 | 15 | with pytest.raises(ValueError): |
17 | - SUT(name='a b', value="a space in not allowed in an ID") | |
16 | + Rule(name='a b') # "A space in not allowed in an ID | |
18 | 17 | |
19 | -def test_needID(): | |
20 | - with pytest.raises(TypeError): | |
21 | - SUT(name='Forgot_a_Value') | |
22 | 18 |
@@ -1,22 +1,22 @@ | ||
1 | 1 | import pytest |
2 | 2 | |
3 | -## Notice `test_1_Rules.py` and `test_1_Settings.py` are the same, but for the SUT; in the line below -- Keep it that way!! | |
4 | -from castle.peg import Setting as SUT | |
3 | + | |
4 | +from castle.peg import Setting | |
5 | 5 | |
6 | 6 | def test_a_ID(): |
7 | 7 | a_name, a_val = 'aName', 42 |
8 | - s=SUT(name=a_name, value=a_val) | |
8 | + s=Setting(name=a_name, value=a_val) | |
9 | 9 | assert s.name == a_name, "Remember the ID" |
10 | 10 | assert s.value == a_val, "Remember the value" |
11 | 11 | |
12 | 12 | |
13 | 13 | def test_needID(): |
14 | 14 | with pytest.raises(ValueError): |
15 | - SUT(name=42, value="the name should be an ID, or string") | |
15 | + Setting(name=42, value="the name should be an ID, or string") | |
16 | 16 | with pytest.raises(ValueError): |
17 | - SUT(name='a b', value="a space in not allowed in an ID") | |
17 | + Setting(name='a b', value="a space in not allowed in an ID") | |
18 | 18 | |
19 | 19 | def test_needID(): |
20 | 20 | with pytest.raises(TypeError): |
21 | - SUT(name='Forgot_a_Value') | |
21 | + Setting(name='Forgot_a_Value') | |
22 | 22 |