test for all literals to be present in the method
authorClaus Gittinger <cg@exept.de>
Wed, 08 Oct 2003 17:06:04 +0200
changeset 213 9764b38bebf5
parent 212 e9fd35632b04
child 214 42be02486832
test for all literals to be present in the method
RegressionTests__CompilerTest.st
--- a/RegressionTests__CompilerTest.st	Tue Oct 07 18:59:10 2003 +0200
+++ b/RegressionTests__CompilerTest.st	Wed Oct 08 17:06:04 2003 +0200
@@ -1832,6 +1832,117 @@
 
 ! !
 
+!CompilerTest methodsFor:'tests-literals'!
+
+compile:someCode
+    |m|
+
+    m := Compiler 
+            compile:someCode
+            forClass:nil
+            install:false.
+
+    self assert:(m notNil and:[m ~~ #Error]).
+    ^ m
+!
+
+testLiterals
+    "
+     self new testLiterals
+    "
+    |m|
+
+    "/ literals must be present, even if code has been optimized away
+    "/ (otherwise, searches do not work correctly)
+
+    m := self compile:'foo:arg |v| ^ (v ~~ 0) not'. 
+    self assert:(m literals includesIdentical:#'~~').
+    self assert:(m literals includesIdentical:#'not').
+
+    m := self compile:'foo:arg |v| ^ (v == 0) not'. 
+    self assert:(m literals includesIdentical:#'==').
+    self assert:(m literals includesIdentical:#'not').
+
+
+    m := self compile:'foo:arg |v| v := v+1'. 
+    self assert:(m literals includesIdentical:#'+').
+
+    m := self compile:'foo:arg |v| v := v-1'. 
+    self assert:(m literals includesIdentical:#'-').
+
+
+    m := self compile:'foo:arg |v| v := v not'. 
+    self assert:(m literals includesIdentical:#'not').
+
+
+    m := self compile:'foo:arg ^ arg ifTrue:1'. 
+    self assert:(m literals includesIdentical:#'ifTrue:').
+
+    m := self compile:'foo:arg ^ arg ifFalse:1'. 
+    self assert:(m literals includesIdentical:#'ifFalse:').
+
+    m := self compile:'foo:arg ^ arg ifTrue:1 ifFalse:2'. 
+    self assert:(m literals includesIdentical:#'ifTrue:ifFalse:').
+
+    m := self compile:'foo:arg ^ arg ifFalse:1 ifTrue:2'. 
+    self assert:(m literals includesIdentical:#'ifFalse:ifTrue:').
+
+
+    m := self compile:'foo:arg ^ arg isNil ifTrue:1'. 
+    self assert:(m literals includesIdentical:#'ifTrue:').
+    self assert:(m literals includesIdentical:#'isNil').
+
+    m := self compile:'foo:arg ^ arg isNil ifFalse:1'. 
+    self assert:(m literals includesIdentical:#'ifFalse:').
+    self assert:(m literals includesIdentical:#'isNil').
+
+    m := self compile:'foo:arg ^ arg isNil ifTrue:1 ifFalse:2'. 
+    self assert:(m literals includesIdentical:#'ifTrue:ifFalse:').
+    self assert:(m literals includesIdentical:#'isNil').
+
+    m := self compile:'foo:arg ^ arg isNil ifFalse:1 ifTrue:2'. 
+    self assert:(m literals includesIdentical:#'ifFalse:ifTrue:').
+    self assert:(m literals includesIdentical:#'isNil').
+
+
+    m := self compile:'foo:arg ^ arg notNil ifTrue:1'. 
+    self assert:(m literals includesIdentical:#'ifTrue:').
+    self assert:(m literals includesIdentical:#'notNil').
+
+    m := self compile:'foo:arg ^ arg notNil ifFalse:1'. 
+    self assert:(m literals includesIdentical:#'ifFalse:').
+    self assert:(m literals includesIdentical:#'notNil').
+
+    m := self compile:'foo:arg ^ arg notNil ifTrue:1 ifFalse:2'. 
+    self assert:(m literals includesIdentical:#'ifTrue:ifFalse:').
+    self assert:(m literals includesIdentical:#'notNil').
+
+    m := self compile:'foo:arg ^ arg notNil ifFalse:1 ifTrue:2'. 
+    self assert:(m literals includesIdentical:#'ifFalse:ifTrue:').
+    self assert:(m literals includesIdentical:#'notNil').
+
+
+    m := self compile:'foo:arg ^ arg not ifTrue:1'. 
+    self assert:(m literals includesIdentical:#'ifTrue:').
+    self assert:(m literals includesIdentical:#'not').
+
+    m := self compile:'foo:arg ^ arg not ifFalse:1'. 
+    self assert:(m literals includesIdentical:#'ifFalse:').
+    self assert:(m literals includesIdentical:#'not').
+
+    m := self compile:'foo:arg ^ arg not ifTrue:1 ifFalse:2'. 
+    self assert:(m literals includesIdentical:#'ifTrue:ifFalse:').
+    self assert:(m literals includesIdentical:#'not').
+
+    m := self compile:'foo:arg ^ arg not ifFalse:1 ifTrue:2'. 
+    self assert:(m literals includesIdentical:#'ifFalse:ifTrue:').
+    self assert:(m literals includesIdentical:#'not').
+
+    "
+     self new testLiterals
+    "
+! !
+
 !CompilerTest::DummyClass methodsFor:'accessing'!
 
 _y0