Browse Source

Root modify only failing on actual change.

Herbert Vojčík 6 years ago
parent
commit
02893a45c6
4 changed files with 70 additions and 25 deletions
  1. 44 6
      src/Axxord-Tests.js
  2. 9 3
      src/Axxord-Tests.st
  3. 14 12
      src/Axxord.js
  4. 3 4
      src/Axxord.st

+ 44 - 6
src/Axxord-Tests.js

@@ -269,7 +269,7 @@ $globals.PlainConsumeTransformTest);
 
 $core.addMethod(
 $core.method({
-selector: "testRootTransformBlockIsNotRun",
+selector: "testRootTransformBlockIsRun",
 protocol: "tests",
 fn: function (){
 var self=this,$self=this;
@@ -285,7 +285,8 @@ return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
 return $recv(model)._axes_transform_([],(function(r){
 result=r;
-return result;
+result;
+return model;
 
 }));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -294,18 +295,55 @@ return result;
 }))._on_do_($globals.Error,(function(){
 
 }));
-$self._assert_($recv(result)._isNil());
+$self._assert_equals_(result,model);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testRootTransformBlockIsRun",{model:model,result:result},$globals.PlainConsumeTransformTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testRootTransformBlockIsRun\x0a| model result |\x0aresult := nil.\x0amodel := #(2 #(1 0)).\x0a[model axes: #() transform: [:r | result := r. model]] on: Error do: [].\x0aself assert: result equals: model",
+referencedClasses: ["Error"],
+//>>excludeEnd("ide");
+messageSends: ["on:do:", "axes:transform:", "assert:equals:"]
+}),
+$globals.PlainConsumeTransformTest);
+
+$core.addMethod(
+$core.method({
+selector: "testRootTransformFailsOnActualChange",
+protocol: "tests",
+fn: function (){
+var self=this,$self=this;
+var model;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+model=[(2), [(1), (0)]];
+$self._should_raise_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv(model)._axes_transform_([],(function(r){
+return "new";
+
+}));
+//>>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,"testRootTransformBlockIsNotRun",{model:model,result:result},$globals.PlainConsumeTransformTest)});
+}, function($ctx1) {$ctx1.fill(self,"testRootTransformFailsOnActualChange",{model:model},$globals.PlainConsumeTransformTest)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "testRootTransformBlockIsNotRun\x0a| model result |\x0aresult := nil.\x0amodel := #(2 #(1 0)).\x0a[model axes: #() transform: [:r | result := r]] on: Error do: [].\x0aself assert: result isNil",
+source: "testRootTransformFailsOnActualChange\x0a| model |\x0amodel := #(2 #(1 0)).\x0aself should: [model axes: #() transform: [:r | #new]] raise: Error",
 referencedClasses: ["Error"],
 //>>excludeEnd("ide");
-messageSends: ["on:do:", "axes:transform:", "assert:", "isNil"]
+messageSends: ["should:raise:", "axes:transform:"]
 }),
 $globals.PlainConsumeTransformTest);
 

+ 9 - 3
src/Axxord-Tests.st

@@ -66,12 +66,18 @@ model axes: #() consume: [:r | result := r].
 self assert: #(1 #(2 3)) equals: result
 !
 
-testRootTransformBlockIsNotRun
+testRootTransformBlockIsRun
 | model result |
 result := nil.
 model := #(2 #(1 0)).
-[model axes: #() transform: [:r | result := r]] on: Error do: [].
-self assert: result isNil
+[model axes: #() transform: [:r | result := r. model]] on: Error do: [].
+self assert: result equals: model
+!
+
+testRootTransformFailsOnActualChange
+| model |
+model := #(2 #(1 0)).
+self should: [model axes: #() transform: [:r | #new]] raise: Error
 ! !
 
 DumbAxon subclass: #TestSpyAxon

+ 14 - 12
src/Axxord.js

@@ -1217,26 +1217,28 @@ selector: "axes:transform:",
 protocol: "*Axxord",
 fn: function (aCollection,aBlock){
 var self=this,$self=this;
-var value;
+var value,newValue;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$receiver;
+var $1,$2,$receiver;
 var $early={};
 try {
-$recv(aCollection)._last();
 value=$self._atAxes_ifAbsent_(aCollection,(function(){
 throw $early=[self];
 
 }));
-value=$recv(aBlock)._value_(value);
-value=$self._atAxes_ifAbsent_put_(aCollection,(function(){
+newValue=$recv(aBlock)._value_(value);
+$1=$recv(value).__eq_eq(newValue);
+if(!$core.assert($1)){
+$self._atAxes_ifAbsent_put_(aCollection,(function(){
 throw $early=[self];
 
-}),value);
-$1=$self._registeredAxon();
-if(($receiver = $1) == null || $receiver.a$nil){
-$1;
+}),newValue);
+}
+$2=$self._registeredAxon();
+if(($receiver = $2) == null || $receiver.a$nil){
+$2;
 } else {
 var axon;
 axon=$receiver;
@@ -1246,15 +1248,15 @@ return self;
 }
 catch(e) {if(e===$early)return e[0]; throw e}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"axes:transform:",{aCollection:aCollection,aBlock:aBlock,value:value},$globals.Object)});
+}, function($ctx1) {$ctx1.fill(self,"axes:transform:",{aCollection:aCollection,aBlock:aBlock,value:value,newValue:newValue},$globals.Object)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aCollection", "aBlock"],
-source: "axes: aCollection transform: aBlock\x0a\x09| value |\x0a\x09aCollection last. \x22raise if empty\x22\x0a\x09value := self atAxes: aCollection ifAbsent: [ ^self ].\x0a\x09value := aBlock value: value.\x0a\x09value := self atAxes: aCollection ifAbsent: [ ^self ] put: value.\x0a\x09self registeredAxon ifNotNil: [:axon | axon changed: aCollection]",
+source: "axes: aCollection transform: aBlock\x0a\x09| value newValue |\x0a\x09value := self atAxes: aCollection ifAbsent: [ ^self ].\x0a\x09newValue := aBlock value: value.\x0a\x09value == newValue ifFalse: [ self atAxes: aCollection ifAbsent: [ ^self ] put: newValue ].\x0a\x09self registeredAxon ifNotNil: [:axon | axon changed: aCollection]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["last", "atAxes:ifAbsent:", "value:", "atAxes:ifAbsent:put:", "ifNotNil:", "registeredAxon", "changed:"]
+messageSends: ["atAxes:ifAbsent:", "value:", "ifFalse:", "==", "atAxes:ifAbsent:put:", "ifNotNil:", "registeredAxon", "changed:"]
 }),
 $globals.Object);
 

+ 3 - 4
src/Axxord.st

@@ -274,11 +274,10 @@ axes: aCollection consume: aBlock
 !
 
 axes: aCollection transform: aBlock
-	| value |
-	aCollection last. "raise if empty"
+	| value newValue |
 	value := self atAxes: aCollection ifAbsent: [ ^self ].
-	value := aBlock value: value.
-	value := self atAxes: aCollection ifAbsent: [ ^self ] put: value.
+	newValue := aBlock value: value.
+	value == newValue ifFalse: [ self atAxes: aCollection ifAbsent: [ ^self ] put: newValue ].
 	self registeredAxon ifNotNil: [:axon | axon changed: aCollection]
 !