How to use __Basic__ method in storybook-root

Best JavaScript code snippet using storybook-root

a9text.js

Source:a9text.js Github

copy

Full Screen

1/**2UTF8(BOM) LGPL trydofor.com May.20073===========================================================4void parse(a9dom)5*/67var A9TextParser = function()8{9 var __regexp__ = 10 {11 root$foot : /^[  \t]*\^{3,}/,12 info : /^[  \t]*\\*-[  \t]*/,13 sect : /^[  \t]*\\*([0-9]+\.)+[  \t]+/,14 sect$foot : /^[  \t]*\^{3,}/,15 list$item : /^[  \t]*\\*([\*\+\-])[  \t]*\)?[  \t]+/,16 list$auto : /^[  \t]*\\*(#)[  \t]*[\.\)][  \t]+/,17 list$digt : /^[  \t]*\\*([0-9]+)[  \t]*[\.\)][  \t]+/,18 list$lchr : /^[  \t]*\\*([a-z]+)[  \t]*[\.\)][  \t]+/,19 list$uchr : /^[  \t]*\\*([A-Z]+)[  \t]*[\.\)][  \t]+/,20 dict : /^[  \t]*\[?([^:\]]+)[  \t]*\]?\\*(:{2,})/,21 area$head : /^[  \t]*\\*={9,}[  \t]*(\*?\w+)[  \t]*(.*[^=])?={9,}$/,22 area$args : /^[  \t]*\\*args:[  \t]*(.*)/,23 area$foot : /^[  \t]*\\*={9,}$/,24 area$etxt : /^[  \t]*\\*\.{9,}$/,25 para$line3 : /^[  \t]*\\*#{9,}$/,26 para$line2 : /^[  \t]*\\*={9,}$/,27 para$line1 : /^[  \t]*\\*-{9,}$/,28 para$line0 : /^\\*[  \t]*$/,29 mode_trig : /\[(!|\/|_|\-|'|,|(#[0-9a-fA-F]{6})|(&[0-9a-fA-F]{6})|(%[0-9]+))+\[/,30 mode_link : /\[\[.*=>/,31 mode_join : /\[((\d+%?)?\*(\d+%?)?)?\[.*<=/,32 mode_$htm : /\[\*htm\[/33 };34 ////35 var __crlf__ = "\r\n";36 var __lines__ = [];37 var __index__ = 0;38 var __super__ = null; // top a9dom39 var __basic__ = null; // parent a9dom40 var __sect_flag__ = []; // hold sects info41 var __args_sect__ = {};42 var __args_dict__ = {};43 var __args_area__ = {};44 var __args_hash__ = {};45 var __args_join__ = {};46 var __join_ext__ = A9Conf.getConf("parser.join.text.name");47 48 var __simple_link__ = [];49 for(var i=1;;i++){5051 var addr = A9Conf.getConf("parser.link.simple-"+i+".addr");52 var regexp = A9Conf.getConf("parser.link.simple-"+i+".regexp");53 if(addr == null || regexp == null) break;54 __simple_link__.push({'addr':addr,'regexp':new RegExp(regexp,"i")});55 }56 57 var __progress_bar__ = null;58 var __total_lines__ = 0;59 60 // public61 this.setProgressBar = function(pgb){62 if(pgb != null)__progress_bar__ = pgb;63 }64 65 this.parse = function(a9dom,func)66 {67 var text = a9dom.getText();68 if(text == null || text == "") return;69 70 // clear71 __super__ = a9dom;72 __basic__ = a9dom;73 __index__ = 0;74 __crlf__ = A9Util.getCRLF(text);75 __lines__ = text.split(__crlf__);76 __sect_flag__ = [];77 __args_sect__ = {};78 __args_dict__ = {};79 __args_area__ = {};80 __args_hash__ = {};81 __args_join__ = {};82 __total_lines__ = __lines__.length;83 84 // a9text root and info85 __parseRoot__();86 87 // elements of root88 var lastLine = 0;89 for(;__hasLine__(); __index__ ++)90 {91 //92 if(__progress_bar__ != null){93 try{94 __progress_bar__.work(Math.ceil(40*(__index__-lastLine)/__total_lines__));95 }catch(e){};96 }97 lastLine = __index__;98 //99 if(__meetSect__())100 __parseSect__();101 else if (__meetList__())102 __parseList__();103 else if (__meetDict__())104 __parseDict__();105 else if (__meetArea__())106 __parseArea__();107 else if (__meetArea$etxt__())108 __parseArea$etxt__(); 109 else 110 __parsePara__();111 112113 }114 115 //116 a9dom.putInfo(A9Dom.type.root$dict,__args_dict__);117 a9dom.putInfo(A9Dom.type.root$sect,__args_sect__);118 a9dom.putInfo(A9Dom.type.root$area,__args_area__);119 a9dom.putInfo(A9Dom.type.root$hash,__args_hash__);120 a9dom.putInfo(A9Dom.type.root$join,__args_join__);121 122 123 if(func instanceof Function){124 A9Loader.runAfterClassLoaded(function(){func(a9dom)});125 }126 }127 128 /* private member */129 130 // check and escape131 132 function __meetSect__()133 {134 return __regexp__.sect.test(__lines__[__index__]);135 }136 137 function __meetList__()138 {139 if(__regexp__.para$line1.test(__lines__[__index__])) return false;140 141 //142 return __regexp__.list$item.test(__lines__[__index__]) ||143 __regexp__.list$auto.test(__lines__[__index__]) ||144 __regexp__.list$digt.test(__lines__[__index__]) ||145 __regexp__.list$lchr.test(__lines__[__index__]) ||146 __regexp__.list$uchr.test(__lines__[__index__]) ;147 }148 149 function __meetDict__()150 {151 return __regexp__.dict.test(__lines__[__index__]);152 }153 154 function __meetArea__()155 {156 return __regexp__.area$head.test(__lines__[__index__]);157 }158 159 function __meetArea$etxt__()160 {161 return __regexp__.area$etxt.test(__lines__[__index__]);162 }163 164 // parsers165 function __parseRoot__()166 {167 if(__index__ != 0) return; // must the first line.168 if(!__regexp__.root$foot.test(__lines__[1]))return;169170 // parse root171 __super__.putInfo(A9Dom.type.root$name,__lines__[0]);172 173 __index__ = 2;174 var hasInfo = false;175 while(__hasLine__() && __regexp__.info.test(__lines__[__index__]))176 {177 var stpos = __lines__[__index__].indexOf('-');178 if(__lines__[__index__].charAt(stpos-1) == '\\') // escape179 {180 __lines__[__index__] = A9Util.trimEscape(__lines__[__index__],stpos-1);181 break;182 }183 184 if(!hasInfo)185 {186 __basic__ = __super__.newChild(A9Dom.type.info);187 hasInfo = true;188 }189 __lines__[__index__] = A9Util.trimLeft(__lines__[__index__].substr(stpos+1));190 __parsePara__();191 __index__ ++;192 }193 194 __basic__ = __super__;195 }196 197 function __parseSect__() //escape198 {199 //sect : /^[  \t]*\\*([0-9]+\.)+/,200 var para = __lines__[__index__];201 var dpos = __lines__[__index__].search(/[0-9]/);202 if(__lines__[__index__].charAt(dpos-1) == '\\') // escape 203 {204 __lines__[__index__] = A9Util.trimEscape(__lines__[__index__],dpos-1);205 __parsePara__();206 return;207 }208 209 // check the sect foot token210 if(!__regexp__.sect$foot.test(__lines__[__index__+1])) // must be list(digit)211 {212 if(__meetList__()) __parseList__();213 return;214 }215 216 //217 __index__ ++;218 var title = para.replace(__regexp__.sect,'');219 var infos = para.substring(0,para.length - title.length).split('.'); //1.2. => ['1','2','']220 var flagPos = infos.length-2; // '2'221 var flagVal = infos[flagPos] * 1;222 223 __basic__ = __super__.newChild(A9Dom.type.sect);224 __basic__.setText(para);225 __basic__.putInfo(A9Dom.type.sect$title,title);226 __basic__.putInfo(A9Dom.type.sect$level,0);227 __basic__.putInfo(A9Dom.type.sect$flag,'');228 229 // set sect's no.230 if(flagVal > 0)231 {232 // init sect no.233 for(var i=0;i<flagPos;i++)// the last itme is '';234 if(__sect_flag__[i] == null)235 __sect_flag__[i] = 1;236 237 // set or increase the last no.238 if(__sect_flag__[flagPos] == null)239 __sect_flag__[flagPos] = 1;240 else241 __sect_flag__[flagPos] = __sect_flag__[flagPos] + 1;242 243 // clear dirty sect no.244 for(var i = flagPos+1; i<__sect_flag__.length;i++)245 __sect_flag__[i] = null;246 247 var flag = '';248 var level = 1;249 for(var i =0;i<__sect_flag__.length;i++)250 {251 if(__sect_flag__[i] != null)252 {253 flag +=__sect_flag__[i]+".";254 level++;255 }256 }257 258 __basic__.putInfo(A9Dom.type.sect$level,level);259 __basic__.putInfo(A9Dom.type.sect$flag,flag);260 __args_sect__[flag]=__basic__;261 }262 }263 264 function __parseList__(pTier) //escape265 {266 var para = __lines__[__index__];267 var token = RegExp.$1;268 269 var pos = para.indexOf(token);270 if(para.charAt(pos-1) == '\\') // escape list271 {272 __lines__[__index__] = A9Util.trimEscape(para,pos-1);273 __parsePara__();274 return;275 }276 277 var tier = A9Util.calTier(para); // get list tier278 279 280 var headBlank = "";281 for(var i = tier + token.length; i>=0; i--) headBlank += " ";282 283 // organise line284 var cut = pos+token.length;285 for(var i = cut; i<para.length;i++)286 if(".)  \t".indexOf(para.charAt(i)) < 0)287 {288 cut = i;289 break;290 }291 292 __lines__[__index__] = headBlank+A9Util.trimLeft(para.substr(cut));293 294 if(pTier == tier) __basic__ = __basic__.getParent(); 295 296 __basic__ = __basic__.newChild(A9Dom.type.list);297 __basic__.putInfo(A9Dom.type.list$type,token);298 __basic__.setTier(tier);299 __basic__.setText(para);300 301 __parsePara__();302 303 while(__hasLine__())304 {305 __index__ ++;306 var cTier = A9Util.calTier(__lines__[__index__]);307 308 if( cTier < tier)309 {310 __index__ --;311 break;312 }313 else // children314 {315 // child list to parse316 if (__meetList__())317 {318 var cpos = __lines__[__index__].indexOf(RegExp.$1);319 if(__lines__[__index__].charAt(cpos-1) == '\\') // escape list320 {321 if(cTier == tier)322 {323 __index__ --;324 break;325 }326 else327 {328 __lines__[__index__] = headBlank+A9Util.trimLeft(A9Util.trimEscape(__lines__[__index__],cpos-1));329 __parsePara__();330 }331 }332 else333 {334 __parseList__(tier);335 break;336 }337 }338 else // lines to merger339 {340 if(cTier == tier)341 {342 __index__ --;343 break;344 }345 else346 {347 __lines__[__index__] = headBlank+A9Util.trimLeft(__lines__[__index__]);348 __parsePara__();349 }350 }351 }352 }353 //354 if(pTier != tier) __basic__ = __basic__.getParent(); 355 }356 357 function __parseDict__() //escape358 {359 var para = __lines__[__index__];360 var token = RegExp.$2;361 var pos = para.indexOf(token);362 var key = RegExp.$1;363 if(para.charAt(pos-1) =='\\')364 {365 __lines__[__index__] = A9Util.trimEscape(__lines__[__index__],pos-1);366 __parsePara__();367 return;368 }369 370 var keyPart = para.substring(0,pos);371 var lt = keyPart.indexOf('[');372 var rt = keyPart.indexOf(']');373 if((lt>=0 && rt <0) || (lt<0 && rt >=0)) // 374 {375 __parsePara__();376 return;377 }378 379 //380 var tier = A9Util.calTier(para);381 var dom = __basic__.newChild(A9Dom.type.dict);382 dom.setTier(tier);383384 // token385 if(token.length > 2) key = key +" "+token.substr(2);386 dom.putInfo(A9Dom.type.dict$key,key);387388 // inline389 if(pos+token.length == para.length)390 {391 __index__++;392 dom.putInfo(A9Dom.type.dict$line,false); // other line393 }394 else395 {396 __lines__[__index__] = A9Util.trimLeft(para.substr(pos+token.length));397 dom.putInfo(A9Dom.type.dict$line,true);398 }399 400 // hint401 if(keyPart.indexOf(']') > 0)402 {403 dom.putInfo(A9Dom.type.dict$hint,true);404 }405 else406 {407 dom.putInfo(A9Dom.type.dict$hint,false);408 __args_dict__[key]=dom;409 }410 411 // children para412 __basic__ = dom;413 __parsePara__();414 415 while(__hasLine__())416 {417 __index__ ++;418 var cTier = A9Util.calTier(__lines__[__index__]);419 if(cTier <= tier)420 {421 __index__ --;422 break;423 }424 __parsePara__();425 }426 __basic__ = dom.getParent();427 }428429 function __parsePara__() // escape case430 {431 var dom = null;432 var para = __lines__[__index__];433 var tier = A9Util.calTier(para);434 //435 436 if(__regexp__.para$line0.test(para) ||437 __regexp__.para$line1.test(para) ||438 __regexp__.para$line2.test(para) ||439 __regexp__.para$line3.test(para))440 {441 var slash = para.lastIndexOf('\\');442 if(slash < 0)443 {444 var size = 0;445 if(para.indexOf('-')>=0) size = 1;446 else if(para.indexOf('=')>=0) size = 2;447 else if(para.indexOf('#')>=0) size = 4;448 449 dom = __basic__.newChild(A9Dom.type.para_line);450 dom.setTier(tier);451 dom.setText(para);452 dom.putInfo(A9Dom.type.para_line$size,size);453 dom.putInfo(A9Dom.type.para_line$lgth,para.length-tier);454 } 455 else456 {457 para = A9Util.trimEscape(para,slash);458 tier = A9Util.calTier(para);459 460 dom = __basic__.newChild(A9Dom.type.para_text);461 dom.setTier(tier);462 dom.setText(para);463 __parseMode__(dom,A9Util.trimBoth(para));464 }465 }466 else467 {468 // parse modes469 var spara = __softLine__();470 dom = __basic__.newChild(A9Dom.type.para_text);471 dom.setTier(tier);472 dom.setText(spara);473 __parseMode__(dom,A9Util.trimBoth(spara));474 }475 }476 477 function __parseMode__(dom,para) // escape case478 {479 if(para == "") return;480 481 var doneStr = "";482 var todoStr = para;483 var trigHeads = [];484 485 while(todoStr != null && todoStr != "")486 {487 var modeType = 1;488 var modePos1 = todoStr.search(__regexp__.mode_$htm);489 var modePos2 = todoStr.search(__regexp__.mode_link);490 var modePos3 = todoStr.search(__regexp__.mode_join);491 var modePos4 = todoStr.search(__regexp__.mode_trig);492 493 var modePos = modePos1;494 if(modePos2 >=0 && ( modePos2 < modePos || modePos < 0))495 {496 modePos = modePos2;497 modeType = 2;498 }499 if(modePos3 >=0 && ( modePos3 < modePos || modePos < 0))500 {501 modePos = modePos3;502 modeType = 3;503 }504 if(modePos4 >=0 && ( modePos4 < modePos || modePos < 0))505 {506 modePos = modePos4; 507 modeType = 4;508 }509 510 // check unclosed trig511 while(trigHeads.length > 0)512 {513 var ep = todoStr.indexOf("]]");514 //515 if(ep < 0 ||(ep > modePos && modePos >=0)) break;516 517 if(A9Util.isEscape(todoStr,ep-1))518 {519 doneStr += A9Util.trimEscape(todoStr.substring(0,ep+2),ep-1);520 todoStr = todoStr.substr(ep+2);521 modePos = modePos-ep-2;522 continue;523 }524 525 if(ep>0 || doneStr.length >0)526 {527 var modeDom = dom.newChild(A9Dom.type.mode_text);528 modeDom.setText(doneStr+todoStr.substring(0,ep));529 }530531 var modeDom = dom.newChild(A9Dom.type.mode_trig_foot);532 //document.writeln("<br><font color=red>head_length:"+trigHeads.length+"</font>");533 var trigHead = trigHeads.pop();534 //[trigHeads.length-1];535 //delete trigHeads[trigHeads.length-1];536 //document.writeln("<br><font color=red>foot_length:"+trigHeads.length+"</font>");537 538 var nInfo = trigHead.getInfo();539 for(var key in nInfo)540 modeDom.putInfo(key,nInfo[key]);541 trigHead.putInfo(A9Dom.type.mode_trig$pair,modeDom.getId());542 modeDom.putInfo(A9Dom.type.mode_trig$pair,trigHead.getId());543 544 doneStr = "";545 todoStr = todoStr.substr(ep+2);546 modePos = modePos-ep-2;547 }548 549 550 // no mode, the text mode551 if(modePos < 0)552 {553 var str = doneStr+todoStr;554 if(str.length > 0)555 {556 while(true){557 var sk = -1;558 for(var i=0;i< __simple_link__.length;i++){559 if(__simple_link__[i]['regexp'].test(str)){560 sk = i;561 break;562 }563 }564 if(sk < 0){565 var modeDom = dom.newChild(A9Dom.type.mode_text);566 modeDom.setText(str);567 break;568 }else{569 var slStr = RegExp.$1;570 var pos = str.indexOf(slStr);571 var modeDom = dom.newChild(A9Dom.type.mode_text);572 modeDom.setText(str.substr(0,pos));573 574 //575 var modeDom = dom.newChild(A9Dom.type.mode_link);576 modeDom.setText(slStr);577 modeDom.putInfo(A9Dom.type.mode_link$join,false);578 modeDom.putInfo(A9Dom.type.mode_link$name,slStr);579 modeDom.putInfo(A9Dom.type.mode_link$addr,slStr.replace(__simple_link__[sk]['regexp'],__simple_link__[sk]['addr']));580 581 str = str.substr(pos+slStr.length);582 }583 }584 }585 break;586 }587 588 // escape mode, shift it589 if(A9Util.isEscape(todoStr,modePos-1))590 {591 doneStr += A9Util.trimEscape(todoStr.substring(0,modePos),modePos-1) + todoStr.substring(modePos,modePos+2);592 todoStr = todoStr.substr(modePos+2);593 //document.writeln("<font color=red>doneStr:"+doneStr+"||todoStr:"+todoStr+"</font>");594 continue; // escape595 }596 597 // take inside mode to front;598 if(modePos >0)599 {600 var modeDom = dom.newChild(A9Dom.type.mode_text);601 modeDom.setText(doneStr + todoStr.substring(0,modePos));602 doneStr = "";603 todoStr = todoStr.substr(modePos);604 modePos = 0;605 }606 607 // mode shoot608 if(modeType == 4) // tirg609 {610 var endp = todoStr.indexOf("[",modePos+1);611 var trig = todoStr.substring(1,endp);612 todoStr = todoStr.substr(endp+1);613614 var modeDom = dom.newChild(A9Dom.type.mode_trig_head);615 616 var bToken = ["!","/","_","-",",","'"];617 var bKey = [A9Dom.type.mode_trig$flag_st, 618 A9Dom.type.mode_trig$flag_em,619 A9Dom.type.mode_trig$flag_ul,620 A9Dom.type.mode_trig$flag_de,621 A9Dom.type.mode_trig$flag_sb,622 A9Dom.type.mode_trig$flag_sp623 ];624 for(var i = 0; i < bToken.length; i++)625 {626 if(trig.indexOf(bToken[i])>=0)627 modeDom.putInfo(bKey[i],true);628 }629 630 var nToken = ["#","&","%"];631 var nKey = [A9Dom.type.mode_trig$flag_fg,632 A9Dom.type.mode_trig$flag_bg,633 A9Dom.type.mode_trig$flag_sz634 ];635 var nValid = "0123456789abcdefABCDEF";636 for(var i = 0; i < nToken.length; i++)637 {638 var s = trig.indexOf(nToken[i]);639 if(s >= 0)640 {641 var e = s+1;642 while(e<trig.length && nValid.indexOf(trig.charAt(e))>=0) e++;643 modeDom.putInfo(nKey[i],trig.substring(s+1,e));644 }645 }646 647 trigHeads[trigHeads.length] = modeDom;648 continue;649 }650 else651 {652 // search the end;653 var modeEnd = 0;654 var toescape = [];655 while(true)656 {657 modeEnd = todoStr.indexOf("]]",modeEnd+2);658 var isEscape = A9Util.isEscape(todoStr,modeEnd-1);659 660 //document.writeln("<br><font color=red>"+isEscape+":"+modePos+"-"+modeEnd+"::"+todoStr+"</font>");661 if(isEscape)662 toescape[toescape.length] = modeEnd-1;663 else664 break;665 }666 667 // make mode text and todo text;668 var modeTxt;669 if(modeEnd < 0)670 {671 modeTxt = todoStr;672 todoStr = null;673 }674 else675 {676 modeTxt = todoStr.substring(0,modeEnd);677 todoStr = modeEnd+2 < todoStr.length ?todoStr.substr(modeEnd+2):null;678 }679 680 // escape ']]'681 for(var i=toescape.length -1;i>=0;i--)682 modeTxt = A9Util.trimEscape(modeTxt,toescape[i]);683 684 var modeHead = modeTxt.substr(1,modeTxt.indexOf('[',1)-1);685 var modeBody = modeTxt.substr(modeTxt.indexOf('[',1)+1);686 687 //document.writeln("<br><font color=red>modeTxt:"+modeTxt+" || "+todoStr+"</font>");688 689 //690 if(modeType == 1) //*htm691 {692 var modeDom = dom.newChild(A9Dom.type.mode_$htm);693 modeDom.setText(modeBody);694 }695 else if(modeType == 3) //join696 {697 var jp = modeBody.indexOf("<=");698 var joName = jp<=0?"":A9Util.trimBoth(modeBody.substr(0,jp));699 var joAddr = A9Util.trimBoth(modeBody.substr(jp+2));700 701 if(A9Util.hasVariable(joAddr)) // join a variable702 {703 // no need to render path;704 }705 else // join file706 {707 joAddr = A9Util.getFile(joAddr,__super__.getInfo(A9Dom.type.root$path));708 var extnm = joAddr.substr(joAddr.lastIndexOf(".")).toLowerCase();709 710 if(__join_ext__.indexOf(extnm) >= 0) // join a9text to parse711 {712 var lt = A9Loader.syncLoadText(joAddr);713 if(lt != null && lt != "") // merge into basic a9text714 {715 var crlf = A9Util.getCRLF(lt);716 var lines = lt.split(crlf);717 if(lines.length == 1)718 {719 if(todoStr == null || todoStr == "")720 todoStr = lines[0];721 else722 todoStr = lines[0]+todoStr;723 }724 else725 {726 var nlinex = [];727 for(var i=0;i<__index__;i++) // step 1728 nlinex.push(__lines__[i]);729 730 nlinex.push(doneStr); // step 2731 732 for(var i=0;i<lines.length;i++) // step 3733 nlinex.push(lines[i]);734 735 if(todoStr != null && todoStr != "") // step 4736 nlinex.push(todoStr);737 738 for(var i=__index__+1;i<__lines__.length;i++) // step 5739 nlinex.push(__lines__[i]);740 741 __lines__ = nlinex; // step 6742 todoStr = null;743 }744 }745 continue; // merged and continue to parse746 }747 }748 //749 var modeDom = dom.newChild(A9Dom.type.mode_join);750 modeDom.setText(modeBody);751 modeDom.putInfo(A9Dom.type.mode_join$name,joName);752 modeDom.putInfo(A9Dom.type.mode_join$addr,joAddr);753 if(modeHead != null && modeHead != ''){754 var pstar = modeHead.indexOf('*');755 if(pstar >=0){756 modeDom.putInfo(A9Dom.type.mode_join$width,modeHead.substr(0,pstar));757 modeDom.putInfo(A9Dom.type.mode_join$height,modeHead.substr(pstar+1));758 }759 }760 __setJoinAlign__(dom,modeDom,todoStr);761762 if(joName != '') __args_join__[joName]=modeDom;763 }764 else // link __args_hash__765 {766 var lp = modeBody.indexOf("=>");767 var jo = (modeBody.indexOf("<=")==0);768 var lkName = A9Util.trimBoth(modeBody.substring(jo?2:0,lp));769 var lkAddr = A9Util.trimBoth(modeBody.substr(lp+2));770 771 var modeDom = dom.newChild(A9Dom.type.mode_link);772 modeDom.setText(modeBody);773 modeDom.putInfo(A9Dom.type.mode_link$join,jo);774 modeDom.putInfo(A9Dom.type.mode_link$name,lkName);775 modeDom.putInfo(A9Dom.type.mode_link$addr,A9Util.getFile(lkAddr,__super__.getInfo(A9Dom.type.root$path)));776 777 if(jo)__setJoinAlign__(dom,modeDom,todoStr);778 779 if(lkAddr == '')__args_hash__[lkName]=modeDom;780 }781 }782 }783 }784 785 function __parseArea__() //escape case786 {787 var eqpos = __lines__[__index__].indexOf('=');788 if(__lines__[__index__].charAt(eqpos-1) =='\\') // escape789 {790 __lines__[__index__] = A9Util.trimEscape(__lines__[__index__],eqpos-1);791 __parsePara__();792 return;793 }794 795 //796 var tier = A9Util.calTier(__lines__[__index__]);797 var type = RegExp.$1;798 if(type != null) type = type.toLowerCase();799 800 var info = A9Util.trimBoth(RegExp.$2);801 var name = '';802 if(info != null)803 {804 var ni = info.indexOf(':');805 if(ni>=0){806 name = A9Util.trimRight(info.substr(0,ni));807 info = A9Util.trimLeft(info.substr(ni+1));808 }809 }810 811 // args812 var args = {};813 __index__ ++;814 if(__regexp__.area$args.test(__lines__[__index__])) 815 {816 var pos = __lines__[__index__].indexOf('args:');817 if(__lines__[__index__].charAt(pos-1) == '\\') //escape818 {819 __lines__[__index__] = A9Util.trimEscape(__lines__[__index__],pos -1);820 }821 else822 {823 // soft lines824 var para = RegExp.$1;825 while(__hasLine__() && A9Util.isEscapeLine(para))826 {827 // pure soft line828 __index__ ++;829 if(para.charAt(para.length -1)== '\\') // escape830 para = A9Util.trimEscape(para,para.length -1) + A9Util.trimLeft(__lines__[__index__]);831 else // space832 para = para.substring(0,para.length -1) + A9Util.trimLeft(__lines__[__index__]);833 }834 835 var keyvals = para.split(/[  \t]*;[  \t]*/);836 for(var i = 0; i< keyvals.length; i++)837 {838 if(keyvals[i] == "")continue;839 840 var kv = keyvals[i].split(/[  \t]*=[  \t]*/);841 842 if(kv.length ==2) args[kv[0]] = kv[1];843 else args[kv[0]] = true;844 }845 __index__ ++;846 }847 }848 849 // text850 var dom = __basic__.newChild(A9Dom.type.area);851 dom.setTier(tier);852 dom.putInfo(A9Dom.type.area$type,type);853 dom.putInfo(A9Dom.type.area$name,name);854 dom.putInfo(A9Dom.type.area$info,info);855 dom.putInfo(A9Dom.type.area$args,args);856 dom.putInfo(A9Dom.type.area$crlf,__crlf__);857 858 if(name != '') __args_area__[name] = dom;859 //860 var buffer = [];861 for(;__hasLine__(); __index__ ++)862 {863 if(__regexp__.area$foot.test(__lines__[__index__]))864 {865 var slpos = __lines__[__index__].indexOf('\\');866 if(slpos< 0)867 {868 dom.setText(buffer.join(__crlf__));869 break;870 }871 else // escape872 {873 buffer[buffer.length] = A9Util.shiftBlank(A9Util.trimEscape(__lines__[__index__],slpos),tier);874 }875 }876 else877 {878 buffer[buffer.length] = A9Util.shiftBlank(__lines__[__index__],tier);879 }880 }881 882 // ext parser883 var extBall = A9Conf.getConf("parser.area."+type+".ball");884 if(extBall != null && extBall != "")885 {886 try887 {888 var extClzz = extBall+"."+A9Conf.getConf("parser.area."+type+".clzz");889 var ferLen = Math.ceil(40*(buffer.length)/__total_lines__);890 try{891 __progress_bar__.work(-ferLen);892 }catch(e){};893 894 A9Loader.asyncLoadClass(extBall);895 A9Loader.runAfterClassLoaded(function(){896 try{897 __progress_bar__.work(ferLen);898 }catch(e){};899 try{900 eval("var extParser = new "+extClzz+"();");901 extParser.parse(dom)902 }catch(e){903 dom.putInfo(A9Dom.type.area$type,'text');904 }905 });906 }907 catch(e)908 {909 //alert(e);910 }911 }912 }913 914 function __parseArea$etxt__() //escape case915 {916 var eqpos = __lines__[__index__].indexOf('.');917 if(__lines__[__index__].charAt(eqpos-1) =='\\') // escape918 {919 __lines__[__index__] = A9Util.trimEscape(__lines__[__index__],eqpos-1);920 __parsePara__();921 return;922 }923 924 var dom = __basic__.newChild(A9Dom.type.area);925 dom.putInfo(A9Dom.type.area$type,'text');926 927 var buffer = [];928 __index__ ++;929 for(;__hasLine__(); __index__ ++)930 {931 932 if(__regexp__.area$etxt.test(__lines__[__index__]))933 {934 var slpos = __lines__[__index__].indexOf('\\');935 if(slpos< 0)936 {937 dom.setText(buffer.join(__crlf__));938 break;939 }940 else // escape941 {942 buffer[buffer.length] = A9Util.trimEscape(__lines__[__index__],slpos);943 }944 }945 else946 {947 buffer[buffer.length] = __lines__[__index__];948 }949 }950 }951 952 /* helper */953 954 function __hasLine__()955 {956 return __index__ < __lines__.length;957 }958 959 function __softLine__()960 {961 var todoStr = __lines__[__index__];962 var doneStr = "";963 var modecnt = 0;964 965 // merge soft lines966 while(__hasLine__())967 {968 // pure soft line969 if (A9Util.isEscapeLine(todoStr))970 {971 __index__ ++;972 if(todoStr.charAt(todoStr.length -1)== '\\') // escape973 todoStr = A9Util.trimEscape(todoStr,todoStr.length -1) + A9Util.trimLeft(__lines__[__index__]);974 else // space975 todoStr = todoStr.substring(0,todoStr.length -1) + A9Util.trimLeft(__lines__[__index__]);976 977 continue;978 }979 980 // count mode head981 var modePos = 0;982 var modeDone = "";983 var modeTodo = todoStr;984 var firstPos = -1;985 while( modePos >= 0 )986 {987 modePos = modeTodo.search(__regexp__.mode_trig);988 if( modePos < 0 ) modePos = modeTodo.search(__regexp__.mode_join);989 if( modePos < 0 ) modePos = modeTodo.search(__regexp__.mode_link);990 if( modePos < 0 ) modePos = modeTodo.search(__regexp__.mode_$htm);991 992 if( modePos < 0 ) break;993 994 if(! A9Util.isEscape(modeTodo,modePos-1)) // escape995 {996 if(firstPos <0 && modecnt ==0) firstPos = modeDone.length+modePos;997 modecnt ++;998 }999 //1000 var lastHead = modeTodo.indexOf('[',modePos+1);1001 modeDone += modeTodo.substring(0,lastHead+1);1002 modeTodo = modeTodo.substr(lastHead+1);1003 }1004 1005 if(modecnt <= 0) break; // no mode1006 1007 //1008 modePos = 0;1009 doneStr += modeDone;1010 todoStr = modeTodo;1011 1012 modeTodo = modeDone+modeTodo;1013 if(firstPos>=0) modeTodo = modeTodo.substr(firstPos);1014 1015 while( modePos >= 0 )1016 {1017 modePos = modeTodo.indexOf("]]",modePos);1018 if(modePos <0) break;1019 1020 if(!A9Util.isEscape(modeTodo,modePos-1)) // escape1021 modecnt --;1022 //1023 modePos += 2;1024 }1025 1026 if(modecnt <= 0) break; // matches all1027 1028 __index__++;1029 todoStr = todoStr+ A9Util.trimLeft(__lines__[__index__]);1030 }1031 1032 return doneStr + todoStr;1033 }1034 1035 function __setJoinAlign__(dom,modeDom,todoStr)1036 {1037 var pb = modeDom.getPrevBrother();1038 1039 if( pb != null) // inline1040 {1041 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_ilinside);1042 }1043 else if (pb == null && (todoStr != null && todoStr != '')) // inline1044 {1045 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_illeft);1046 }1047 else // new line1048 {1049 var pt = dom.getTier();1050 var ppb = dom.getPrevBrother();1051 if(ppb == null) // first child of para1052 {1053 if( pt== 0)1054 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_nlleft);1055 else if(pt>10)1056 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_nlright);1057 else1058 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_nlcenter);1059 }1060 else1061 {1062 var ppt = ppb.getTier();1063 if(pt<=ppt)1064 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_nlleft);1065 else if((pt-ppt)>10)1066 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_nlright);1067 else1068 modeDom.putInfo(A9Dom.type.mode_join$algn,A9Dom.type.mode_join$algn_nlcenter);1069 }1070 }1071 } ...

Full Screen

Full Screen

qunit.state-dashboard-unit-tests.js

Source:qunit.state-dashboard-unit-tests.js Github

copy

Full Screen

1// Constants.Require2test( "unit.mui.constants.require", function() {3 ok( typeof require('constants') !== 'undefined' , "Submodule found correctly." );4});5test( "unit.mui.constants.require", function() {6 throws(function(){7 require('')8 }, RangeError, "Submodule threw RangeError." );9});10// Debug.Out11test( "unit.mui.debug.out", function() {12 ok( typeof require('debug').info !== 'undefined' , "Pipe found correctly." );13});14test( "unit.mui.debug.out", function() {15 ok( typeof require('debug').warning === 'undefined' , "Pipe not found." );16});17// Toolkit.LocalStorage.Exists18test( "unit.mui.toolkit.localStorage.exists", function() {19 ok( require('toolkit').localStorage.exists() === true , "Browser has localStorage." );20});21test( "unit.mui.toolkit.localStorage.exists", function() {22 ok( require('toolkit').localStorage.exists() !== false , "Browser has localStorage." );23});24// Toolkit.LocalStorage.Set25test( "unit.mui.toolkit.localStorage.set", function() {26 ok( typeof require('toolkit').localStorage.set("cat", 10) === 'undefined', "Added content" );27});28test( "unit.mui.toolkit.localStorage.set", function() {29 ok( typeof require('toolkit').localStorage.set("cata", 0) === 'undefined', "Added content" );30});31// Toolkit.LocalStorage.Get32test( "unit.mui.toolkit.localStorage.get", function() {33 ok( require('toolkit').localStorage.get("cat") == 10, "LocalStorage gets data.");34});35test( "unit.mui.toolkit.localStorage.get", function() {36 ok( require('toolkit').localStorage.get("cata") == 0, "LocalStorage gets data.");37});38// Toolkit.LocalStorage.Has39test( "unit.mui.toolkit.localStorage.has", function() {40 ok( require('toolkit').localStorage.has("cata") === true, "LocalStorage contains data.");41});42test( "unit.mui.toolkit.localStorage.has", function() {43 ok( require('toolkit').localStorage.has("catas") === false, "LocalStorage does not contain data.");44});45// Toolkit.Safely46test( "unit.mui.toolkit.safely", function() {47 48 var x = 0;49 require('toolkit').safely(x)50 .exists(function(){51 ok( true, "Variable exists.");52 }).noexists(function(){53 ok( false, "Variable exists; however it does not exit.");54 });55});56test( "unit.mui.toolkit.safely", function() {57 58 var x = undefined;59 require('toolkit').safely(x)60 .exists(function(){61 ok( false, "Variable does not exist; however it does exit.");62 }).noexists(function(){63 ok( true, "Variable exists.");64 });65});66// Toolkit.Extend67test( "unit.mui.toolkit.safely", function() {68 69 var x = undefined;70 require('toolkit').safely(x)71 .exists(function(){72 ok( false, "Variable does not exist; however it does exit.");73 }).noexists(function(){74 ok( true, "Variable exists.");75 });76});77// Toolkit.Validate78test("unit.mui.toolkit.validate", function(){79 ok( require('toolkit').validate.email('breant@gmail.com') === true, "Valid email detected.")80});81test("unit.mui.toolkit.validate", function(){82 ok( require('toolkit').validate.email() === false, "Invalid email detected.")83});84// Toolkit.Fire85var __test__ = function(){}86test("unit.mui.toolkit.fire", function(){87 require('toolkit', __test__);88 ok( true, "Fired callback!");89});90test("unit.mui.toolkit.fire", function(){91 require('toolkit', undefined);92 ok( true, "Null callback");93});94// Toolkit.URI95var __hash__ = "#state[music]:test[qunit]:criteria[unit]";96var __basic__ = "?state=music&test=qunit&criteria=unit";97var __obj__ = {98 state : "music",99 test : "qunit",100 criteria : "unit"101};102var __equalsObj__ = function(obj){103 for(var k in obj)104 if(__obj__[k] !== obj[k])105 return false;106 return true;107};108test("unit.mui.toolkit.uri.decodeFromBasic", function(){109 ok(__equalsObj__(require('toolkit').uri.decodeFromBasic(__basic__)), "Decoded correctly.");110});111test("unit.mui.toolkit.uri.decodeFromBasic", function(){112 ok(typeof require('toolkit').uri.decodeFromBasic("") === 'object' , "Decoded correctly."); 113});114test("unit.mui.toolkit.uri.decodeFromHash", function(){115 ok(__equalsObj__(require('toolkit').uri.decodeFromHash(__hash__)), "Decoded correctly."); 116});117test("unit.mui.toolkit.uri.decodeFromHash", function(){118 ok(typeof require('toolkit').uri.decodeFromHash("") === 'object' , "Decoded correctly."); 119});120test("unit.mui.toolkit.uri.encodeToBasic", function(){121 ok(require('toolkit').uri.encodeToBasic(__obj__) === __basic__, "Encoded correctly.");122});123test("unit.mui.toolkit.uri.encodeToBasic", function(){124 ok(require('toolkit').uri.encodeToBasic({}) === "" , "Encoded correctly."); 125});126test("unit.mui.toolkit.uri.encodeToHash", function(){127 ok(require('toolkit').uri.encodeToHash(__obj__) === __hash__, "Encoded correctly.");128});129test("unit.mui.toolkit.uri.encodeToHash", function(){130 ok(require('toolkit').uri.encodeToHash({}) === "" , "Encoded correctly."); ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2};3const path = require('path');4module.exports = async ({ config, mode }) => {5 config.module.rules.push({6 test: /\.(ts|tsx)$/,7 include: path.resolve(__dirname, '../packages'),8 {9 loader: require.resolve('awesome-typescript-loader'),10 options: {11 },12 },13 {14 loader: require.resolve('react-docgen-typescript-loader'),15 },16 });17 config.resolve.extensions.push('.ts', '.tsx');18 return config;19};20{21 "compilerOptions": {22 "paths": {23 },24 },25}

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withKnobs, text } from '@storybook/addon-knobs/react';4import { action } from '@storybook/addon-actions';5import { linkTo } from '@storybook/addon-links';6import { Button, Welcome } from '@storybook/react/demo';7storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);8storiesOf('Button', module)9 .addDecorator(withKnobs)10 .add('with text', () => (11 <Button onClick={action('clicked')}>{text('Label', 'Hello Button')}</Button>12 .add('with some emoji', () => (13 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>14 ));

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful