compiler/tests/PPCNodeTest.st
changeset 438 20598d7ce9fa
parent 422 116d2b2af905
child 451 989570319d14
child 452 9f4558b3be66
--- a/compiler/tests/PPCNodeTest.st	Tue Apr 21 17:20:11 2015 +0100
+++ b/compiler/tests/PPCNodeTest.st	Thu Apr 30 23:43:14 2015 +0200
@@ -3,7 +3,7 @@
 "{ NameSpace: Smalltalk }"
 
 TestCase subclass:#PPCNodeTest
-	instanceVariableNames:''
+	instanceVariableNames:'node'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'PetitCompiler-Tests-Nodes'
@@ -13,27 +13,54 @@
 !PPCNodeTest methodsFor:'as yet unclassified'!
 
 testCopy
-	| n1 n2 |
-	n1 := PPCDelegateNode new
+	| newNode |
+	node := PPCDelegateNode new
 		child: #foo;
 		yourself.
-	n2 := n1 copy.
-	self assert: (n1 = n2).
+	newNode := node copy.
+	self assert: (node = newNode).
+	self assert: (node hash = newNode hash).
 	
-	n2 child: #bar.
-	self assert: (n1 = n2) not.
+	newNode child: #bar.
+	self assert: (node = newNode) not.
 !
 
 testCopy2
-	| n1 n2 |
-	n1 := PPCSequenceNode new
-		children: (Array with: #foo with: #bar);
+	|  newNode |
+	node := PPCSequenceNode new
+		children: { #foo . #bar }
 		yourself.
-	n2 := n1 copy.
-	self assert: (n1 = n2).
+	newNode := node copy.
+
+	self assert: (node = newNode).
+	self assert: (node hash = newNode hash).
 	
-	n2 children at: 1 put: #zorg.
-	self assert: (n1 = n2) not.
+	node children at: 1 put: #zorg.
+	self assert: (node = newNode) not.
+!
+
+testCopy3
+	| newNode |
+	node := PPCMessagePredicateNode new
+		predicate: #block;
+		message: #message;
+		yourself.
+		
+	newNode := node copy.
+	
+	self assert: (node == newNode) not.
+	self assert: (node = newNode).
+	self assert: node hash = newNode hash.
+!
+
+testCopy4
+	| node1 node2 |
+	node1 := #letter asParser asCompilerNode.
+	node2 := #letter asParser asCompilerNode.
+	
+	self assert: (node == node2) not.
+	self assert: (node1 = node2).
+	self assert: node1 hash = node2 hash.
 !
 
 testEquals
@@ -54,6 +81,26 @@
 		
 	self assert: (n1 = n3).
 	self assert: (n1 = n2) not.
+!
+
+testReplaceNode
+	| literalNode anotherLiteralNode |
+	literalNode := PPCLiteralNode new
+		literal: 'foo';
+		yourself.
+		
+	anotherLiteralNode := PPCLiteralNode new
+		literal: 'bar';
+		yourself.
+		
+	node := PPCForwardNode new
+		child: literalNode;
+		yourself.
+	
+	self assert: node child == literalNode.
+	node replace: literalNode with: anotherLiteralNode.
+	self assert: node child == anotherLiteralNode.
+	self assert: (node child == literalNode) not.
 ! !
 
 !PPCNodeTest methodsFor:'test support'!
@@ -131,22 +178,32 @@
 	tree := parser asCompilerTree optimizeTree.
 	
 	self assert: tree type: PPCTrimmingTokenNode.
-	self assert: tree child type: PPCInlineLiteralNode.
+	self assert: tree child type: PPCLiteralNode.
+	self assert: tree child isMarkedForInline.
 	self assert: (tree whitespace allNodes allSatisfy: [ :n | n isKindOf: PPCNode ]).
+!
 
+testConvertTrimmingToken2
+	| parser tree |
 	parser := ('foo' asParser, $b asParser) trimmingToken.
 	tree := parser asCompilerTree optimizeTree.
 	
 	self assert: tree type: PPCTrimmingTokenNode.
 	self assert: tree child type: PPCTokenSequenceNode.
-	self assert: tree whitespace type: PPCInlineTokenStarSeparatorNode.
+	self assert: tree whitespace type: PPCTokenStarSeparatorNode.
+	self assert: tree whitespace isMarkedForInline.
+!
+
+testConvertTrimmingToken3
+	| parser tree |
 	
 	parser := $d asParser trimmingToken star.
 	tree := parser asCompilerTree optimizeTree.
 	
 	self assert: tree type: PPCStarNode.
 	self assert: tree child type: PPCTrimmingTokenNode.
-	self assert: tree child child type: PPCInlineCharacterNode.
+	self assert: tree child child type: PPCCharacterNode.	
+	self assert: tree child child isMarkedForInline.
 ! !
 
 !PPCNodeTest methodsFor:'tests - epsilon'!