瀏覽代碼

Relegate example lists to separate file

Maybe this file will become a test suite some day. Probably not.
Ryan C. Thompson 6 年之前
父節點
當前提交
db7edcbe8c
共有 2 個文件被更改,包括 76 次插入72 次删除
  1. 74 0
      examples.py
  2. 2 72
      roll.py

+ 74 - 0
examples.py

@@ -0,0 +1,74 @@
+test_parse(Number, '+6.0223e23')
+test_parse(RollExpr, [
+    '4d4',
+    '2d20K',
+    '8d6x1',
+    '8d4!p<=1',
+    '8d4r4',
+    '8d6r1>3f<3',
+])
+test_parse(Expression, [
+    'x+1',
+    '4d4+4',
+    '2*2',
+    '(2*2)',
+    '2d20K + d6 + (2 * 2 ^ 2)',
+])
+test_parse(VarAssignment, [
+    'x= 5',
+    'int = d20 + 7',
+])
+test_parse(InputParser, [
+    '4d4',
+    '2d20K',
+    '8d6x1',
+    '8d4!p<=1',
+    '8d4r4',
+    '8d6r1>3f<3',
+    'x+1',
+    '4d4+4',
+    '2*2',
+    '(2*2)',
+    '2d20K + d6 + (2 * 2 ^ 2)',
+    'x= 5',
+    'int = d20 + 7',
+    'del x',
+    'delete x',
+    'help',
+    'quit',
+    'v',
+])
+
+
+# examples = [
+#     '1+1',
+#     '1 + 1 + x',
+#     '3d8',
+#     '2e3 * 4d6 + 2',
+#     '2d20k',
+#     '3d20x2',
+#     '4d4rK3',
+#     '4d4R4',
+#     '4d4R>=3',
+#     '4d4r>=3',
+#     '4d4!1',
+#     '4d4!<3',
+#     '4d4!p',
+#     '2D20K+10',
+#     '2D20k+10',
+#     '10d6X4',
+#     '4d8r + 6',
+#     '20d6R≤2',
+#     '6d10!≥8+6',
+#     '10d4!p',
+#     '20d6≥6',
+#     '8d12≥10f≤2',
+# ]
+
+# example_results = {}
+# for x in examples:
+#     try:
+#         example_results[x] = parse_roll(x)
+#     except ParseException as ex:
+#         example_results[x] = ex
+# example_results

+ 2 - 72
roll.py

@@ -12,6 +12,7 @@ from random import SystemRandom
 from copy import copy
 from copy import copy
 
 
 from arpeggio import ParserPython, RegExMatch, Optional, ZeroOrMore, OneOrMore, OrderedChoice, Sequence, Combine, Not, EOF, PTNodeVisitor, visit_parse_tree, ParseTreeNode, SemanticActionResults
 from arpeggio import ParserPython, RegExMatch, Optional, ZeroOrMore, OneOrMore, OrderedChoice, Sequence, Combine, Not, EOF, PTNodeVisitor, visit_parse_tree, ParseTreeNode, SemanticActionResults
+
 from typing import Union, List, Any, Tuple, Dict, Callable, Set, TextIO
 from typing import Union, List, Any, Tuple, Dict, Callable, Set, TextIO
 from typing import Optional as OptionalType
 from typing import Optional as OptionalType
 
 
@@ -187,46 +188,6 @@ def test_parse(rule, text):
     else:
     else:
         return [ test_parse(rule, x) for x in text ]
         return [ test_parse(rule, x) for x in text ]
 
 
-test_parse(Number, '+6.0223e23')
-test_parse(RollExpr, [
-    '4d4',
-    '2d20K',
-    '8d6x1',
-    '8d4!p<=1',
-    '8d4r4',
-    '8d6r1>3f<3',
-])
-test_parse(Expression, [
-    'x+1',
-    '4d4+4',
-    '2*2',
-    '(2*2)',
-    '2d20K + d6 + (2 * 2 ^ 2)',
-])
-test_parse(VarAssignment, [
-    'x= 5',
-    'int = d20 + 7',
-])
-test_parse(InputParser, [
-    '4d4',
-    '2d20K',
-    '8d6x1',
-    '8d4!p<=1',
-    '8d4r4',
-    '8d6r1>3f<3',
-    'x+1',
-    '4d4+4',
-    '2*2',
-    '(2*2)',
-    '2d20K + d6 + (2 * 2 ^ 2)',
-    'x= 5',
-    'int = d20 + 7',
-    'del x',
-    'delete x',
-    'help',
-    'quit',
-    'v',
-])
 
 
 def eval_infix(terms: List[float],
 def eval_infix(terms: List[float],
                operators: List[Callable[[float,float],float]],
                operators: List[Callable[[float,float],float]],
@@ -578,38 +539,7 @@ def roll_dice(roll_desc: Dict) -> DiceRolled:
         roll_text = roll_desc['roll_text'],
         roll_text = roll_desc['roll_text'],
     )
     )
 
 
-# examples = [
-#     '1+1',
-#     '1 + 1 + x',
-#     '3d8',
-#     '2e3 * 4d6 + 2',
-#     '2d20k',
-#     '3d20x2',
-#     '4d4rK3',
-#     '4d4R4',
-#     '4d4R>=3',
-#     '4d4r>=3',
-#     '4d4!1',
-#     '4d4!<3',
-#     '4d4!p',
-#     '2D20K+10',
-#     '2D20k+10',
-#     '10d6X4',
-#     '4d8r + 6',
-#     '20d6R≤2',
-#     '6d10!≥8+6',
-#     '10d4!p',
-#     '20d6≥6',
-#     '8d12≥10f≤2',
-# ]
-
-# example_results = {}
-# for x in examples:
-#     try:
-#         example_results[x] = parse_roll(x)
-#     except ParseException as ex:
-#         example_results[x] = ex
-# example_results
+
 class QuitRequested(BaseException):
 class QuitRequested(BaseException):
     pass
     pass