Explorar o código

Isolator >> model:read:

Herbert Vojčík %!s(int64=12) %!d(string=hai) anos
pai
achega
245baffe70
Modificáronse 7 ficheiros con 629 adicións e 2 borrados
  1. 2 2
      devel.html
  2. 105 0
      js/Trapped-Tests.deploy.js
  3. 130 0
      js/Trapped-Tests.js
  4. 116 0
      js/Trapped.deploy.js
  5. 162 0
      js/Trapped.js
  6. 47 0
      st/Trapped-Tests.st
  7. 67 0
      st/Trapped.st

+ 2 - 2
devel.html

@@ -6,10 +6,10 @@
 <body>
 <script type="text/javascript"> 
 	loadAmber({
-		files: ['Trapped.js'],
+		files: ['Trapped.js', 'Trapped-Tests.js'],
 		packageHome: './',
 		ready: function() {
-			smalltalk.Browser._open();
+			smalltalk.Browser._openOn_(smalltalk.IsolatorTest);
 	}});
 </script>
 <div>

+ 105 - 0
js/Trapped-Tests.deploy.js

@@ -0,0 +1,105 @@
+smalltalk.addPackage('Trapped-Tests', {});
+smalltalk.addClass('IsolatorTest', smalltalk.TestCase, ['rootModel'], 'Trapped-Tests');
+smalltalk.addMethod(
+"_setUp",
+smalltalk.method({
+selector: "setUp",
+fn: function (){
+var self=this;
+var $1,$2;
+$1=smalltalk.send((smalltalk.EavModel || EavModel),"_new",[]);
+smalltalk.send($1,"_getBlock_",[(function(x){
+return smalltalk.send(x,"_root",[]);
+})]);
+$2=smalltalk.send($1,"_putBlock_",[(function(x,y){
+return smalltalk.send(x,"_root_",[y]);
+})]);
+self["@rootModel"]=$2;
+return self}
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testNontrivialModelReturnsAppropriateValue",
+smalltalk.method({
+selector: "testNontrivialModelReturnsAppropriateValue",
+fn: function (){
+var self=this;
+var bb;
+var model;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("foo","__minus_gt",[["bar", [(1), [(2), (3)]], "baz"]]),smalltalk.send("moo","__minus_gt",["zoo"])])]);
+model=smalltalk.send(smalltalk.send((smalltalk.EavModel || EavModel),"_new",[]),"_getBlock_",[(function(x){
+return smalltalk.send(smalltalk.send(smalltalk.send(x,"_root",[]),"_at_",["foo"]),"_at_",[(2)]);
+})]);
+smalltalk.send(bb,"_model_read_",[model,(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (3)]],result]);
+return self}
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testRootModelReturnsDeeplyIsolatedRoot",
+smalltalk.method({
+selector: "testRootModelReturnsDeeplyIsolatedRoot",
+fn: function (){
+var self=this;
+var bb;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[[(1), [(2), (3)]]]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+return smalltalk.send(smalltalk.send(r,"_at_",[(2)]),"_at_put_",[(1),(0)]);
+})]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (3)]],result]);
+return self}
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testRootModelReturnsIsolatedRoot",
+smalltalk.method({
+selector: "testRootModelReturnsIsolatedRoot",
+fn: function (){
+var self=this;
+var bb;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[[(1), [(2), (4)]]]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+return smalltalk.send(r,"_at_put_",[(2),nil]);
+})]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (4)]],result]);
+return self}
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testRootModelReturnsRoot",
+smalltalk.method({
+selector: "testRootModelReturnsRoot",
+fn: function (){
+var self=this;
+var bb;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[[(1), [(2), (3)]]]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (3)]],result]);
+return self}
+}),
+smalltalk.IsolatorTest);
+
+
+

+ 130 - 0
js/Trapped-Tests.js

