ソースを参照

JSObjectProxyTest>>testAtIfAbsent: also test for property with 'undefined' value

Manfred Kroehnert 11 年 前
コミット
b4e91be3fd
3 ファイル変更34 行追加21 行削除
  1. 12 7
      js/Kernel-Tests.deploy.js
  2. 15 10
      js/Kernel-Tests.js
  3. 7 4
      st/Kernel-Tests.st

+ 12 - 7
js/Kernel-Tests.deploy.js

@@ -1831,10 +1831,10 @@ smalltalk.addMethod(
 "_jsObject",
 smalltalk.method({
 selector: "jsObject",
-fn: function () {
+fn: function (){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null};
-return self}, function($ctx1) {$ctx1.fill(self,"jsObject",{}, smalltalk.JSObjectProxyTest)});}
+return smalltalk.withContext(function($ctx1) { 
return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null, 'f': undefined};
+return self}, function($ctx1) {$ctx1.fill(self,"jsObject",{}, smalltalk.JSObjectProxyTest)})}
 }),
 smalltalk.JSObjectProxyTest);
 
@@ -1844,16 +1844,21 @@ smalltalk.method({
 selector: "testAtIfAbsent",
 fn: function (){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
_st(self)._assert_equals_("Property does not exist",_st(_st(self)._jsObject())._at_ifAbsent_("abc",(function(){
+var testObject;
+return smalltalk.withContext(function($ctx1) { 
testObject=_st(self)._jsObject();
+_st(self)._assert_equals_("Property does not exist",_st(testObject)._at_ifAbsent_("abc",(function(){
+return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
+_st(self)._assert_equals_(nil,_st(testObject)._at_ifAbsent_("e",(function(){
 return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
-_st(self)._assert_equals_(nil,_st(_st(self)._jsObject())._at_ifAbsent_("e",(function(){
+_st(self)._assert_equals_((1),_st(testObject)._at_ifAbsent_("a",(function(){
 return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
-_st(self)._assert_equals_((1),_st(_st(self)._jsObject())._at_ifAbsent_("a",(function(){
+_st(self)._assert_equals_(nil,_st(testObject)._at_ifAbsent_("f",(function(){
 return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
-return self}, function($ctx1) {$ctx1.fill(self,"testAtIfAbsent",{}, smalltalk.JSObjectProxyTest)})}
+return self}, function($ctx1) {$ctx1.fill(self,"testAtIfAbsent",{testObject:testObject}, smalltalk.JSObjectProxyTest)})}
 }),
 smalltalk.JSObjectProxyTest);
 

+ 15 - 10
js/Kernel-Tests.js

@@ -2347,12 +2347,12 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "jsObject",
 category: 'accessing',
-fn: function () {
+fn: function (){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null};
-return self}, function($ctx1) {$ctx1.fill(self,"jsObject",{}, smalltalk.JSObjectProxyTest)});},
+return smalltalk.withContext(function($ctx1) { 
return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null, 'f': undefined};
+return self}, function($ctx1) {$ctx1.fill(self,"jsObject",{}, smalltalk.JSObjectProxyTest)})},
 args: [],
-source: "jsObject\x0a\x09<return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null}>",
+source: "jsObject\x0a\x09<return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null, 'f': undefined}>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -2365,19 +2365,24 @@ selector: "testAtIfAbsent",
 category: 'tests',
 fn: function (){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
_st(self)._assert_equals_("Property does not exist",_st(_st(self)._jsObject())._at_ifAbsent_("abc",(function(){
+var testObject;
+return smalltalk.withContext(function($ctx1) { 
testObject=_st(self)._jsObject();
+_st(self)._assert_equals_("Property does not exist",_st(testObject)._at_ifAbsent_("abc",(function(){
+return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
+_st(self)._assert_equals_(nil,_st(testObject)._at_ifAbsent_("e",(function(){
 return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
-_st(self)._assert_equals_(nil,_st(_st(self)._jsObject())._at_ifAbsent_("e",(function(){
+_st(self)._assert_equals_((1),_st(testObject)._at_ifAbsent_("a",(function(){
 return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
-_st(self)._assert_equals_((1),_st(_st(self)._jsObject())._at_ifAbsent_("a",(function(){
+_st(self)._assert_equals_(nil,_st(testObject)._at_ifAbsent_("f",(function(){
 return smalltalk.withContext(function($ctx2) {
return "Property does not exist";
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})));
-return self}, function($ctx1) {$ctx1.fill(self,"testAtIfAbsent",{}, smalltalk.JSObjectProxyTest)})},
+return self}, function($ctx1) {$ctx1.fill(self,"testAtIfAbsent",{testObject:testObject}, smalltalk.JSObjectProxyTest)})},
 args: [],
-source: "testAtIfAbsent\x0a\x09self assert: 'Property does not exist' equals: (self jsObject at: 'abc' ifAbsent: ['Property does not exist']).\x0a\x09self assert: nil equals: (self jsObject at: 'e' ifAbsent: ['Property does not exist']).\x0a    self assert: 1 equals: (self jsObject at: 'a' ifAbsent: ['Property does not exist']).",
-messageSends: ["assert:equals:", "at:ifAbsent:", "jsObject"],
+source: "testAtIfAbsent\x0a\x09| testObject |\x0a    testObject := self jsObject.\x0a\x09self assert: 'Property does not exist' equals: (testObject at: 'abc' ifAbsent: ['Property does not exist']).\x0a\x09self assert: nil equals: (testObject at: 'e' ifAbsent: ['Property does not exist']).\x0a    self assert: 1 equals: (testObject at: 'a' ifAbsent: ['Property does not exist']).\x0a    self assert: nil equals: (testObject at: 'f' ifAbsent: ['Property does not exist']).",
+messageSends: ["jsObject", "assert:equals:", "at:ifAbsent:"],
 referencedClasses: []
 }),
 smalltalk.JSObjectProxyTest);

+ 7 - 4
st/Kernel-Tests.st

@@ -931,15 +931,18 @@ TestCase subclass: #JSObjectProxyTest
 !JSObjectProxyTest methodsFor: 'accessing'!
 
 jsObject
-	<return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null}>
+	<return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null, 'f': undefined}>
 ! !
 
 !JSObjectProxyTest methodsFor: 'tests'!
 
 testAtIfAbsent
-	self assert: 'Property does not exist' equals: (self jsObject at: 'abc' ifAbsent: ['Property does not exist']).
-	self assert: nil equals: (self jsObject at: 'e' ifAbsent: ['Property does not exist']).
-    self assert: 1 equals: (self jsObject at: 'a' ifAbsent: ['Property does not exist']).
+	| testObject |
+    testObject := self jsObject.
+	self assert: 'Property does not exist' equals: (testObject at: 'abc' ifAbsent: ['Property does not exist']).
+	self assert: nil equals: (testObject at: 'e' ifAbsent: ['Property does not exist']).
+    self assert: 1 equals: (testObject at: 'a' ifAbsent: ['Property does not exist']).
+    self assert: nil equals: (testObject at: 'f' ifAbsent: ['Property does not exist']).
 !
 
 testDNU