compiler/tests/PPCOptimizeChoicesTest.st
changeset 452 9f4558b3be66
child 529 439c4057517f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/tests/PPCOptimizeChoicesTest.st	Sun May 10 06:28:36 2015 +0100
@@ -0,0 +1,44 @@
+"{ Package: 'stx:goodies/petitparser/compiler/tests' }"
+
+"{ NameSpace: Smalltalk }"
+
+TestCase subclass:#PPCOptimizeChoicesTest
+	instanceVariableNames:'node result visitor configuration'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Tests-Visitors'
+!
+
+!PPCOptimizeChoicesTest methodsFor:'as yet unclassified'!
+
+asPPCTree: parser
+    ^ parser compileWithConfiguration: configuration
+!
+
+setUp
+    | arguments |
+    super setUp.
+
+    visitor := PPCOptimizeChoices new.
+    
+    arguments := PPCArguments default
+        profile: true.
+                
+    configuration := PPCPluggableConfiguration on: [ :_self | 
+        _self toPPCIr.
+        _self cacheFirstFollow.
+    ].
+    configuration arguments: arguments.
+    
+!
+
+testHasCommonPrefix
+    | foo bar |
+    foo := 'foo' asParser name: 'foo'; yourself.
+    bar := 'bar' asParser.
+    
+    node := self asPPCTree: (foo, bar) / foo.
+
+    self assert: (visitor hasCommonPrefix: node children).
+! !
+