@@ -0,0 +1,130 @@
+smalltalk.addPackage('Trapped-Tests', {});
+smalltalk.addClass('IsolatorTest', smalltalk.TestCase, ['rootModel'], 'Trapped-Tests');
+smalltalk.addMethod(
+"_setUp",
+smalltalk.method({
+selector: "setUp",
+category: 'running',
+fn: function (){
+var self=this;
+var $1,$2;
+$1=smalltalk.send((smalltalk.EavModel || EavModel),"_new",[]);
+smalltalk.send($1,"_getBlock_",[(function(x){
+return smalltalk.send(x,"_root",[]);
+})]);
+$2=smalltalk.send($1,"_putBlock_",[(function(x,y){
+return smalltalk.send(x,"_root_",[y]);
+})]);
+self["@rootModel"]=$2;
+return self},
+args: [],
+source: "setUp\x0a\x0arootModel := EavModel new\x0a\x09getBlock: [:x | x root];\x0a    putBlock: [:x :y | x root: y].\x0a",
+messageSends: ["getBlock:", "root", "new", "putBlock:", "root:"],
+referencedClasses: ["EavModel"]
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testNontrivialModelReturnsAppropriateValue",
+smalltalk.method({
+selector: "testNontrivialModelReturnsAppropriateValue",
+category: 'tests',
+fn: function (){
+var self=this;
+var bb;
+var model;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("foo","__minus_gt",[["bar", [(1), [(2), (3)]], "baz"]]),smalltalk.send("moo","__minus_gt",["zoo"])])]);
+model=smalltalk.send(smalltalk.send((smalltalk.EavModel || EavModel),"_new",[]),"_getBlock_",[(function(x){
+return smalltalk.send(smalltalk.send(smalltalk.send(x,"_root",[]),"_at_",["foo"]),"_at_",[(2)]);
+})]);
+smalltalk.send(bb,"_model_read_",[model,(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (3)]],result]);
+return self},
+args: [],
+source: "testNontrivialModelReturnsAppropriateValue\x0a| bb model result |\x0abb := Isolator on: #{ 'foo' -> #('bar' #(1 #(2 3)) 'baz'). 'moo' -> 'zoo' }.\x0amodel := EavModel new getBlock: [ :x | (x root at: 'foo') at: 2 ].\x0abb model: model read: [:r|result := r].\x0aself assert: #(1 #(2 3)) equals: result\x0a",
+messageSends: ["on:", "->", "getBlock:", "at:", "root", "new", "model:read:", "assert:equals:"],
+referencedClasses: ["Isolator", "EavModel"]
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testRootModelReturnsDeeplyIsolatedRoot",
+smalltalk.method({
+selector: "testRootModelReturnsDeeplyIsolatedRoot",
+category: 'tests',
+fn: function (){
+var self=this;
+var bb;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[[(1), [(2), (3)]]]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+return smalltalk.send(smalltalk.send(r,"_at_",[(2)]),"_at_put_",[(1),(0)]);
+})]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (3)]],result]);
+return self},
+args: [],
+source: "testRootModelReturnsDeeplyIsolatedRoot\x0a| bb result |\x0abb := Isolator on: #(1 #(2 3)).\x0abb model: rootModel read: [:r|(r at: 2) at: 1 put: 0].\x0abb model: rootModel read: [:r|result := r].\x0aself assert: #(1 #(2 3)) equals: result\x0a",
+messageSends: ["on:", "model:read:", "at:put:", "at:", "assert:equals:"],
+referencedClasses: ["Isolator"]
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testRootModelReturnsIsolatedRoot",
+smalltalk.method({
+selector: "testRootModelReturnsIsolatedRoot",
+category: 'tests',
+fn: function (){
+var self=this;
+var bb;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[[(1), [(2), (4)]]]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+return smalltalk.send(r,"_at_put_",[(2),nil]);
+})]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (4)]],result]);
+return self},
+args: [],
+source: "testRootModelReturnsIsolatedRoot\x0a| bb result |\x0abb := Isolator on: #(1 #(2 4)).\x0abb model: rootModel read: [:r|r at: 2 put: nil].\x0abb model: rootModel read: [:r|result := r].\x0aself assert: #(1 #(2 4)) equals: result\x0a",
+messageSends: ["on:", "model:read:", "at:put:", "assert:equals:"],
+referencedClasses: ["Isolator"]
+}),
+smalltalk.IsolatorTest);
+
+smalltalk.addMethod(
+"_testRootModelReturnsRoot",
+smalltalk.method({
+selector: "testRootModelReturnsRoot",
+category: 'tests',
+fn: function (){
+var self=this;
+var bb;
+var result;
+bb=smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[[(1), [(2), (3)]]]);
+smalltalk.send(bb,"_model_read_",[self["@rootModel"],(function(r){
+result=r;
+return result;
+})]);
+smalltalk.send(self,"_assert_equals_",[[(1), [(2), (3)]],result]);
+return self},
+args: [],
+source: "testRootModelReturnsRoot\x0a| bb result |\x0abb := Isolator on: #(1 #(2 3)).\x0abb model: rootModel read: [:r|result := r].\x0aself assert: #(1 #(2 3)) equals: result\x0a",
+messageSends: ["on:", "model:read:", "assert:equals:"],
+referencedClasses: ["Isolator"]
+}),
+smalltalk.IsolatorTest);
+
+
+

