Browse Source

Collection >> #copyEmpty

Herby Vojčík 4 years ago
parent
commit
6e4527c9ab

+ 6 - 0
lang/API-CHANGES.txt

@@ -1,3 +1,9 @@
+0.25.1:
+
++ Collection >>
+  + copyEmpty
+
+
 0.25.0:
 
 * Deprecate Behavior >> javascriptConstructor(:)

+ 23 - 0
lang/src/Kernel-Collections.js

@@ -755,6 +755,29 @@ return $recv(stream)._contents();
 }; }),
 $globals.Collection);
 
+$core.addMethod(
+$core.method({
+selector: "copyEmpty",
+protocol: "copying",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "copyEmpty\x0a\x09^ self class new",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["new", "class"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self._class())._new();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"copyEmpty",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.Collection);
+
 $core.addMethod(
 $core.method({
 selector: "copyWith:",

+ 4 - 0
lang/src/Kernel-Collections.st

@@ -229,6 +229,10 @@ asSet
 		yourself
 !
 
+copyEmpty
+	^ self class new
+!
+
 copyWith: anObject
 	^ self copy add: anObject; yourself
 !

+ 66 - 0
lang/src/Kernel-Tests.js

@@ -4104,6 +4104,72 @@ return self;
 }; }),
 $globals.CollectionTest);
 
+$core.addMethod(
+$core.method({
+selector: "testCopyEmpty",
+protocol: "tests",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testCopyEmpty\x0a\x09self assert: self collectionClass new copyEmpty equals: self collectionClass new.\x0a\x09self assert: self collection copyEmpty equals: self collectionClass new.\x0a\x09self assert: self collectionWithNewValue copyEmpty equals: self collectionClass new",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["assert:equals:", "copyEmpty", "new", "collectionClass", "collection", "collectionWithNewValue"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+[$self._assert_equals_([$recv([$recv([$self._collectionClass()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["collectionClass"]=1
+//>>excludeEnd("ctx");
+][0])._new()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["new"]=1
+//>>excludeEnd("ctx");
+][0])._copyEmpty()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["copyEmpty"]=1
+//>>excludeEnd("ctx");
+][0],[$recv([$self._collectionClass()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["collectionClass"]=2
+//>>excludeEnd("ctx");
+][0])._new()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["new"]=2
+//>>excludeEnd("ctx");
+][0])
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["assert:equals:"]=1
+//>>excludeEnd("ctx");
+][0];
+[$self._assert_equals_([$recv($self._collection())._copyEmpty()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["copyEmpty"]=2
+//>>excludeEnd("ctx");
+][0],[$recv([$self._collectionClass()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["collectionClass"]=3
+//>>excludeEnd("ctx");
+][0])._new()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["new"]=3
+//>>excludeEnd("ctx");
+][0])
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["assert:equals:"]=2
+//>>excludeEnd("ctx");
+][0];
+$self._assert_equals_($recv($self._collectionWithNewValue())._copyEmpty(),$recv($self._collectionClass())._new());
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testCopyEmpty",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.CollectionTest);
+
 $core.addMethod(
 $core.method({
 selector: "testCopySeparates",

+ 6 - 0
lang/src/Kernel-Tests.st

@@ -810,6 +810,12 @@ testCopy
 	self deny: self collection copy = self collectionWithNewValue
 !
 
+testCopyEmpty
+	self assert: self collectionClass new copyEmpty equals: self collectionClass new.
+	self assert: self collection copyEmpty equals: self collectionClass new.
+	self assert: self collectionWithNewValue copyEmpty equals: self collectionClass new
+!
+
 testCopySeparates
 	| original copy |
 	original := self collection.