Updated to PetitCompiler-JanKurs.100, PetitCompiler-Tests-JanKurs.44 and PetitCompiler-Benchmarks-JanKurs.4
Name: PetitCompiler-JanKurs.100
Author: JanKurs
Time: 30-04-2015, 10:48:52.165 AM
UUID: 80196870-5921-46d9-ac20-a43bf5c2f3c2
Name: PetitCompiler-Tests-JanKurs.44
Author: JanKurs
Time: 30-04-2015, 10:49:22.489 AM
UUID: 348c02e8-18ce-48f6-885d-fcff4516a298
Name: PetitCompiler-Benchmarks-JanKurs.4
Author: JanKurs
Time: 30-04-2015, 10:58:44.890 AM
UUID: 18cadb42-f9ef-45fb-82e9-8469ade56c8b
"{ Package: 'stx:goodies/petitparser/compiler/tests' }"
"{ NameSpace: Smalltalk }"
PPAbstractParserTest subclass:#PPCCompilerTest
instanceVariableNames:'parser result context node compiler id node2 id2 id1 node1 node3
arguments configuration'
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Tests-Core'
!
!PPCCompilerTest methodsFor:'as yet unclassified'!
assert: p parse: whatever
^ result := super assert: p parse: whatever.
!
context
^ context := PPCProfilingContext new
!
setUp
arguments := PPCArguments default
profile: true;
yourself.
configuration := PPCFirstPrototype new
arguments: arguments;
yourself.
!
tearDown
| parserClass |
parserClass := (Smalltalk at: #PPGeneratedParser ifAbsent: [nil]).
parserClass notNil ifTrue:[
parserClass removeFromSystem
].
! !
!PPCCompilerTest methodsFor:'tests - first set'!
testFirstSetSuchThat
| a b fs at |
a := $a asParser.
at := a trim.
b := $b asParser.
parser := b optional, at.
fs := parser firstSetSuchThat: [ :e | (e isKindOf: PPTrimmingParser) or: [ e isTerminal ] ].
self assert: (fs anySatisfy: [ :e | e = at ]).
self assert: (fs anySatisfy: [ :e | e = b ]).
self assert: (fs noneSatisfy: [ :e | e = a ]).
!
testFirstSetSuchThat2
| a b fs at bt |
a := $a asParser optional.
at := a trim.
b := $b asParser.
bt := b trim.
parser := at, bt.
fs := parser firstSetSuchThat: [ :e | (e isKindOf: PPTrimmingParser) or: [ e isTerminal ] ].
self assert: (fs anySatisfy: [ :e | e = at ]).
self assert: (fs anySatisfy: [ :e | e = bt ]).
self assert: fs size = 2.
!
testFirstSetSuchThat3
| a b c fs at bt ct |
a := $a asParser optional.
at := a trim.
b := $b asParser.
bt := b trim.
c := $c asParser.
ct := c trim.
parser := (at, bt optional) wrapped, at, ct.
fs := parser firstSetSuchThat: [ :e | (e isKindOf: PPTrimmingParser) or: [ e isTerminal ] ].
self assert: (fs anySatisfy: [ :e | e = at ]).
self assert: (fs anySatisfy: [ :e | e = bt ]).
self assert: (fs anySatisfy: [ :e | e = ct ]).
self assert: fs size = 3.
! !
!PPCCompilerTest methodsFor:'tests - guard'!
testChoiceGuard
parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken / $d asParser trimmingToken plus)
compileWithConfiguration: configuration.
self assert: parser parse: 'foo'.
self assert: result inputValue = 'foo'.
self assert: (context invocations anySatisfy: [ :e | e beginsWith: 'token' ]).
self assert: parser parse: 'bar'.
self assert: result inputValue = 'bar'.
self assert: parser parse: ' foo'.
self assert: result inputValue = 'foo'.
self assert: parser parse: ' d'.
self assert: result first inputValue = 'd'.
self assert: parser fail: ''.
self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'predicate' ]).
self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'token' ]).
self assert: parser fail: 'zorg'.
self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'token' ]).
!
testEmptyChoiceGuard
parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken / $d asParser trimmingToken star)
compileWithConfiguration: configuration.
self assert: parser parse: 'foo'.
self assert: result inputValue = 'foo'.
self assert: parser parse: 'bar'.
self assert: result inputValue = 'bar'.
self assert: parser parse: ' foo'.
self assert: result inputValue = 'foo'.
self assert: parser parse: ' d'.
self assert: result first inputValue = 'd'.
self assert: parser parse: ''.
self assert: parser parse: 'zorg' end: 0.
!
testGuardSmalltlakToken
parser := (#letter asParser, #word asParser star) smalltalkToken compileWithConfiguration: configuration.
self assert: parser parse: 'bar'.
self assert: (context invocations anySatisfy: [ :e | e beginsWith: 'seq' ]).
self assert: parser fail: '123'.
self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'seq' ]).
!
testSequenceGuard
parser := ((#any asParser, #any asParser) wrapped, (#any asParser, #any asParser)) compileWithConfiguration: configuration.
self assert: parser parse: 'fooo' to: #(#($f $o) #($o $o)).
self assert: parser parse: 'fo oo' to: #(#($f $o) #($ $o)) end: 4.
self assert: parser fail: 'fo'.
!
testTrimmerGuard
parser := $a asParser trim, $b asParser compileWithConfiguration: configuration.
self assert: parser parse: 'ab'.
self assert: parser parse: ' ab'.
! !
!PPCCompilerTest methodsFor:'tests - ids'!
testId1
node := PPCNode new
name: 'foo'.
compiler := PPCCompiler new.
id := compiler idFor: node.
self assert: compiler ids size = 1.
self assert: id = 'foo'.
!
testId2
node1 := PPCNode new
name: 'foo'.
node2 := PPCNode new
name: 'foo'.
compiler := PPCCompiler new.
id1 := compiler idFor: node1.
self assert: compiler ids size = 1.
self assert: id1 = 'foo'.
id2 := compiler idFor: node2.
self assert: compiler ids size = 2.
self assert: id2 = 'foo_1'.
self assert: (id1 = id2) not.
!
testId3
node1 := PPCNode new
name: 'foo'.
node2 := node1.
compiler := PPCCompiler new.
id1 := compiler idFor: node1.
self assert: compiler ids size = 1.
self assert: id1 = 'foo'.
id2 := compiler idFor: node2.
self assert: compiler ids size = 1.
self assert: id2 = 'foo'.
self assert: (id1 == id2).
!
testId4
node1 := PPCNode new
name: 'foo+='.
node2 := PPCNode new
name: 'foo+='.
compiler := PPCCompiler new.
id1 := compiler idFor: node1.
self assert: compiler ids size = 1.
self assert: id1 = 'foo'.
id2 := compiler idFor: node2.
self assert: compiler ids size = 2.
self assert: id2 = 'foo_1'.
self assert: (id1 = id2) not.
! !
!PPCCompilerTest class methodsFor:'documentation'!
version_HG
^ '$Changeset: <not expanded> $'
! !