1
0
Kaynağa Gözat

- unit tests
- separate #release from #destroy

Nicolas Petton 12 yıl önce
ebeveyn
işleme
a81b14cc92
3 değiştirilmiş dosya ile 147 ekleme ve 17 silme
  1. 51 4
      js/Spaces.deploy.js
  2. 72 10
      js/Spaces.js
  3. 24 3
      st/Spaces.st

+ 51 - 4
js/Spaces.deploy.js

@@ -51,9 +51,15 @@ smalltalk.method({
 selector: "do:",
 fn: function (aBlock) {
     var self = this;
-    var $1;
-    $1 = smalltalk.send(smalltalk.send(self['@frame'], "_contentWindow", []), "_eval_", [smalltalk.send(smalltalk.send("(", "__comma", [smalltalk.send(aBlock, "_compiledSource", [])]), "__comma", [")()"])]);
-    return $1;
+    var $1, $2, $3;
+    $1 = smalltalk.send(self, "_isConnected", []);
+    if (!smalltalk.assert($1)) {
+        $2 = smalltalk.send(smalltalk.ObjectSpaceConnectionError ||
+            ObjectSpaceConnectionError, "_signal", []);
+        return $2;
+    }
+    $3 = smalltalk.send(smalltalk.send(self['@frame'], "_contentWindow", []), "_eval_", [smalltalk.send(smalltalk.send("(", "__comma", [smalltalk.send(aBlock, "_compiledSource", [])]), "__comma", [")()"])]);
+    return $3;
 }
 }),
 smalltalk.ObjectSpace);
@@ -82,6 +88,19 @@ fn: function () {
 }),
 smalltalk.ObjectSpace);
 
+smalltalk.addMethod(
+"_isConnected",
+smalltalk.method({
+selector: "isConnected",
+fn: function () {
+    var self = this;
+    var $1;
+    $1 = smalltalk.send(smalltalk.send(self, "_frame", []), "_notNil", []);
+    return $1;
+}
+}),
+smalltalk.ObjectSpace);
+
 smalltalk.addMethod(
 "_release",
 smalltalk.method({
@@ -124,6 +143,20 @@ fn: function (aFrame) {
 smalltalk.ObjectSpace.klass);
 
 
+smalltalk.addClass('ObjectSpaceConnectionError', smalltalk.Error, [], 'Spaces');
+smalltalk.addMethod(
+"_messageText",
+smalltalk.method({
+selector: "messageText",
+fn: function () {
+    var self = this;
+    return "The ObjectSpace is not connected";
+}
+}),
+smalltalk.ObjectSpaceConnectionError);
+
+
+
 smalltalk.addClass('ObjectSpaceTest', smalltalk.TestCase, ['space'], 'Spaces');
 smalltalk.addMethod(
 "_setUp",
@@ -144,7 +177,20 @@ selector: "tearDown",
 fn: function () {
     var self = this;
     smalltalk.send(self['@space'], "_destroy", []);
-    self['@space'] = nil;
+    return self;
+}
+}),
+smalltalk.ObjectSpaceTest);
+
+smalltalk.addMethod(
+"_testConnection",
+smalltalk.method({
+selector: "testConnection",
+fn: function () {
+    var self = this;
+    smalltalk.send(self['@space'], "_destroy", []);
+    smalltalk.send(self, "_deny_", [smalltalk.send(self['@space'], "_isConnected", [])]);
+    smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@space'], "_do_", [function () {}]);}, smalltalk.ObjectSpaceConnectionError || ObjectSpaceConnectionError]);
     return self;
 }
 }),
@@ -157,6 +203,7 @@ selector: "testCreate",
 fn: function () {
     var self = this;
     smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(self['@space'], "_frame", []), "_notNil", [])]);
+    smalltalk.send(self, "_assert_", [smalltalk.send(self['@space'], "_isConnected", [])]);
     return self;
 }
 }),

+ 72 - 10
js/Spaces.js

@@ -68,14 +68,20 @@ selector: "do:",
 category: 'evaluating',
 fn: function (aBlock) {
     var self = this;
-    var $1;
-    $1 = smalltalk.send(smalltalk.send(self['@frame'], "_contentWindow", []), "_eval_", [smalltalk.send(smalltalk.send("(", "__comma", [smalltalk.send(aBlock, "_compiledSource", [])]), "__comma", [")()"])]);
-    return $1;
+    var $1, $2, $3;
+    $1 = smalltalk.send(self, "_isConnected", []);
+    if (!smalltalk.assert($1)) {
+        $2 = smalltalk.send(smalltalk.ObjectSpaceConnectionError ||
+            ObjectSpaceConnectionError, "_signal", []);
+        return $2;
+    }
+    $3 = smalltalk.send(smalltalk.send(self['@frame'], "_contentWindow", []), "_eval_", [smalltalk.send(smalltalk.send("(", "__comma", [smalltalk.send(aBlock, "_compiledSource", [])]), "__comma", [")()"])]);
+    return $3;
 },
 args: ["aBlock"],
-source: "do: aBlock\x0a\x09^ frame contentWindow eval: '(', aBlock compiledSource, ')()'",
-messageSends: ["eval:", ",", "compiledSource", "contentWindow"],
-referencedClasses: []
+source: "do: aBlock\x0a\x09self isConnected ifFalse: [ ^ ObjectSpaceConnectionError signal ].\x0a\x09^ frame contentWindow eval: '(', aBlock compiledSource, ')()'",
+messageSends: ["ifFalse:", "signal", "isConnected", "eval:", ",", "compiledSource", "contentWindow"],
+referencedClasses: ["ObjectSpaceConnectionError"]
 }),
 smalltalk.ObjectSpace);
 
