initial checkin draft
authorClaus Gittinger <cg@exept.de>
Mon, 02 Jul 2018 07:35:26 +0200
changeset 562 8e07a5704f6b
parent 561 9885688dbd3b
child 563 83d74d6e70fa
initial checkin
tests/PPLambdaParserTest.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/PPLambdaParserTest.st	Mon Jul 02 07:35:26 2018 +0200
@@ -0,0 +1,156 @@
+"{ Package: 'stx:goodies/petitparser/tests' }"
+
+"{ NameSpace: Smalltalk }"
+
+PPCompositeParserTest subclass:#PPLambdaParserTest
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitTests-Tests'
+!
+
+
+!PPLambdaParserTest methodsFor:'accessing'!
+
+parserClass
+	^ PPLambdaParser
+! !
+
+!PPLambdaParserTest methodsFor:'testing'!
+
+testAbstraction
+	self assert: '\x.y' is: #('x' 'y').
+	self assert: '\x.\y.z' is: #('x' ('y' 'z'))
+!
+
+testApplication
+	self assert: '(x x)' is: #('x' 'x').
+	self assert: '(x y)' is: #('x' 'y').
+	self assert: '((x y) z)' is: #(('x' 'y') 'z').
+	self assert: '(x (y z))' is: #('x' ('y' 'z'))
+!
+
+testVariable
+	self assert: 'x' is: 'x'.
+	self assert: 'xy' is: 'xy'.
+	self assert: 'x12' is: 'x12'
+! !
+
+!PPLambdaParserTest methodsFor:'testing-curch'!
+
+testAnd
+	self assert: self parserClass and = #('p' ('q' (('p' 'q') 'p')))
+!
+
+testFalse
+	self assert: self parserClass false = #('x' ('y' 'y'))
+!
+
+testIfThenElse
+	self assert: self parserClass ifthenelse = #('p' 'p')
+!
+
+testNot
+	self assert: self parserClass not = #('p' ('a' ('b' (('p' 'b') 'a'))))
+!
+
+testOr
+	self assert: self parserClass or = #('p' ('q' (('p' 'p') 'q')))
+!
+
+testTrue
+	self assert: self parserClass true = #('x' ('y' 'x'))
+! !
+
+!PPLambdaParserTest methodsFor:'testing-utilities'!
+
+testParseOnError
+	| beenHere |
+	result := self parserClass
+		parse: '\x.y'
+		onError: [ self fail ].
+	self assert: result = #('x' 'y').
+
+	beenHere := false.
+	result := self parserClass
+		parse: '\x.'
+		onError: [ beenHere := true ].
+	self assert: beenHere.
+
+	beenHere := false.
+	result := self parserClass
+		parse: '\x.'
+		onError: [ :fail | beenHere := true. fail ].
+	self assert: beenHere.
+	self assert: (result message findString: '$(') > 0.
+	self assert: (result message findString: 'expected') > 0.
+	self assert: (result position = 0).
+
+	beenHere := false.
+	result := self parserClass
+		parse: '\x.'
+		onError: [ :msg :pos | 
+			self assert: (msg findString: '$(') > 0.
+			self assert: (msg findString: 'expected') > 0.
+			self assert: (pos = 0).
+			beenHere := true ].
+	self assert: result.
+	self assert: beenHere
+!
+
+testParseStartingAtOnError
+	| beenHere |
+	result := self parserClass
+		parse: 'x'
+		startingAt: #variable
+		onError: [ self fail ].
+	self assert: result = 'x'.
+	
+	beenHere := false.
+	result := self parserClass
+		parse: '\'
+		startingAt: #variable
+		onError: [ beenHere := true ].
+	self assert: beenHere.
+	
+	beenHere := false.
+	result := self parserClass
+		parse: '\'
+		startingAt: #variable
+		onError: [ :fail | beenHere := true. fail ].
+	self assert: beenHere.
+	self assert: result message = 'letter expected'.
+	self assert: result position = 0.
+
+	beenHere := false.
+	result := self parserClass
+		parse: '\'
+		startingAt: #variable
+		onError: [ :msg :pos | 
+			self assert: msg = 'letter expected'.
+			self assert: pos = 0.
+			beenHere := true ].
+	self assert: beenHere
+!
+
+testProductionAt
+	self assert: (parser productionAt: #foo) isNil.
+	self assert: (parser productionAt: #foo ifAbsent: [ true ]).
+	
+	self assert: (parser productionAt: #start) notNil.
+	self assert: (parser productionAt: #start ifAbsent: [ true ]) notNil.
+	
+	self assert: (parser productionAt: #variable) notNil.
+	self assert: (parser productionAt: #variable ifAbsent: [ true ]) notNil
+! !
+
+!PPLambdaParserTest class methodsFor:'documentation'!
+
+version
+    ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
+! !
+