root / trunk / web / dojo / dojox / widget / DocTester.js @ 12
History | View | Annotate | Download (3.25 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.widget.DocTester"]){ |
||
9 | dojo._hasResource["dojox.widget.DocTester"]=true; |
||
10 | dojo.provide("dojox.widget.DocTester");
|
||
11 | dojo.require("dojo.string");
|
||
12 | dojo.require("dijit._Widget");
|
||
13 | dojo.require("dijit._Templated");
|
||
14 | dojo.require("dojox.form.BusyButton");
|
||
15 | dojo.require("dojox.testing.DocTest");
|
||
16 | dojo.declare("dojox.widget.DocTester",[dijit._Widget,dijit._Templated],{templateString:dojo.cache("dojox.widget","DocTester/DocTester.html","<div dojoAttachPoint=\"domNode\" class=\"dojoxDocTester\">\n\t<div dojoAttachPoint=\"containerNode\"></div>\n\t<button dojoType=\"dojox.form.BusyButton\" busyLabel=\"Testing...\" dojoAttachPoint=\"runButtonNode\">Run tests</button>\n\t<button dojoType=\"dijit.form.Button\" dojoAttachPoint=\"resetButtonNode\" style=\"display:none;\">Reset</button>\n\t<span>\n\t\t<span dojoAttachPoint=\"numTestsNode\">0</span> tests,\n\t\t<span dojoAttachPoint=\"numTestsOkNode\">0</span> passed,\n\t\t<span dojoAttachPoint=\"numTestsNokNode\">0</span> failed\n\t</span>\n</div>\n"),widgetsInTemplate:true,_fillContent:function(_1){ |
||
17 | var _2=_1.innerHTML;
|
||
18 | this.doctests=new dojox.testing.DocTest(); |
||
19 | this.tests=this.doctests.getTestsFromString(this._unescapeHtml(_2)); |
||
20 | var _3=dojo.map(this.tests,"return item.line-1"); |
||
21 | var _4=_2.split("\n"); |
||
22 | var _5="<div class=\"actualResult\">FAILED, actual result was: <span class=\"result\"></span></div>"; |
||
23 | var _6="<pre class=\"testCase testNum0 odd\">"; |
||
24 | for(var i=0;i<_4.length;i++){ |
||
25 | var _7=dojo.indexOf(_3,i);
|
||
26 | if(_7>0&&_7!=-1){ |
||
27 | var _8=_7%2?"even":"odd"; |
||
28 | _6+=_5; |
||
29 | _6+="</pre><pre class=\"testCase testNum"+_7+" "+_8+"\">"; |
||
30 | } |
||
31 | _6+=_4[i].replace(/^\s+/,"")+"\n"; |
||
32 | } |
||
33 | _6+=_5+"</pre>";
|
||
34 | this.containerNode.innerHTML=_6;
|
||
35 | },postCreate:function(){ |
||
36 | this.inherited("postCreate",arguments); |
||
37 | dojo.connect(this.runButtonNode,"onClick",dojo.hitch(this,"runTests")); |
||
38 | dojo.connect(this.resetButtonNode,"onClick",dojo.hitch(this,"reset")); |
||
39 | this.numTestsNode.innerHTML=this.tests.length; |
||
40 | },runTests:function(){ |
||
41 | var _9={ok:0,nok:0}; |
||
42 | for(var i=0;i<this.tests.length;i++){ |
||
43 | var _a=this.doctests.runTest(this.tests[i].commands,this.tests[i].expectedResult); |
||
44 | dojo.query(".testNum"+i,this.domNode).addClass(_a.success?"resultOk":"resultNok"); |
||
45 | if(!_a.success){
|
||
46 | _9.nok++; |
||
47 | this.numTestsNokNode.innerHTML=_9.nok;
|
||
48 | var _b=dojo.query(".testNum"+i+" .actualResult",this.domNode)[0]; |
||
49 | dojo.style(_b,"display","inline"); |
||
50 | dojo.query(".result",_b)[0].innerHTML=dojo.toJson(_a.actualResult); |
||
51 | }else{
|
||
52 | _9.ok++; |
||
53 | this.numTestsOkNode.innerHTML=_9.ok;
|
||
54 | } |
||
55 | } |
||
56 | this.runButtonNode.cancel();
|
||
57 | dojo.style(this.runButtonNode.domNode,"display","none"); |
||
58 | dojo.style(this.resetButtonNode.domNode,"display",""); |
||
59 | },reset:function(){ |
||
60 | dojo.style(this.runButtonNode.domNode,"display",""); |
||
61 | dojo.style(this.resetButtonNode.domNode,"display","none"); |
||
62 | this.numTestsOkNode.innerHTML="0"; |
||
63 | this.numTestsNokNode.innerHTML="0"; |
||
64 | dojo.query(".actualResult",this.domNode).style("display","none"); |
||
65 | dojo.query(".testCase",this.domNode).removeClass("resultOk").removeClass("resultNok"); |
||
66 | },_unescapeHtml:function(_c){ |
||
67 | _c=String(_c).replace(/&/gm,"&").replace(/</gm,"<").replace(/>/gm,">").replace(/"/gm,"\""); |
||
68 | return _c;
|
||
69 | }}); |
||
70 | } |