@@ -113,6 +119,24 @@ referencedClasses: []
 }),
 smalltalk.ObjectSpace);
 
+smalltalk.addMethod(
+"_isConnected",
+smalltalk.method({
+selector: "isConnected",
+category: 'initialization',
+fn: function () {
+    var self = this;
+    var $1;
+    $1 = smalltalk.send(smalltalk.send(self, "_frame", []), "_notNil", []);
+    return $1;
+},
+args: [],
+source: "isConnected\x0a\x09^ self frame notNil",
+messageSends: ["notNil", "frame"],
+referencedClasses: []
+}),
+smalltalk.ObjectSpace);
+
 smalltalk.addMethod(
 "_release",
 smalltalk.method({
@@ -170,6 +194,25 @@ referencedClasses: []
 smalltalk.ObjectSpace.klass);
 
 
+smalltalk.addClass('ObjectSpaceConnectionError', smalltalk.Error, [], 'Spaces');
+smalltalk.addMethod(
+"_messageText",
+smalltalk.method({
+selector: "messageText",
+category: 'accessing',
+fn: function () {
+    var self = this;
+    return "The ObjectSpace is not connected";
+},
+args: [],
+source: "messageText\x0a\x09^ 'The ObjectSpace is not connected'",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.ObjectSpaceConnectionError);
+
+
+
 smalltalk.addClass('ObjectSpaceTest', smalltalk.TestCase, ['space'], 'Spaces');
 smalltalk.addMethod(
 "_setUp",
@@ -196,16 +239,34 @@ category: 'initialization',
 fn: function () {
     var self = this;
     smalltalk.send(self['@space'], "_destroy", []);
-    self['@space'] = nil;
     return self;
 },
 args: [],
-source: "tearDown\x0a\x09space destroy.\x0a\x09space := nil",
+source: "tearDown\x0a\x09space destroy",
 messageSends: ["destroy"],
 referencedClasses: []
 }),
 smalltalk.ObjectSpaceTest);
 
+smalltalk.addMethod(
+"_testConnection",
+smalltalk.method({
+selector: "testConnection",
+category: 'tests',
+fn: function () {
+    var self = this;
+    smalltalk.send(self['@space'], "_destroy", []);
+    smalltalk.send(self, "_deny_", [smalltalk.send(self['@space'], "_isConnected", [])]);
+    smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@space'], "_do_", [function () {}]);}, smalltalk.ObjectSpaceConnectionError || ObjectSpaceConnectionError]);
+    return self;
+},
+args: [],
+source: "testConnection\x0a\x09space destroy.\x0a\x09self deny: space isConnected.\x0a\x09self should: [ space do: [] ] raise: ObjectSpaceConnectionError",
+messageSends: ["destroy", "deny:", "isConnected", "should:raise:", "do:"],
+referencedClasses: ["ObjectSpaceConnectionError"]
+}),
+smalltalk.ObjectSpaceTest);
+
 smalltalk.addMethod(
 "_testCreate",
 smalltalk.method({
@@ -214,11 +275,12 @@ category: 'tests',
 fn: function () {
     var self = this;
     smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(self['@space'], "_frame", []), "_notNil", [])]);
+    smalltalk.send(self, "_assert_", [smalltalk.send(self['@space'], "_isConnected", [])]);
     return self;
 },
 args: [],
-source: "testCreate\x0a\x0a\x09self assert: space frame notNil",
-messageSends: ["assert:", "notNil", "frame"],
+source: "testCreate\x0a\x0a\x09self assert: space frame notNil.\x0a\x09self assert: space isConnected",
+messageSends: ["assert:", "notNil", "frame", "isConnected"],
 referencedClasses: []
 }),
 smalltalk.ObjectSpaceTest);

+ 24 - 3
st/Spaces.st

@@ -27,6 +27,7 @@ frame
 !ObjectSpace methodsFor: 'evaluating'!
 
 do: aBlock
+	self isConnected ifFalse: [ ^ ObjectSpaceConnectionError signal ].
 	^ frame contentWindow eval: '(', aBlock compiledSource, ')()'
 ! !
 
@@ -54,6 +55,10 @@ create
 initialize
 	super initialize.
 	self create
+!
+
+isConnected
+	^ self frame notNil
 ! !
 
 !ObjectSpace methodsFor: 'releasing'!
@@ -77,6 +82,16 @@ on: aFrame
 		yourself
 ! !
 
+Error subclass: #ObjectSpaceConnectionError
+	instanceVariableNames: ''
+	package: 'Spaces'!
+
+!ObjectSpaceConnectionError methodsFor: 'accessing'!
+
+messageText
+	^ 'The ObjectSpace is not connected'
+! !
+
 TestCase subclass: #ObjectSpaceTest
 	instanceVariableNames: 'space'
 	package: 'Spaces'!
@@ -88,15 +103,21 @@ setUp
 !
 
 tearDown
-	space destroy.
-	space := nil
+	space destroy
 ! !
 
 !ObjectSpaceTest methodsFor: 'tests'!
 
+testConnection
+	space destroy.
+	self deny: space isConnected.
+	self should: [ space do: [] ] raise: ObjectSpaceConnectionError
+!
+
 testCreate
 
-	self assert: space frame notNil
+	self assert: space frame notNil.
+	self assert: space isConnected
 !
 
 testEvaluation