Browse Source

Merge pull request #315 from herby/invalid-boolean

`ifTrue:ifFalse:` did not work with boxed booleans
Nicolas Petton 12 years ago
parent
commit
cef43f3108
4 changed files with 176 additions and 1 deletions
  1. 72 0
      js/Kernel-Tests.deploy.js
  2. 82 0
      js/Kernel-Tests.js
  3. 1 1
      js/boot.js
  4. 21 0
      st/Kernel-Tests.st

+ 72 - 0
js/Kernel-Tests.deploy.js

@@ -261,6 +261,65 @@ return self}
 }),
 smalltalk.BooleanTest);
 
+smalltalk.addMethod(
+"_testIfTrueIfFalseWithBoxing",
+smalltalk.method({
+selector: "testIfTrueIfFalseWithBoxing",
+fn: function (){
+var self=this;
+var $2,$1,$4,$3,$6,$5,$8,$7,$10,$9,$12,$11,$14,$13,$16,$15;
+$2=smalltalk.send(true,"_boxed",[]);
+if(smalltalk.assert($2)){
+$1="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($1,"__eq",["alternative block"])]);
+$4=smalltalk.send(true,"_boxed",[]);
+if(! smalltalk.assert($4)){
+$3="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($3,"__eq",[nil])]);
+$6=smalltalk.send(false,"_boxed",[]);
+if(smalltalk.assert($6)){
+$5="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($5,"__eq",[nil])]);
+$8=smalltalk.send(false,"_boxed",[]);
+if(! smalltalk.assert($8)){
+$7="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($7,"__eq",["alternative block"])]);
+$10=smalltalk.send(false,"_boxed",[]);
+if(smalltalk.assert($10)){
+$9="alternative block";
+} else {
+$9="alternative block2";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($9,"__eq",["alternative block2"])]);
+$12=smalltalk.send(false,"_boxed",[]);
+if(smalltalk.assert($12)){
+$11="alternative block2";
+} else {
+$11="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($11,"__eq",["alternative block"])]);
+$14=smalltalk.send(true,"_boxed",[]);
+if(smalltalk.assert($14)){
+$13="alternative block";
+} else {
+$13="alternative block2";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($13,"__eq",["alternative block"])]);
+$16=smalltalk.send(true,"_boxed",[]);
+if(smalltalk.assert($16)){
+$15="alternative block2";
+} else {
+$15="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($15,"__eq",["alternative block2"])]);
+return self}
+}),
+smalltalk.BooleanTest);
+
 smalltalk.addMethod(
 "_testLogic",
 smalltalk.method({
@@ -2720,3 +2779,16 @@ smalltalk.UndefinedTest);
 
 
 
+smalltalk.addMethod(
+"_boxed",
+smalltalk.method({
+selector: "boxed",
+fn: function (){
+var self=this;
+var $1;
+$1=self;
+return $1;
+}
+}),
+smalltalk.Boolean);
+

+ 82 - 0
js/Kernel-Tests.js

@@ -321,6 +321,70 @@ referencedClasses: []
 }),
 smalltalk.BooleanTest);
 
+smalltalk.addMethod(
+"_testIfTrueIfFalseWithBoxing",
+smalltalk.method({
+selector: "testIfTrueIfFalseWithBoxing",
+category: 'tests',
+fn: function (){
+var self=this;
+var $2,$1,$4,$3,$6,$5,$8,$7,$10,$9,$12,$11,$14,$13,$16,$15;
+$2=smalltalk.send(true,"_boxed",[]);
+if(smalltalk.assert($2)){
+$1="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($1,"__eq",["alternative block"])]);
+$4=smalltalk.send(true,"_boxed",[]);
+if(! smalltalk.assert($4)){
+$3="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($3,"__eq",[nil])]);
+$6=smalltalk.send(false,"_boxed",[]);
+if(smalltalk.assert($6)){
+$5="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($5,"__eq",[nil])]);
+$8=smalltalk.send(false,"_boxed",[]);
+if(! smalltalk.assert($8)){
+$7="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($7,"__eq",["alternative block"])]);
+$10=smalltalk.send(false,"_boxed",[]);
+if(smalltalk.assert($10)){
+$9="alternative block";
+} else {
+$9="alternative block2";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($9,"__eq",["alternative block2"])]);
+$12=smalltalk.send(false,"_boxed",[]);
+if(smalltalk.assert($12)){
+$11="alternative block2";
+} else {
+$11="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($11,"__eq",["alternative block"])]);
+$14=smalltalk.send(true,"_boxed",[]);
+if(smalltalk.assert($14)){
+$13="alternative block";
+} else {
+$13="alternative block2";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($13,"__eq",["alternative block"])]);
+$16=smalltalk.send(true,"_boxed",[]);
+if(smalltalk.assert($16)){
+$15="alternative block2";
+} else {
+$15="alternative block";
+};
+smalltalk.send(self,"_assert_",[smalltalk.send($15,"__eq",["alternative block2"])]);
+return self},
+args: [],
+source: "testIfTrueIfFalseWithBoxing\x0a \x0a\x09self assert: (true boxed ifTrue: ['alternative block']) = 'alternative block'.\x0a\x09self assert: (true boxed ifFalse: ['alternative block']) = nil.\x0a\x0a\x09self assert: (false boxed ifTrue: ['alternative block']) = nil.\x0a\x09self assert: (false boxed ifFalse: ['alternative block']) = 'alternative block'.\x0a\x0a\x09self assert: (false boxed ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block2'.\x0a\x09self assert: (false boxed ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block'.\x0a\x0a\x09self assert: (true boxed ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.\x0a\x09self assert: (true boxed ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.",
+messageSends: ["assert:", "=", "ifTrue:", "boxed", "ifFalse:", "ifTrue:ifFalse:", "ifFalse:ifTrue:"],
+referencedClasses: []
+}),
+smalltalk.BooleanTest);
+
 smalltalk.addMethod(
 "_testLogic",
 smalltalk.method({
@@ -3525,3 +3589,21 @@ smalltalk.UndefinedTest);
 
 
 
+smalltalk.addMethod(
+"_boxed",
+smalltalk.method({
+selector: "boxed",
+category: '*Kernel-Tests',
+fn: function (){
+var self=this;
+var $1;
+$1=self;
+return $1;
+},
+args: [],
+source: "boxed\x0a\x09^self",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Boolean);
+

+ 1 - 1
js/boot.js

@@ -578,7 +578,7 @@ function Smalltalk(){
     /* Boolean assertion */
     st.assert = function(shouldBeBoolean) {
         if ((undefined !== shouldBeBoolean) && (shouldBeBoolean.klass === smalltalk.Boolean)) {
-            return shouldBeBoolean;
+            return shouldBeBoolean == true;
         } else {
             smalltalk.NonBooleanReceiver._new()._object_(shouldBeBoolean)._signal();
         }

+ 21 - 0
st/Kernel-Tests.st

@@ -121,6 +121,21 @@ testIfTrueIfFalse
 	self assert: (true ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
 !
 
+testIfTrueIfFalseWithBoxing
+ 
+	self assert: (true boxed ifTrue: ['alternative block']) = 'alternative block'.
+	self assert: (true boxed ifFalse: ['alternative block']) = nil.
+
+	self assert: (false boxed ifTrue: ['alternative block']) = nil.
+	self assert: (false boxed ifFalse: ['alternative block']) = 'alternative block'.
+
+	self assert: (false boxed ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block2'.
+	self assert: (false boxed ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block'.
+
+	self assert: (true boxed ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.
+	self assert: (true boxed ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
+!
+
 testLogic
  
 	"Trivial logic table"
@@ -1413,3 +1428,9 @@ testIsNil
 	self deny: nil notNil.
 ! !
 
+!Boolean methodsFor: '*Kernel-Tests'!
+
+boxed
+	^self
+! !
+