Nicolas Petton 12 лет назад
Родитель
Сommit
af2e579d59
6 измененных файлов с 404 добавлено и 364 удалено
  1. 2 6
      js/Kernel-Collections.deploy.js
  2. 3 7
      js/Kernel-Collections.js
  3. 187 169
      js/Kernel-Tests.deploy.js
  4. 199 176
      js/Kernel-Tests.js
  5. 2 6
      st/Kernel-Collections.st
  6. 11 0
      st/Kernel-Tests.st

+ 2 - 6
js/Kernel-Collections.deploy.js

@@ -1389,12 +1389,8 @@ selector: "at:ifAbsent:",
 fn: function (anIndex, aBlock) {
 var self=this;
 
-	    var value = self[anIndex - 1];
-	    if(value === undefined) {
-		return aBlock();
-	    } else {
-		return value;
-	    }
+		if((anIndex < 1) || (self.length < anIndex)) {return aBlock()};
+		return self[anIndex - 1];
 	;
 return self;}
 }),

+ 3 - 7
js/Kernel-Collections.js

@@ -1956,16 +1956,12 @@ category: 'accessing',
 fn: function (anIndex, aBlock) {
 var self=this;
 
-	    var value = self[anIndex - 1];
-	    if(value === undefined) {
-		return aBlock();
-	    } else {
-		return value;
-	    }
+		if((anIndex < 1) || (self.length < anIndex)) {return aBlock()};
+		return self[anIndex - 1];
 	;
 return self;},
 args: ["anIndex", "aBlock"],
-source: "at: anIndex ifAbsent: aBlock\x0a\x09<\x0a\x09    var value = self[anIndex - 1];\x0a\x09    if(value === undefined) {\x0a\x09\x09return aBlock();\x0a\x09    } else {\x0a\x09\x09return value;\x0a\x09    }\x0a\x09>",
+source: "at: anIndex ifAbsent: aBlock\x0a\x09<\x0a\x09\x09if((anIndex < 1) || (self.length < anIndex)) {return aBlock()};\x0a\x09\x09return self[anIndex - 1];\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),

Разница между файлами не показана из-за своего большого размера
+ 187 - 169
js/Kernel-Tests.deploy.js


Разница между файлами не показана из-за своего большого размера
+ 199 - 176
js/Kernel-Tests.js


+ 2 - 6
st/Kernel-Collections.st

@@ -739,12 +739,8 @@ SequenceableCollection subclass: #Array
 
 at: anIndex ifAbsent: aBlock
 	<
-	    var value = self[anIndex - 1];
-	    if(value === undefined) {
-		return aBlock();
-	    } else {
-		return value;
-	    }
+		if((anIndex < 1) || (self.length < anIndex)) {return aBlock()};
+		return self[anIndex - 1];
 	>
 !
 

+ 11 - 0
st/Kernel-Tests.st

@@ -5,6 +5,17 @@ TestCase subclass: #ArrayTest
 
 !ArrayTest methodsFor: 'testing'!
 
+testAtIfAbsent
+	| array |
+	array := #('hello' 'world').
+	self assert: (array at: 1) equals: 'hello'.
+	self assert: (array at: 2) equals: 'world'.
+	self assert: (array at: 2 ifAbsent: ['not found']) equals: 'world'.
+	self assert: (array at: 0 ifAbsent: ['not found']) equals: 'not found'.
+	self assert: (array at: -10 ifAbsent: ['not found']) equals: 'not found'.
+	self assert: (array at: 3 ifAbsent: ['not found']) equals: 'not found'.
+!
+
 testFirstN
 	self assert: {1. 2. 3} equals: ({1. 2. 3. 4. 5} first: 3).
 !

Некоторые файлы не были показаны из-за большого количества измененных файлов