Best JavaScript code snippet using stryker-parent
rfc1738.ts
Source:rfc1738.ts
...8 ch,9 opt,10 end11} from "../src/parser";12const genericurl = createParser();13const url = createParser();14const _scheme = createParser();15const scheme = createParser();16const schemepart = createParser();17const ipSchemepart = createParser();18const login = createParser();19const hostport = createParser();20const host = createParser();21const hostname = createParser();22const domainlabel = createParser();23const toplabel = createParser();24const alphadigit = createParser();25const hostnumber = createParser();26const port = createParser();27const otherurl = createParser();28const user = createParser();29const password = createParser();30const urlpath = createParser();31const ftpurl = createParser();32const newsurl = createParser();33const nntpurl = createParser();34const telneturl = createParser();35const gopherurl = createParser();36const waisurl = createParser();37const mailtourl = createParser();38const prosperourl = createParser();39const fpath = createParser();40const fsegment = createParser();41const ftptype = createParser();42const fileurl = createParser();43const httpurl = createParser();44const hpath = createParser();45const hsegment = createParser();46const search = createParser();47const lowalpha = createParser();48const hialpha = createParser();49const alpha = createParser();50const digit = createParser();51const safe = createParser();52const extra = createParser();53const national = createParser();54const punctuation = createParser();55const reserved = createParser();56const hex = createParser();57const escape = createParser();58const unreserved = createParser();59const uchar = createParser();60const xchar = createParser();61const digits = createParser();62const gtype = createParser();63const selector = createParser();64const gopher_string = createParser();65const encoded822addr = createParser();66const grouppart = createParser();67const group = createParser();68const _articlePart = createParser();69const article = createParser();70const waisdatabase = createParser();71const waisindex = createParser();72const waisdoc = createParser();73const database = createParser();74const wpath = createParser();75const wtype = createParser();76const ppath = createParser();77const fieldspec = createParser();78const psegment = createParser();79const fieldname = createParser();80const fieldvalue = createParser();81// const fieldspec = createParser();82// ; The generic form of a URL is:83// genericurl = scheme ":" schemepart84setParser(genericurl, seq(scheme, ch(":"), schemepart));85// ; Specific predefined schemes are defined here; new schemes86// ; may be registered with IANA87// url = httpurl | ftpurl | newsurl |88// nntpurl | telneturl | gopherurl |89// waisurl | mailtourl | fileurl |90// prosperourl | otherurl91setParser(92 url,93 alt(94 httpurl,95 ftpurl,96 newsurl,97 nntpurl,98 telneturl,99 gopherurl,100 waisurl,101 mailtourl,102 fileurl,103 prosperourl,104 otherurl,105 )106);107// ; new schemes follow the general syntax108// otherurl = genericurl109setParser(otherurl, genericurl);110// ; the scheme is in lower case; interpreters should use case-ignore111// scheme = 1*[ lowalpha | digit | "+" | "-" | "." ]112setParser(_scheme, alt(lowalpha, digit, ch("+"), ch("-"), ch(".")));113setParser(scheme, seq(_scheme, rep(_scheme)));114// schemepart = *xchar | ip-schemepart115setParser(schemepart, alt(rep(xchar), ipSchemepart));116// ; URL schemeparts for ip based protocols:117// ip-schemepart = "//" login [ "/" urlpath ]118setParser(ipSchemepart, seq(ch("//"), login, opt(seq(ch("/"), urlpath))));119// login = [ user [ ":" password ] "@" ] hostport120setParser(121 login,122 seq(opt(seq(user, opt(seq(ch(":"), password)), ch("@"))), hostport)123);124// hostport = host [ ":" port ]125setParser(hostport, seq(host, opt(seq(ch(":"), port))));126// host = hostname | hostnumber127setParser(host, alt(hostname, hostnumber));128// hostname = *[ domainlabel "." ] toplabel129setParser(130 hostname,131 seq(132 rep(133 seq(134 domainlabel,135 ch(".")136 )137 ),138 toplabel139 )140);141// domainlabel = alphadigit | alphadigit *[ alphadigit | "-" ] alphadigit142setParser(143 domainlabel,144 alt(alphadigit, seq(alphadigit, rep(alt(alphadigit, ch("-"))), alphadigit))145);146// toplabel = alpha | alpha *[ alphadigit | "-" ] alphadigit147setParser(148 toplabel,149 alt(alpha, seq(alpha, rep(alt(alphadigit, ch("-"))), alphadigit))150);151// alphadigit = alpha | digit152setParser(alphadigit, alt(alpha, digit));153// hostnumber = digits "." digits "." digits "." digits154setParser(155 hostnumber,156 seq(digits, ch("."), digits, ch("."), digits, ch("."), digits)157);158// port = digits159// If set directly, it will be [[ undefined ]]160setParser(port, seq(digit, rep(digit)));161// user = *[ uchar | ";" | "?" | "&" | "=" ]162setParser(user, rep(alt(uchar, ch(";"), ch("?"), ch("&"), ch("="))));163// password = *[ uchar | ";" | "?" | "&" | "=" ]164setParser(password, rep(alt(uchar, ch(";"), ch("?"), ch("&"), ch("="))));165// urlpath = *xchar ; depends on protocol see section 3.1166setParser(urlpath, rep(xchar));167// ; The predefined schemes:168// ; FTP (see also RFC959)169// ftpurl = "ftp://" login [ "/" fpath [ ";type=" ftptype ]]170setParser(171 ftpurl,172 seq(173 ch("ftp://"),174 login,175 opt(176 seq(177 ch("/"),178 fpath,179 opt(180 seq(181 ch(";type="),182 ftptype183 )184 )185 )186 )187 )188);189// fpath = fsegment *[ "/" fsegment ]190setParser(fpath, seq(fsegment, rep(seq(ch("/"), fsegment))));191// fsegment = *[ uchar | "?" | ":" | "@" | "&" | "=" ]192setParser(193 fsegment,194 rep(alt(uchar, ch("?"), ch(":"), ch("@"), ch("&"), ch("=")))195);196// ftptype = "A" | "I" | "D" | "a" | "i" | "d"197setParser(ftptype, alt(ch("A"), ch("I"), ch("D"), ch("a"), ch("i"), ch("d")));198// ; FILE199// fileurl = "file://" [ host | "localhost" ] "/" fpath200setParser(201 ftpurl,202 seq(ch("file://"), opt(alt(host, ch("localhost"))), ch("/"), fpath)203);204// ; HTTP205// httpurl = "http://" hostport [ "/" hpath [ "?" search ]]206setParser(207 httpurl,208 seq(209 ch("http://"),210 hostport,211 opt(seq(ch("/"), hpath, opt(seq(ch("?"), search))))212 )213);214// hpath = hsegment *[ "/" hsegment ]215setParser(hpath, seq(hsegment, rep(seq(ch("/"), hsegment))));216// hsegment = *[ uchar | ";" | ":" | "@" | "&" | "=" ]217setParser(218 hsegment,219 rep(alt(uchar, ch(";"), ch(":"), ch("@"), ch("&"), ch("=")))220);221// search = *[ uchar | ";" | ":" | "@" | "&" | "=" ]222setParser(search, rep(alt(uchar, ch(";"), ch(":"), ch("@"), ch("&"), ch("="))));223// ; GOPHER (see also RFC1436)224// gopherurl = "gopher://" hostport [ / [ gtype [ selector225// [ "%09" search [ "%09" gopher+_string ] ] ] ] ]226// "gopher://" hostport [ / [ gtype [ selector [ "%09" search [ "%09" gopher+_string ] ] ] ] ]227setParser(228 gopherurl,229 seq(230 ch("gopher://"),231 hostport,232 opt(233 seq(234 ch("/"),235 opt(236 seq(237 gtype,238 opt(239 seq(240 selector,241 opt(242 seq(243 ch("%09"),244 search,245 opt(246 seq(247 ch("%09"),248 gopher_string249 )250 )251 )252 )253 )254 )255 )256 )257 )258 )259 )260);261// gtype = xchar262setParser(gtype, alt(unreserved, reserved, escape));263// selector = *xchar264setParser(selector, rep(xchar));265// gopher+_string = *xchar266setParser(gopher_string, rep(xchar));267// ; MAILTO (see also RFC822)268// mailtourl = "mailto:" encoded822addr269setParser(mailtourl, seq(ch("mailto:"), encoded822addr));270// encoded822addr = 1*xchar ; further defined in RFC822271setParser(encoded822addr, seq(xchar, rep(xchar)));272// ; NEWS (see also RFC1036)273// newsurl = "news:" grouppart274setParser(newsurl, seq(ch("news:"), grouppart));275// grouppart = "*" | group | article276setParser(grouppart, alt(ch("*"), group, article));277// group = alpha *[ alpha | digit | "-" | "." | "+" | "_" ]278setParser(group, seq(alpha, rep(alt(279 alpha,280 digit,281 ch("-"),282 ch("."),283 ch("+"),284 ch("_"),285))));286// article = 1*[ uchar | ";" | "/" | "?" | ":" | "&" | "=" ] "@" host287setParser(288 _articlePart,289 alt(290 uchar,291 ch(";"),292 ch("/"),293 ch("?"),294 ch(":"),295 ch("&"),296 ch("="),297 )298);299setParser(300 article,301 seq(302 _articlePart,303 rep(_articlePart),304 ch("@"),305 host306 )307);308// ; NNTP (see also RFC977)309// nntpurl = "nntp://" hostport "/" group [ "/" digits ]310setParser(nntpurl, seq(ch("nntp:"), hostport, ch("/"), group, opt(seq(ch("/"), digits))));311// ; TELNET312// telneturl = "telnet://" login [ "/" ]313setParser(telneturl, seq(ch("telnet:"), login, opt(ch("/"))));314// ; WAIS (see also RFC1625)315// waisurl = waisdatabase | waisindex | waisdoc316setParser(317 waisurl,318 alt(319 waisdatabase,320 waisindex,321 waisdoc322 )323);324// waisdatabase = "wais://" hostport "/" database325setParser(waisdatabase, seq(ch("wais://"), hostport, ch("/"), database));326// waisindex = "wais://" hostport "/" database "?" search327setParser(waisindex, seq(ch("wais://"), hostport, ch("/"), database, ch("?"), search));328// waisdoc = "wais://" hostport "/" database "/" wtype "/" wpath329setParser(waisindex, seq(ch("wais://"), hostport, ch("/"), database, ch("?"), search));330// database = *uchar331setParser(database, rep(uchar));332// wtype = *uchar333setParser(wtype, rep(uchar));334// wpath = *uchar335setParser(wpath, rep(uchar));336// ; PROSPERO337// prosperourl = "prospero://" hostport "/" ppath *[ fieldspec ]338setParser(prosperourl, seq(ch("prospero://"), hostport, ch("/"), ppath, rep(fieldspec)));339// ppath = psegment *[ "/" psegment ]340setParser(ppath, seq(psegment, rep(seq(ch("/"), psegment))));341// psegment = *[ uchar | "?" | ":" | "@" | "&" | "=" ]342setParser(psegment, rep(343 alt(344 uchar,345 ch("?"),346 ch(":"),347 ch("@"),348 ch("&"),349 ch("="),350 )351));352// fieldspec = ";" fieldname "=" fieldvalue353setParser(fieldspec, seq(ch(";"), fieldname, ch("="), fieldvalue));354// fieldname = *[ uchar | "?" | ":" | "@" | "&" ]355setParser(fieldname, rep(356 alt(357 uchar,358 ch("?"),359 ch(":"),360 ch("@"),361 ch("&")362 )363));364// fieldvalue = *[ uchar | "?" | ":" | "@" | "&" ]365setParser(fieldvalue, rep(366 alt(367 uchar,368 ch("?"),369 ch(":"),370 ch("@"),371 ch("&")372 )373));374// ; Miscellaneous definitions375// lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |376// "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |377// "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |378// "y" | "z"379setParser(lowalpha, regex("[a-z]"));380// hialpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |381// "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |382// "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"383setParser(hialpha, regex("[A-Z]"));384// alpha = lowalpha | hialpha385setParser(alpha, alt(lowalpha, hialpha));386// digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |387// "8" | "9"388setParser(digit, regex("[0-9]"));389// safe = "$" | "-" | "_" | "." | "+"390setParser(safe, alt(ch("$"), ch("-"), ch("_"), ch("."), ch("+")));391// extra = "!" | "*" | "'" | "(" | ")" | ","392setParser(extra, alt(ch("!"), ch("*"), ch("'"), ch("("), ch(")"), ch(",")));393// national = "{" | "}" | "|" | "\" | "^" | "~" | "[" | "]" | "`"394setParser(395 national,396 alt(397 ch("{"),398 ch("}"),399 ch("|"),400 ch("\\"),401 ch("^"),402 ch("~"),403 ch("["),404 ch("]"),405 ch("`")406 )407);408// punctuation = "<" | ">" | "#" | "%" | <">409setParser(punctuation, alt(ch("<"), ch(">"), ch("#"), ch("%"), ch('"')));410// reserved = ";" | "/" | "?" | ":" | "@" | "&" | "="411setParser(412 reserved,413 alt(ch(";"), ch("/"), ch("?"), ch(":"), ch("@"), ch("&"), ch("="))414);415// hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |416// "a" | "b" | "c" | "d" | "e" | "f"417setParser(hex, alt(digit, regex("[A-F]"), regex("[a-f]")));418// escape = "%" hex hex419setParser(escape, seq(ch("%"), hex, hex));420// unreserved = alpha | digit | safe | extra421setParser(unreserved, alt(alpha, digit, safe, extra));422// uchar = unreserved | escape423setParser(uchar, alt(unreserved, escape));424// xchar = unreserved | reserved | escape425setParser(xchar, alt(unreserved, reserved, escape));426// digits = 1*digit427setParser(digits, seq(digit, rep(digit)));428const genericurlParser = createParser();429setParser(genericurlParser, seq(genericurl, end()));430function isGenericurl(input: string) {431 const result = genericurlParser[0](input);432 if (result.length) {433 return true;434 }435 return false;436}437const urlParser = createParser();438setParser(urlParser, seq(url, end()));439function isUrl(input: string) {440 const result = urlParser[0](input);441 if (result.length) {442 return true;443 }444 return false;445}446const httpurlParser = createParser();447setParser(httpurlParser, seq(httpurl, end()));448function isHttpurl(input: string) {449 const result = httpurlParser[0](input);450 if (result.length) {451 return true;452 }453 return false;454}455const ftpurlParser = createParser();456setParser(ftpurlParser, seq(ftpurl, end()));457function isFtpurl(input: string) {458 const result = ftpurlParser[0](input);459 if (result.length) {460 return true;461 }462 return false;463}464const newsurlParser = createParser();465setParser(newsurlParser, seq(newsurl, end()));466function isNewsurl(input: string) {467 const result = newsurlParser[0](input);468 if (result.length) {469 return true;470 }471 return false;472}473const nntpurlParser = createParser();474setParser(nntpurlParser, seq(nntpurl, end()));475function isNntpurl(input: string) {476 const result = nntpurlParser[0](input);477 if (result.length) {478 return true;479 }480 return false;481}482const telneturlParser = createParser();483setParser(telneturlParser, seq(telneturl, end()));484function isTelneturl(input: string) {485 const result = telneturlParser[0](input);486 if (result.length) {487 return true;488 }489 return false;490}491const gopherurlParser = createParser();492setParser(gopherurlParser, seq(gopherurl, end()));493function isGopherurl(input: string) {494 const result = gopherurlParser[0](input);495 if (result.length) {496 return true;497 }498 return false;499}500const waisurlParser = createParser();501setParser(waisurlParser, seq(waisurl, end()));502function isWaisurl(input: string) {503 const result = waisurlParser[0](input);504 if (result.length) {505 return true;506 }507 return false;508}509const mailtourlParser = createParser();510setParser(mailtourlParser, seq(mailtourl, end()));511function isMailtourl(input: string) {512 const result = mailtourlParser[0](input);513 if (result.length) {514 return true;515 }516 return false;517}518const fileurlParser = createParser();519setParser(fileurlParser, seq(fileurl, end()));520function isFileurl(input: string) {521 const result = fileurlParser[0](input);522 if (result.length) {523 return true;524 }525 return false;526}527const prosperourlParser = createParser();528setParser(prosperourlParser, seq(prosperourl, end()));529function isProsperourl(input: string) {530 const result = prosperourlParser[0](input);531 if (result.length) {532 return true;533 }534 return false;535}536const otherurlParser = createParser();537setParser(otherurlParser, seq(otherurl, end()));538function isOtherurl(input: string) {539 const result = otherurlParser[0](input);540 if (result.length) {541 return true;542 }543 return false;544}545export {546 isGenericurl,547 isUrl,548 isHttpurl,549 isFtpurl,550 isNewsurl,...
parser.js
Source:parser.js
12var parsers = require('../lib/parsers.js');34exports['Get integer'] = function (test) {5 var parser = parsers.createParser("123");6 7 var result = parser.parse("Integer");8 9 test.ok(result);10 test.equal(result.value.evaluate(null), 123);11 test.equal(result.type, "Integer");12 13 test.equal(parser.parse("Integer"), null);14}1516exports['Get negative integer'] = function (test) {17 var parser = parsers.createParser("-123");18 19 var result = parser.parse("Integer");20 21 test.ok(result);22 test.equal(result.value.evaluate(null), -123);23 test.equal(result.type, "Integer");24 25 test.equal(parser.parse("Integer"), null);26}2728exports['Get real'] = function (test) {29 var parser = parsers.createParser("123.45");30 31 var result = parser.parse("Real");32 33 test.ok(result);34 test.equal(result.value.evaluate(null), 123.45);35 test.equal(result.type, "Real");36 37 test.equal(parser.parse("Real"), null);38}3940exports['Get negative real'] = function (test) {41 var parser = parsers.createParser("-123.45");42 43 var result = parser.parse("Real");44 45 test.ok(result);46 test.equal(result.value.evaluate(null), -123.45);47 test.equal(result.type, "Real");48 49 test.equal(parser.parse("Real"), null);50}5152exports['Get integer with spaces'] = function (test) {53 var parser = parsers.createParser(" 123 s");54 55 var result = parser.parse("Integer");56 57 test.ok(result);58 test.equal(result.value.evaluate(null), 123);59 test.equal(result.type, "Integer");60 61 test.equal(parser.parse("Integer"), null);62}6364exports['Get string'] = function (test) {65 var parser = parsers.createParser('"foo"');66 67 var result = parser.parse("String");68 69 test.ok(result);70 test.equal(result.value.evaluate(null), 'foo');71 test.equal(result.type, "String");72 73 test.equal(parser.parse("String"), null);74}7576exports['Get string with escaped characters'] = function (test) {77 var parser = parsers.createParser('"foo\\n\\t\\r\\\\"');78 79 var result = parser.parse("String");80 81 test.ok(result);82 test.equal(result.value.evaluate(null), 'foo\n\t\r\\');83 test.equal(result.type, "String");84 85 test.equal(parser.parse("String"), null);86}8788exports['Get array'] = function (test) {89 var parser = parsers.createParser("[1,2,3]");90 91 var result = parser.parse("Array");92 93 test.ok(result);94 test.ok(result.value);95 test.ok(result.value.evaluate);96}9798exports['Get empty array'] = function (test) {99 var parser = parsers.createParser("[]");100 101 var result = parser.parse("Array");102 103 test.ok(result);104 test.ok(result.value);105 test.ok(result.value.evaluate);106}107108exports['Get dot'] = function (test) {109 var parser = parsers.createParser(".");110 111 var result = parser.parse("Dot");112 113 test.ok(result);114 test.ok(result.value);115}116117exports['Get logical or'] = function (test) {118 var parser = parsers.createParser("||");119 120 var result = parser.parse("LogicalOr");121 122 test.ok(result);123 test.ok(result.value);124}125126exports['Get logical and'] = function (test) {127 var parser = parsers.createParser("&&");128 129 var result = parser.parse("LogicalAnd");130 131 test.ok(result);132 test.ok(result.value);133}134135exports['Get array expression'] = function (test) {136 var parser = parsers.createParser("a[0]");137 138 var result = parser.parse("Term");139 140 test.ok(result);141 test.ok(result.value);142 test.ok(result.value.evaluate);143 test.equal(result.value.getName, null);144 145 test.equal(parser.next(), null);146}147148exports['Get name'] = function (test) {149 var parser = parsers.createParser("name");150 151 var result = parser.parse("Name");152 153 test.ok(result);154 test.equal(result.value.getName(), "name");155 test.equal(result.type, "Name");156 157 test.equal(parser.parse("Name"), null);158}159160exports['Get keyword'] = function (test) {161 var parser = parsers.createParser(":foo");162 163 var result = parser.parse("Keyword");164 165 test.ok(result);166 test.equal(result.type, "Keyword");167 168 test.equal(parser.parse("Keyword"), null);169}170171exports['Get keyword as Term'] = function (test) {172 var parser = parsers.createParser(":foo");173 174 var result = parser.parse("Term");175 176 test.ok(result);177 test.equal(result.type, "Term");178 179 test.equal(parser.parse("Term"), null);180}181182exports['Get name and integer'] = function (test) {183 var parser = parsers.createParser("name 1");184 185 var result = parser.parse("Name");186 187 test.ok(result);188 test.equal(result.value.getName(), "name");189 test.equal(result.type, "Name");190 191 test.ok(parser.parse("Integer"));192 193 test.equal(parser.parse("Name"), null);194}195196exports['Get name with underscore'] = function (test) {197 var parser = parsers.createParser("get_name");198 199 var result = parser.parse("Name");200 201 test.ok(result);202 test.equal(result.value.getName(), "get_name");203 test.equal(result.type, "Name");204 205 test.equal(parser.parse("Name"), null);206}207208exports['Get name with digits'] = function (test) {209 var parser = parsers.createParser("answer42");210 211 var result = parser.parse("Name");212 213 test.ok(result);214 test.equal(result.value.getName(), "answer42");215 test.equal(result.type, "Name");216 217 test.equal(parser.parse("Name"), null);218}219220exports['Get name with spaces'] = function (test) {221 var parser = parsers.createParser(" name ");222 223 var result = parser.parse("Name");224 225 test.ok(result);226 test.equal(result.value.getName(), "name");227 test.equal(result.type, "Name");228 229 test.equal(parser.parse("Name"), null);230}231232exports['Get modulus expression'] = function (test) {233 var parser = parsers.createParser("3%2");234 235 var result = parser.parse("Expression");236 test.ok(result);237 test.equal(parser.next(), null);238}239240exports['Get statement with end of line'] = function (test) {241 var parser = parsers.createParser("1+2\n");242 243 var result = parser.parse("Statement");244 test.ok(result);245 test.equal(parser.parse("Statement"), null);246}247248exports['Get two statements with end of line'] = function (test) {249 var parser = parsers.createParser("1+2\n3+2\n");250 251 var result = parser.parse("Statement");252 test.ok(result);253 254 result = parser.parse("Statement");255 test.ok(result);256 257 test.equal(parser.parse("Statement"), null);258}259260exports['Get two statements with semicolon'] = function (test) {261 var parser = parsers.createParser("1+2;3+2;");262 263 var result = parser.parse("Statement");264 test.ok(result);265 266 result = parser.parse("Statement");267 test.ok(result);268 269 test.equal(parser.parse("Statement"), null);270}271272exports['Get while expression'] = function (test) {273 var parser = parsers.createParser("while 1\na=1\nend");274 275 var result = parser.parse("Expression");276 test.ok(result);277 278 test.equal(parser.parse("Expression"), null);279}280281exports['Get while expression with do'] = function (test) {282 var parser = parsers.createParser("while 1 do\na=1\nend");283 284 var result = parser.parse("Expression");285 test.ok(result);286 287 test.equal(parser.parse("Expression"), null);288}289290exports['Get until expression'] = function (test) {291 var parser = parsers.createParser("until 1\na=1\nend");292 293 var result = parser.parse("Expression");294 test.ok(result);295 296 test.equal(parser.parse("Expression"), null);297}298299exports['Get until expression with do'] = function (test) {300 var parser = parsers.createParser("until 1 do\na=1\nend");301 302 var result = parser.parse("Expression");303 test.ok(result);304 305 test.equal(parser.parse("Expression"), null);306}307308exports['Get class expression'] = function (test) {309 var parser = parsers.createParser("class Dog\nend");310 311 var result = parser.parse("Expression");312 test.ok(result);313 test.ok(result.value);314 test.equal(result.value.getName(), "Dog");315 test.equal(result.value.getSuperName(), null);316 317 test.equal(parser.parse("Expression"), null);318}319320exports['Get class expression with super class'] = function (test) {321 var parser = parsers.createParser("class Dog < Animal\nend");322 323 var result = parser.parse("Expression");324 test.ok(result);325 test.ok(result.value);326 test.equal(result.value.getName(), "Dog");327 test.equal(result.value.getSuperName(), 'Animal');328 329 test.equal(parser.parse("Expression"), null);330}331332exports['Get class expression with empty def'] = function (test) {333 var parser = parsers.createParser("class Dog\ndef foo\nend\nend");334 335 var result = parser.parse("Expression");336 test.ok(result);337 test.ok(result.value);338 test.equal(result.value.getName(), "Dog");339 340 test.equal(parser.parse("Expression"), null);341}342343exports['Get module expression'] = function (test) {344 var parser = parsers.createParser("module Dog\nend");345 346 var result = parser.parse("Expression");347 test.ok(result);348 test.ok(result.value);349 test.equal(result.value.getName(), "Dog");350 351 test.equal(parser.parse("Expression"), null);352}353354exports['Get module expression with empty def'] = function (test) {355 var parser = parsers.createParser("module Dog\ndef foo\nend\nend");356 357 var result = parser.parse("Expression");358 test.ok(result);359 test.ok(result.value);360 test.equal(result.value.getName(), "Dog");361 362 test.equal(parser.parse("Expression"), null);363}364365exports['Get expression enclosed in parenthesis'] = function (test) {366 var parser = parsers.createParser("(2+3)");367 368 var result = parser.parse("Expression");369 test.ok(result);370 371 test.equal(parser.parse("Expression"), null);372}373374exports['Get expression enclosed in parenthesis and multiply'] = function (test) {375 var parser = parsers.createParser("(2+3)*3");376 377 var result = parser.parse("Expression");378 test.ok(result);379 380 test.equal(parser.parse("Expression"), null);381}382383exports['Skip line comment'] = function (test) {384 var parser = parsers.createParser("# this is a comment\r\n42");385 var result = parser.parse('Statement');386 test.ok(result);387 test.equal(result.value.evaluate(), 42);388 test.equal(parser.next(), null);389}390391exports['Get qualified name'] = function (test) {392 var parser = parsers.createParser("a.b");393 var result = parser.parse('QualifiedName');394 test.ok(result);395 test.equal(result.value.getName(), "b");396 test.equal(result.value.getTarget().getName(), "a");397}398399exports['Get qualified call'] = function (test) {400 var parser = parsers.createParser("a.b");401 var result = parser.parse('QualifiedCall');402 test.ok(result);403}404405exports['Get empty def'] = function (test) {406 var parser = parsers.createParser("def foo\nend");407 var result = parser.parse('Statement');408 test.ok(result);409 test.equal(parser.next(), null);410}411412exports['Get empty def using self'] = function (test) {413 var parser = parsers.createParser("def self.foo\nend");414 var result = parser.parse('Statement');415 test.ok(result);416 test.equal(parser.next(), null);417}418419exports['Get empty def with parenthesis'] = function (test) {420 var parser = parsers.createParser("def foo()\nend");421 var result = parser.parse('Statement');422 test.ok(result);423 test.equal(parser.next(), null);424}425426exports['Get empty def with argument'] = function (test) {427 var parser = parsers.createParser("def foo(a)\nend");428 var result = parser.parse('Statement');429 test.ok(result);430 test.equal(parser.next(), null);431}432433exports['Get empty def with arguments'] = function (test) {434 var parser = parsers.createParser("def foo(a,b)\nend");435 var result = parser.parse('Statement');436 test.ok(result);437 test.equal(parser.next(), null);438}439440exports['Get begin end'] = function (test) {441 var parser = parsers.createParser("begin\na=1\nb=2\end");442 var result = parser.parse('Expression');443 test.ok(result);444 test.equal(parser.next(), null);445}446447exports['Get instance variable'] = function (test) {448 var parser = parsers.createParser("@foo");449 var result = parser.parse('Expression');450 test.ok(result);451 test.equal(parser.next(), null);452}453454exports['Get class variable'] = function (test) {455 var parser = parsers.createParser("@@foo");456 var result = parser.parse('Expression');457 test.ok(result);458 test.equal(parser.next(), null);459}460461exports['Get global variable'] = function (test) {462 var parser = parsers.createParser("$foo");463 var result = parser.parse('Expression');464 test.ok(result);465 test.equal(parser.next(), null);466}467468exports['Get expression with unless'] = function (test) {469 var parser = parsers.createParser("a unless b");470 471 var result = parser.parse("Expression");472 473 test.ok(result);474 test.equal(result.type, "Expression");475 476 test.equal(parser.parse("Expression"), null);477}
...
parser.spec.ts
Source:parser.spec.ts
2import { Absynth } from '../Absynth';3import { ModuleCore } from '../modules/ModuleCore';4import { ModuleExpressions } from '../modules/ModuleExpressions';5import { ModuleExperimental } from '../modules/experimental';6function createParser() {7 return new Absynth([new ModuleCore(), new ModuleExpressions(), new ModuleExperimental()]).parser;8}9describe('Parser', () => {10 it('parse simple assignment expression with strings', () => {11 let parser = createParser();12 let res = parser.parse('let i = \'123\'');13 expect(res).toMatchSnapshot();14 });15 it('parse simple assignment expression with calculus', () => {16 let parser = createParser();17 let res = parser.parse('let i = 123 + 1/2');18 expect(res).toMatchSnapshot();19 });20 it('should parse statements', () => {21 let parser = createParser();22 let res = parser.parse('let i = 123 + 1/2; let j = 0;');23 expect(res).toMatchSnapshot();24 });25 it('should parse calls', () => {26 let parser = createParser();27 let res = parser.parse('println()');28 expect(res).toMatchSnapshot();29 res = parser.parse('println(123,3444)');30 expect(res).toMatchSnapshot();31 });32 it('should parse calls multiple lines', () => {33 let parser = createParser();34 let res = parser.parse('println()\nprintln()');35 expect(res).toMatchSnapshot();36 });37 it('should handle empty lines', () => {38 let parser = createParser();39 let res = parser.parse('\n\nprintln()\nprintln()');40 expect(res).toMatchSnapshot();41 });42 it('should handle braces', () => {43 let parser = createParser();44 let res = parser.parse('{ \n\nprintln()\nprintln() }');45 expect(res).toMatchSnapshot();46 res = parser.parse('{println()\nprintln()}');47 expect(res).toMatchSnapshot();48 res = parser.parse('{\nprintln();\n}');49 expect(res).toMatchSnapshot();50 });51 it('should handle modules', () => {52 let parser = createParser();53 let res = parser.parse(`model Module { field name: string }`);54 expect(res).toMatchSnapshot();55 });...
Using AI Code Generation
1var stryker = require('stryker-parent');2var parser = stryker.createParser();3parser.addArgument(['--foo'], { help: 'foo bar' });4parser.addArgument(['--bar'], { help: 'bar foo' });5var args = parser.parseArgs();6var stryker = require('stryker');7var parser = stryker.createParser();8parser.addArgument(['--foo'], { help: 'foo bar' });9parser.addArgument(['--bar'], { help: 'bar foo' });10var args = parser.parseArgs();
Using AI Code Generation
1const { createParser } = require('stryker-parent');2const parser = createParser();3const { parse } = require('stryker-parent');4const config = parse();5const { parseCliArgs } = require('stryker-parent');6const config = parseCliArgs();7const { parseConfig } = require('stryker-parent');8const config = parseConfig();9const { parseConfigFile } = require('stryker-parent');10const config = parseConfigFile();11const { parseEnv } = require('stryker-parent');12const config = parseEnv();13const { parseJson } = require('stryker-parent');14const config = parseJson();15const { parseJsonFile } = require('stryker-parent');16const config = parseJsonFile();17const { parseJsonFile } = require('stryker-parent');18const config = parseJsonFile();19const { parseJsonFile } = require('stryker-parent');20const config = parseJsonFile();21const { parseJsonFile } = require('stryker-parent');22const config = parseJsonFile();23const { parseJsonFile } = require('stryker-parent');24const config = parseJsonFile();25const { parseJsonFile } = require('stryker-parent');26const config = parseJsonFile();27const { parseJsonFile } = require('stryker-parent');28const config = parseJsonFile();29const { parseJsonFile } = require('stryker-parent');30const config = parseJsonFile();31const { parseJsonFile }
Using AI Code Generation
1var parser = require('stryker-parent').createParser();2parser.parse('some string');3var parser = require('stryker-parent').createParser();4parser.parse('some string');5var parser = require('stryker-parent').createParser();6parser.parse('some string');7var parser = require('stryker-parent').createParser();8parser.parse('some string');9var parser = require('stryker-parent').createParser();10parser.parse('some string');11var parser = require('stryker-parent').createParser();12parser.parse('some string');13var parser = require('stryker-parent').createParser();14parser.parse('some string');15var parser = require('stryker-parent').createParser();16parser.parse('some string');17var parser = require('stryker-parent').createParser();18parser.parse('some string');19var parser = require('stryker-parent').createParser();20parser.parse('some string');21var parser = require('stryker-parent').createParser();22parser.parse('some string');23var parser = require('stryker-parent').createParser();24parser.parse('some string');25var parser = require('stryker-parent').createParser();26parser.parse('some string');27var parser = require('stryker-parent').createParser();28parser.parse('some string');
Using AI Code Generation
1const createParser = require('stryker-parent').createParser;2const parser = createParser();3parser.parse('test');4module.exports = {5 createParser: function() {6 return {7 parse: function(input) {8 console.log(input);9 }10 }11 }12}
Using AI Code Generation
1function createParser() {2}3function createParser() {4}5I am trying to use jest.mock() to mock a function in a module that is imported from a different module. I have a module called "util" that looks like this:6export function doSomething() {7}8export function doSomethingElse() {9}10export function doSomethingElseAgain() {11}12I have another module called "index" that imports the "doSomething" function from "util" and then calls it:13import { doSomething } from './util';14doSomething();15import { doSomething } from './util';16jest.mock('./util', () => ({17 doSomething: jest.fn()18}));19describe('index', () => {20 it('should call doSomething', () => {21 require('./index');22 expect(doSomething).toHaveBeenCalled();23 });24});
Using AI Code Generation
1const { createParser } = require('stryker-parent');2const parser = createParser({3});4const parsed = parser.parse(process.argv.slice(2));5console.log(parsed);6{7 "scripts": {8 },9 "dependencies": {10 }11}12module.exports = function(config) {13 config.set({14 mochaOptions: {15 }16 });17};18{ _: [], help: false, version: false, config: 'stryker.conf.js' }19[2017-07-18 11:03:28.024] [INFO] SandboxPool - Creating 1 test runners (based on CPU count)20[2017-07-18 11:03:28.034] [INFO] MutatorFacade - 0 Mutant(s) generated
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!