Explorar o código

Fix tests using `assertBodyEndsWithOneOf:`

Herbert Vojčík %!s(int64=9) %!d(string=hai) anos
pai
achega
aaae979197
Modificáronse 2 ficheiros con 96 adicións e 4 borrados
  1. 79 3
      src/Silk-Tests.js
  2. 17 1
      src/Silk-Tests.st

+ 79 - 3
src/Silk-Tests.js

@@ -77,6 +77,82 @@ messageSends: ["replace:with:", "innerHTML", "body", "assert:", ">=", "size", "a
 }),
 $globals.SilkTest);
 
+$core.addMethod(
+$core.method({
+selector: "assertBodyEndsWithOneOf:",
+protocol: 'fixture',
+fn: function (aStringArray){
+var self=this;
+var sanitizedBody,err;
+function $Error(){return $globals.Error||(typeof Error=="undefined"?nil:Error)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$3,$1,$4,$5,$receiver;
+var $early={};
+try {
+sanitizedBody=$recv($recv($recv(document)._body())._innerHTML())._replace_with_("\x5cs*","");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["replace:with:"]=1;
+//>>excludeEnd("ctx");
+$recv(aStringArray)._do_((function(aString){
+var sanitizedAssertion;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+sanitizedAssertion=$recv(aString)._replace_with_("\x5cs*","");
+sanitizedAssertion;
+return $recv((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx3) {
+//>>excludeEnd("ctx");
+$2=$recv(sanitizedBody)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx3.sendIdx["size"]=1;
+//>>excludeEnd("ctx");
+$3=$recv(sanitizedAssertion)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx3.sendIdx["size"]=2;
+//>>excludeEnd("ctx");
+$1=$recv($2).__gt_eq($3);
+self._assert_($1);
+$4=self._assert_equals_($recv(sanitizedBody)._last_($recv(sanitizedAssertion)._size()),sanitizedAssertion);
+$4;
+throw $early=[self];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
+//>>excludeEnd("ctx");
+}))._on_do_($Error(),(function(e){
+err=e;
+return err;
+
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({aString:aString,sanitizedAssertion:sanitizedAssertion},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
+$5=err;
+if(($receiver = $5) == null || $receiver.isNil){
+$5;
+} else {
+$recv(err)._signal();
+};
+return self;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"assertBodyEndsWithOneOf:",{aStringArray:aStringArray,sanitizedBody:sanitizedBody,err:err},$globals.SilkTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aStringArray"],
+source: "assertBodyEndsWithOneOf: aStringArray\x0a\x09| sanitizedBody err |\x0a\x09sanitizedBody := document body innerHTML replace: '\x5cs*' with: ''.\x0a\x09aStringArray do: [ :aString |\x0a\x09\x09| sanitizedAssertion |\x0a\x09\x09sanitizedAssertion := aString replace: '\x5cs*' with: ''.\x0a\x09\x09[ self\x0a\x09\x09\x09assert: sanitizedBody size >= sanitizedAssertion size;\x0a\x09\x09\x09assert: (sanitizedBody last: sanitizedAssertion size)\x0a\x09\x09\x09equals: sanitizedAssertion. ^ self ] on: Error do: [ :e | err := e ]].\x0a\x09err ifNotNil: [ err signal ]",
+referencedClasses: ["Error"],
+//>>excludeEnd("ide");
+messageSends: ["replace:with:", "innerHTML", "body", "do:", "on:do:", "assert:", ">=", "size", "assert:equals:", "last:", "ifNotNil:", "signal"]
+}),
+$globals.SilkTest);
+
 $core.addMethod(
 $core.method({
 selector: "setUp",
@@ -317,7 +393,7 @@ return $recv($Transcript())._show_("button pressed");
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
 }));
-self._assertBodyEndsWith_(">sentinel<div class=\x22mySilkContainerClass\x22 id=\x22container\x22><div id=\x22contentarea\x22>here comes the content</div><div class=\x22myToolbarClass\x22 id=\x22toolbar\x22><button>do something</button></div></div></div>");
+self._assertBodyEndsWithOneOf_([">sentinel<div class=\x22mySilkContainerClass\x22 id=\x22container\x22><div id=\x22contentarea\x22>here comes the content</div><div class=\x22myToolbarClass\x22 id=\x22toolbar\x22><button>do something</button></div></div></div>", ">sentinel<div id=\x22container\x22 class=\x22mySilkContainerClass\x22><div id=\x22contentarea\x22>here comes the content</div><div id=\x22toolbar\x22 class=\x22myToolbarClass\x22><button>do something</button></div></div></div>"]);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"testNestedDIVsWithAttributes",{s:s},$globals.SilkTest)});
@@ -325,10 +401,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "testNestedDIVsWithAttributes\x0a \x22demonstrates how DIVs are nested and given attributes\x22\x0a\x09| s |\x0a\x0a\x09s := '#fixture' asSilk.\x0a\x09\x0a\x09s := s DIV << ('id' -> 'container') << ('class' -> 'mySilkContainerClass').\x0a\x09s DIV << ('id' -> 'contentarea') << 'here comes the content'.\x0a\x09s := s DIV << ('id' -> 'toolbar') << ('class' -> 'myToolbarClass').\x0a\x09(s BUTTON: 'do something') on: 'click' bind: [Transcript show: 'button pressed'].\x0a\x09\x0a\x09self assertBodyEndsWith: '>sentinel<div class=\x22mySilkContainerClass\x22 id=\x22container\x22><div id=\x22contentarea\x22>here comes the content</div><div class=\x22myToolbarClass\x22 id=\x22toolbar\x22><button>do something</button></div></div></div>'",
+source: "testNestedDIVsWithAttributes\x0a \x22demonstrates how DIVs are nested and given attributes\x22\x0a\x09| s |\x0a\x0a\x09s := '#fixture' asSilk.\x0a\x09\x0a\x09s := s DIV << ('id' -> 'container') << ('class' -> 'mySilkContainerClass').\x0a\x09s DIV << ('id' -> 'contentarea') << 'here comes the content'.\x0a\x09s := s DIV << ('id' -> 'toolbar') << ('class' -> 'myToolbarClass').\x0a\x09(s BUTTON: 'do something') on: 'click' bind: [Transcript show: 'button pressed'].\x0a\x09\x0a\x09self assertBodyEndsWithOneOf: #(\x0a\x09\x09'>sentinel<div class=\x22mySilkContainerClass\x22 id=\x22container\x22><div id=\x22contentarea\x22>here comes the content</div><div class=\x22myToolbarClass\x22 id=\x22toolbar\x22><button>do something</button></div></div></div>'\x0a\x09\x09'>sentinel<div id=\x22container\x22 class=\x22mySilkContainerClass\x22><div id=\x22contentarea\x22>here comes the content</div><div id=\x22toolbar\x22 class=\x22myToolbarClass\x22><button>do something</button></div></div></div>'\x0a\x09)",
 referencedClasses: ["Transcript"],
 //>>excludeEnd("ide");
-messageSends: ["asSilk", "<<", "DIV", "->", "on:bind:", "BUTTON:", "show:", "assertBodyEndsWith:"]
+messageSends: ["asSilk", "<<", "DIV", "->", "on:bind:", "BUTTON:", "show:", "assertBodyEndsWithOneOf:"]
 }),
 $globals.SilkTest);
 

+ 17 - 1
src/Silk-Tests.st

@@ -26,6 +26,19 @@ assertBodyEndsWith: aString
 		equals: sanitizedAssertion
 !
 
+assertBodyEndsWithOneOf: aStringArray
+	| sanitizedBody err |
+	sanitizedBody := document body innerHTML replace: '\s*' with: ''.
+	aStringArray do: [ :aString |
+		| sanitizedAssertion |
+		sanitizedAssertion := aString replace: '\s*' with: ''.
+		[ self
+			assert: sanitizedBody size >= sanitizedAssertion size;
+			assert: (sanitizedBody last: sanitizedAssertion size)
+			equals: sanitizedAssertion. ^ self ] on: Error do: [ :e | err := e ]].
+	err ifNotNil: [ err signal ]
+!
+
 setUp
 	fixtureDiv := document createElement: 'div'.
 	document body appendChild: fixtureDiv.
@@ -94,7 +107,10 @@ testNestedDIVsWithAttributes
 	s := s DIV << ('id' -> 'toolbar') << ('class' -> 'myToolbarClass').
 	(s BUTTON: 'do something') on: 'click' bind: [Transcript show: 'button pressed'].
 	
-	self assertBodyEndsWith: '>sentinel<div class="mySilkContainerClass" id="container"><div id="contentarea">here comes the content</div><div class="myToolbarClass" id="toolbar"><button>do something</button></div></div></div>'
+	self assertBodyEndsWithOneOf: #(
+		'>sentinel<div class="mySilkContainerClass" id="container"><div id="contentarea">here comes the content</div><div class="myToolbarClass" id="toolbar"><button>do something</button></div></div></div>'
+		'>sentinel<div id="container" class="mySilkContainerClass"><div id="contentarea">here comes the content</div><div id="toolbar" class="myToolbarClass"><button>do something</button></div></div></div>'
+	)
 !
 
 testOnClickEvent