-
Notifications
You must be signed in to change notification settings - Fork 0
/
rustictest.min.js
1 lines (1 loc) · 1.4 KB
/
rustictest.min.js
1
export class RusticTest{constructor(){this.failNum=0,this.passNum=0,this.failInfo=[],this.passInfo=[]}initData(){this.failNum=0,this.passNum=0,this.failInfo=[],this.passInfo=[]}fail(s,t,i){this.failNum++;let a="FAIL "+s+" - "+t+": "+i;this.failInfo.push(a),console.error(a)}pass(s,t,i){this.passNum++;let a="PASS "+s+" - "+t+": "+i;this.passInfo.push(a),console.log(a)}assert(s,t,i=""){t?this.pass(s,"assert",i):this.fail(s,"assert",i)}assertEquals(s,t,i,a=""){t!=i?this.fail(s,"assertEquals",t+" != "+i+" "+a):this.pass(s,"assertEquals",t+" == "+i+" "+a)}assertStrictEquals(s,t,i,a=""){t!==i?this.fail(s,"assertStrictEquals",t+" !== "+i+" "+a):this.pass(s,"assertStrictEquals",t+" === "+i+" "+a)}testResults(s=!1){var t="",i="",a="",l="",e=this.passNum+this.failNum;if(!0===s)console.log("Passed tests: "+this.passNum),console.log("Failed tests: "+this.failNum),console.log("Total tests: "+e);else{t=this.passNum>0?"font-weight:bold;":"",i=this.failNum>0?"font-weight:bold;":"";var h='<div style="color:green;'+t+'">Passed tests: '+this.passNum+"</div>",o='<div style="color:red;'+i+'">Failed tests: '+this.failNum+"</div>";this.passInfo.length>0&&this.passInfo.forEach(s=>{a=a+"<div>"+s+"</div>"}),this.failInfo.length>0&&this.failInfo.forEach(s=>{l=l+'<div style="color:red;font-weight:bold;">'+s+"</div>"});var f=h+o+'<div style="color:black;font-weight:bold;">Total tests: '+e+"</div><hr />"+a+l;document.body.innerHTML=f}}}