Best JavaScript code snippet using mountebank
regexTesterSpec.ts
Source:regexTesterSpec.ts
1/// <reference path="../../Scripts/typings/angularjs/angular.d.ts"/>2/// <reference path="../../Scripts/typings/angularjs/angular-route.d.ts"/>3/// <reference path="../../Scripts/typings/angularjs/angular-mocks.d.ts"/>4/// <reference path="../../Scripts/typings/bootstrap/index.d.ts"/>5/// <reference path="../../Scripts/typings/jasmine/jasmine.d.ts"/>6/// <reference path="../../app.ts"/>7/// <reference path="../../regexTester/regexTester.ts"/>8interface IRegexFlagsTestData {9 flags: string;10 global: boolean;11 ignoreCase: boolean;12 multiline: boolean;13 sticky: boolean;14 unicode: boolean;15}16interface IRegexFlagsConstructorTestData extends IRegexFlagsTestData {17 arg0: string | null | undefined;18}19describe('MyGitHubPages regexTester', function () {20 describe('RegexFlags', function () {21 describe('Constructor', function () {22 it('new regexTester.RegexFlags()', function () {23 const flags: regexTester.RegexFlags = new regexTester.RegexFlags();24 expect(flags.flags).toEqual('', '#flags');25 expect(flags.global).toEqual(false, '#global');26 expect(flags.ignoreCase).toEqual(false, '#ignoreCase');27 expect(flags.multiline).toEqual(false, '#multiline');28 expect(flags.sticky).toEqual(false, '#sticky');29 expect(flags.unicode).toEqual(false, '#unicode');30 });31 it('new regexTester.RegexFlags(undefined)', function () {32 const flags: regexTester.RegexFlags = new regexTester.RegexFlags(undefined);33 expect(flags.flags).toEqual('', '#flags');34 expect(flags.global).toEqual(false, '#global');35 expect(flags.ignoreCase).toEqual(false, '#ignoreCase');36 expect(flags.multiline).toEqual(false, '#multiline');37 expect(flags.sticky).toEqual(false, '#sticky');38 expect(flags.unicode).toEqual(false, '#unicode');39 });40 it('new regexTester.RegexFlags(null)', function () {41 const flags: regexTester.RegexFlags = new regexTester.RegexFlags(null);42 expect(flags.flags).toEqual('', '#flags');43 expect(flags.global).toEqual(false, '#global');44 expect(flags.ignoreCase).toEqual(false, '#ignoreCase');45 expect(flags.multiline).toEqual(false, '#multiline');46 expect(flags.sticky).toEqual(false, '#sticky');47 expect(flags.unicode).toEqual(false, '#unicode');48 });49 [50 <IRegexFlagsConstructorTestData>{ arg0: '', flags: '', global: false, ignoreCase: false, multiline: false, sticky: false,51 unicode: false },52 <IRegexFlagsConstructorTestData>{ arg0: ' ', flags: '', global: false, ignoreCase: false, multiline: false, sticky: false,53 unicode: false },54 <IRegexFlagsConstructorTestData>{ arg0: 'a', flags: '', global: false, ignoreCase: false, multiline: false, sticky: false,55 unicode: false },56 <IRegexFlagsConstructorTestData>{ arg0: 'g', flags: 'g', global: true, ignoreCase: false, multiline: false, sticky: false,57 unicode: false },58 <IRegexFlagsConstructorTestData>{ arg0: 'i', flags: 'i', global: false, ignoreCase: true, multiline: false, sticky: false,59 unicode: false },60 <IRegexFlagsConstructorTestData>{ arg0: 'm', flags: 'm', global: false, ignoreCase: false, multiline: true, sticky: false,61 unicode: false },62 <IRegexFlagsConstructorTestData>{ arg0: 'u', flags: 'u', global: false, ignoreCase: false, multiline: false, sticky: false,63 unicode: true },64 <IRegexFlagsConstructorTestData>{ arg0: 'y', flags: 'y', global: false, ignoreCase: false, multiline: false, sticky: true,65 unicode: false },66 <IRegexFlagsConstructorTestData>{ arg0: ' g', flags: 'g', global: true, ignoreCase: false, multiline: false, sticky: false,67 unicode: false },68 <IRegexFlagsConstructorTestData>{ arg0: 'i ', flags: 'i', global: false, ignoreCase: true, multiline: false, sticky: false,69 unicode: false },70 <IRegexFlagsConstructorTestData>{ arg0: 'am', flags: 'm', global: false, ignoreCase: false, multiline: true, sticky: false,71 unicode: false },72 <IRegexFlagsConstructorTestData>{ arg0: 'ua', flags: 'u', global: false, ignoreCase: false, multiline: false, sticky: false,73 unicode: true },74 <IRegexFlagsConstructorTestData>{ arg0: 'yy', flags: 'y', global: false, ignoreCase: false, multiline: false, sticky: true,75 unicode: false },76 <IRegexFlagsConstructorTestData>{ arg0: 'gi', flags: 'gi', global: true, ignoreCase: true, multiline: false, sticky: false,77 unicode: false },78 <IRegexFlagsConstructorTestData>{ arg0: 'mi', flags: 'mi', global: false, ignoreCase: true, multiline: true, sticky: false,79 unicode: false },80 <IRegexFlagsConstructorTestData>{ arg0: 'mgiyu', flags: 'mgiyu', global: true, ignoreCase: true, multiline: true,81 sticky: true, unicode: true },82 <IRegexFlagsConstructorTestData>{ arg0: 'gimuy', flags: 'gimuy', global: true, ignoreCase: true, multiline: true,83 sticky: true, unicode: true },84 <IRegexFlagsConstructorTestData>{ arg0: ' uyixgmz', flags: 'uyigm', global: true, ignoreCase: true, multiline: true,85 sticky: true, unicode: true }86 ].forEach(function (testData: IRegexFlagsConstructorTestData) {87 it('new regexTester.RegexFlags(' + JSON.stringify(testData.arg0) + ')', function () {88 const flags: regexTester.RegexFlags = new regexTester.RegexFlags(testData.arg0);89 expect(flags.flags).toEqual(testData.flags, '#flags');90 expect(flags.global).toEqual(testData.global, '#global');91 expect(flags.ignoreCase).toEqual(testData.ignoreCase, '#ignoreCase');92 expect(flags.multiline).toEqual(testData.multiline, '#multiline');93 expect(flags.sticky).toEqual(testData.sticky, '#sticky');94 expect(flags.unicode).toEqual(testData.unicode, '#unicode');95 });96 });97 });98 describe('Modifiers', function () {99 ['', 'g', 'i', 'm', 'u', 'y'].forEach(function (f: string) {100 describe('(' + JSON.stringify(f) + ')', function () {101 describe('setGlobal', function () {102 describe('true', function () {103 let source: any, target: any;104 beforeAll(function () {105 try { source = new regexTester.RegexFlags(f); } catch (err) {106 source = err;107 pending('Constructor failed: ' + target);108 return;109 }110 try {111 if (source instanceof regexTester.RegexFlags) {112 target = source.setGlobal(true);113 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))114 throw new Error('setGlobal failed');115 } else116 target = 'Constructor failed: ' + source;117 } catch (err) { target = err; }118 });119 it('invoke', function () {120 if (source instanceof regexTester.RegexFlags) {121 const obj: regexTester.RegexFlags = source.setGlobal(true);122 expect(obj).toBeDefined();123 expect(obj).not.toBeNull();124 expect(obj instanceof regexTester.RegexFlags).toEqual(true);125 } else126 pending(target);127 });128 it('source.global', function () {129 if (source instanceof regexTester.RegexFlags)130 expect(source.global).toEqual(f == 'g');131 else132 pending(source);133 });134 it('target.global', function () {135 if (target instanceof regexTester.RegexFlags)136 expect(target.global).toEqual(true);137 else138 pending(target);139 });140 it('source.ignoreCase', function () {141 if (source instanceof regexTester.RegexFlags)142 expect(source.ignoreCase).toEqual(f == 'i');143 else144 pending(source);145 });146 it('target.ignoreCase', function () {147 if (target instanceof regexTester.RegexFlags)148 expect(target.ignoreCase).toEqual(f == 'i');149 else150 pending(target);151 });152 it('source.multiline', function () {153 if (source instanceof regexTester.RegexFlags)154 expect(source.multiline).toEqual(f == 'm');155 else156 pending(source);157 });158 it('target.multiline', function () {159 if (target instanceof regexTester.RegexFlags)160 expect(target.multiline).toEqual(f == 'm');161 else162 pending(target);163 });164 it('source.unicode', function () {165 if (source instanceof regexTester.RegexFlags)166 expect(source.unicode).toEqual(f == 'u');167 else168 pending(source);169 });170 it('target.unicode', function () {171 if (target instanceof regexTester.RegexFlags)172 expect(target.unicode).toEqual(f == 'u');173 else174 pending(target);175 });176 it('source.sticky', function () {177 if (source instanceof regexTester.RegexFlags)178 expect(source.sticky).toEqual(f == 'y');179 else180 pending(source);181 });182 it('target.sticky', function () {183 if (target instanceof regexTester.RegexFlags)184 expect(target.sticky).toEqual(f == 'y');185 else186 pending(target);187 });188 it('source.flags', function () {189 if (source instanceof regexTester.RegexFlags)190 expect(source.flags).toEqual(f);191 else192 pending(source);193 });194 it('target.flags', function () {195 if (target instanceof regexTester.RegexFlags)196 expect(target.flags).toEqual((f == 'g') ? f : f + 'g');197 else198 pending(target);199 });200 });201 describe('false', function () {202 let source: any, target: any;203 beforeAll(function () {204 try { source = new regexTester.RegexFlags(f); } catch (err) {205 source = err;206 pending('Constructor failed: ' + target);207 return;208 }209 try {210 if (source instanceof regexTester.RegexFlags) {211 target = source.setGlobal(false);212 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))213 throw new Error('setGlobal failed');214 } else215 target = 'Constructor failed: ' + source;216 } catch (err) { target = err; }217 });218 it('invoke', function () {219 if (source instanceof regexTester.RegexFlags) {220 const obj: regexTester.RegexFlags = source.setGlobal(false);221 expect(obj).toBeDefined();222 expect(obj).not.toBeNull();223 expect(obj instanceof regexTester.RegexFlags).toEqual(true);224 } else225 pending(target);226 });227 it('source.global', function () {228 if (source instanceof regexTester.RegexFlags)229 expect(source.global).toEqual(f == 'g');230 else231 pending(source);232 });233 it('target.global', function () {234 if (target instanceof regexTester.RegexFlags)235 expect(target.global).toEqual(false);236 else237 pending(target);238 });239 it('source.ignoreCase', function () {240 if (source instanceof regexTester.RegexFlags)241 expect(source.ignoreCase).toEqual(f == 'i');242 else243 pending(source);244 });245 it('target.ignoreCase', function () {246 if (target instanceof regexTester.RegexFlags)247 expect(target.ignoreCase).toEqual(f == 'i');248 else249 pending(target);250 });251 it('source.multiline', function () {252 if (source instanceof regexTester.RegexFlags)253 expect(source.multiline).toEqual(f == 'm');254 else255 pending(source);256 });257 it('target.multiline', function () {258 if (target instanceof regexTester.RegexFlags)259 expect(target.multiline).toEqual(f == 'm');260 else261 pending(target);262 });263 it('source.unicode', function () {264 if (source instanceof regexTester.RegexFlags)265 expect(source.unicode).toEqual(f == 'u');266 else267 pending(source);268 });269 it('target.unicode', function () {270 if (target instanceof regexTester.RegexFlags)271 expect(target.unicode).toEqual(f == 'u');272 else273 pending(target);274 });275 it('source.sticky', function () {276 if (source instanceof regexTester.RegexFlags)277 expect(source.sticky).toEqual(f == 'y');278 else279 pending(source);280 });281 it('target.sticky', function () {282 if (target instanceof regexTester.RegexFlags)283 expect(target.sticky).toEqual(f == 'y');284 else285 pending(target);286 });287 it('source.flags', function () {288 if (source instanceof regexTester.RegexFlags)289 expect(source.flags).toEqual(f);290 else291 pending(source);292 });293 it('target.flags', function () {294 if (target instanceof regexTester.RegexFlags)295 expect(target.flags).toEqual((f == 'g') ? '' : f);296 else297 pending(target);298 });299 });300 });301 describe('setIgnoreCase', function () {302 describe('true', function () {303 let source: any, target: any;304 beforeAll(function () {305 try { source = new regexTester.RegexFlags(f); } catch (err) {306 source = err;307 pending('Constructor failed: ' + target);308 return;309 }310 try {311 if (source instanceof regexTester.RegexFlags) {312 target = source.setIgnoreCase(true);313 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))314 throw new Error('setIgnoreCase failed');315 } else316 target = 'Constructor failed: ' + source;317 } catch (err) { target = err; }318 });319 it('invoke', function () {320 if (source instanceof regexTester.RegexFlags) {321 const obj: regexTester.RegexFlags = source.setIgnoreCase(true);322 expect(obj).toBeDefined();323 expect(obj).not.toBeNull();324 expect(obj instanceof regexTester.RegexFlags).toEqual(true);325 } else326 pending(target);327 });328 it('source.global', function () {329 if (source instanceof regexTester.RegexFlags)330 expect(source.global).toEqual(f == 'g');331 else332 pending(source);333 });334 it('target.global', function () {335 if (target instanceof regexTester.RegexFlags)336 expect(target.global).toEqual(f == 'g');337 else338 pending(target);339 });340 it('source.ignoreCase', function () {341 if (source instanceof regexTester.RegexFlags)342 expect(source.ignoreCase).toEqual(f == 'i');343 else344 pending(source);345 });346 it('target.ignoreCase', function () {347 if (target instanceof regexTester.RegexFlags)348 expect(target.ignoreCase).toEqual(true);349 else350 pending(target);351 });352 it('source.multiline', function () {353 if (source instanceof regexTester.RegexFlags)354 expect(source.multiline).toEqual(f == 'm');355 else356 pending(source);357 });358 it('target.multiline', function () {359 if (target instanceof regexTester.RegexFlags)360 expect(target.multiline).toEqual(f == 'm');361 else362 pending(target);363 });364 it('source.unicode', function () {365 if (source instanceof regexTester.RegexFlags)366 expect(source.unicode).toEqual(f == 'u');367 else368 pending(source);369 });370 it('target.unicode', function () {371 if (target instanceof regexTester.RegexFlags)372 expect(target.unicode).toEqual(f == 'u');373 else374 pending(target);375 });376 it('source.sticky', function () {377 if (source instanceof regexTester.RegexFlags)378 expect(source.sticky).toEqual(f == 'y');379 else380 pending(source);381 });382 it('target.sticky', function () {383 if (target instanceof regexTester.RegexFlags)384 expect(target.sticky).toEqual(f == 'y');385 else386 pending(target);387 });388 it('source.flags', function () {389 if (source instanceof regexTester.RegexFlags)390 expect(source.flags).toEqual(f);391 else392 pending(source);393 });394 it('target.flags', function () {395 if (target instanceof regexTester.RegexFlags)396 expect(target.flags).toEqual((f == 'i') ? f : f + 'i');397 else398 pending(target);399 });400 });401 describe('false', function () {402 let source: any, target: any;403 beforeAll(function () {404 try { source = new regexTester.RegexFlags(f); } catch (err) {405 source = err;406 pending('Constructor failed: ' + target);407 return;408 }409 try {410 if (source instanceof regexTester.RegexFlags) {411 target = source.setIgnoreCase(false);412 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))413 throw new Error('setIgnoreCase failed');414 } else415 target = 'Constructor failed: ' + source;416 } catch (err) { target = err; }417 });418 it('invoke', function () {419 if (source instanceof regexTester.RegexFlags) {420 const obj: regexTester.RegexFlags = source.setIgnoreCase(false);421 expect(obj).toBeDefined();422 expect(obj).not.toBeNull();423 expect(obj instanceof regexTester.RegexFlags).toEqual(true);424 } else425 pending(target);426 });427 it('source.global', function () {428 if (source instanceof regexTester.RegexFlags)429 expect(source.global).toEqual(f == 'g');430 else431 pending(source);432 });433 it('target.global', function () {434 if (target instanceof regexTester.RegexFlags)435 expect(target.global).toEqual(f == 'g');436 else437 pending(target);438 });439 it('source.ignoreCase', function () {440 if (source instanceof regexTester.RegexFlags)441 expect(source.ignoreCase).toEqual(f == 'i');442 else443 pending(source);444 });445 it('target.ignoreCase', function () {446 if (target instanceof regexTester.RegexFlags)447 expect(target.ignoreCase).toEqual(false);448 else449 pending(target);450 });451 it('source.multiline', function () {452 if (source instanceof regexTester.RegexFlags)453 expect(source.multiline).toEqual(f == 'm');454 else455 pending(source);456 });457 it('target.multiline', function () {458 if (target instanceof regexTester.RegexFlags)459 expect(target.multiline).toEqual(f == 'm');460 else461 pending(target);462 });463 it('source.unicode', function () {464 if (source instanceof regexTester.RegexFlags)465 expect(source.unicode).toEqual(f == 'u');466 else467 pending(source);468 });469 it('target.unicode', function () {470 if (target instanceof regexTester.RegexFlags)471 expect(target.unicode).toEqual(f == 'u');472 else473 pending(target);474 });475 it('source.sticky', function () {476 if (source instanceof regexTester.RegexFlags)477 expect(source.sticky).toEqual(f == 'y');478 else479 pending(source);480 });481 it('target.sticky', function () {482 if (target instanceof regexTester.RegexFlags)483 expect(target.sticky).toEqual(f == 'y');484 else485 pending(target);486 });487 it('source.flags', function () {488 if (source instanceof regexTester.RegexFlags)489 expect(source.flags).toEqual(f);490 else491 pending(source);492 });493 it('target.flags', function () {494 if (target instanceof regexTester.RegexFlags)495 expect(target.flags).toEqual((f == 'i') ? '' : f);496 else497 pending(target);498 });499 });500 });501 describe('setMultiline', function () {502 describe('true', function () {503 let source: any, target: any;504 beforeAll(function () {505 try { source = new regexTester.RegexFlags(f); } catch (err) {506 source = err;507 pending('Constructor failed: ' + target);508 return;509 }510 try {511 if (source instanceof regexTester.RegexFlags) {512 target = source.setMultiline(true);513 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))514 throw new Error('setMultiline failed');515 } else516 target = 'Constructor failed: ' + source;517 } catch (err) { target = err; }518 });519 it('invoke', function () {520 if (source instanceof regexTester.RegexFlags) {521 const obj: regexTester.RegexFlags = source.setMultiline(true);522 expect(obj).toBeDefined();523 expect(obj).not.toBeNull();524 expect(obj instanceof regexTester.RegexFlags).toEqual(true);525 } else526 pending(target);527 });528 it('source.global', function () {529 if (source instanceof regexTester.RegexFlags)530 expect(source.global).toEqual(f == 'g');531 else532 pending(source);533 });534 it('target.global', function () {535 if (target instanceof regexTester.RegexFlags)536 expect(target.global).toEqual(f == 'g');537 else538 pending(target);539 });540 it('source.ignoreCase', function () {541 if (source instanceof regexTester.RegexFlags)542 expect(source.ignoreCase).toEqual(f == 'i');543 else544 pending(source);545 });546 it('target.ignoreCase', function () {547 if (target instanceof regexTester.RegexFlags)548 expect(target.ignoreCase).toEqual(f == 'i');549 else550 pending(target);551 });552 it('source.multiline', function () {553 if (source instanceof regexTester.RegexFlags)554 expect(source.multiline).toEqual(f == 'm');555 else556 pending(source);557 });558 it('target.multiline', function () {559 if (target instanceof regexTester.RegexFlags)560 expect(target.multiline).toEqual(true);561 else562 pending(target);563 });564 it('source.unicode', function () {565 if (source instanceof regexTester.RegexFlags)566 expect(source.unicode).toEqual(f == 'u');567 else568 pending(source);569 });570 it('target.unicode', function () {571 if (target instanceof regexTester.RegexFlags)572 expect(target.unicode).toEqual(f == 'u');573 else574 pending(target);575 });576 it('source.sticky', function () {577 if (source instanceof regexTester.RegexFlags)578 expect(source.sticky).toEqual(f == 'y');579 else580 pending(source);581 });582 it('target.sticky', function () {583 if (target instanceof regexTester.RegexFlags)584 expect(target.sticky).toEqual(f == 'y');585 else586 pending(target);587 });588 it('source.flags', function () {589 if (source instanceof regexTester.RegexFlags)590 expect(source.flags).toEqual(f);591 else592 pending(source);593 });594 it('target.flags', function () {595 if (target instanceof regexTester.RegexFlags)596 expect(target.flags).toEqual((f == 'm') ? f : f + 'm');597 else598 pending(target);599 });600 });601 describe('false', function () {602 let source: any, target: any;603 beforeAll(function () {604 try { source = new regexTester.RegexFlags(f); } catch (err) {605 source = err;606 pending('Constructor failed: ' + target);607 return;608 }609 try {610 if (source instanceof regexTester.RegexFlags) {611 target = source.setMultiline(false);612 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))613 throw new Error('setMultiline failed');614 } else615 target = 'Constructor failed: ' + source;616 } catch (err) { target = err; }617 });618 it('invoke', function () {619 if (source instanceof regexTester.RegexFlags) {620 const obj: regexTester.RegexFlags = source.setMultiline(false);621 expect(obj).toBeDefined();622 expect(obj).not.toBeNull();623 expect(obj instanceof regexTester.RegexFlags).toEqual(true);624 } else625 pending(target);626 });627 it('source.global', function () {628 if (source instanceof regexTester.RegexFlags)629 expect(source.global).toEqual(f == 'g');630 else631 pending(source);632 });633 it('target.global', function () {634 if (target instanceof regexTester.RegexFlags)635 expect(target.global).toEqual(f == 'g');636 else637 pending(target);638 });639 it('source.ignoreCase', function () {640 if (source instanceof regexTester.RegexFlags)641 expect(source.ignoreCase).toEqual(f == 'i');642 else643 pending(source);644 });645 it('target.ignoreCase', function () {646 if (target instanceof regexTester.RegexFlags)647 expect(target.ignoreCase).toEqual(f == 'i');648 else649 pending(target);650 });651 it('source.multiline', function () {652 if (source instanceof regexTester.RegexFlags)653 expect(source.multiline).toEqual(f == 'm');654 else655 pending(source);656 });657 it('target.multiline', function () {658 if (target instanceof regexTester.RegexFlags)659 expect(target.multiline).toEqual(false);660 else661 pending(target);662 });663 it('source.unicode', function () {664 if (source instanceof regexTester.RegexFlags)665 expect(source.unicode).toEqual(f == 'u');666 else667 pending(source);668 });669 it('target.unicode', function () {670 if (target instanceof regexTester.RegexFlags)671 expect(target.unicode).toEqual(f == 'u');672 else673 pending(target);674 });675 it('source.sticky', function () {676 if (source instanceof regexTester.RegexFlags)677 expect(source.sticky).toEqual(f == 'y');678 else679 pending(source);680 });681 it('target.sticky', function () {682 if (target instanceof regexTester.RegexFlags)683 expect(target.sticky).toEqual(f == 'y');684 else685 pending(target);686 });687 it('source.flags', function () {688 if (source instanceof regexTester.RegexFlags)689 expect(source.flags).toEqual(f);690 else691 pending(source);692 });693 it('target.flags', function () {694 if (target instanceof regexTester.RegexFlags)695 expect(target.flags).toEqual((f == 'm') ? '' : f);696 else697 pending(target);698 });699 });700 });701 describe('setUnicode', function () {702 describe('true', function () {703 let source: any, target: any;704 beforeAll(function () {705 try { source = new regexTester.RegexFlags(f); } catch (err) {706 source = err;707 pending('Constructor failed: ' + target);708 return;709 }710 try {711 if (source instanceof regexTester.RegexFlags) {712 target = source.setUnicode(true);713 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))714 throw new Error('setUnicode failed');715 } else716 target = 'Constructor failed: ' + source;717 } catch (err) { target = err; }718 });719 it('invoke', function () {720 if (source instanceof regexTester.RegexFlags) {721 const obj: regexTester.RegexFlags = source.setUnicode(true);722 expect(obj).toBeDefined();723 expect(obj).not.toBeNull();724 expect(obj instanceof regexTester.RegexFlags).toEqual(true);725 } else726 pending(target);727 });728 it('source.global', function () {729 if (source instanceof regexTester.RegexFlags)730 expect(source.global).toEqual(f == 'g');731 else732 pending(source);733 });734 it('target.global', function () {735 if (target instanceof regexTester.RegexFlags)736 expect(target.global).toEqual(f == 'g');737 else738 pending(target);739 });740 it('source.ignoreCase', function () {741 if (source instanceof regexTester.RegexFlags)742 expect(source.ignoreCase).toEqual(f == 'i');743 else744 pending(source);745 });746 it('target.ignoreCase', function () {747 if (target instanceof regexTester.RegexFlags)748 expect(target.ignoreCase).toEqual(f == 'i');749 else750 pending(target);751 });752 it('source.multiline', function () {753 if (source instanceof regexTester.RegexFlags)754 expect(source.multiline).toEqual(f == 'm');755 else756 pending(source);757 });758 it('target.multiline', function () {759 if (target instanceof regexTester.RegexFlags)760 expect(target.multiline).toEqual(f == 'm');761 else762 pending(target);763 });764 it('source.unicode', function () {765 if (source instanceof regexTester.RegexFlags)766 expect(source.unicode).toEqual(f == 'u');767 else768 pending(source);769 });770 it('target.unicode', function () {771 if (target instanceof regexTester.RegexFlags)772 expect(target.unicode).toEqual(true);773 else774 pending(target);775 });776 it('source.sticky', function () {777 if (source instanceof regexTester.RegexFlags)778 expect(source.sticky).toEqual(f == 'y');779 else780 pending(source);781 });782 it('target.sticky', function () {783 if (target instanceof regexTester.RegexFlags)784 expect(target.sticky).toEqual(f == 'y');785 else786 pending(target);787 });788 it('source.flags', function () {789 if (source instanceof regexTester.RegexFlags)790 expect(source.flags).toEqual(f);791 else792 pending(source);793 });794 it('target.flags', function () {795 if (target instanceof regexTester.RegexFlags)796 expect(target.flags).toEqual((f == 'u') ? f : f + 'u');797 else798 pending(target);799 });800 });801 describe('false', function () {802 let source: any, target: any;803 beforeAll(function () {804 try { source = new regexTester.RegexFlags(f); } catch (err) {805 source = err;806 pending('Constructor failed: ' + target);807 return;808 }809 try {810 if (source instanceof regexTester.RegexFlags) {811 target = source.setUnicode(false);812 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))813 throw new Error('setUnicode failed');814 } else815 target = 'Constructor failed: ' + source;816 } catch (err) { target = err; }817 });818 it('invoke', function () {819 if (source instanceof regexTester.RegexFlags) {820 const obj: regexTester.RegexFlags = source.setUnicode(false);821 expect(obj).toBeDefined();822 expect(obj).not.toBeNull();823 expect(obj instanceof regexTester.RegexFlags).toEqual(true);824 } else825 pending(target);826 });827 it('source.global', function () {828 if (source instanceof regexTester.RegexFlags)829 expect(source.global).toEqual(f == 'g');830 else831 pending(source);832 });833 it('target.global', function () {834 if (target instanceof regexTester.RegexFlags)835 expect(target.global).toEqual(f == 'g');836 else837 pending(target);838 });839 it('source.ignoreCase', function () {840 if (source instanceof regexTester.RegexFlags)841 expect(source.ignoreCase).toEqual(f == 'i');842 else843 pending(source);844 });845 it('target.ignoreCase', function () {846 if (target instanceof regexTester.RegexFlags)847 expect(target.ignoreCase).toEqual(f == 'i');848 else849 pending(target);850 });851 it('source.multiline', function () {852 if (source instanceof regexTester.RegexFlags)853 expect(source.multiline).toEqual(f == 'm');854 else855 pending(source);856 });857 it('target.multiline', function () {858 if (target instanceof regexTester.RegexFlags)859 expect(target.multiline).toEqual(f == 'm');860 else861 pending(target);862 });863 it('source.unicode', function () {864 if (source instanceof regexTester.RegexFlags)865 expect(source.unicode).toEqual(f == 'u');866 else867 pending(source);868 });869 it('target.unicode', function () {870 if (target instanceof regexTester.RegexFlags)871 expect(target.unicode).toEqual(false);872 else873 pending(target);874 });875 it('source.sticky', function () {876 if (source instanceof regexTester.RegexFlags)877 expect(source.sticky).toEqual(f == 'y');878 else879 pending(source);880 });881 it('target.sticky', function () {882 if (target instanceof regexTester.RegexFlags)883 expect(target.sticky).toEqual(f == 'y');884 else885 pending(target);886 });887 it('source.flags', function () {888 if (source instanceof regexTester.RegexFlags)889 expect(source.flags).toEqual(f);890 else891 pending(source);892 });893 it('target.flags', function () {894 if (target instanceof regexTester.RegexFlags)895 expect(target.flags).toEqual((f == 'u') ? '' : f);896 else897 pending(target);898 });899 });900 });901 describe('setSticky', function () {902 describe('true', function () {903 let source: any, target: any;904 beforeAll(function () {905 try { source = new regexTester.RegexFlags(f); } catch (err) {906 source = err;907 pending('Constructor failed: ' + target);908 return;909 }910 try {911 if (source instanceof regexTester.RegexFlags) {912 target = source.setSticky(true);913 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))914 throw new Error('setSticky failed');915 } else916 target = 'Constructor failed: ' + source;917 } catch (err) { target = err; }918 });919 it('invoke', function () {920 if (source instanceof regexTester.RegexFlags) {921 const obj: regexTester.RegexFlags = source.setSticky(true);922 expect(obj).toBeDefined();923 expect(obj).not.toBeNull();924 expect(obj instanceof regexTester.RegexFlags).toEqual(true);925 } else926 pending(target);927 });928 it('source.global', function () {929 if (source instanceof regexTester.RegexFlags)930 expect(source.global).toEqual(f == 'g');931 else932 pending(source);933 });934 it('target.global', function () {935 if (target instanceof regexTester.RegexFlags)936 expect(target.global).toEqual(f == 'g');937 else938 pending(target);939 });940 it('source.ignoreCase', function () {941 if (source instanceof regexTester.RegexFlags)942 expect(source.ignoreCase).toEqual(f == 'i');943 else944 pending(source);945 });946 it('target.ignoreCase', function () {947 if (target instanceof regexTester.RegexFlags)948 expect(target.ignoreCase).toEqual(f == 'i');949 else950 pending(target);951 });952 it('source.multiline', function () {953 if (source instanceof regexTester.RegexFlags)954 expect(source.multiline).toEqual(f == 'm');955 else956 pending(source);957 });958 it('target.multiline', function () {959 if (target instanceof regexTester.RegexFlags)960 expect(target.multiline).toEqual(f == 'm');961 else962 pending(target);963 });964 it('source.unicode', function () {965 if (source instanceof regexTester.RegexFlags)966 expect(source.unicode).toEqual(f == 'u');967 else968 pending(source);969 });970 it('target.unicode', function () {971 if (target instanceof regexTester.RegexFlags)972 expect(target.unicode).toEqual(f == 'u');973 else974 pending(target);975 });976 it('source.sticky', function () {977 if (source instanceof regexTester.RegexFlags)978 expect(source.sticky).toEqual(f == 'y');979 else980 pending(source);981 });982 it('target.sticky', function () {983 if (target instanceof regexTester.RegexFlags)984 expect(target.sticky).toEqual(true);985 else986 pending(target);987 });988 it('source.flags', function () {989 if (source instanceof regexTester.RegexFlags)990 expect(source.flags).toEqual(f);991 else992 pending(source);993 });994 it('target.flags', function () {995 if (target instanceof regexTester.RegexFlags)996 expect(target.flags).toEqual((f == 'y') ? f : f + 'y');997 else998 pending(target);999 });1000 });1001 describe('false', function () {1002 let source: any, target: any;1003 beforeAll(function () {1004 try { source = new regexTester.RegexFlags(f); } catch (err) {1005 source = err;1006 pending('Constructor failed: ' + target);1007 return;1008 }1009 try {1010 if (source instanceof regexTester.RegexFlags) {1011 target = source.setSticky(false);1012 if (typeof target !== 'object' || target === null || !(target instanceof regexTester.RegexFlags))1013 throw new Error('setSticky failed');1014 } else1015 target = 'Constructor failed: ' + source;1016 } catch (err) { target = err; }1017 });1018 it('invoke', function () {1019 if (source instanceof regexTester.RegexFlags) {1020 const obj: regexTester.RegexFlags = source.setSticky(false);1021 expect(obj).toBeDefined();1022 expect(obj).not.toBeNull();1023 expect(obj instanceof regexTester.RegexFlags).toEqual(true);1024 } else1025 pending(target);1026 });1027 it('source.global', function () {1028 if (source instanceof regexTester.RegexFlags)1029 expect(source.global).toEqual(f == 'g');1030 else1031 pending(source);1032 });1033 it('target.global', function () {1034 if (target instanceof regexTester.RegexFlags)1035 expect(target.global).toEqual(f == 'g');1036 else1037 pending(target);1038 });1039 it('source.ignoreCase', function () {1040 if (source instanceof regexTester.RegexFlags)1041 expect(source.ignoreCase).toEqual(f == 'i');1042 else1043 pending(source);1044 });1045 it('target.ignoreCase', function () {1046 if (target instanceof regexTester.RegexFlags)1047 expect(target.ignoreCase).toEqual(f == 'i');1048 else1049 pending(target);1050 });1051 it('source.multiline', function () {1052 if (source instanceof regexTester.RegexFlags)1053 expect(source.multiline).toEqual(f == 'm');1054 else1055 pending(source);1056 });1057 it('target.multiline', function () {1058 if (target instanceof regexTester.RegexFlags)1059 expect(target.multiline).toEqual(f == 'm');1060 else1061 pending(target);1062 });1063 it('source.unicode', function () {1064 if (source instanceof regexTester.RegexFlags)1065 expect(source.unicode).toEqual(f == 'u');1066 else1067 pending(source);1068 });1069 it('target.unicode', function () {1070 if (target instanceof regexTester.RegexFlags)1071 expect(target.unicode).toEqual(f == 'u');1072 else1073 pending(target);1074 });1075 it('source.sticky', function () {1076 if (source instanceof regexTester.RegexFlags)1077 expect(source.sticky).toEqual(f == 'y');1078 else1079 pending(source);1080 });1081 it('target.sticky', function () {1082 if (target instanceof regexTester.RegexFlags)1083 expect(target.sticky).toEqual(false);1084 else1085 pending(target);1086 });1087 it('source.flags', function () {1088 if (source instanceof regexTester.RegexFlags)1089 expect(source.flags).toEqual( f);1090 else1091 pending(source);1092 });1093 it('target.flags', function () {1094 if (target instanceof regexTester.RegexFlags)1095 expect(target.flags).toEqual((f == 'y') ? '' : f);1096 else1097 pending(target);1098 });1099 });1100 });1101 });1102 });1103 });1104 });1105 describe('ValueVersion', function() {1106 let q: ng.IQService;1107 beforeAll(inject(function($q: ng.IQService) {1108 q = $q;1109 }));1110 describe('constructor', function() {1111 describe('<string>("test")', function() {1112 let target: regexTester.ValueVersion<string>;1113 beforeAll(function() {1114 target = new regexTester.ValueVersion<string>('test');1115 });1116 it('name equals "test"', function() {1117 expect(target.name).toEqual('test');1118 });1119 it('isResolved equals false', function() {1120 expect(target.isResolved).toEqual(false);1121 });1122 it('getValueAsync to be rejected', function(done: DoneFn) {1123 target.getValueAsync(q).then(function(promiseValue: { value: string; token: symbol; }): void {1124 fail('Did not expect to resolve');1125 done();1126 }, function(reason: any): void {1127 expect(reason).toBeDefined();1128 expect(reason).not.toBeNull();1129 done();1130 });1131 });1132 });1133 describe('<string>("test", "text")', function() {1134 let target: regexTester.ValueVersion<string>;1135 beforeAll(function() {1136 target = new regexTester.ValueVersion<string>('test', 'text');1137 });1138 it('name equals "test"', function() {1139 expect(target.name).toEqual('test');1140 });1141 it('isResolved equals true', function() {1142 expect(target.isResolved).toEqual(true);1143 });1144 it('value equals "text"', function() {1145 expect(target.value).toEqual('text');1146 });1147 it('getValueAsync to be resolved', function(done: DoneFn) {1148 target.getValueAsync(q).then(function(promiseValue: { value: string; token: symbol; }): void {1149 expect(promiseValue.value).toEqual('text');1150 done();1151 }, function(reason: any): void {1152 fail(reason);1153 done();1154 });1155 });1156 });1157 describe('<number>("test", 45)', function() {1158 let target: regexTester.ValueVersion<number>;1159 beforeAll(function() {1160 target = new regexTester.ValueVersion<number>('test', 45);1161 });1162 it('name equals "test"', function() {1163 expect(target.name).toEqual('test');1164 });1165 it('isResolved equals true', function() {1166 expect(target.isResolved).toEqual(true);1167 });1168 it('value equals "text"', function() {1169 expect(target.value).toEqual(45);1170 });1171 it('getValueAsync to be resolved', function(done: DoneFn) {1172 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1173 expect(promiseValue.value).toEqual(45);1174 done();1175 }, function(reason: any): void {1176 fail(reason);1177 done();1178 });1179 });1180 });1181 });1182 describe('resolve', function() {1183 describe('<string>("test")', function() {1184 it('resolves as "TEXT"', function() {1185 const target: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('test');1186 const token: symbol = target.versionToken;1187 target.resolve('TEXT');1188 expect(target.name).toEqual('test');1189 expect(target.isResolved).toEqual(true);1190 expect(target.value).toEqual('TEXT');1191 expect(token).not.toEqual(target.versionToken);1192 });1193 it('getValueAsync to be resolved as "TEXT"', function(done: DoneFn) {1194 const target: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('test');1195 const token: symbol = target.versionToken;1196 target.resolve('TEXT');1197 target.getValueAsync(q).then(function(promiseValue: { value: string; token: symbol; }): void {1198 expect(promiseValue.value).toEqual('TEXT');1199 expect(token).not.toEqual(promiseValue.token);1200 done();1201 }, function(reason: any): void {1202 fail(reason);1203 done();1204 });1205 });1206 });1207 describe('<string>("test", "text")', function() {1208 it('resolves as "TEXT"', function() {1209 const target: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('test', 'text');1210 const token: symbol = target.versionToken;1211 target.resolve('TEXT');1212 expect(target.name).toEqual('test');1213 expect(target.isResolved).toEqual(true);1214 expect(target.value).toEqual('TEXT');1215 expect(token).not.toEqual(target.versionToken);1216 });1217 it('getValueAsync to be resolved as "TEXT"', function(done: DoneFn) {1218 const target: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('test', 'text');1219 const token: symbol = target.versionToken;1220 target.resolve('TEXT');1221 target.getValueAsync(q).then(function(promiseValue: { value: string; token: symbol; }): void {1222 expect(promiseValue.value).toEqual('TEXT');1223 expect(token).not.toEqual(promiseValue.token);1224 done();1225 }, function(reason: any): void {1226 fail(reason);1227 done();1228 });1229 });1230 });1231 describe('<string>("test", "text", [insensitive comparer])', function() {1232 it('resolves as "TEXT"', function() {1233 const target: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('test', 'text',1234 function(x: string, y: string): boolean {1235 return (typeof x === 'string') ? (typeof y === 'string' && x.toLowerCase() === y.toLowerCase()) :1236 typeof y !== 'string';1237 });1238 const token: symbol = target.versionToken;1239 target.resolve('TEXT');1240 expect(target.name).toEqual('test');1241 expect(target.isResolved).toEqual(true);1242 expect(target.value).toEqual('TEXT');1243 expect(token).toEqual(target.versionToken);1244 });1245 it('getValueAsync to be resolved as "TEXT"', function(done: DoneFn) {1246 const target: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('test', 'text',1247 function(x: string, y: string): boolean {1248 return (typeof x === 'string') ? (typeof y === 'string' && x.toLowerCase() === y.toLowerCase()) :1249 typeof y !== 'string';1250 });1251 const token: symbol = target.versionToken;1252 target.resolve('TEXT');1253 target.getValueAsync(q).then(function(promiseValue: { value: string; token: symbol; }): void {1254 expect(promiseValue.value).toEqual('TEXT');1255 expect(token).toEqual(promiseValue.token);1256 done();1257 }, function(reason: any): void {1258 fail(reason);1259 done();1260 });1261 });1262 });1263 describe('<number>("test", 45)', function() {1264 it('resolves as 12', function() {1265 const target: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('test', 45);1266 const token: symbol = target.versionToken;1267 target.resolve(12);1268 expect(target.name).toEqual('test');1269 expect(target.isResolved).toEqual(true);1270 expect(target.value).toEqual(12);1271 expect(token).not.toEqual(target.versionToken);1272 });1273 it('getValueAsync to be resolved as 12', function(done: DoneFn) {1274 const target: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('test', 45);1275 const token: symbol = target.versionToken;1276 target.resolve(12);1277 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1278 expect(promiseValue.value).toEqual(12);1279 expect(token).not.toEqual(promiseValue.token);1280 done();1281 }, function(reason: any): void {1282 fail(reason);1283 done();1284 });1285 });1286 });1287 });1288 });1289 describe('ValueProducer', function() {1290 let q: ng.IQService;1291 beforeAll(inject(function($q: ng.IQService) {1292 q = $q;1293 }));1294 describe('constructor', function() {1295 describe('before getValueAsync', function() {1296 let target: regexTester.ValueProducer<number>;1297 let component: regexTester.ValueVersion<string>;1298 beforeAll(function() {1299 component = new regexTester.ValueVersion<string>('number', '12');1300 target = regexTester.ValueProducer.create<string, number>('test',1301 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, value: string) {1302 const n = parseFloat(value);1303 if (isNaN(n))1304 reject('not a number');1305 else1306 resolve(n);1307 }, component);1308 });1309 it('name equals "test"', function() {1310 expect(target.name).toEqual('test');1311 });1312 it('isResolved equals false', function() {1313 expect(target.isResolved).toEqual(false);1314 });1315 });1316 describe('with getValueAsync', function() {1317 it('getValueAsync to be resolved', function(done: DoneFn) {1318 const component: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('number', '12');1319 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<string, number>('test',1320 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, value: string) {1321 const n = parseFloat(value);1322 if (isNaN(n))1323 reject('not a number');1324 else1325 resolve(n);1326 }, component);1327 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1328 expect(promiseValue.value).toEqual(12);1329 done();1330 }, function(reason: any): void {1331 fail(reason);1332 done();1333 });1334 });1335 });1336 describe('Multiple', function() {1337 it('getValueAsync to be resolved', function(done: DoneFn) {1338 const cA: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('first', 1);1339 const cB: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('second', 2);1340 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<number, number, number>('test',1341 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, v0: number, v1: number) {1342 resolve(v0 / v1);1343 }, cA, cB);1344 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1345 expect(promiseValue.value).toEqual(0.5);1346 done();1347 }, function(reason: any): void {1348 fail(reason);1349 done();1350 });1351 });1352 it('getValueAsync to be rejected', function(done: DoneFn) {1353 const cA: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('first', 1);1354 const cB: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('second', 0);1355 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<number, number, number>('test',1356 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, v0: number, v1: number) {1357 resolve(v0 / v1);1358 }, cA, cB);1359 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1360 fail('expected divide by zero');1361 done();1362 }, function(reason: any): void {1363 expect(reason).toBeDefined();1364 expect(reason).not.toBeNull();1365 done();1366 });1367 });1368 });1369 });1370 describe('resolve', function() {1371 describe('resolve different number', function() {1372 it('getValueAsync to be resolved', function(done: DoneFn) {1373 const component: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('number', '12');1374 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<string, number>('test',1375 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, value: string) {1376 const n = parseFloat(value);1377 if (isNaN(n))1378 reject('not a number');1379 else1380 resolve(n);1381 }, component);1382 component.resolve('88');1383 const token: symbol = target.versionToken;1384 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1385 expect(promiseValue.value).toEqual(88);1386 expect(token).not.toEqual(promiseValue.token);1387 done();1388 }, function(reason: any): void {1389 fail(reason);1390 done();1391 });1392 });1393 });1394 describe('resolve same number', function() {1395 it('getValueAsync to be resolved', function(done: DoneFn) {1396 const component: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('number', '12');1397 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<string, number>('test',1398 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, value: string) {1399 const n = parseFloat(value);1400 if (isNaN(n))1401 reject('not a number');1402 else1403 resolve(n);1404 }, component);1405 component.resolve('12');1406 const token: symbol = target.versionToken;1407 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1408 expect(promiseValue.value).toEqual(12);1409 expect(token).toEqual(promiseValue.token);1410 done();1411 }, function(reason: any): void {1412 fail(reason);1413 done();1414 });1415 });1416 });1417 describe('resolve same result', function() {1418 it('getValueAsync to be resolved', function(done: DoneFn) {1419 const component: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('number', '12');1420 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<string, number>('test',1421 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, value: string) {1422 const n = parseFloat(value);1423 if (isNaN(n))1424 reject('not a number');1425 else1426 resolve(n);1427 }, component);1428 component.resolve('012');1429 const token: symbol = target.versionToken;1430 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1431 expect(promiseValue.value).toEqual(12);1432 expect(token).toEqual(promiseValue.token);1433 done();1434 }, function(reason: any): void {1435 fail(reason);1436 done();1437 });1438 });1439 });1440 describe('resolve invalid number', function() {1441 it('getValueAsync to be rejected', function(done: DoneFn) {1442 const component: regexTester.ValueVersion<string> = new regexTester.ValueVersion<string>('number', '12');1443 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<string, number>('test',1444 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, value: string) {1445 const n = parseFloat(value);1446 if (isNaN(n))1447 reject('not a number');1448 else1449 resolve(n);1450 }, component);1451 component.resolve('x');1452 const token: symbol = target.versionToken;1453 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1454 fail('Expected NaN');1455 done();1456 }, function(reason: any): void {1457 expect(reason).toBeDefined();1458 expect(reason).not.toBeNull();1459 done();1460 });1461 });1462 });1463 describe('Multiple', function() {1464 it('getValueAsync to be resolved', function(done: DoneFn) {1465 const cA: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('first', 1);1466 const cB: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('second', 2);1467 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<number, number, number>('test',1468 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, v0: number, v1: number) {1469 resolve(v0 / v1);1470 }, cA, cB);1471 cA.resolve(10);1472 const token: symbol = target.versionToken;1473 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1474 expect(promiseValue.value).toEqual(5);1475 expect(token).not.toEqual(promiseValue.token);1476 done();1477 }, function(reason: any): void {1478 fail(reason);1479 done();1480 });1481 });1482 it('getValueAsync to be resolved from same result', function(done: DoneFn) {1483 const cA: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('first', 1);1484 const cB: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('second', 2);1485 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<number, number, number>('test',1486 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, v0: number, v1: number) {1487 resolve(v0 + v1);1488 }, cA, cB);1489 cA.resolve(2);1490 cB.resolve(1);1491 const token: symbol = target.versionToken;1492 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1493 expect(promiseValue.value).toEqual(3);1494 expect(token).toEqual(promiseValue.token);1495 done();1496 }, function(reason: any): void {1497 fail(reason);1498 done();1499 });1500 });1501 it('getValueAsync to be rejected', function(done: DoneFn) {1502 const cA: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('first', 1);1503 const cB: regexTester.ValueVersion<number> = new regexTester.ValueVersion<number>('second', 2);1504 const target: regexTester.ValueProducer<number> = regexTester.ValueProducer.create<number, number, number>('test',1505 function(resolve: ng.IQResolveReject<number>, reject: ng.IQResolveReject<any>, v0: number, v1: number) {1506 resolve(v0 / v1);1507 }, cA, cB);1508 cB.resolve(0);1509 target.getValueAsync(q).then(function(promiseValue: { value: number; token: symbol; }): void {1510 fail('expected divide by zero');1511 done();1512 }, function(reason: any): void {1513 expect(reason).toBeDefined();1514 expect(reason).not.toBeNull();1515 done();1516 });1517 });1518 });1519 });1520 });1521 describe('RegexParserService', function () {1522 beforeEach(function () {1523 angular.mock.module('MyGitHubPages');1524 });1525 it('Injectable', inject(function ($rootScope: ng.IRootScopeService, regexParser: regexTester.RegexParserService) {1526 expect(regexParser).toBeDefined();1527 expect(regexParser).not.toBeNull();1528 expect(regexParser[Symbol.toStringTag]).toEqual('regexParser');1529 const flags: regexTester.RegexFlags = regexParser.flags();1530 expect(flags).toBeDefined('flags');1531 expect(flags).not.toBeNull('flags');1532 expect(flags.flags).toEqual('', 'flags');1533 expect(regexParser.pattern()).toEqual('(?:)', 'pattern');1534 const regexp: regexTester.ValueProducer<RegExp> = regexParser.regex();1535 expect(regexp).toBeDefined('regex');1536 expect(regexp).not.toBeNull('regex');1537 }));1538 });...
index.js
Source:index.js
1let Control_MonadZero = require("../Control.MonadZero/index.js");2const data = require("../data");3let Data_Monoid = require("../Data.Monoid/index.js");4let Data_Semigroup = require("../Data.Semigroup/index.js");5let Data_Show = require("../Data.Show/index.js");6let Data_String_Common = require("../Data.String.Common/index.js");7let RegexFlags = (function () {8 function RegexFlags(value0) {9 this.value0 = value0;10 };11 RegexFlags.create = function (value0) {12 return new RegexFlags(value0);13 };14 return RegexFlags;15})();16let unicode = new RegexFlags({17 global: false,18 ignoreCase: false,19 multiline: false,20 sticky: false,21 unicode: true22});23let sticky = new RegexFlags({24 global: false,25 ignoreCase: false,26 multiline: false,27 sticky: true,28 unicode: false29});30let showRegexFlags = new Data_Show.Show(function (v) {31 let usedFlags = Data_Semigroup.append(Data_Semigroup.semigroupArray)([ ])(Data_Semigroup.append(Data_Semigroup.semigroupArray)(data.voidLeft(data.functorArray)(Control_MonadZero.guard(Control_MonadZero.monadZeroArray)(v.value0.global))("global"))(Data_Semigroup.append(Data_Semigroup.semigroupArray)(data.voidLeft(data.functorArray)(Control_MonadZero.guard(Control_MonadZero.monadZeroArray)(v.value0.ignoreCase))("ignoreCase"))(Data_Semigroup.append(Data_Semigroup.semigroupArray)(data.voidLeft(data.functorArray)(Control_MonadZero.guard(Control_MonadZero.monadZeroArray)(v.value0.multiline))("multiline"))(Data_Semigroup.append(Data_Semigroup.semigroupArray)(data.voidLeft(data.functorArray)(Control_MonadZero.guard(Control_MonadZero.monadZeroArray)(v.value0.sticky))("sticky"))(data.voidLeft(data.functorArray)(Control_MonadZero.guard(Control_MonadZero.monadZeroArray)(v.value0.unicode))("unicode"))))));32 let $6 = data.eq(data.eqArray(data.eqString))(usedFlags)([ ]);33 if ($6) {34 return "noFlags";35 };36 return "(" + (Data_String_Common.joinWith(" <> ")(usedFlags) + ")");37});38let semigroupRegexFlags = new Data_Semigroup.Semigroup(function (v) {39 return function (v1) {40 return new RegexFlags({41 global: v.value0.global || v1.value0.global,42 ignoreCase: v.value0.ignoreCase || v1.value0.ignoreCase,43 multiline: v.value0.multiline || v1.value0.multiline,44 sticky: v.value0.sticky || v1.value0.sticky,45 unicode: v.value0.unicode || v1.value0.unicode46 });47 };48});49let noFlags = new RegexFlags({50 global: false,51 ignoreCase: false,52 multiline: false,53 sticky: false,54 unicode: false55});56let multiline = new RegexFlags({57 global: false,58 ignoreCase: false,59 multiline: true,60 sticky: false,61 unicode: false62});63let monoidRegexFlags = new Data_Monoid.Monoid(function () {64 return semigroupRegexFlags;65}, noFlags);66let ignoreCase = new RegexFlags({67 global: false,68 ignoreCase: true,69 multiline: false,70 sticky: false,71 unicode: false72});73let global = new RegexFlags({74 global: true,75 ignoreCase: false,76 multiline: false,77 sticky: false,78 unicode: false79});80let eqRegexFlags = new data.Eq(function (v) {81 return function (v1) {82 return v.value0.global === v1.value0.global && (v.value0.ignoreCase === v1.value0.ignoreCase && (v.value0.multiline === v1.value0.multiline && (v.value0.sticky === v1.value0.sticky && v.value0.unicode === v1.value0.unicode)));83 };84});85module.exports = {86 RegexFlags: RegexFlags,87 noFlags: noFlags,88 global: global,89 ignoreCase: ignoreCase,90 multiline: multiline,91 sticky: sticky,92 unicode: unicode,93 semigroupRegexFlags: semigroupRegexFlags,94 monoidRegexFlags: monoidRegexFlags,95 eqRegexFlags: eqRegexFlags,96 showRegexFlags: showRegexFlags...
logic.js
Source:logic.js
1import { SpecialTokens, TextDirection } from "./constants";2export function getTextDirection(text) {3 const hebrewRegex = /[\u0590-\u05FF]/;4 const arabicRegex = /[\u0600-\u06FF]/;5 return [hebrewRegex, arabicRegex].some((semiticLanguage) => semiticLanguage.test(text))6 ? TextDirection.RTL : TextDirection.LTR;7}8export function translateByDictionary(originalText, dictionary, ignoreCase) {9 if (dictionary === null) return originalText;10 const regexFlags = ignoreCase ? 'gi' : 'g';11 return dictionary.content.reduce((ans, replacement) => {12 const { original, target } = replacement;13 if (original.endsWith(SpecialTokens.END_OF_WORD)) {14 const originalWithoutSpecialCharacter = original.slice(0, -1);15 return ans.replace(new RegExp(`${originalWithoutSpecialCharacter}([ \n,.!?:;]|$)`, regexFlags), `${target}$1`);16 } else if (target === SpecialTokens.EMPTY_STRING) {17 return ans.replace(new RegExp(original, regexFlags), '');18 }19 return ans.replace(new RegExp(original, regexFlags), target);20 }, originalText);...
Using AI Code Generation
1var mountebank = require('mountebank');2var mb = mountebank.create({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' });3var regexFlags = mb.regexFlags;4var imposter = {5 {6 {7 equals: {8 }9 }10 {11 is: {12 }13 }14 }15};16mb.start()17 .then(function () {18 return mb.post('/imposters', imposter);19})20 .then(function (response) {21 return mb.get('/imposters/' + response.body.port);22})23 .then(function (response) {24 console.log('GET /imposters/' + response.body.port + ' response');25 console.log(response.body.stubs[0].predicates[0].equals.path);26 console.log(regexFlags(response.body.stubs[0].predicates[0].equals.path));27})28 .finally(function () {29 mb.stop();30});31 console.log(response.body.stubs[0].predicates[0].equals.path.match(/\/test/).flags);
Using AI Code Generation
1var mb = require('mountebank');2var flags = mb.regexFlags('i');3var mb = require('mountebank');4var flags = mb.regexFlags('i', 'g');5var mb = require('mountebank');6var flags = mb.regexFlags('i', 'g', 'm');7var mb = require('mountebank');8var flags = mb.regexFlags('i', 'g', 'm', 'y');9var mb = require('mountebank');10var flags = mb.regexFlags('i', 'g', 'm', 'y', 'u');11var mb = require('mountebank');12var flags = mb.regexFlags('i', 'g', 'm', 'y', 'u', 's');13var mb = require('mountebank');14var flags = mb.regexFlags('i', 'g', 'm', 'y', 'u', 's', 'd');15var mb = require('mountebank');16var flags = mb.regexFlags('i', 'g', 'm', 'y', 'u', 's', 'd', 'x');17var mb = require('mountebank');18var flags = mb.regexFlags('i', 'g', 'm', 'y', 'u', 's', 'd', 'x', 'a');
Using AI Code Generation
1var mb = require('mountebank');2var port = 2525;3var protocol = 'http';4{5 {6 is: {7 headers: {8 },9 body: {10 }11 }12 }13}];14var options = {15};16mb.create(options)17 .then(function (server) {18 console.log('mountebank server started on port ' + server.port);19 })20 .catch(function (error) {21 console.error(error);22 });23In the above code, we have imported mountebank module and created an instance of it. Then, we have created a server with the help of the create method of mountebank. This method takes an object as an argument. The object has the following properties:24var mb = require('mountebank');25var port = 2525;26var protocol = 'https';27{28 {29 is: {30 headers: {31 },32 body: {33 }34 }35 }36}];
Using AI Code Generation
1var regexFlags = require('mountebank').regexFlags;2var imposter = {3 {4 {5 equals: {6 headers: {7 }8 }9 }10 {11 is: {12 headers: {13 },14 body: JSON.stringify({status: 'success'})15 }16 }17 }18};19var mb = require('mountebank');20var mbHelper = require('mountebank-helper');21var mbHelperOptions = {22};23mbHelper.startMb(mbHelperOptions, function () {24 console.log('mountebank started');25 mb.create(mbHelperOptions.mbPort, imposter, function () {26 console.log('imposter started');27 });28});29var request = require('request');30var options = {31 headers: {32 },33 body: JSON.stringify({status: 'success'})34};35request(options, function (error, response, body) {36 console.log('error:', error);37 console.log('statusCode:', response && response.statusCode);38 console.log('body:', body);39});40mbHelper.stopMb(mbHelperOptions, function () {41 console.log('mountebank stopped');42});
Using AI Code Generation
1var mb = require('mountebank');2var flags = mb.regexFlags;3var mb = require('mountebank');4var flags = mb.regexFlags;5var mb = require('mountebank');6var flags = mb.regexFlags;7var mb = require('mountebank');8var flags = mb.regexFlags;9var mb = require('mountebank');10var flags = mb.regexFlags;11var mb = require('mountebank');12var flags = mb.regexFlags;13var mb = require('mountebank');14var flags = mb.regexFlags;15var mb = require('mountebank');16var flags = mb.regexFlags;17var mb = require('mountebank');18var flags = mb.regexFlags;19var mb = require('mountebank');20var flags = mb.regexFlags;
Using AI Code Generation
1var mb = require('mountebank');2var mbHelper = require('./mb-helper');3var mbPort = 2525;4var mbAdminPort = 2526;5var mbServer = mb.create({6});7mbServer.start(function () {8 mbHelper(mbPort, mbAdminPort).then(function (helper) {9 var imposter = {10 stubs: [{11 responses: [{12 is: {13 }14 }]15 }]16 };17 helper.createImposter(imposter).then(function (imposter) {18 helper.get('/').then(function (response) {19 console.log(response.body);20 helper.deleteImposter(imposter.port).then(function () {21 mbServer.stop();22 });23 });24 });25 });26});27var Q = require('q');28var request = require('request');29function mbHelper (mbPort, mbAdminPort) {30 function get (path) {31 var deferred = Q.defer();32 request.get(mbUrl + path, function (error, response, body) {33 if (error) {34 deferred.reject(error);35 }36 else {37 deferred.resolve(response);38 }39 });40 return deferred.promise;41 }42 function post (path, body) {43 var deferred = Q.defer();44 request.post({45 }, function (error, response, body) {46 if (error) {47 deferred.reject(error);48 }49 else {50 deferred.resolve(response);51 }52 });53 return deferred.promise;54 }55 function del (path) {56 var deferred = Q.defer();57 request.del(mbAdminUrl + path, function (error, response, body) {58 if (error) {59 deferred.reject(error);60 }61 else {62 deferred.resolve(response);
Using AI Code Generation
1const mbHelper = require('./mbHelper');2mbHelper.regexFlags('test');3const mb = require('mountebank');4exports.regexFlags = function (value) {5 const regex = new mb.Imposter({ protocol: 'http', port: 4545 });6 regex.addStub({7 predicates: [{ equals: { method: 'GET', path: '/test' } }],8 responses: [{ is: { body: value } }]9 });10 return regex;11};
Using AI Code Generation
1var mb = require('mountebank');2var regex = new RegExp("abc", "i");3console.log(mb.helpers.regexFlags(regex));4var mb = require('mountebank');5var regex = new RegExp("abc", "i");6console.log(mb.helpers.regexFlags(regex));7var mb = require('mountebank');8var regex = new RegExp("abc", "i");9console.log(mb.helpers.regexFlags(regex));10var mb = require('mountebank');11var regex = new RegExp("abc", "i");12console.log(mb.helpers.regexFlags(regex));13var mb = require('mountebank');14var regex = new RegExp("abc", "i");15console.log(mb.helpers.regexFlags(regex));16var mb = require('mountebank');17var regex = new RegExp("abc", "i");18console.log(mb.helpers.regexFlags(regex));19var mb = require('mountebank');20var regex = new RegExp("abc", "i");21console.log(mb.helpers.regexFlags(regex));22var mb = require('mountebank');23var regex = new RegExp("abc", "i");24console.log(mb.helpers.regexFlags(regex));25var mb = require('mountebank');
Using AI Code Generation
1var imposter = require('mountebank').create();2var port = 3000;3var path = '/api/v1/endpoint';4var method = 'GET';5var response = {message: 'Hello World!'};6var stub = {7 {8 is: {9 headers: {10 },11 }12 }13};14imposter.addStub({responses: [{is: {statusCode: 404}}]});15imposter.addStub({responses: [{is: {statusCode: 500}}]});16imposter.addStub({responses: [{is: {statusCode: 401}}]});17imposter.addStub({responses: [{is: {statusCode: 400}}]});18imposter.addStub({responses: [{is: {statusCode: 204}}]});19imposter.addStub({responses: [{is: {statusCode: 404}}]});20imposter.addStub({responses: [{is: {statusCode: 500}}]});21imposter.addStub({responses: [{is: {statusCode: 401}}]});22imposter.addStub({responses: [{is: {statusCode: 400}}]});23imposter.addStub({responses: [{is: {statusCode: 204}}]});24imposter.addStub({25 {26 equals: {27 }28 }29 {30 is: {31 headers: {32 },33 }34 }35});36imposter.addStub({37 {38 equals: {39 }40 }41 {42 is: {43 headers: {44 },45 }46 }47});48imposter.addStub({49 {50 equals: {51 }52 }53 {54 is: {55 headers: {56 },
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!!