+ 116 - 0
js/Trapped.deploy.js

@@ -1,4 +1,120 @@
 smalltalk.addPackage('Trapped', {});
+smalltalk.addClass('EavModel', smalltalk.Object, ['getBlock', 'putBlock'], 'Trapped');
+smalltalk.addMethod(
+"_getBlock_",
+smalltalk.method({
+selector: "getBlock:",
+fn: function (aBlock){
+var self=this;
+self["@getBlock"]=aBlock;
+return self}
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_initialize",
+smalltalk.method({
+selector: "initialize",
+fn: function (){
+var self=this;
+self["@getBlock"]=(function(){
+return smalltalk.send(self,"_error_",["No getter block."]);
+});
+self["@putBlock"]=(function(){
+return smalltalk.send(self,"_error_",["No putter block."]);
+});
+return self}
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_on_",
+smalltalk.method({
+selector: "on:",
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@getBlock"],"_value_",[anObject]);
+return $1;
+}
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_on_put_",
+smalltalk.method({
+selector: "on:put:",
+fn: function (anObject,anObject2){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@putBlock"],"_value_value_",[anObject,anObject2]);
+return $1;
+}
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_putBlock_",
+smalltalk.method({
+selector: "putBlock:",
+fn: function (aBlock){
+var self=this;
+self["@putBlock"]=aBlock;
+return self}
+}),
+smalltalk.EavModel);
+
+
+
+smalltalk.addClass('Isolator', smalltalk.Object, ['root'], 'Trapped');
+smalltalk.addMethod(
+"_model_read_",
+smalltalk.method({
+selector: "model:read:",
+fn: function (anEavModel,aBlock){
+var self=this;
+smalltalk.send(aBlock,"_value_",[smalltalk.send(smalltalk.send(anEavModel,"_on_",[self]),"_deepCopy",[])]);
+return self}
+}),
+smalltalk.Isolator);
+
+smalltalk.addMethod(
+"_root",
+smalltalk.method({
+selector: "root",
+fn: function (){
+var self=this;
+return self["@root"];
+}
+}),
+smalltalk.Isolator);
+
+smalltalk.addMethod(
+"_root_",
+smalltalk.method({
+selector: "root:",
+fn: function (anObject){
+var self=this;
+self["@root"]=anObject;
+return self}
+}),
+smalltalk.Isolator);
+
+
+smalltalk.addMethod(
+"_on_",
+smalltalk.method({
+selector: "on:",
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(self,"_new",[]),"_root_",[anObject]);
+return $1;
+}
+}),
+smalltalk.Isolator.klass);
+
+
 smalltalk.addClass('Trapped', smalltalk.Object, [], 'Trapped');
 
 

+ 162 - 0
js/Trapped.js

@@ -1,4 +1,166 @@
 smalltalk.addPackage('Trapped', {});
+smalltalk.addClass('EavModel', smalltalk.Object, ['getBlock', 'putBlock'], 'Trapped');
+smalltalk.EavModel.comment="External actor value model."
+smalltalk.addMethod(
+"_getBlock_",
+smalltalk.method({
+selector: "getBlock:",
+category: 'accessing',
+fn: function (aBlock){
+var self=this;
+self["@getBlock"]=aBlock;
+return self},
+args: ["aBlock"],
+source: "getBlock: aBlock\x0a\x0agetBlock := aBlock",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_initialize",
+smalltalk.method({
+selector: "initialize",
+category: 'initialization',
+fn: function (){
+var self=this;
+self["@getBlock"]=(function(){
+return smalltalk.send(self,"_error_",["No getter block."]);
+});
+self["@putBlock"]=(function(){
+return smalltalk.send(self,"_error_",["No putter block."]);
+});
+return self},
+args: [],
+source: "initialize\x0a\x0agetBlock := [ self error: 'No getter block.' ].\x0aputBlock := [ self error: 'No putter block.' ].",
+messageSends: ["error:"],
+referencedClasses: []
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_on_",
+smalltalk.method({
+selector: "on:",
+category: 'accessing',
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@getBlock"],"_value_",[anObject]);
+return $1;
+},
+args: ["anObject"],
+source: "on: anObject\x0a\x22Returns value of model applied on object\x22\x0a\x0a^getBlock value: anObject",
+messageSends: ["value:"],
+referencedClasses: []
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_on_put_",
+smalltalk.method({
+selector: "on:put:",
+category: 'accessing',
+fn: function (anObject,anObject2){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@putBlock"],"_value_value_",[anObject,anObject2]);
+return $1;
+},
+args: ["anObject", "anObject2"],
+source: "on: anObject put: anObject2\x0a\x22Puts a value via model applied on object\x22\x0a\x0a^putBlock value: anObject value: anObject2",
+messageSends: ["value:value:"],
+referencedClasses: []
+}),
+smalltalk.EavModel);
+
+smalltalk.addMethod(
+"_putBlock_",
+smalltalk.method({
+selector: "putBlock:",
+category: 'accessing',
+fn: function (aBlock){
+var self=this;
+self["@putBlock"]=aBlock;
+return self},
+args: ["aBlock"],
+source: "putBlock: aBlock\x0a\x0aputBlock := aBlock",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.EavModel);
+
+
+
+smalltalk.addClass('Isolator', smalltalk.Object, ['root'], 'Trapped');
+smalltalk.addMethod(
+"_model_read_",
+smalltalk.method({
+selector: "model:read:",
+category: 'action',
+fn: function (anEavModel,aBlock){
+var self=this;
+smalltalk.send(aBlock,"_value_",[smalltalk.send(smalltalk.send(anEavModel,"_on_",[self]),"_deepCopy",[])]);
+return self},
+args: ["anEavModel", "aBlock"],
+source: "model: anEavModel read: aBlock\x0a\x0aaBlock value: (anEavModel on: self) deepCopy",
+messageSends: ["value:", "deepCopy", "on:"],
+referencedClasses: []
+}),
+smalltalk.Isolator);
+
+smalltalk.addMethod(
+"_root",
+smalltalk.method({
+selector: "root",
+category: 'accessing',
+fn: function (){
+var self=this;
+return self["@root"];
+},
+args: [],
+source: "root\x0a\x0a^root\x0a",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Isolator);
+
+smalltalk.addMethod(
+"_root_",
+smalltalk.method({
+selector: "root:",
+category: 'accessing',
+fn: function (anObject){
+var self=this;
+self["@root"]=anObject;
+return self},
+args: ["anObject"],
+source: "root: anObject\x0a\x0aroot := anObject",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Isolator);
+
+
+smalltalk.addMethod(
+"_on_",
+smalltalk.method({
+selector: "on:",
+category: 'initialization',
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(self,"_new",[]),"_root_",[anObject]);
+return $1;
+},
+args: ["anObject"],
+source: "on: anObject\x0a^self new root: anObject",
+messageSends: ["root:", "new"],
+referencedClasses: []
+}),
+smalltalk.Isolator.klass);
+
+
 smalltalk.addClass('Trapped', smalltalk.Object, [], 'Trapped');
 
 

+ 47 - 0
st/Trapped-Tests.st

@@ -0,0 +1,47 @@
+Smalltalk current createPackage: 'Trapped-Tests' properties: #{}!
+TestCase subclass: #IsolatorTest
+	instanceVariableNames: 'rootModel'
+	package: 'Trapped-Tests'!
+
+!IsolatorTest methodsFor: 'running'!
+
+setUp
+
+rootModel := EavModel new
+	getBlock: [:x | x root];
+    putBlock: [:x :y | x root: y].
+! !
+
+!IsolatorTest methodsFor: 'tests'!
+
+testNontrivialModelReturnsAppropriateValue
+| bb model result |
+bb := Isolator on: #{ 'foo' -> #('bar' #(1 #(2 3)) 'baz'). 'moo' -> 'zoo' }.
+model := EavModel new getBlock: [ :x | (x root at: 'foo') at: 2 ].
+bb model: model read: [:r|result := r].
+self assert: #(1 #(2 3)) equals: result
+!
+
+testRootModelReturnsDeeplyIsolatedRoot
+| bb result |
+bb := Isolator on: #(1 #(2 3)).
+bb model: rootModel read: [:r|(r at: 2) at: 1 put: 0].
+bb model: rootModel read: [:r|result := r].
+self assert: #(1 #(2 3)) equals: result
+!
+
+testRootModelReturnsIsolatedRoot
+| bb result |
+bb := Isolator on: #(1 #(2 4)).
+bb model: rootModel read: [:r|r at: 2 put: nil].
+bb model: rootModel read: [:r|result := r].
+self assert: #(1 #(2 4)) equals: result
+!
+
+testRootModelReturnsRoot
+| bb result |
+bb := Isolator on: #(1 #(2 3)).
+bb model: rootModel read: [:r|result := r].
+self assert: #(1 #(2 3)) equals: result
+! !
+

+ 67 - 0
st/Trapped.st

@@ -1,4 +1,71 @@
 Smalltalk current createPackage: 'Trapped' properties: #{}!
+Object subclass: #EavModel
+	instanceVariableNames: 'getBlock putBlock'
+	package: 'Trapped'!
+!EavModel commentStamp!
+External actor value model.!
+
+!EavModel methodsFor: 'accessing'!
+
+getBlock: aBlock
+
+getBlock := aBlock
+!
+
+on: anObject
+"Returns value of model applied on object"
+
+^getBlock value: anObject
+!
+
+on: anObject put: anObject2
+"Puts a value via model applied on object"
+
+^putBlock value: anObject value: anObject2
+!
+
+putBlock: aBlock
+
+putBlock := aBlock
+! !
+
+!EavModel methodsFor: 'initialization'!
+
+initialize
+
+getBlock := [ self error: 'No getter block.' ].
+putBlock := [ self error: 'No putter block.' ].
+! !
+
+Object subclass: #Isolator
+	instanceVariableNames: 'root'
+	package: 'Trapped'!
+
+!Isolator methodsFor: 'accessing'!
+
+root
+
+^root
+!
+
+root: anObject
+
+root := anObject
+! !
+
+!Isolator methodsFor: 'action'!
+
+model: anEavModel read: aBlock
+
+aBlock value: (anEavModel on: self) deepCopy
+! !
+
+!Isolator class methodsFor: 'initialization'!
+
+on: anObject
+^self new root: anObject
+! !
+
 Object subclass: #Trapped
 	instanceVariableNames: ''
 	package: 'Trapped'!