compiler/tests/extras/PPTokenizedLL1ExpressionGrammarTest.st
changeset 464 f6d77fee9811
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/tests/extras/PPTokenizedLL1ExpressionGrammarTest.st	Thu May 21 14:12:22 2015 +0100
@@ -0,0 +1,140 @@
+"{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"
+
+"{ NameSpace: Smalltalk }"
+
+PPCompositeParserTest subclass:#PPTokenizedLL1ExpressionGrammarTest
+	instanceVariableNames:'context'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Extras-Tests-Expressions'
+!
+
+!PPTokenizedLL1ExpressionGrammarTest class methodsFor:'as yet unclassified'!
+
+resources
+    ^ (OrderedCollection with: PPTokenizedLL1ExpressionGrammarResource)
+        addAll: super resources;
+        yourself
+! !
+
+!PPTokenizedLL1ExpressionGrammarTest methodsFor:'as yet unclassified'!
+
+compilerArguments
+    ^ PPCArguments default
+        profile: true;
+        ll: true;
+        yourself
+!
+
+context
+    ^ context := PPCProfilingContext new
+!
+
+parserClass
+    ^ Smalltalk at: #PPTokenizedLL1ExpressionGrammar
+!
+
+parserInstanceFor: aSymbol
+    ^ (Smalltalk at: #PPTokenizedLL1ExpressionGrammar) new startSymbol: aSymbol
+!
+
+testAdd
+    result := self parse: '1+2' rule: #term.
+    self assert: result isArray.
+    self assert: result first = 1.
+    self assert: result second inputValue = '+'.
+    self assert: result third = 2.
+!
+
+testMul
+    result := self parse: '1 * 2' rule: #mul.
+    self assert: result isArray.
+    self assert: result first = 1.
+    self assert: result second inputValue = '*'.
+    self assert: result third = 2.
+!
+
+testNumber
+    result := self parse: '1' rule: #number.
+    self assert: result = 1.
+!
+
+testParens
+    result := self parse: '(1)' rule: #parens.
+    self assert: result size = 3.
+    self assert: result first inputValue = '('.
+    self assert: result second = 1.
+    self assert: result third inputValue = ')'.
+    
+!
+
+testPrim
+    result := self parse: '1' rule: #prim.
+    self assert: result = 1.
+!
+
+testPrim2
+    result := self parse: '(1)' rule: #prim.
+    self assert: result size = 3.
+    self assert: result second = 1.
+!
+
+testProd
+    result := self parse: '1' rule: #prod.
+    self assert: result = 1.
+!
+
+testTerm01
+    result := self parse: '1' rule: #term.
+    self assert: result = 1.
+
+    self assert: context lwRememberCount = 2.	
+    self assert: context lwRestoreCount = 0.
+!
+
+testTerm02
+    result := self parse: '1+2' rule: #term.
+    self assert: result size = 3.
+    
+    self assert: context lwRestoreCount = 0.
+!
+
+testTerm03
+    result := self parse: '1*2+3*4' rule: #term.
+    self assert: result size = 3.
+    
+
+    self assert: context lwRestoreCount = 0.
+!
+
+testTerm11
+    result := self parse: '1 + 2' rule: #term.
+    self assert: result size = 3.
+    self assert: result first = 1.
+    self assert: result second inputValue = '+'.
+    self assert: result third = 2.
+    
+!
+
+testTerm12
+    result := self parse: '1 + 2 * 3' rule: #term.
+    self assert: result size = 3.
+    self assert: result second inputValue = '+'.
+    self assert: result first = 1.
+    self assert: result third isArray.
+    self assert: result third first = 2.
+    self assert: result third second inputValue = '*'.
+    self assert: result third third = 3.	
+!
+
+testTerm13
+    result := self parse: '1 * 2 + 3' rule: #term.
+    self assert: result size = 3.
+    self assert: result first isArray.
+    self assert: result first first = 1.
+    self assert: result first second inputValue = '*'.
+    self assert: result first third = 2.	
+    self assert: result second inputValue = '+'.
+    self assert: result third = 3.
+! !
+