Procházet zdrojové kódy

Merge branch 'master', remote-tracking branch 'herby/master'

Nicolas Petton před 12 roky
rodič
revize
c076616347
3 změnil soubory, kde provedl 118 přidání a 3 odebrání
  1. 37 0
      js/Kernel-Tests.deploy.js
  2. 49 2
      js/Kernel-Tests.js
  3. 32 1
      st/Kernel-Tests.st

+ 37 - 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({
@@ -852,6 +872,8 @@ var o=nil;
 (o=smalltalk.send((smalltalk.Object || Object), "_new", []));
 smalltalk.send(self, "_deny_", [smalltalk.send(o, "__eq_eq", [smalltalk.send((smalltalk.Object || Object), "_new", [])])]);
 smalltalk.send(self, "_assert_", [smalltalk.send(o, "__eq_eq", [o])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(o, "_yourself", []), "__eq_eq", [o])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(o, "__eq_eq", [smalltalk.send(o, "_yourself", [])])]);
 return self;}
 }),
 smalltalk.ObjectTest);
@@ -1295,6 +1317,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({

+ 49 - 2
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({
@@ -1138,10 +1163,12 @@ var o=nil;
 (o=smalltalk.send((smalltalk.Object || Object), "_new", []));
 smalltalk.send(self, "_deny_", [smalltalk.send(o, "__eq_eq", [smalltalk.send((smalltalk.Object || Object), "_new", [])])]);
 smalltalk.send(self, "_assert_", [smalltalk.send(o, "__eq_eq", [o])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(o, "_yourself", []), "__eq_eq", [o])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(o, "__eq_eq", [smalltalk.send(o, "_yourself", [])])]);
 return self;},
 args: [],
-source: "testIdentity\x0a\x09| o |\x0a\x09o := Object new.\x0a\x09self deny: o == Object new.\x0a\x09self assert: o == o",
-messageSends: ["new", "deny:", "==", "assert:"],
+source: "testIdentity\x0a\x09| o |\x0a\x09o := Object new.\x0a\x09self deny: o == Object new.\x0a\x09self assert: o == o.\x0a\x09self assert: o yourself == o.\x0a\x09self assert: o == o yourself",
+messageSends: ["new", "deny:", "==", "assert:", "yourself"],
 referencedClasses: ["Object"]
 }),
 smalltalk.ObjectTest);
@@ -1750,6 +1777,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({

+ 32 - 1
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'.
@@ -570,7 +588,9 @@ testIdentity
 	| o |
 	o := Object new.
 	self deny: o == Object new.
-	self assert: o == o
+	self assert: o == o.
+	self assert: o yourself == o.
+	self assert: o == o yourself
 !
 
 testIfNil
@@ -839,6 +859,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').