Browse Source

Tests for primitive identity. Regression for GH-203.

Herbert Vojčík 12 years ago
parent
commit
89f1212eba
3 changed files with 109 additions and 0 deletions
  1. 35 0
      js/Kernel-Tests.deploy.js
  2. 45 0
      js/Kernel-Tests.js
  3. 29 0
      st/Kernel-Tests.st

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

@@ -172,6 +172,26 @@ return self;}
 }),
 smalltalk.BooleanTest);
 
+smalltalk.addMethod(
+"_testIdentity",
+smalltalk.method({
+selector: "testIdentity",
+fn: function (){
+var self=this;
+smalltalk.send(self, "_deny_", [smalltalk.send((0), "__eq_eq", [false])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(false, "__eq_eq", [(0)])]);
+smalltalk.send(self, "_deny_", [smalltalk.send("", "__eq_eq", [false])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(false, "__eq_eq", [""])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(true, "__eq_eq", [true])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(false, "__eq_eq", [true])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(true, "__eq_eq", [false])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(false, "__eq_eq", [false])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [true])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [smalltalk.send(true, "_yourself", [])])]);
+return self;}
+}),
+smalltalk.BooleanTest);
+
 smalltalk.addMethod(
 "_testIfTrueIfFalse",
 smalltalk.method({
@@ -1295,6 +1315,21 @@ return self;}
 }),
 smalltalk.StringTest);
 
+smalltalk.addMethod(
+"_testIdentity",
+smalltalk.method({
+selector: "testIdentity",
+fn: function (){
+var self=this;
+smalltalk.send(self, "_assert_", [smalltalk.send("hello", "__eq_eq", ["hello"])]);
+smalltalk.send(self, "_deny_", [smalltalk.send("hello", "__eq_eq", ["world"])]);
+smalltalk.send(self, "_assert_", [smalltalk.send("hello", "__eq_eq", [smalltalk.send("hello", "_yourself", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send("hello", "_yourself", []), "__eq_eq", ["hello"])]);
+smalltalk.send(self, "_deny_", [smalltalk.send("", "__eq_eq", [(0)])]);
+return self;}
+}),
+smalltalk.StringTest);
+
 smalltalk.addMethod(
 "_testIncludesSubString",
 smalltalk.method({

+ 45 - 0
js/Kernel-Tests.js

@@ -232,6 +232,31 @@ referencedClasses: []
 }),
 smalltalk.BooleanTest);
 
+smalltalk.addMethod(
+"_testIdentity",
+smalltalk.method({
+selector: "testIdentity",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_deny_", [smalltalk.send((0), "__eq_eq", [false])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(false, "__eq_eq", [(0)])]);
+smalltalk.send(self, "_deny_", [smalltalk.send("", "__eq_eq", [false])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(false, "__eq_eq", [""])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(true, "__eq_eq", [true])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(false, "__eq_eq", [true])]);
+smalltalk.send(self, "_deny_", [smalltalk.send(true, "__eq_eq", [false])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(false, "__eq_eq", [false])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [true])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [smalltalk.send(true, "_yourself", [])])]);
+return self;},
+args: [],
+source: "testIdentity\x0a\x09\x22We're on top of JS...just be sure to check the basics!\x22\x0a\x0a\x09self deny: 0 == false. \x0a\x09self deny: false == 0.\x0a\x09self deny: '' == false.\x0a\x09self deny: false == ''.\x0a\x0a\x09self assert: true == true.\x0a\x09self deny: false == true.\x0a\x09self deny: true == false.\x0a\x09self assert: false == false.\x0a\x0a\x09\x22JS may do some type coercing after sending a message\x22\x0a\x09self assert: true yourself == true.\x0a\x09self assert: true yourself == true yourself",
+messageSends: ["deny:", "==", "assert:", "yourself"],
+referencedClasses: []
+}),
+smalltalk.BooleanTest);
+
 smalltalk.addMethod(
 "_testIfTrueIfFalse",
 smalltalk.method({
@@ -1750,6 +1775,26 @@ referencedClasses: []
 }),
 smalltalk.StringTest);
 
+smalltalk.addMethod(
+"_testIdentity",
+smalltalk.method({
+selector: "testIdentity",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_assert_", [smalltalk.send("hello", "__eq_eq", ["hello"])]);
+smalltalk.send(self, "_deny_", [smalltalk.send("hello", "__eq_eq", ["world"])]);
+smalltalk.send(self, "_assert_", [smalltalk.send("hello", "__eq_eq", [smalltalk.send("hello", "_yourself", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send("hello", "_yourself", []), "__eq_eq", ["hello"])]);
+smalltalk.send(self, "_deny_", [smalltalk.send("", "__eq_eq", [(0)])]);
+return self;},
+args: [],
+source: "testIdentity\x0a\x09self assert: 'hello' == 'hello'.\x0a\x09self deny: 'hello' == 'world'.\x0a\x0a\x09self assert: 'hello' == 'hello' yourself.\x0a\x09self assert: 'hello' yourself == 'hello'.\x0a\x0a\x09\x22test JS falsy value\x22\x0a\x09self deny: '' == 0",
+messageSends: ["assert:", "==", "deny:", "yourself"],
+referencedClasses: []
+}),
+smalltalk.StringTest);
+
 smalltalk.addMethod(
 "_testIncludesSubString",
 smalltalk.method({

+ 29 - 0
st/Kernel-Tests.st

@@ -109,6 +109,24 @@ testEquality
 	self assert: true yourself = true yourself
 !
 
+testIdentity
+	"We're on top of JS...just be sure to check the basics!!"
+
+	self deny: 0 == false. 
+	self deny: false == 0.
+	self deny: '' == false.
+	self deny: false == ''.
+
+	self assert: true == true.
+	self deny: false == true.
+	self deny: true == false.
+	self assert: false == false.
+
+	"JS may do some type coercing after sending a message"
+	self assert: true yourself == true.
+	self assert: true yourself == true yourself
+!
+
 testIfTrueIfFalse
  
 	self assert: (true ifTrue: ['alternative block']) = 'alternative block'.
@@ -839,6 +857,17 @@ testEquality
 	self deny: '' = 0
 !
 
+testIdentity
+	self assert: 'hello' == 'hello'.
+	self deny: 'hello' == 'world'.
+
+	self assert: 'hello' == 'hello' yourself.
+	self assert: 'hello' yourself == 'hello'.
+
+	"test JS falsy value"
+	self deny: '' == 0
+!
+
 testIncludesSubString
 	self assert: ('amber' includesSubString: 'ber').
 	self deny: ('amber' includesSubString: 'zork').