Browse Source

Regression tests for #1224.

Herbert Vojčík 6 years ago
parent
commit
81f4b551fe
4 changed files with 110 additions and 0 deletions
  1. 24 0
      src/Kernel-Collections.js
  2. 4 0
      src/Kernel-Collections.st
  3. 69 0
      src/Kernel-Tests.js
  4. 13 0
      src/Kernel-Tests.st

+ 24 - 0
src/Kernel-Collections.js

@@ -5966,6 +5966,30 @@ messageSends: ["errorReadOnly"]
 }),
 $globals.CharacterArray);
 
+$core.addMethod(
+$core.method({
+selector: "remove:ifAbsent:",
+protocol: "adding/removing",
+fn: function (anObject,aBlock){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$self._errorReadOnly();
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"remove:ifAbsent:",{anObject:anObject,aBlock:aBlock},$globals.CharacterArray)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject", "aBlock"],
+source: "remove: anObject ifAbsent: aBlock\x0a\x09self errorReadOnly",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["errorReadOnly"]
+}),
+$globals.CharacterArray);
+
 $core.addMethod(
 $core.method({
 selector: "symbolPrintString",

+ 4 - 0
src/Kernel-Collections.st

@@ -1410,6 +1410,10 @@ add: anObject
 
 remove: anObject
 	self errorReadOnly
+!
+
+remove: anObject ifAbsent: aBlock
+	self errorReadOnly
 ! !
 
 !CharacterArray methodsFor: 'converting'!

+ 69 - 0
src/Kernel-Tests.js

@@ -4546,6 +4546,37 @@ messageSends: ["anyOne", "collection", "deny:", "noneSatisfy:", "=", "assert:",
 }),
 $globals.CollectionTest);
 
+$core.addMethod(
+$core.method({
+selector: "testRegression1224",
+protocol: "tests",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $3,$2,$1;
+$3=$recv($self._collectionClass())._new();
+$recv($3)._remove_ifAbsent_($self._sampleNewValue(),(function(){
+
+}));
+$2=$recv($3)._yourself();
+$1=$recv($2)._size();
+$self._assert_equals_($1,(0));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testRegression1224",{},$globals.CollectionTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testRegression1224\x0a\x09self assert: (self collectionClass new\x0a\x09\x09remove: self sampleNewValue ifAbsent: [];\x0a\x09\x09yourself) size equals: 0",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["assert:equals:", "size", "remove:ifAbsent:", "new", "collectionClass", "sampleNewValue", "yourself"]
+}),
+$globals.CollectionTest);
+
 $core.addMethod(
 $core.method({
 selector: "testRemoveAll",
@@ -9226,6 +9257,44 @@ messageSends: ["assert:equals:", "join:"]
 }),
 $globals.StringTest);
 
+$core.addMethod(
+$core.method({
+selector: "testRegression1224",
+protocol: "tests",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$1;
+$self._should_raise_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+$2=$recv($self._collectionClass())._new();
+$recv($2)._remove_ifAbsent_($self._sampleNewValue(),(function(){
+
+}));
+$1=$recv($2)._yourself();
+return $recv($1)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),$globals.Error);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testRegression1224",{},$globals.StringTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testRegression1224\x0a\x09\x22String instances are read-only\x22\x0a\x09self should: [ (self collectionClass new\x0a\x09\x09remove: self sampleNewValue ifAbsent: [];\x0a\x09\x09yourself) size ] raise: Error",
+referencedClasses: ["Error"],
+//>>excludeEnd("ide");
+messageSends: ["should:raise:", "size", "remove:ifAbsent:", "new", "collectionClass", "sampleNewValue", "yourself"]
+}),
+$globals.StringTest);
+
 $core.addMethod(
 $core.method({
 selector: "testRemoveAll",

+ 13 - 0
src/Kernel-Tests.st

@@ -791,6 +791,12 @@ testNoneSatisfy
 	self assert: (self collection noneSatisfy: [ :each | each = Object new ])
 !
 
+testRegression1224
+	self assert: (self collectionClass new
+		remove: self sampleNewValue ifAbsent: [];
+		yourself) size equals: 0
+!
+
 testRemoveAll
 	self assert: (self collection removeAll; yourself) equals: self collectionClass new
 !
@@ -1671,6 +1677,13 @@ testJoin
 	self assert: (',' join: #('hello' 'world')) equals: 'hello,world'
 !
 
+testRegression1224
+	"String instances are read-only"
+	self should: [ (self collectionClass new
+		remove: self sampleNewValue ifAbsent: [];
+		yourself) size ] raise: Error
+!
+
 testRemoveAll
 	self should: [ self collection removeAll ] raise: Error
 !