Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Révision | 8508bf239c70bf358d09dfa53e7b08dc75e748cd (tree) |
---|---|
l'heure | 2022-01-01 05:32:14 |
Auteur | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
refactored test: added assert_ID()
@@ -7,18 +7,27 @@ | ||
7 | 7 | |
8 | 8 | from . import parse |
9 | 9 | |
10 | +def assert_ID(id, name:str=None, err_message="Not correct Name"): | |
11 | + assert name is not None | |
12 | + assert isinstance(id, peg.ID), "The id should be an ID" | |
13 | + peg.ID.validate_or_raise(id) # with correct syntax | |
14 | + assert id.name == name, err_message if err_message else f"Note correct name, expected {name}" | |
15 | + | |
16 | + | |
17 | + | |
18 | + | |
10 | 19 | def test_trivial_rule_with_2IDS(): |
11 | 20 | """The most simple rule has only two IDs""" |
12 | 21 | |
13 | 22 | txt="trivial <- cross ;" |
14 | - | |
15 | 23 | ast = parse(txt, grammar.rule) |
16 | - assert isinstance(ast, peg.Rule), "It should be an ID" | |
17 | 24 | |
18 | - name, expr = ast.name, ast.expr; | |
19 | - assert isinstance(name, peg.ID) | |
25 | + assert isinstance(ast, peg.Rule), "It should be an ID" | |
26 | + assert_ID(ast.name, txt.split()[0], "The name of a rule is a ID with the left-side ID as name") | |
27 | + | |
28 | + expr = ast.expr; | |
20 | 29 | assert isinstance(expr, peg.Expression), "The expression is an Expression ..." |
21 | 30 | assert isinstance(expr, peg.Sequence), " .. and a Sequence .." |
22 | 31 | assert len(expr) ==1, " .. of length==1" |
23 | - assert name.name == txt.split()[0], "the name of the (ID of ) rule is the first ID" | |
24 | - assert expr[0].name == txt.split()[2], "The single element of the expression is the 2nnd ID, which name os the 3 part of the txt" | |
32 | + assert_ID(expr[0], txt.split()[2], "The single element of the expression is an ID (the 2nd) -- which name is the 3 part of the txt") | |
33 | + |