Browse Source

Browser defaults to the all protocol after selecting a class

Ryan Simmons 9 years ago
parent
commit
fa443ba59b
6 changed files with 162 additions and 24 deletions
  1. 1 1
      Gruntfile.js
  2. 118 0
      src/Helios-Browser-Tests.js
  3. 29 0
      src/Helios-Browser-Tests.st
  4. 11 19
      src/Helios-Core.js
  5. 2 4
      src/Helios-Core.st
  6. 1 0
      src/all.js

+ 1 - 1
Gruntfile.js

@@ -53,7 +53,7 @@ module.exports = function(grunt) {
           'src/Helios-Transcript.st', 'src/Helios-Workspace.st', 'src/Helios-Debugger.st',
           'src/Helios-SUnit.st',
           // list all tests in dependency order
-          'src/Helios-Workspace-Tests.st', 'src/Helios-SUnit-Tests.st'
+          'src/Helios-Browser-Tests.st', 'src/Helios-Workspace-Tests.st', 'src/Helios-SUnit-Tests.st'
         ],
         libraries: ['Web', 'SUnit'],
         amd_namespace: 'helios',

+ 118 - 0
src/Helios-Browser-Tests.js

@@ -0,0 +1,118 @@
+define("helios/Helios-Browser-Tests", ["amber/boot", "amber_core/SUnit"], function($boot){
+var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
+var smalltalk=$core,_st=$recv,globals=$globals;
+$core.addPackage('Helios-Browser-Tests');
+$core.packages["Helios-Browser-Tests"].transport = {"type":"amd","amdNamespace":"helios"};
+
+$core.addClass('HLBrowserTest', $globals.TestCase, ['browser'], 'Helios-Browser-Tests');
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.HLBrowserTest.comment="Test cases for the functionality of  `HLBrowserModel`";
+//>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "setUp",
+protocol: 'tests',
+fn: function (){
+var self=this;
+function $HLBrowserModel(){return $globals.HLBrowserModel||(typeof HLBrowserModel=="undefined"?nil:HLBrowserModel)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) { 
+//>>excludeEnd("ctx");
+self["@browser"]=$recv($HLBrowserModel())._new();
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"setUp",{},$globals.HLBrowserTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "setUp\x0a\x09browser := HLBrowserModel new.",
+referencedClasses: ["HLBrowserModel"],
+//>>excludeEnd("ide");
+messageSends: ["new"]
+}),
+$globals.HLBrowserTest);
+
+$core.addMethod(
+$core.method({
+selector: "testAllProtocolsSelectedWhenSelectingAClass",
+protocol: 'tests',
+fn: function (){
+var self=this;
+function $Object(){return $globals.Object||(typeof Object=="undefined"?nil:Object)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) { 
+//>>excludeEnd("ctx");
+var $2,$1;
+$2=$recv(self["@browser"])._selectedProtocol();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["selectedProtocol"]=1;
+//>>excludeEnd("ctx");
+$1=$recv($2)._isNil();
+self._assert_($1);
+$recv(self["@browser"])._selectedClass_($Object());
+self._assert_equals_($recv(self["@browser"])._selectedProtocol(),$recv(self["@browser"])._allProtocol());
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testAllProtocolsSelectedWhenSelectingAClass",{},$globals.HLBrowserTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testAllProtocolsSelectedWhenSelectingAClass\x0a\x09self assert: browser selectedProtocol isNil.\x0a\x09browser selectedClass: Object.\x0a\x09self assert: browser selectedProtocol equals: browser allProtocol.",
+referencedClasses: ["Object"],
+//>>excludeEnd("ide");
+messageSends: ["assert:", "isNil", "selectedProtocol", "selectedClass:", "assert:equals:", "allProtocol"]
+}),
+$globals.HLBrowserTest);
+
+$core.addMethod(
+$core.method({
+selector: "testProtocolSelectedWhenChangingClass",
+protocol: 'tests',
+fn: function (){
+var self=this;
+var protocolSelectedCalled;
+function $HLProtocolSelected(){return $globals.HLProtocolSelected||(typeof HLProtocolSelected=="undefined"?nil:HLProtocolSelected)}
+function $Object(){return $globals.Object||(typeof Object=="undefined"?nil:Object)}
+function $ProtoObject(){return $globals.ProtoObject||(typeof ProtoObject=="undefined"?nil:ProtoObject)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) { 
+//>>excludeEnd("ctx");
+protocolSelectedCalled=(0);
+$recv($recv(self["@browser"])._announcer())._on_do_for_($HLProtocolSelected(),(function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+protocolSelectedCalled=$recv(protocolSelectedCalled).__plus((1));
+return protocolSelectedCalled;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),self);
+$recv(self["@browser"])._selectedClass_($Object());
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["selectedClass:"]=1;
+//>>excludeEnd("ctx");
+self._assert_equals_(protocolSelectedCalled,(1));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["assert:equals:"]=1;
+//>>excludeEnd("ctx");
+$recv(self["@browser"])._selectedClass_($ProtoObject());
+self._assert_equals_(protocolSelectedCalled,(2));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testProtocolSelectedWhenChangingClass",{protocolSelectedCalled:protocolSelectedCalled},$globals.HLBrowserTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testProtocolSelectedWhenChangingClass\x0a\x09| protocolSelectedCalled |\x0a\x09protocolSelectedCalled := 0.\x0a\x09browser announcer on: HLProtocolSelected do: [protocolSelectedCalled := protocolSelectedCalled + 1] for: self.\x0a\x09browser selectedClass: Object.\x0a\x09self assert: protocolSelectedCalled equals: 1.\x0a\x09browser selectedClass: ProtoObject.\x0a\x09self assert: protocolSelectedCalled equals: 2.",
+referencedClasses: ["HLProtocolSelected", "Object", "ProtoObject"],
+//>>excludeEnd("ide");
+messageSends: ["on:do:for:", "announcer", "+", "selectedClass:", "assert:equals:"]
+}),
+$globals.HLBrowserTest);
+
+
+});

+ 29 - 0
src/Helios-Browser-Tests.st

@@ -0,0 +1,29 @@
+Smalltalk createPackage: 'Helios-Browser-Tests'!
+TestCase subclass: #HLBrowserTest
+	instanceVariableNames: 'browser'
+	package: 'Helios-Browser-Tests'!
+!HLBrowserTest commentStamp!
+Test cases for the functionality of  `HLBrowserModel`!
+
+!HLBrowserTest methodsFor: 'tests'!
+
+setUp
+	browser := HLBrowserModel new.
+!
+
+testAllProtocolsSelectedWhenSelectingAClass
+	self assert: browser selectedProtocol isNil.
+	browser selectedClass: Object.
+	self assert: browser selectedProtocol equals: browser allProtocol.
+!
+
+testProtocolSelectedWhenChangingClass
+	| protocolSelectedCalled |
+	protocolSelectedCalled := 0.
+	browser announcer on: HLProtocolSelected do: [protocolSelectedCalled := protocolSelectedCalled + 1] for: self.
+	browser selectedClass: Object.
+	self assert: protocolSelectedCalled equals: 1.
+	browser selectedClass: ProtoObject.
+	self assert: protocolSelectedCalled equals: 2.
+! !
+

+ 11 - 19
src/Helios-Core.js

@@ -1501,15 +1501,12 @@ function $HLClassSelected(){return $globals.HLClassSelected||(typeof HLClassSele
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) { 
 //>>excludeEnd("ctx");
-var $3,$2,$1,$4,$6,$5,$7,$receiver;
+var $3,$2,$1,$5,$4,$6,$receiver;
 $3=self._selectedClass();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["selectedClass"]=1;
 //>>excludeEnd("ctx");
 $2=$recv($3).__eq(aClass);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["="]=1;
-//>>excludeEnd("ctx");
 $1=$recv($2)._and_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
@@ -1526,25 +1523,18 @@ self._withChangesDo_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$4=$recv(self["@selectedClass"]).__eq(aClass);
-if($core.assert($4)){
-self._selectedProtocol_(nil);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx["selectedProtocol:"]=1;
-//>>excludeEnd("ctx");
-};
 if(($receiver = aClass) == null || $receiver.isNil){
 self["@selectedClass"]=nil;
 self["@selectedClass"];
 } else {
-$6=$recv(aClass)._theNonMetaClass();
+$5=$recv(aClass)._theNonMetaClass();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["theNonMetaClass"]=1;
 //>>excludeEnd("ctx");
-$5=$recv($6)._package();
-self._selectedPackage_($5);
-$7=self._showInstance();
-if($core.assert($7)){
+$4=$recv($5)._package();
+self._selectedPackage_($4);
+$6=self._showInstance();
+if($core.assert($6)){
 self["@selectedClass"]=$recv(aClass)._theNonMetaClass();
 self["@selectedClass"];
 } else {
@@ -1552,7 +1542,9 @@ self["@selectedClass"]=$recv(aClass)._theMetaClass();
 self["@selectedClass"];
 };
 };
-self._selectedProtocol_(nil);
+self["@selectedProtocol"]=nil;
+self["@selectedProtocol"];
+self._selectedProtocol_(self._allProtocol());
 return $recv(self._announcer())._announce_($recv($HLClassSelected())._on_(self._selectedClass()));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
@@ -1565,10 +1557,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aClass"],
-source: "selectedClass: aClass\x0a\x09(self selectedClass = aClass and: [ aClass isNil ]) \x0a\x09\x09ifTrue: [ ^ self ].\x0a\x09\x0a\x09self withChangesDo: [\x0a\x09\x09selectedClass = aClass ifTrue: [ \x0a\x09\x09\x09self selectedProtocol: nil ].\x0a    \x0a\x09\x09aClass \x0a   \x09\x09\x09ifNil: [ selectedClass := nil ]\x0a    \x09\x09ifNotNil: [\x0a\x09\x09\x09\x09self selectedPackage: aClass theNonMetaClass package.\x0a\x09\x09\x09\x09self showInstance \x0a   \x09\x09\x09\x09\x09ifTrue: [ selectedClass := aClass theNonMetaClass ]\x0a     \x09\x09\x09\x09ifFalse: [ selectedClass := aClass theMetaClass ] ].\x0a\x09\x09self selectedProtocol: nil.\x0a\x09\x09self announcer announce: (HLClassSelected on: self selectedClass) ]",
+source: "selectedClass: aClass\x0a\x09(self selectedClass = aClass and: [ aClass isNil ]) \x0a\x09\x09ifTrue: [ ^ self ].\x0a\x09\x0a\x09self withChangesDo: [\x0a\x09\x09aClass \x0a   \x09\x09\x09ifNil: [ selectedClass := nil ]\x0a    \x09\x09ifNotNil: [\x0a\x09\x09\x09\x09self selectedPackage: aClass theNonMetaClass package.\x0a\x09\x09\x09\x09self showInstance \x0a   \x09\x09\x09\x09\x09ifTrue: [ selectedClass := aClass theNonMetaClass ]\x0a     \x09\x09\x09\x09ifFalse: [ selectedClass := aClass theMetaClass ] ].\x0a\x09\x09selectedProtocol := nil.\x0a\x09\x09self selectedProtocol: self allProtocol.\x0a\x09\x09self announcer announce: (HLClassSelected on: self selectedClass) ]",
 referencedClasses: ["HLClassSelected"],
 //>>excludeEnd("ide");
-messageSends: ["ifTrue:", "and:", "=", "selectedClass", "isNil", "withChangesDo:", "selectedProtocol:", "ifNil:ifNotNil:", "selectedPackage:", "package", "theNonMetaClass", "ifTrue:ifFalse:", "showInstance", "theMetaClass", "announce:", "announcer", "on:"]
+messageSends: ["ifTrue:", "and:", "=", "selectedClass", "isNil", "withChangesDo:", "ifNil:ifNotNil:", "selectedPackage:", "package", "theNonMetaClass", "ifTrue:ifFalse:", "showInstance", "theMetaClass", "selectedProtocol:", "allProtocol", "announce:", "announcer", "on:"]
 }),
 $globals.HLToolModel);
 

+ 2 - 4
src/Helios-Core.st

@@ -174,9 +174,6 @@ selectedClass: aClass
 		ifTrue: [ ^ self ].
 	
 	self withChangesDo: [
-		selectedClass = aClass ifTrue: [ 
-			self selectedProtocol: nil ].
-    
 		aClass 
    			ifNil: [ selectedClass := nil ]
     		ifNotNil: [
@@ -184,7 +181,8 @@ selectedClass: aClass
 				self showInstance 
    					ifTrue: [ selectedClass := aClass theNonMetaClass ]
      				ifFalse: [ selectedClass := aClass theMetaClass ] ].
-		self selectedProtocol: nil.
+		selectedProtocol := nil.
+		self selectedProtocol: self allProtocol.
 		self announcer announce: (HLClassSelected on: self selectedClass) ]
 !
 

+ 1 - 0
src/all.js

@@ -9,6 +9,7 @@ define([
 	'./Helios-Layout',
 	'./Helios-KeyBindings',
 	'./Helios-Browser',
+	'./Helios-Browser-Tests',
 	'./Helios-Workspace',
 	'./Helios-Transcript',
 	'./Helios-SUnit',