• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

Revisão1cf678da302c684a3d0b34a7505222c95c1043a1 (tree)
Hora2022-01-02 04:32:19
AutorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Mensagem de Log

refactored tests: added more assert_XXX()

Mudança Sumário

Diff

diff -r 34fd10eda4e2 -r 1cf678da302c Arpeggio/pytst/d2_ast/__init__.py
--- a/Arpeggio/pytst/d2_ast/__init__.py Sat Jan 01 17:02:51 2022 +0100
+++ b/Arpeggio/pytst/d2_ast/__init__.py Sat Jan 01 20:32:19 2022 +0100
@@ -1,6 +1,9 @@
11 import visitor
22 import arpeggio
33
4+import sys; sys.path.append("./../AST/") ; sys.path.append("./../../AST/")
5+from castle import peg # has the AST clases
6+
47 def parse(txt, rule):
58 parser = arpeggio.ParserPython(rule)
69 pt = parser.parse(txt)
@@ -8,3 +11,10 @@
811 ast = arpeggio.visit_parse_tree(pt, visitor.PegVisitor())
912 assert ast.position == 0 and ast.position_end == len(txt), f"Also the AST (type={type(ast)}) should include all input"
1013 return ast
14+
15+
16+def assert_ID(id, name:str=None, err_message="Not correct Name"):
17+ assert name is not None
18+ assert isinstance(id, peg.ID), "The id should be an ID"
19+ peg.ID.validate_or_raise(id) # with correct syntax
20+ assert id.name == name, err_message if err_message else f"Note correct name, expected {name}"
diff -r 34fd10eda4e2 -r 1cf678da302c Arpeggio/pytst/d2_ast/test_1_term.py
--- a/Arpeggio/pytst/d2_ast/test_1_term.py Sat Jan 01 17:02:51 2022 +0100
+++ b/Arpeggio/pytst/d2_ast/test_1_term.py Sat Jan 01 20:32:19 2022 +0100
@@ -7,32 +7,34 @@
77
88 from . import parse
99
10+def assert_Term(term, term_type:type(peg.Terminal), value:str=None, err_message="Not correct value"):
11+ assert value is not None
12+ assert isinstance(term, peg.Terminal), "It should be a term ..."
13+ assert isinstance(term, term_type), f"... of the correct kind: {term_type} "
14+ assert term.value == value, err_message if err_message else f"Note correct name, expected {name}"
15+
16+
1017 def test_simple_str():
1118 txt="'a string'"
1219 ast = parse(txt, grammar.term)
13- assert isinstance(ast, peg.Terminal), "It should be a term ..."
14- assert isinstance(ast, peg.StrTerm), "... and a str"
15- assert ast.value == "a string", "It's correct value should be without quotes"
20+ assert_Term(ast, peg.StrTerm, txt[1:-1], "It's correct value should be without quotes")
21+
1622
1723 def test_simple_str_d3():
1824 txt='"""triple string"""' # A triple double quotes in Castle is also a simple string
1925 ast = parse(txt, grammar.term)
20- assert isinstance(ast, peg.Terminal), "It should be a term ..."
21- assert isinstance(ast, peg.StrTerm), "... and a str"
22- assert ast.value == "triple string", "It's correct value should be without quotes"
26+ assert_Term(ast, peg.StrTerm, txt[3:-3], "It's correct value should be without quotes")
2327
2428 def test_regex_RE():
2529 txt='/a reg.ex/'
2630 ast = parse(txt, grammar.term)
27- assert isinstance(ast, peg.Terminal), "It should be a term ..."
28- assert isinstance(ast, peg.RegExpTerm), "... and a RegExp"
29- assert ast.value == 'a reg.ex', "It's correct value should be without slahes -- note: the regex itself is a string"
31+ assert_Term(ast, peg.RegExpTerm, txt[1:-1], "It's correct value should be without slahes -- note: the regex itself is a string")
32+
33+
3034
3135 def regex_variants(txt, expect):
3236 ast = parse(txt, grammar.term)
33- assert isinstance(ast, peg.Terminal), "It should be a term ..."
34- assert isinstance(ast, peg.RegExpTerm), "... and a RegExp"
35- assert ast.value == expect, "And the regex-pre/postfix should be removed from the value"
37+ assert_Term(ast, peg.RegExpTerm, expect, "And the regex-pre/postfix should be removed from the value")
3638
3739 def test_regex_variants():
3840 regex_variants(txt:="""/a reg.ex/""", expect=txt[1:-1]) # Same a test_regex_RE
@@ -48,13 +50,6 @@
4850 regex_variants(txt:='''R"""re__Rstr_d3"""''', expect=txt[4:-3])
4951 regex_variants(txt:='''r"""re__rstr_d3"""''', expect=txt[4:-3])
5052
51-@pytest.mark.skip(reason="single_expr has no visitor -- as that is now in expressions")
52-def test_term_as_single_expr(): # A term is **ALSO** a single_expr
53- txt="'a string'"
54- ast = parse(txt, grammar.single_expr)
55- assert isinstance(ast, peg.Expression), "A (str)term is also an Expression"
56- assert len(ast.value) == 1, "An expression with length==1"
57- assert ast.value[0].value == txt[1:-1], "It's correct value should be without quotes"
5853
5954
6055 def test_term_as_expressions(): # A term is **ALSO an expressions
diff -r 34fd10eda4e2 -r 1cf678da302c Arpeggio/pytst/d2_ast/test_2_ID.py
--- a/Arpeggio/pytst/d2_ast/test_2_ID.py Sat Jan 01 17:02:51 2022 +0100
+++ b/Arpeggio/pytst/d2_ast/test_2_ID.py Sat Jan 01 20:32:19 2022 +0100
@@ -5,36 +5,33 @@
55 import sys; sys.path.append("./../AST/") ; sys.path.append("./../../AST/")
66 from castle import peg # has the AST clases
77
8-from . import parse
8+from . import parse, assert_ID
9+
910
1011 def test_rule_name():
1112 """The name of a rule is an ID"""
13+
1214 txt="aName"
1315 ast = parse(txt, grammar.rule_name)
14- assert isinstance(ast, peg.ID), "It should be an ID"
15- assert ast.name == txt
16+ assert_ID(ast, name=txt)
17+
1618
1719 def test_rule_crossref():
1820 """The rule's expressions can also refer an ID"""
21+
1922 txt="aRef"
2023 ast = parse(txt, grammar.rule_crossref)
21- assert isinstance(ast, peg.ID), "It should be an ID"
22- assert ast.name == txt
23-
24-
25-@pytest.mark.skip(reason="single_expr has no visitor -- as that is now in expressions")
26-def test_ID_as_single_expr():
27- txt="aRef"
28- ast = parse(txt, grammar.single_expr)
29- assert isinstance(ast, peg.Expression), "A crossref is also an Expression"
30- assert len(ast.value) == 1, "An expression with length==1"
31- assert ast.value[0].name == txt, "The name of the (ID of the) Expression-value is still the same"
24+ assert_ID(ast, name=txt)
3225
3326
3427 def test_ID_as_expressions():
28+ """ An ID is also an expression"""
29+
3530 txt="aRef"
3631 ast = parse(txt, grammar.expressions)
32+
3733 assert isinstance(ast, peg.Expression), "A crossref is also an Expression"
3834 assert len(ast.value) == 1, "An expression with length==1"
39- assert ast.value[0].name == txt, "The name of the (ID of the) Expression-value is still the same"
35+ assert_ID(ast.value[0], name=txt, err_message= "The name of the (ID of the) Expression-value is still the same")
4036
37+
diff -r 34fd10eda4e2 -r 1cf678da302c Arpeggio/pytst/d2_ast/test_3_rule.py
--- a/Arpeggio/pytst/d2_ast/test_3_rule.py Sat Jan 01 17:02:51 2022 +0100
+++ b/Arpeggio/pytst/d2_ast/test_3_rule.py Sat Jan 01 20:32:19 2022 +0100
@@ -5,13 +5,7 @@
55 import sys; sys.path.append("./../AST/") ; sys.path.append("./../../AST/")
66 from castle import peg # has the AST clases
77
8-from . import parse
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}"
8+from . import parse, assert_ID
159
1610
1711 def test_trivial_rule_with_2IDS():