Browse Source

JSObjectProxyTest: add test for >>at:ifAbsent:

Manfred Kroehnert 12 years ago
parent
commit
2ce4e33ba9
3 changed files with 49 additions and 0 deletions
  1. 19 0
      js/Kernel-Tests.deploy.js
  2. 24 0
      js/Kernel-Tests.js
  3. 6 0
      st/Kernel-Tests.st

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

@@ -1838,6 +1838,25 @@ return self}, function($ctx1) {$ctx1.fill(self,"jsObject",{}, smalltalk.JSObject
 }),
 smalltalk.JSObjectProxyTest);
 
+smalltalk.addMethod(
+"_testAtIfAbsent",
+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(){
+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(){
+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(){
+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)})}
+}),
+smalltalk.JSObjectProxyTest);
+
 smalltalk.addMethod(
 "_testDNU",
 smalltalk.method({

+ 24 - 0
js/Kernel-Tests.js

@@ -2358,6 +2358,30 @@ referencedClasses: []
 }),
 smalltalk.JSObjectProxyTest);
 
+smalltalk.addMethod(
+"_testAtIfAbsent",
+smalltalk.method({
+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(){
+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(){
+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(){
+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)})},
+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"],
+referencedClasses: []
+}),
+smalltalk.JSObjectProxyTest);
+
 smalltalk.addMethod(
 "_testDNU",
 smalltalk.method({

+ 6 - 0
st/Kernel-Tests.st

@@ -936,6 +936,12 @@ jsObject
 
 !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']).
+!
+
 testDNU
 	self should: [self jsObject foo] raise: MessageNotUnderstood
 !