|
@@ -47,6 +47,218 @@ $globals.ResultAnnouncement);
|
|
|
|
|
|
|
|
|
|
|
|
+$core.addClass("Teachable", $globals.Object, ["learnings"], "SUnit");
|
|
|
+
|
|
|
+$globals.Teachable.comment="An object you can teach how to behave. Have a look at the \x0aclass side for an example.\x0a\x0aFor more infos have a look at: http://lists.squeakfoundation.org/pipermail/squeak-dev/2002-April/038170.html";
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "acceptSend:",
|
|
|
+protocol: "teaching",
|
|
|
+
|
|
|
+args: ["aSymbol"],
|
|
|
+source: "acceptSend: aSymbol\x0a\x0a\x09self whenSend: aSymbol return: self",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+pragmas: [],
|
|
|
+messageSends: ["whenSend:return:"]
|
|
|
+}, function ($methodClass){ return function (aSymbol){
|
|
|
+var self=this,$self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+$self._whenSend_return_(aSymbol,self);
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"acceptSend:",{aSymbol:aSymbol})});
|
|
|
+
|
|
|
+}; }),
|
|
|
+$globals.Teachable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "doesNotUnderstand:",
|
|
|
+protocol: "private",
|
|
|
+
|
|
|
+args: ["aMessage"],
|
|
|
+source: "doesNotUnderstand: aMessage\x0a\x0a\x09| learning |\x0a\x09learning := self learnings \x0a\x09\x09at: aMessage selector \x0a\x09\x09ifAbsent:[ ^super doesNotUnderstand: aMessage ].\x0a\x09^ learning class == Association\x0a\x09\x09ifTrue: [learning value]\x0a\x09\x09ifFalse: [learning valueWithPossibleArguments: aMessage arguments]",
|
|
|
+referencedClasses: ["Association"],
|
|
|
+
|
|
|
+pragmas: [],
|
|
|
+messageSends: ["at:ifAbsent:", "learnings", "selector", "doesNotUnderstand:", "ifTrue:ifFalse:", "==", "class", "value", "valueWithPossibleArguments:", "arguments"]
|
|
|
+}, function ($methodClass){ return function (aMessage){
|
|
|
+var self=this,$self=this;
|
|
|
+var learning;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $1,$2;
|
|
|
+var $early={};
|
|
|
+try {
|
|
|
+learning=$recv($self._learnings())._at_ifAbsent_($recv(aMessage)._selector(),(function(){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+$1=(
|
|
|
+
|
|
|
+$ctx2.supercall = true,
|
|
|
+
|
|
|
+($methodClass.superclass||$boot.nilAsClass).fn.prototype._doesNotUnderstand_.call($self,aMessage));
|
|
|
+
|
|
|
+$ctx2.supercall = false;
|
|
|
+
|
|
|
+throw $early=[$1];
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+
|
|
|
+}));
|
|
|
+$2=$recv($recv(learning)._class()).__eq_eq($globals.Association);
|
|
|
+if($core.assert($2)){
|
|
|
+return $recv(learning)._value();
|
|
|
+} else {
|
|
|
+return $recv(learning)._valueWithPossibleArguments_($recv(aMessage)._arguments());
|
|
|
+}
|
|
|
+}
|
|
|
+catch(e) {if(e===$early)return e[0]; throw e}
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage,learning:learning})});
|
|
|
+
|
|
|
+}; }),
|
|
|
+$globals.Teachable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "learnings",
|
|
|
+protocol: "private",
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "learnings\x0a\x0a\x09learnings isNil ifTrue: [learnings := Dictionary new].\x0a\x09^learnings",
|
|
|
+referencedClasses: ["Dictionary"],
|
|
|
+
|
|
|
+pragmas: [],
|
|
|
+messageSends: ["ifTrue:", "isNil", "new"]
|
|
|
+}, function ($methodClass){ return function (){
|
|
|
+var self=this,$self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $1;
|
|
|
+$1=$recv($self.learnings)._isNil();
|
|
|
+if($core.assert($1)){
|
|
|
+$self.learnings=$recv($globals.Dictionary)._new();
|
|
|
+$self.learnings;
|
|
|
+}
|
|
|
+return $self.learnings;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"learnings",{})});
|
|
|
+
|
|
|
+}; }),
|
|
|
+$globals.Teachable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "whenSend:evaluate:",
|
|
|
+protocol: "teaching",
|
|
|
+
|
|
|
+args: ["aSymbol", "aBlock"],
|
|
|
+source: "whenSend: aSymbol evaluate: aBlock\x0a\x0a\x09self learnings at: aSymbol put: aBlock",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+pragmas: [],
|
|
|
+messageSends: ["at:put:", "learnings"]
|
|
|
+}, function ($methodClass){ return function (aSymbol,aBlock){
|
|
|
+var self=this,$self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+$recv($self._learnings())._at_put_(aSymbol,aBlock);
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"whenSend:evaluate:",{aSymbol:aSymbol,aBlock:aBlock})});
|
|
|
+
|
|
|
+}; }),
|
|
|
+$globals.Teachable);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "whenSend:return:",
|
|
|
+protocol: "teaching",
|
|
|
+
|
|
|
+args: ["aSymbol", "anObject"],
|
|
|
+source: "whenSend: aSymbol return: anObject\x0a\x0a\x09self learnings at: aSymbol put: (#return -> anObject)",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+pragmas: [],
|
|
|
+messageSends: ["at:put:", "learnings", "->"]
|
|
|
+}, function ($methodClass){ return function (aSymbol,anObject){
|
|
|
+var self=this,$self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+$recv($self._learnings())._at_put_(aSymbol,"return".__minus_gt(anObject));
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"whenSend:return:",{aSymbol:aSymbol,anObject:anObject})});
|
|
|
+
|
|
|
+}; }),
|
|
|
+$globals.Teachable);
|
|
|
+
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "example",
|
|
|
+protocol: "examples",
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "example\x0a\x09| teachable |\x0a\x09teachable := self new.\x0a\x09teachable \x0a\x09\x09whenSend: #help return: 'ok';\x0a\x09\x09whenSend: #doit evaluate: [1 inspect];\x0a\x09\x09acceptSend: #noDebugger;\x0a\x09\x09whenSend: #negate: evaluate: [:num | num negated].\x0a\x09teachable help.\x0a\x09teachable doit.\x0a\x09teachable noDebugger.\x0a\x09teachable negate: 120",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+pragmas: [],
|
|
|
+messageSends: ["new", "whenSend:return:", "whenSend:evaluate:", "inspect", "acceptSend:", "negated", "help", "doit", "noDebugger", "negate:"]
|
|
|
+}, function ($methodClass){ return function (){
|
|
|
+var self=this,$self=this;
|
|
|
+var teachable;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $1;
|
|
|
+teachable=$self._new();
|
|
|
+$1=teachable;
|
|
|
+$recv($1)._whenSend_return_("help","ok");
|
|
|
+$recv($1)._whenSend_evaluate_("doit",(function(){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+return (1)._inspect();
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+
|
|
|
+}));
|
|
|
+
|
|
|
+$ctx1.sendIdx["whenSend:evaluate:"]=1;
|
|
|
+
|
|
|
+$recv($1)._acceptSend_("noDebugger");
|
|
|
+$recv($1)._whenSend_evaluate_("negate:",(function(num){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+return $recv(num)._negated();
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({num:num},$ctx1,2)});
|
|
|
+
|
|
|
+}));
|
|
|
+$recv(teachable)._help();
|
|
|
+$recv(teachable)._doit();
|
|
|
+$recv(teachable)._noDebugger();
|
|
|
+$recv(teachable)._negate_((120));
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"example",{teachable:teachable})});
|
|
|
+
|
|
|
+}; }),
|
|
|
+$globals.Teachable.a$cls);
|
|
|
+
|
|
|
+
|
|
|
$core.addClass("TestCase", $globals.Object, ["testSelector", "asyncTimeout", "context"], "SUnit");
|
|
|
|
|
|
$globals.TestCase.comment="I am an implementation of the command pattern to run a test.\x0a\x0a## API\x0a\x0aMy instances are created with the class method `#selector:`,\x0apassing the symbol that names the method to be executed when the test case runs.\x0a\x0aWhen you discover a new fixture, subclass `TestCase` and create a `#test...` method for the first test.\x0aAs that method develops and more `#test...` methods are added, you will find yourself refactoring temps\x0ainto instance variables for the objects in the fixture and overriding `#setUp` to initialize these variables.\x0aAs required, override `#tearDown` to nil references, release objects and deallocate.";
|