How to use parseString method in Playwright Internal

Best JavaScript code snippet using playwright-internal

parseString.js

Source:parseString.js Github

copy

Full Screen

...4const { createFormat } = require('../dist');56describe('parseString', () => {7 it('Case #1', () => {8 const itemObject = parseString(9 'Cool Killstreak Aqua Marine Rocket Launcher (Battle Scarred)'10 );1112 assert.deepEqual(itemObject, {13 name: 'Rocket Launcher',14 craftable: true,15 killstreak: 'Killstreak',16 wear: 'Battle Scarred',17 texture: 'Aqua Marine',18 effect: 'Cool',19 quality: 'Unusual',20 });21 });2223 it('Case #2', () => {24 const itemObject = parseString(25 "Strange High Roller's Rocket Launcher (Factory New)"26 );2728 assert.deepEqual(itemObject, {29 name: 'Rocket Launcher',30 craftable: true,31 wear: 'Factory New',32 texture: "High Roller's",33 quality: 'Strange',34 });35 });3637 it('Case #3', () => {38 const itemObject = parseString(39 "Collector's Battalion's Backup Chemistry Set"40 );4142 assert.deepEqual(itemObject, {43 name: 'Chemistry Set',44 craftable: true,45 output: "Battalion's Backup",46 outputQuality: "Collector's",47 quality: 'Unique',48 });49 });5051 it('Case #4', () => {52 const itemObject = parseString(53 'Strange Festivized Professional Killstreak Australium Scattergun'54 );5556 assert.deepEqual(itemObject, {57 name: 'Scattergun',58 craftable: true,59 australium: true,60 festivized: true,61 killstreak: 'Professional Killstreak',62 quality: 'Strange',63 });64 });6566 it('Case #5', () => {67 const itemObject = parseString('Demonflame Modest Pile of Hat');6869 assert.deepEqual(itemObject, {70 name: 'Modest Pile of Hat',71 craftable: true,72 effect: 'Demonflame',73 quality: 'Unusual',74 });75 });7677 it('Case #6', () => {78 const itemObject = parseString('Strange Omniscient Orb Balloonihoodie');7980 assert.deepEqual(itemObject, {81 name: 'Balloonihoodie',82 craftable: true,83 effect: 'Omniscient Orb',84 quality: 'Unusual',85 elevated: true,86 });87 });8889 it('Case #7', () => {90 const itemObject = parseString(91 'Non-Craftable Specialized Killstreak Gunboats Kit Fabricator'92 );9394 assert.deepEqual(itemObject, {95 name: 'Specialized Killstreak Kit Fabricator',96 craftable: false,97 killstreak: 'Specialized Killstreak',98 target: 'Gunboats',99 quality: 'Unique',100 });101 });102103 it('Case #8', () => {104 const itemObject = parseString('Archimedes Strangifier Chemistry Set');105106 assert.deepEqual(itemObject, {107 name: 'Chemistry Set',108 craftable: true,109 target: 'Archimedes',110 output: 'Strangifier',111 outputQuality: 'Unique',112 quality: 'Unique',113 });114 });115116 it('Case #9', () => {117 const itemObject = parseString('Strange Backwards Ballcap');118119 assert.deepEqual(itemObject, {120 name: 'Backwards Ballcap',121 craftable: true,122 quality: 'Strange',123 });124 });125126 it('Case #10', () => {127 const itemObject = parseString(128 'Professional Killstreak Iron Curtain Kit Fabricator'129 );130131 assert.deepEqual(itemObject, {132 name: 'Professional Killstreak Kit Fabricator',133 craftable: true,134 killstreak: 'Professional Killstreak',135 target: 'Iron Curtain',136 quality: 'Unique',137 });138 });139140 it('Case #11', () => {141 const itemObject = parseString(142 'Strange Professional Killstreak Festive Grenade Launcher'143 );144145 assert.deepEqual(itemObject, {146 name: 'Festive Grenade Launcher',147 craftable: true,148 killstreak: 'Professional Killstreak',149 quality: 'Strange',150 });151 });152153 it('Case #12', () => {154 const itemObject = parseString('Strange Unique Sniper Rifle');155156 assert.deepEqual(itemObject, {157 name: 'Sniper Rifle',158 craftable: true,159 quality: 'Unique',160 elevated: true,161 });162 });163164 it('Case #13', () => {165 const itemObject = parseString('Australium Gold');166167 assert.deepEqual(itemObject, {168 name: 'Australium Gold',169 craftable: true,170 quality: 'Unique',171 });172 });173174 it('Case #14', () => {175 const itemObject = parseString('Blue Moon Case #118');176177 assert.deepEqual(itemObject, {178 name: 'Blue Moon Case',179 craftable: true,180 itemNumber: { type: 'crate', value: 118 },181 quality: 'Unique',182 });183 });184185 it('Case #15', () => {186 const itemObject = parseString('Hat #25');187188 assert.deepEqual(itemObject, {189 name: 'Hat',190 craftable: true,191 itemNumber: { type: 'craft', value: 25 },192 quality: 'Unique',193 });194 });195196 it('Case #16', () => {197 const itemObject = parseString('The Tartan Shade');198199 assert.deepEqual(itemObject, {200 name: 'Tartan Shade',201 craftable: true,202 quality: 'Unique',203 isUniqueHat: true,204 });205 });206207 it('Case #17', () => {208 const itemObject = parseString('Strange Cool Breeze');209210 assert.deepEqual(itemObject, {211 name: 'Cool Breeze',212 craftable: true,213 quality: 'Strange',214 });215 });216217 it('Case #18', () => {218 const itemObject = parseString('Strange Hot Case');219220 assert.deepEqual(itemObject, {221 name: 'Hot Case',222 craftable: true,223 quality: 'Strange',224 });225 });226227 it('Case #18', () => {228 const itemObject = parseString('Strange Hot Heels');229230 assert.deepEqual(itemObject, {231 name: 'Hot Heels',232 craftable: true,233 quality: 'Strange',234 });235 });236237 it('Case #19', () => {238 const itemObject = parseString('Strange A Head Full of Hot Air');239240 assert.deepEqual(itemObject, {241 name: 'A Head Full of Hot Air',242 craftable: true,243 quality: 'Strange',244 });245 });246247 it('Case #20', () => {248 const itemObject = parseString('Strange Vintage Tyrolean');249250 assert.deepEqual(itemObject, {251 name: 'Vintage Tyrolean',252 quality: 'Strange',253 craftable: true,254 });255 });256257 it('Case #21', () => {258 const itemObject = parseString('Strange Vintage Vintage Tyrolean');259260 assert.deepEqual(itemObject, {261 name: 'Vintage Tyrolean',262 quality: 'Vintage',263 elevated: true,264 craftable: true,265 });266 });267268 it('Case #22', () => {269 const itemObject = parseString('Vintage Tyrolean');270271 assert.deepEqual(itemObject, {272 name: 'Vintage Tyrolean',273 quality: 'Unique',274 craftable: true,275 });276 });277278 it('Case #23', () => {279 const itemObject = parseString('Vintage Vintage Tyrolean');280281 assert.deepEqual(itemObject, {282 name: 'Vintage Tyrolean',283 quality: 'Vintage',284 craftable: true,285 });286 });287288 it('Case #24', () => {289 const itemObject = parseString('Strange Haunted Hat');290291 assert.deepEqual(itemObject, {292 name: 'Haunted Hat',293 quality: 'Strange',294 craftable: true,295 });296 });297298 it('Case #25', () => {299 const itemObject = parseString('Strange Haunted Haunted Hat');300301 assert.deepEqual(itemObject, {302 name: 'Haunted Hat',303 quality: 'Haunted',304 elevated: true,305 craftable: true,306 });307 });308309 it('Case #26', () => {310 const itemObject = parseString('Haunted Hat');311312 assert.deepEqual(itemObject, {313 name: 'Haunted Hat',314 quality: 'Unique',315 craftable: true,316 });317 });318319 it('Case #27', () => {320 const itemObject = parseString('Haunted Haunted Hat');321322 assert.deepEqual(itemObject, {323 name: 'Haunted Hat',324 quality: 'Haunted',325 craftable: true,326 });327 });328329 it('Case #28', () => {330 const itemObject = parseString(331 'Eerie Orbiting Fire Condor Cap',332 false,333 false334 );335336 assert.deepEqual(itemObject, {337 name: 'Condor Cap',338 quality: 'Unusual',339 effect: 'Eerie Orbiting Fire',340 craftable: true,341 });342 });343344 it('Case #29', () => {345 const itemObject = parseString(346 'Haunted Ghosts War Paint (Battle Scarred)',347 false,348 false349 );350351 assert.deepEqual(itemObject, {352 name: 'War Paint',353 quality: 'Decorated Weapon',354 texture: 'Haunted Ghosts',355 craftable: true,356 wear: 'Battle Scarred',357 });358 });359360 it('Case #30', () => {361 const itemObject = parseString(362 'Spellbound Aspect Taunt: Most Wanted',363 false,364 false365 );366367 assert.deepEqual(itemObject, {368 name: 'Taunt: Most Wanted',369 quality: 'Unusual',370 effect: 'Spellbound Aspect',371 craftable: true,372 });373 });374375 it('Case #31', () => {376 const itemObject = parseString(377 'Haunted Phantasm Jr Bonk Boy',378 false,379 false380 );381382 assert.deepEqual(itemObject, {383 name: 'Bonk Boy',384 quality: 'Unusual',385 effect: 'Haunted Phantasm Jr',386 craftable: true,387 });388 });389390 it('Case #32', () => {391 const itemObject = parseString(392 'Ghastly Ghosts Jr Bonk Boy',393 false,394 false395 );396397 assert.deepEqual(itemObject, {398 name: 'Bonk Boy',399 quality: 'Unusual',400 effect: 'Ghastly Ghosts Jr',401 craftable: true,402 });403 });404405 it('Case #33', () => {406 const itemObject = parseString(407 'Haunted Ghosts Battle Boonie',408 false,409 false410 );411412 assert.deepEqual(itemObject, {413 name: 'Battle Boonie',414 quality: 'Unusual',415 effect: 'Haunted Ghosts',416 craftable: true,417 });418 });419420 it('Case #34', () => {421 const itemObject = parseString('Smoking Jacket', false, false);422423 assert.deepEqual(itemObject, {424 name: 'Smoking Jacket',425 craftable: true,426 quality: 'Unique',427 });428 });429430 it('Case #35', () => {431 const itemObject = parseString(432 'Smoking Smoking Skid Lid',433 false,434 false435 );436437 assert.deepEqual(itemObject, {438 name: 'Smoking Skid Lid',439 craftable: true,440 quality: 'Unusual',441 effect: 'Smoking',442 });443 });444445 it('Case #36', () => {446 const itemObject = parseString(447 'Purple Energy Smoking Skid Lid',448 false,449 false450 );451452 assert.deepEqual(itemObject, {453 name: 'Smoking Skid Lid',454 craftable: true,455 quality: 'Unusual',456 effect: 'Purple Energy',457 });458 });459460 it('Case #37', () => {461 const itemObject = parseString('Smoking Skid Lid', false, false);462463 assert.deepEqual(itemObject, {464 name: 'Smoking Skid Lid',465 craftable: true,466 quality: 'Unique',467 });468 });469470 it('Case #38', () => {471 const itemObject = parseString(472 'Strange Cosmetic Part: Kills',473 false,474 false475 );476477 assert.deepEqual(itemObject, {478 name: 'Strange Cosmetic Part: Kills',479 craftable: true,480 quality: 'Unique',481 });482 });483484 it('Case #39', () => {485 const itemObject = parseString('The Value of Teamwork', false, false);486487 assert.deepEqual(itemObject, {488 name: 'The Value of Teamwork',489 craftable: true,490 quality: 'Unique',491 });492 });493494 it('Case #40', () => {495 const itemObject = parseString(496 'The Essential Accessories',497 false,498 false499 );500501 assert.deepEqual(itemObject, {502 name: 'The Essential Accessories',503 craftable: true,504 quality: 'Unique',505 });506 });507508 it('Case #41', () => {509 const itemObject = parseString('Genuine Atomic Accolade', false, false);510511 assert.deepEqual(itemObject, {512 name: 'Atomic Accolade',513 craftable: true,514 quality: 'Genuine',515 });516 });517518 it('Case #42', () => {519 const itemObject = parseString('Bonk! Atomic Punch', false, false);520521 assert.deepEqual(itemObject, {522 name: 'Bonk! Atomic Punch',523 craftable: true,524 quality: 'Unique',525 });526 });527528 it('Case #43 - Item with native `The` with craft number', () => {529 const itemObject = parseString(530 'The Concealed Killer Weapons Case #93',531 false,532 false533 );534535 assert.deepEqual(itemObject, {536 name: 'The Concealed Killer Weapons Case',537 craftable: true,538 quality: 'Unique',539 itemNumber: { type: 'crate', value: 93 },540 });541 });542543 it('Case #44 - Old retired keys', () => {544 const itemObject = parseString(545 'Non-Craftable Naughty Winter Crate Key 2014',546 false,547 false548 );549550 assert.deepEqual(itemObject, {551 name: 'Naughty Winter Crate Key 2014',552 craftable: false,553 quality: 'Unique',554 });555 });556557 it('Case #45 - Munition case', () => {558 const itemObject = parseString(559 'Mann Co. Supply Munition #83',560 false,561 false562 );563564 assert.deepEqual(itemObject, {565 name: 'Mann Co. Supply Munition',566 craftable: true,567 quality: 'Unique',568 itemNumber: { value: 83, type: 'crate' },569 });570 });571572 it('Case #46 - Taunt: The Hot Wheeler', () => {573 const itemObject = parseString('Taunt: The Hot Wheeler', false, false);574575 assert.deepEqual(itemObject, {576 name: 'Taunt: The Hot Wheeler',577 craftable: true,578 quality: 'Unique',579 });580 });581});582583describe('parseString with numbers', () => {584 it('Case #1', () => {585 const itemObject = parseString(586 'Cool Killstreak Aqua Marine Rocket Launcher (Battle Scarred)',587 true,588 false589 );590591 assert.deepEqual(itemObject, {592 name: 'Rocket Launcher',593 craftable: true,594 killstreak: 1,595 wear: 5,596 texture: 57,597 effect: 703,598 quality: 5,599 });600 });601602 it('Case #2', () => {603 const itemObject = parseString(604 "Strange High Roller's Rocket Launcher (Factory New)",605 true,606 false607 );608609 assert.deepEqual(itemObject, {610 name: 'Rocket Launcher',611 craftable: true,612 wear: 1,613 texture: 79,614 quality: 11,615 });616 });617618 it('Case #3', () => {619 const itemObject = parseString(620 "Collector's Battalion's Backup Chemistry Set",621 true,622 false623 );624625 assert.deepEqual(itemObject, {626 name: 'Chemistry Set',627 craftable: true,628 output: "Battalion's Backup",629 outputQuality: 14,630 quality: 6,631 });632 });633634 it('Case #4', () => {635 const itemObject = parseString(636 'Strange Festivized Professional Killstreak Australium Scattergun',637 true,638 false639 );640641 assert.deepEqual(itemObject, {642 name: 'Scattergun',643 craftable: true,644 australium: true,645 festivized: true,646 killstreak: 3,647 quality: 11,648 });649 });650651 it('Case #5', () => {652 const itemObject = parseString(653 'Demonflame Modest Pile of Hat',654 true,655 false656 );657658 assert.deepEqual(itemObject, {659 name: 'Modest Pile of Hat',660 craftable: true,661 effect: 80,662 quality: 5,663 });664 });665666 it('Case #6', () => {667 const itemObject = parseString(668 'Strange Omniscient Orb Balloonihoodie',669 true,670 false671 );672673 assert.deepEqual(itemObject, {674 name: 'Balloonihoodie',675 craftable: true,676 effect: 120,677 quality: 5,678 elevated: true,679 });680 });681682 it('Case #7', () => {683 const itemObject = parseString(684 'Non-Craftable Specialized Killstreak Gunboats Kit Fabricator',685 true,686 false687 );688689 assert.deepEqual(itemObject, {690 name: 'Specialized Killstreak Kit Fabricator',691 craftable: false,692 killstreak: 2,693 target: 'Gunboats',694 quality: 6,695 });696 });697698 it('Case #8', () => {699 const itemObject = parseString(700 'Archimedes Strangifier Chemistry Set',701 true,702 false703 );704705 assert.deepEqual(itemObject, {706 name: 'Chemistry Set',707 craftable: true,708 target: 'Archimedes',709 output: 'Strangifier',710 outputQuality: 6,711 quality: 6,712 });713 });714715 it('Case #9', () => {716 const itemObject = parseString(717 'Strange Backwards Ballcap',718 true,719 false720 );721722 assert.deepEqual(itemObject, {723 name: 'Backwards Ballcap',724 craftable: true,725 quality: 11,726 });727 });728729 it('Case #10', () => {730 const itemObject = parseString(731 'Professional Killstreak Iron Curtain Kit Fabricator',732 true,733 false734 );735736 assert.deepEqual(itemObject, {737 name: 'Professional Killstreak Kit Fabricator',738 craftable: true,739 killstreak: 3,740 target: 'Iron Curtain',741 quality: 6,742 });743 });744745 it('Case #11', () => {746 const itemObject = parseString(747 'Strange Professional Killstreak Festive Grenade Launcher',748 true,749 false750 );751752 assert.deepEqual(itemObject, {753 name: 'Festive Grenade Launcher',754 craftable: true,755 killstreak: 3,756 quality: 11,757 });758 });759760 it('Case #12', () => {761 const itemObject = parseString(762 'Strange Unique Sniper Rifle',763 true,764 false765 );766767 assert.deepEqual(itemObject, {768 name: 'Sniper Rifle',769 craftable: true,770 quality: 6,771 elevated: true,772 });773 });774775 it('Case #13', () => {776 const itemObject = parseString('Australium Gold', true, false);777778 assert.deepEqual(itemObject, {779 name: 'Australium Gold',780 craftable: true,781 quality: 6,782 });783 });784785 it('Case #14', () => {786 const itemObject = parseString('Blue Moon Case #118', true, false);787788 assert.deepEqual(itemObject, {789 name: 'Blue Moon Case',790 craftable: true,791 itemNumber: { type: 'crate', value: 118 },792 quality: 6,793 });794 });795796 it('Case #15', () => {797 const itemObject = parseString('Hat #25', true, false);798799 assert.deepEqual(itemObject, {800 name: 'Hat',801 craftable: true,802 itemNumber: { type: 'craft', value: 25 },803 quality: 6,804 });805 });806807 it('Case #16', () => {808 const itemObject = parseString('The Tartan Shade', true, false);809810 assert.deepEqual(itemObject, {811 name: 'Tartan Shade',812 craftable: true,813 quality: 6,814 isUniqueHat: true,815 });816 });817818 it('Case #17', () => {819 const itemObject = parseString('Strange Cool Breeze', true, false);820821 assert.deepEqual(itemObject, {822 name: 'Cool Breeze',823 craftable: true,824 quality: 11,825 });826 });827828 it('Case #18', () => {829 const itemObject = parseString('Strange Hot Case', true, false);830831 assert.deepEqual(itemObject, {832 name: 'Hot Case',833 craftable: true,834 quality: 11,835 });836 });837838 it('Case #18', () => {839 const itemObject = parseString('Strange Hot Heels', true, false);840841 assert.deepEqual(itemObject, {842 name: 'Hot Heels',843 craftable: true,844 quality: 11,845 });846 });847848 it('Case #19', () => {849 const itemObject = parseString(850 'Strange A Head Full of Hot Air',851 true,852 false853 );854855 assert.deepEqual(itemObject, {856 name: 'A Head Full of Hot Air',857 craftable: true,858 quality: 11,859 });860 });861862 it('Case #20', () => {863 const itemObject = parseString('Strange Vintage Tyrolean', true, false);864865 assert.deepEqual(itemObject, {866 name: 'Vintage Tyrolean',867 quality: 11,868 craftable: true,869 });870 });871872 it('Case #21', () => {873 const itemObject = parseString(874 'Strange Vintage Vintage Tyrolean',875 true,876 false877 );878879 assert.deepEqual(itemObject, {880 name: 'Vintage Tyrolean',881 quality: 3,882 elevated: true,883 craftable: true,884 });885 });886887 it('Case #22', () => {888 const itemObject = parseString('Vintage Tyrolean', true, false);889890 assert.deepEqual(itemObject, {891 name: 'Vintage Tyrolean',892 quality: 6,893 craftable: true,894 });895 });896897 it('Case #23', () => {898 const itemObject = parseString('Vintage Vintage Tyrolean', true, false);899900 assert.deepEqual(itemObject, {901 name: 'Vintage Tyrolean',902 quality: 3,903 craftable: true,904 });905 });906907 it('Case #24', () => {908 const itemObject = parseString('Strange Haunted Hat', true, false);909910 assert.deepEqual(itemObject, {911 name: 'Haunted Hat',912 quality: 11,913 craftable: true,914 });915 });916917 it('Case #25', () => {918 const itemObject = parseString(919 'Strange Haunted Haunted Hat',920 true,921 false922 );923924 assert.deepEqual(itemObject, {925 name: 'Haunted Hat',926 quality: 13,927 elevated: true,928 craftable: true,929 });930 });931932 it('Case #26', () => {933 const itemObject = parseString('Haunted Hat', true, false);934935 assert.deepEqual(itemObject, {936 name: 'Haunted Hat',937 quality: 6,938 craftable: true,939 });940 });941942 it('Case #27', () => {943 const itemObject = parseString('Haunted Haunted Hat', true, false);944945 assert.deepEqual(itemObject, {946 name: 'Haunted Hat',947 quality: 13,948 craftable: true,949 });950 });951952 it('Case #28', () => {953 const itemObject = parseString(954 'Eerie Orbiting Fire Condor Cap',955 true,956 false957 );958959 assert.deepEqual(itemObject, {960 name: 'Condor Cap',961 quality: 5,962 effect: 40,963 craftable: true,964 });965 });966967 it('Case #29', () => {968 const itemObject = parseString(969 'Haunted Ghosts War Paint (Battle Scarred)',970 true,971 false972 );973974 assert.deepEqual(itemObject, {975 name: 'War Paint',976 quality: 15,977 texture: 236,978 craftable: true,979 wear: 5,980 });981 });982983 it('Case #30', () => {984 const itemObject = parseString(985 'Spellbound Aspect Taunt: Most Wanted',986 true,987 false988 );989990 assert.deepEqual(itemObject, {991 name: 'Taunt: Most Wanted',992 quality: 5,993 effect: 3043,994 craftable: true,995 });996 });997998 it('Case #31', () => {999 const itemObject = parseString(1000 'Haunted Phantasm Jr Bonk Boy',1001 true,1002 false1003 );10041005 assert.deepEqual(itemObject, {1006 name: 'Bonk Boy',1007 quality: 5,1008 effect: 86,1009 craftable: true,1010 });1011 });10121013 it('Case #32', () => {1014 const itemObject = parseString(1015 'Ghastly Ghosts Jr Bonk Boy',1016 true,1017 false1018 );10191020 assert.deepEqual(itemObject, {1021 name: 'Bonk Boy',1022 quality: 5,1023 effect: 85,1024 craftable: true,1025 });1026 });10271028 it('Case #33', () => {1029 const itemObject = parseString(1030 'Haunted Ghosts Battle Boonie',1031 true,1032 false1033 );10341035 assert.deepEqual(itemObject, {1036 name: 'Battle Boonie',1037 quality: 5,1038 effect: 8,1039 craftable: true,1040 });1041 });10421043 it('Case #34', () => {1044 const itemObject = parseString('Smoking Jacket', true, false);10451046 assert.deepEqual(itemObject, {1047 name: 'Smoking Jacket',1048 craftable: true,1049 quality: 6,1050 });1051 });10521053 it('Case #35', () => {1054 const itemObject = parseString('Smoking Smoking Skid Lid', true, false);10551056 assert.deepEqual(itemObject, {1057 name: 'Smoking Skid Lid',1058 craftable: true,1059 quality: 5,1060 effect: 35,1061 });1062 });10631064 it('Case #36', () => {1065 const itemObject = parseString(1066 'Purple Energy Smoking Skid Lid',1067 true,1068 false1069 );10701071 assert.deepEqual(itemObject, {1072 name: 'Smoking Skid Lid',1073 craftable: true,1074 quality: 5,1075 effect: 10,1076 });1077 });10781079 it('Case #37', () => {1080 const itemObject = parseString('Smoking Skid Lid', true, false);10811082 assert.deepEqual(itemObject, {1083 name: 'Smoking Skid Lid',1084 craftable: true,1085 quality: 6,1086 });1087 });10881089 it('Case #38', () => {1090 const itemObject = parseString(1091 'Strange Cosmetic Part: Kills',1092 true,1093 false1094 );10951096 assert.deepEqual(itemObject, {1097 name: 'Strange Cosmetic Part: Kills',1098 craftable: true,1099 quality: 6,1100 });1101 });11021103 it('Case #39', () => {1104 const itemObject = parseString('The Value of Teamwork', true, false);11051106 assert.deepEqual(itemObject, {1107 name: 'The Value of Teamwork',1108 craftable: true,1109 quality: 6,1110 });1111 });11121113 it('Case #40', () => {1114 const itemObject = parseString(1115 'The Essential Accessories',1116 true,1117 false1118 );11191120 assert.deepEqual(itemObject, {1121 name: 'The Essential Accessories',1122 craftable: true,1123 quality: 6,1124 });1125 });11261127 it('Case #41', () => {1128 const itemObject = parseString('Genuine Atomic Accolade', true, false);11291130 assert.deepEqual(itemObject, {1131 name: 'Atomic Accolade',1132 craftable: true,1133 quality: 1,1134 });1135 });11361137 it('Case #42', () => {1138 const itemObject = parseString('Bonk! Atomic Punch', true, false);11391140 assert.deepEqual(itemObject, {1141 name: 'Bonk! Atomic Punch',1142 craftable: true,1143 quality: 6,1144 });1145 });11461147 it('Case #43 - Item with native `The` with craft number', () => {1148 const itemObject = parseString(1149 'The Concealed Killer Weapons Case #93',1150 true,1151 false1152 );11531154 assert.deepEqual(itemObject, {1155 name: 'The Concealed Killer Weapons Case',1156 craftable: true,1157 quality: 6,1158 itemNumber: { type: 'crate', value: 93 },1159 });1160 });11611162 it('Case #44 - Old retired keys', () => {1163 const itemObject = parseString(1164 'Non-Craftable Naughty Winter Crate Key 2014',1165 true,1166 false1167 );11681169 assert.deepEqual(itemObject, {1170 name: 'Naughty Winter Crate Key 2014',1171 craftable: false,1172 quality: 6,1173 });1174 });11751176 it('Case #45 - Munition case', () => {1177 const itemObject = parseString(1178 'Mann Co. Supply Munition #83',1179 true,1180 false1181 );11821183 assert.deepEqual(itemObject, {1184 name: 'Mann Co. Supply Munition',1185 craftable: true,1186 quality: 6,1187 itemNumber: { value: 83, type: 'crate' },1188 });1189 });11901191 it('Case #46 - Red Rock Roscoe Texture', () => {1192 class MockSchema extends Schema {1193 getTextureEnum() {1194 this.loadTextures();11951196 return 0;1197 }1198 }11991200 const format = createFormat(new MockSchema());12011202 const itemObject = format.parseString(1203 'Festivized Specialized Killstreak Red Rock Roscoe Pistol (Field-Tested)',1204 true,1205 false1206 );1207 assert.deepEqual(itemObject, {1208 name: 'Pistol',1209 quality: 15,1210 wear: 3,1211 festivized: true,1212 killstreak: 2,1213 texture: 0,1214 craftable: true,1215 });1216 });1217});12181219describe('parseString with defindexes and numbers.', () => {1220 it('Case #1', () => {1221 const itemObject = parseString(1222 'Cool Killstreak Aqua Marine Rocket Launcher (Battle Scarred)',1223 true,1224 true1225 );12261227 assert.deepEqual(itemObject, {1228 name: 'Rocket Launcher',1229 craftable: true,1230 killstreak: 1,1231 wear: 5,1232 texture: 57,1233 effect: 703,1234 quality: 5,1235 defindex: 205,1236 });1237 });12381239 it('Case #2', () => {1240 const itemObject = parseString(1241 "Strange High Roller's Rocket Launcher (Factory New)",1242 true,1243 true1244 );12451246 assert.deepEqual(itemObject, {1247 name: 'Rocket Launcher',1248 craftable: true,1249 wear: 1,1250 texture: 79,1251 quality: 11,1252 defindex: 205,1253 });1254 });1255 /*1256 it('Case #3', () => {1257 const itemObject = parseString(1258 "Collector's Battalion's Backup Chemistry Set",1259 true, true1260 );12611262 assert.deepEqual(itemObject, {1263 name: 'Chemistry Set',1264 craftable: true,1265 output: "Battalion's Backup",1266 outputQuality: 14,1267 quality: 6,1268 outputDefindex: 226,1269 defindex: 20000,1270 });1271 });1272 */1273 it('Case #4', () => {1274 const itemObject = parseString(1275 'Strange Festivized Professional Killstreak Australium Scattergun',1276 true,1277 true1278 );12791280 assert.deepEqual(itemObject, {1281 name: 'Scattergun',1282 craftable: true,1283 australium: true,1284 festivized: true,1285 killstreak: 3,1286 quality: 11,1287 defindex: 200,1288 });1289 });12901291 it('Case #5', () => {1292 const itemObject = parseString(1293 'Demonflame Modest Pile of Hat',1294 true,1295 true1296 );12971298 assert.deepEqual(itemObject, {1299 name: 'Modest Pile of Hat',1300 craftable: true,1301 effect: 80,1302 quality: 5,1303 defindex: 139,1304 });1305 });13061307 it('Case #6', () => {1308 const itemObject = parseString(1309 'Strange Omniscient Orb Balloonihoodie',1310 true,1311 true1312 );13131314 assert.deepEqual(itemObject, {1315 name: 'Balloonihoodie',1316 craftable: true,1317 effect: 120,1318 quality: 5,1319 elevated: true,1320 defindex: 30928,1321 });1322 });13231324 it('Case #7', () => {1325 const itemObject = parseString(1326 'Non-Craftable Specialized Killstreak Gunboats Kit Fabricator',1327 true,1328 true1329 );13301331 assert.deepEqual(itemObject, {1332 name: 'Specialized Killstreak Kit Fabricator',1333 defindex: 'HERE',1334 craftable: false,1335 killstreak: 2,1336 target: 'Gunboats',1337 quality: 6,1338 targetDefindex: 133,1339 defindex: 20002,1340 });1341 });13421343 it('Case #8', () => {1344 const itemObject = parseString(1345 'Archimedes Strangifier Chemistry Set',1346 true,1347 true1348 );13491350 assert.deepEqual(itemObject, {1351 name: 'Chemistry Set',1352 craftable: true,1353 target: 'Archimedes',1354 output: 'Strangifier',1355 outputQuality: 6,1356 quality: 6,1357 targetDefindex: 828,1358 outputDefindex: 5661,1359 defindex: 20005,1360 });1361 });13621363 it('Case #9', () => {1364 const itemObject = parseString('Strange Backwards Ballcap', true, true);13651366 assert.deepEqual(itemObject, {1367 name: 'Backwards Ballcap',1368 craftable: true,1369 quality: 11,1370 defindex: 617,1371 });1372 });13731374 it('Case #10', () => {1375 const itemObject = parseString(1376 'Professional Killstreak Iron Curtain Kit Fabricator',1377 true,1378 true1379 );13801381 assert.deepEqual(itemObject, {1382 name: 'Professional Killstreak Kit Fabricator',1383 craftable: true,1384 killstreak: 3,1385 target: 'Iron Curtain',1386 quality: 6,1387 targetDefindex: 298,1388 defindex: 20003,1389 });1390 });13911392 it('Case #11', () => {1393 const itemObject = parseString(1394 'Strange Professional Killstreak Festive Grenade Launcher',1395 true,1396 true1397 );13981399 assert.deepEqual(itemObject, {1400 name: 'Festive Grenade Launcher',1401 craftable: true,1402 killstreak: 3,1403 quality: 11,1404 defindex: 1007,1405 });1406 });14071408 it('Case #12', () => {1409 const itemObject = parseString(1410 'Strange Unique Sniper Rifle',1411 true,1412 true1413 );14141415 assert.deepEqual(itemObject, {1416 name: 'Sniper Rifle',1417 craftable: true,1418 quality: 6,1419 elevated: true,1420 defindex: 201,1421 });1422 });14231424 it('Case #13', () => {1425 const itemObject = parseString('Australium Gold', true, true);14261427 assert.deepEqual(itemObject, {1428 name: 'Australium Gold',1429 craftable: true,1430 quality: 6,1431 defindex: 5037,1432 });1433 });14341435 it('Case #14', () => {1436 const itemObject = parseString('Blue Moon Case #118', true, true);14371438 assert.deepEqual(itemObject, {1439 name: 'Blue Moon Case',1440 craftable: true,1441 itemNumber: { type: 'crate', value: 118 },1442 quality: 6,1443 });1444 });14451446 it('Case #15', () => {1447 const itemObject = parseString('The Tartan Shade', true, true);14481449 assert.deepEqual(itemObject, {1450 name: 'Tartan Shade',1451 craftable: true,1452 quality: 6,1453 isUniqueHat: true,1454 defindex: 30064,1455 });1456 });14571458 it('Case #16', () => {1459 const itemObject = parseString('Strange Cool Breeze', true, true);14601461 assert.deepEqual(itemObject, {1462 name: 'Cool Breeze',1463 craftable: true,1464 quality: 11,1465 defindex: 979,1466 });1467 });14681469 it('Case #17', () => {1470 const itemObject = parseString('Strange Hot Case', true, true);14711472 assert.deepEqual(itemObject, {1473 name: 'Hot Case',1474 craftable: true,1475 quality: 11,1476 defindex: 30986,1477 });1478 });14791480 it('Case #18', () => {1481 const itemObject = parseString('Strange Hot Heels', true, true);14821483 assert.deepEqual(itemObject, {1484 name: 'Hot Heels',1485 craftable: true,1486 quality: 11,1487 defindex: 30754,1488 });1489 });14901491 it('Case #19', () => {1492 const itemObject = parseString(1493 'Strange A Head Full of Hot Air',1494 true,1495 true1496 );14971498 assert.deepEqual(itemObject, {1499 name: 'A Head Full of Hot Air',1500 craftable: true,1501 quality: 11,1502 defindex: 30662,1503 });1504 });15051506 it('Case #20', () => {1507 const itemObject = parseString(1508 'Taunt: Kazotsky Kick Unusualifier',1509 true,1510 true1511 );15121513 assert.deepEqual(itemObject, {1514 name: 'Unusualifier',1515 craftable: true,1516 quality: 5,1517 defindex: 9258,1518 target: 'Taunt: Kazotsky Kick',1519 targetDefindex: 1157,1520 });1521 });15221523 it('Case #21', () => {1524 const itemObject = parseString('Ghostly Gibus Strangifier', true, true);15251526 assert.deepEqual(itemObject, {1527 name: 'Strangifier',1528 craftable: true,1529 quality: 6,1530 defindex: 5661,1531 target: 'Ghostly Gibus',1532 targetDefindex: 940,1533 });1534 });15351536 it('Case #22', () => {1537 const itemObject = parseString('Strange Bacon Grease', true, true);15381539 assert.deepEqual(itemObject, {1540 name: 'Strange Bacon Grease',1541 craftable: true,1542 quality: 6,1543 defindex: 5633,1544 });1545 });15461547 it('Case #23', () => {1548 const itemObject = parseString('Strange Vintage Tyrolean', true, true);15491550 assert.deepEqual(itemObject, {1551 name: 'Vintage Tyrolean',1552 quality: 11,1553 craftable: true,1554 defindex: 101,1555 });1556 });15571558 it('Case #24', () => {1559 const itemObject = parseString(1560 'Strange Vintage Vintage Tyrolean',1561 true,1562 true1563 );15641565 assert.deepEqual(itemObject, {1566 name: 'Vintage Tyrolean',1567 quality: 3,1568 elevated: true,1569 craftable: true,1570 defindex: 101,1571 });1572 });15731574 it('Case #25', () => {1575 const itemObject = parseString('Vintage Tyrolean', true, true);15761577 assert.deepEqual(itemObject, {1578 name: 'Vintage Tyrolean',1579 quality: 6,1580 craftable: true,1581 defindex: 101,1582 });1583 });15841585 it('Case #26', () => {1586 const itemObject = parseString('Vintage Vintage Tyrolean', true, true);15871588 assert.deepEqual(itemObject, {1589 name: 'Vintage Tyrolean',1590 quality: 3,1591 craftable: true,1592 defindex: 101,1593 });1594 });15951596 it('Case #27', () => {1597 const itemObject = parseString('Strange Haunted Hat', true, true);15981599 assert.deepEqual(itemObject, {1600 name: 'Haunted Hat',1601 quality: 11,1602 craftable: true,1603 defindex: 30300,1604 });1605 });16061607 it('Case #28', () => {1608 const itemObject = parseString(1609 'Strange Haunted Haunted Hat',1610 true,1611 true1612 );16131614 assert.deepEqual(itemObject, {1615 name: 'Haunted Hat',1616 quality: 13,1617 elevated: true,1618 craftable: true,1619 defindex: 30300,1620 });1621 });16221623 it('Case #29', () => {1624 const itemObject = parseString('Haunted Hat', true, true);16251626 assert.deepEqual(itemObject, {1627 name: 'Haunted Hat',1628 quality: 6,1629 craftable: true,1630 defindex: 30300,1631 });1632 });16331634 it('Case #30', () => {1635 const itemObject = parseString('Haunted Haunted Hat', true, true);16361637 assert.deepEqual(itemObject, {1638 name: 'Haunted Hat',1639 defindex: 30300,1640 quality: 13,1641 craftable: true,1642 });1643 });16441645 it('Case #31', () => {1646 const itemObject = parseString(1647 'Eerie Orbiting Fire Condor Cap',1648 true,1649 true1650 );16511652 assert.deepEqual(itemObject, {1653 name: 'Condor Cap',1654 quality: 5,1655 effect: 40,1656 craftable: true,1657 defindex: 30553,1658 });1659 });16601661 it('Case #32', () => {1662 const itemObject = parseString(1663 'Haunted Ghosts War Paint (Battle Scarred)',1664 true,1665 true1666 );16671668 assert.deepEqual(itemObject, {1669 name: 'War Paint',1670 quality: 15,1671 texture: 236,1672 craftable: true,1673 wear: 5,1674 defindex: 9536,1675 });1676 });16771678 it('Case #33', () => {1679 const itemObject = parseString(1680 'Spellbound Aspect Taunt: Most Wanted',1681 true,1682 true1683 );16841685 assert.deepEqual(itemObject, {1686 name: 'Taunt: Most Wanted',1687 quality: 5,1688 effect: 3043,1689 craftable: true,1690 defindex: 30614,1691 });1692 });16931694 it('Case #34', () => {1695 const itemObject = parseString(1696 'Haunted Phantasm Jr Bonk Boy',1697 true,1698 true1699 );17001701 assert.deepEqual(itemObject, {1702 name: 'Bonk Boy',1703 quality: 5,1704 effect: 86,1705 craftable: true,1706 defindex: 451,1707 });1708 });17091710 it('Case #35', () => {1711 const itemObject = parseString(1712 'Ghastly Ghosts Jr Bonk Boy',1713 true,1714 true1715 );17161717 assert.deepEqual(itemObject, {1718 name: 'Bonk Boy',1719 defindex: 451,1720 quality: 5,1721 effect: 85,1722 craftable: true,1723 });1724 });17251726 it('Case #36', () => {1727 const itemObject = parseString(1728 'Haunted Ghosts Battle Boonie',1729 true,1730 true1731 );17321733 assert.deepEqual(itemObject, {1734 name: 'Battle Boonie',1735 quality: 5,1736 effect: 8,1737 craftable: true,1738 defindex: 30907,1739 });1740 });17411742 it('Case #37', () => {1743 const itemObject = parseString('Smoking Jacket', true, true);17441745 assert.deepEqual(itemObject, {1746 name: 'Smoking Jacket',1747 craftable: true,1748 quality: 6,1749 defindex: 31124,1750 });1751 });17521753 it('Case #38', () => {1754 const itemObject = parseString('Smoking Smoking Skid Lid', true, true);17551756 assert.deepEqual(itemObject, {1757 name: 'Smoking Skid Lid',1758 craftable: true,1759 quality: 5,1760 effect: 35,1761 defindex: 30399,1762 });1763 });17641765 it('Case #39', () => {1766 const itemObject = parseString(1767 'Purple Energy Smoking Skid Lid',1768 true,1769 true1770 );17711772 assert.deepEqual(itemObject, {1773 name: 'Smoking Skid Lid',1774 craftable: true,1775 quality: 5,1776 effect: 10,1777 defindex: 30399,1778 });1779 });17801781 it('Case #40', () => {1782 const itemObject = parseString('Smoking Skid Lid', true, true);17831784 assert.deepEqual(itemObject, {1785 name: 'Smoking Skid Lid',1786 craftable: true,1787 quality: 6,1788 defindex: 30399,1789 });1790 });17911792 it('Case #41', () => {1793 const itemObject = parseString(1794 'Strange Cosmetic Part: Kills',1795 true,1796 true1797 );17981799 assert.deepEqual(itemObject, {1800 name: 'Strange Cosmetic Part: Kills',1801 craftable: true,1802 quality: 6,1803 defindex: 6060,1804 });1805 });18061807 it('Case #42', () => {1808 const itemObject = parseString('The Value of Teamwork', true, true);18091810 assert.deepEqual(itemObject, {1811 name: 'The Value of Teamwork',1812 craftable: true,1813 quality: 6,1814 defindex: 5064,1815 });1816 });18171818 it('Case #43', () => {1819 const itemObject = parseString('The Essential Accessories', true, true);18201821 assert.deepEqual(itemObject, {1822 name: 'The Essential Accessories',1823 craftable: true,1824 quality: 6,1825 defindex: 347,1826 });1827 });18281829 it('Case #44', () => {1830 const itemObject = parseString('Genuine Atomic Accolade', true, true);18311832 assert.deepEqual(itemObject, {1833 name: 'Atomic Accolade',1834 defindex: 767,1835 craftable: true,1836 quality: 1,1837 });1838 });18391840 it('Case #45', () => {1841 const itemObject = parseString('Bonk! Atomic Punch', true, true);18421843 assert.deepEqual(itemObject, {1844 name: 'Bonk! Atomic Punch',1845 defindex: 46,1846 craftable: true,1847 quality: 6,1848 });1849 });18501851 it('Case #46 - The Value of Teamwork', () => {1852 const itemObject = parseString('The Value of Teamwork', true, true);18531854 assert.deepEqual(itemObject, {1855 name: 'The Value of Teamwork',1856 quality: 6,1857 craftable: true,1858 defindex: 5064,1859 });1860 });18611862 it('Case #47 - The Bitter Taste of Defeat and Lime', () => {1863 const itemObject = parseString(1864 'The Bitter Taste of Defeat and Lime',1865 true,1866 true1867 );18681869 assert.deepEqual(itemObject, {1870 name: 'The Bitter Taste of Defeat and Lime',1871 quality: 6,1872 craftable: true,1873 defindex: 5054,1874 });1875 });18761877 it('Case #48 - Item with native `The` with craft number', () => {1878 const itemObject = parseString(1879 'The Concealed Killer Weapons Case #93',1880 true,1881 true1882 );18831884 assert.deepEqual(itemObject, {1885 name: 'The Concealed Killer Weapons Case',1886 craftable: true,1887 quality: 6,1888 defindex: 5806,1889 itemNumber: { type: 'crate', value: 93 },1890 });1891 });18921893 it('Case #49 - Old retired keys', () => {1894 const itemObject = parseString(1895 'Non-Craftable Naughty Winter Crate Key 2014',1896 true,1897 true1898 );18991900 assert.deepEqual(itemObject, {1901 name: 'Naughty Winter Crate Key 2014',1902 craftable: false,1903 quality: 6,1904 defindex: 5791,1905 });1906 });19071908 it('Case #50 - Munition case', () => {1909 const itemObject = parseString(1910 'Mann Co. Supply Munition #83',1911 true,1912 true1913 );19141915 assert.deepEqual(itemObject, {1916 name: 'Mann Co. Supply Munition',1917 defindex: 5734,1918 craftable: true,1919 quality: 6,1920 itemNumber: { value: 83, type: 'crate' },1921 });1922 });19231924 it('Case #51 - Bat', () => {1925 class MockSchema extends Schema {1926 getDefindex() {1927 return 0;1928 }1929 }19301931 const format = createFormat(new MockSchema());19321933 const itemObject = format.parseString('Bat', true, true);1934 assert.deepEqual(itemObject, {1935 name: 'Bat',1936 quality: 6,1937 defindex: 0,1938 craftable: true,1939 });1940 });19411942 it('Case #52 - Bat output', () => {1943 class MockSchema extends Schema {1944 getDefindex(input) {1945 if (input === 'Bat') {1946 return 0;1947 }19481949 return super.getDefindex(input);1950 }1951 }19521953 const format = createFormat(new MockSchema());19541955 const itemObject = format.parseString(1956 "Collector's Bat Chemistry Set",1957 true,1958 true1959 );1960 assert.deepEqual(itemObject, {1961 name: 'Chemistry Set',1962 quality: 6,1963 defindex: 20005,1964 craftable: true,1965 output: 'Bat',1966 outputDefindex: 0,1967 outputQuality: 14,1968 });1969 });19701971 it('Case #52 - Bat target', () => {1972 class MockSchema extends Schema {1973 getDefindex(input) {1974 if (input === 'Bat') {1975 return 0;1976 }19771978 return super.getDefindex(input);1979 }1980 }19811982 const format = createFormat(new MockSchema());19831984 const itemObject = format.parseString(1985 'Non-Craftable Specialized Killstreak Bat Kit Fabricator',1986 true,1987 true1988 );1989 assert.deepEqual(itemObject, {1990 name: 'Specialized Killstreak Kit Fabricator',1991 quality: 6,1992 defindex: 20002,1993 craftable: false,1994 killstreak: 2,1995 target: 'Bat',1996 targetDefindex: 0,1997 });1998 });19992000 it('Case #53 - Accursed Apparition', () => {2001 const itemObject = parseString('Accursed Apparition', true, true);2002 assert.deepEqual(itemObject, {2003 name: 'Accursed Apparition',2004 quality: 6,2005 craftable: true,2006 defindex: 30206,2007 });2008 });20092010 it('Case #54 - Unusual Haunted Metal Scrap', () => {2011 const itemObject = parseString('Unusual Haunted Metal Scrap', true, true);2012 assert.deepEqual(itemObject, {2013 name: 'Haunted Metal Scrap',2014 quality: 5,2015 craftable: true,2016 defindex: 267,2017 });2018 });20192020 it('Case #55 - Strange Normal Medi Gun', () => {2021 const itemObject = parseString('Strange Normal Medi Gun', true, true);2022 assert.deepEqual(itemObject, {2023 name: 'Medi Gun',2024 quality: 0,2025 craftable: true,2026 defindex: 211,2027 elevated: true,2028 });2029 }); ...

Full Screen

Full Screen

colorStrings.spec.js

Source:colorStrings.spec.js Github

copy

Full Screen

1import ColorStrings from '../src/colorStrings'2function parseString(string, match, parse) {3 const matched = match.exec(string)4 if (matched !== null) {5 return parse(matched)6 }7 return false8}9describe('ColorStrings', () => {10 describe('RGB', () => {11 test('should parse rgb', () => {12 expect(13 parseString(14 'rgb(100, 150, 200)',15 ColorStrings.RGB.match,16 ColorStrings.RGB.parse17 )18 ).toEqual({19 r: 100,20 g: 150,21 b: 200,22 a: 123 })24 expect(25 parseString(26 'rgba(100, 150, 200, 1)',27 ColorStrings.RGB.match,28 ColorStrings.RGB.parse29 )30 ).toEqual(false)31 expect(32 parseString(33 'hsl(0, 100%, 50%)',34 ColorStrings.RGB.match,35 ColorStrings.RGB.parse36 )37 ).toEqual(false)38 expect(39 parseString(40 'hsla(0, 100%, 50%, 1)',41 ColorStrings.RGB.match,42 ColorStrings.RGB.parse43 )44 ).toEqual(false)45 expect(46 parseString(47 'transparent',48 ColorStrings.RGB.match,49 ColorStrings.RGB.parse50 )51 ).toEqual(false)52 expect(53 parseString('#ffffff', ColorStrings.RGB.match, ColorStrings.RGB.parse)54 ).toEqual(false)55 expect(56 parseString('white', ColorStrings.RGB.match, ColorStrings.RGB.parse)57 ).toEqual(false)58 })59 test('should convent to rgb', () => {60 expect(61 ColorStrings.RGB.to({62 r: 100,63 g: 150,64 b: 200,65 a: 166 })67 ).toEqual('rgb(100, 150, 200)')68 })69 })70 describe('RGBA', () => {71 test('should parse rgba', () => {72 expect(73 parseString(74 'rgba(100, 150, 200, 0.1)',75 ColorStrings.RGBA.match,76 ColorStrings.RGBA.parse77 )78 ).toEqual({79 r: 100,80 g: 150,81 b: 200,82 a: 0.183 })84 expect(85 parseString(86 'rgba(100, 150, 200, 10%)',87 ColorStrings.RGBA.match,88 ColorStrings.RGBA.parse89 )90 ).toEqual({91 r: 100,92 g: 150,93 b: 200,94 a: 0.195 })96 expect(97 parseString(98 'rgb(100, 150, 200)',99 ColorStrings.RGBA.match,100 ColorStrings.RGBA.parse101 )102 ).toEqual(false)103 expect(104 parseString(105 'hsl(0, 100%, 50%)',106 ColorStrings.RGBA.match,107 ColorStrings.RGBA.parse108 )109 ).toEqual(false)110 expect(111 parseString(112 'hsla(0, 100%, 50%, 1)',113 ColorStrings.RGBA.match,114 ColorStrings.RGBA.parse115 )116 ).toEqual(false)117 expect(118 parseString(119 'transparent',120 ColorStrings.RGBA.match,121 ColorStrings.RGBA.parse122 )123 ).toEqual(false)124 expect(125 parseString('#ffffff', ColorStrings.RGBA.match, ColorStrings.RGBA.parse)126 ).toEqual(false)127 expect(128 parseString('white', ColorStrings.RGBA.match, ColorStrings.RGBA.parse)129 ).toEqual(false)130 })131 test('should convent to rgba', () => {132 expect(133 ColorStrings.RGBA.to({134 r: 100,135 g: 150,136 b: 200,137 a: 0.5138 })139 ).toEqual('rgba(100, 150, 200, 0.5)')140 })141 })142 describe('HSL', () => {143 test('should parse hsl', () => {144 expect(145 parseString(146 'hsl(0, 100%, 50%)',147 ColorStrings.HSL.match,148 ColorStrings.HSL.parse149 )150 ).toEqual({151 r: 255,152 g: 0,153 b: 0,154 a: 1155 })156 expect(157 parseString(158 'hsl(480, 1, 0.5)',159 ColorStrings.HSL.match,160 ColorStrings.HSL.parse161 )162 ).toEqual({163 r: 0,164 g: 255,165 b: 0,166 a: 1167 })168 expect(169 parseString(170 'rgb(100, 150, 200)',171 ColorStrings.HSL.match,172 ColorStrings.HSL.parse173 )174 ).toEqual(false)175 expect(176 parseString(177 'rgba(100, 150, 200, 0.1)',178 ColorStrings.HSL.match,179 ColorStrings.HSL.parse180 )181 ).toEqual(false)182 expect(183 parseString(184 'hsla(0, 100%, 50%, 1)',185 ColorStrings.HSL.match,186 ColorStrings.HSL.parse187 )188 ).toEqual(false)189 expect(190 parseString(191 'transparent',192 ColorStrings.HSL.match,193 ColorStrings.HSL.parse194 )195 ).toEqual(false)196 expect(197 parseString('#ffffff', ColorStrings.HSL.match, ColorStrings.HSL.parse)198 ).toEqual(false)199 expect(200 parseString('white', ColorStrings.HSL.match, ColorStrings.HSL.parse)201 ).toEqual(false)202 })203 test('should convent to hsl', () => {204 expect(205 ColorStrings.HSL.to({206 r: 255,207 g: 0,208 b: 0,209 a: 0.5210 })211 ).toEqual('hsl(0, 100%, 50%)')212 })213 })214 describe('HSLA', () => {215 test('should parse hsl', () => {216 expect(217 parseString(218 'hsla(0, 100%, 50%, 50%)',219 ColorStrings.HSLA.match,220 ColorStrings.HSLA.parse221 )222 ).toEqual({223 r: 255,224 g: 0,225 b: 0,226 a: 0.5227 })228 expect(229 parseString(230 'hsla(480, 1, 0.5, 0.5)',231 ColorStrings.HSLA.match,232 ColorStrings.HSLA.parse233 )234 ).toEqual({235 r: 0,236 g: 255,237 b: 0,238 a: 0.5239 })240 expect(241 parseString(242 'rgb(100, 150, 200)',243 ColorStrings.HSLA.match,244 ColorStrings.HSLA.parse245 )246 ).toEqual(false)247 expect(248 parseString(249 'rgba(100, 150, 200, 0.1)',250 ColorStrings.HSLA.match,251 ColorStrings.HSLA.parse252 )253 ).toEqual(false)254 expect(255 parseString(256 'hsl(0, 100%, 50%)',257 ColorStrings.HSLA.match,258 ColorStrings.HSLA.parse259 )260 ).toEqual(false)261 expect(262 parseString(263 'transparent',264 ColorStrings.HSLA.match,265 ColorStrings.HSLA.parse266 )267 ).toEqual(false)268 expect(269 parseString('#ffffff', ColorStrings.HSLA.match, ColorStrings.HSLA.parse)270 ).toEqual(false)271 expect(272 parseString('white', ColorStrings.HSLA.match, ColorStrings.HSLA.parse)273 ).toEqual(false)274 })275 test('should convent to hsla', () => {276 expect(277 ColorStrings.HSLA.to({278 r: 255,279 g: 0,280 b: 0,281 a: 0.5282 })283 ).toEqual('hsla(0, 100%, 50%, 0.5)')284 })285 })286 describe('HEX', () => {287 test('should parse hex', () => {288 expect(289 parseString('#ff0000', ColorStrings.HEX.match, ColorStrings.HEX.parse)290 ).toEqual({291 r: 255,292 g: 0,293 b: 0,294 a: 1295 })296 expect(297 parseString('#fff', ColorStrings.HEX.match, ColorStrings.HEX.parse)298 ).toEqual({299 r: 255,300 g: 255,301 b: 255,302 a: 1303 })304 expect(305 parseString(306 'rgb(100, 150, 200)',307 ColorStrings.HEX.match,308 ColorStrings.HEX.parse309 )310 ).toEqual(false)311 expect(312 parseString(313 'rgba(100, 150, 200, 0.1)',314 ColorStrings.HEX.match,315 ColorStrings.HEX.parse316 )317 ).toEqual(false)318 expect(319 parseString(320 'hsl(0, 100%, 50%)',321 ColorStrings.HEX.match,322 ColorStrings.HEX.parse323 )324 ).toEqual(false)325 expect(326 parseString(327 'hsla(0, 100%, 50%, 0.1)',328 ColorStrings.HEX.match,329 ColorStrings.HEX.parse330 )331 ).toEqual(false)332 expect(333 parseString(334 'transparent',335 ColorStrings.HEX.match,336 ColorStrings.HEX.parse337 )338 ).toEqual(false)339 expect(340 parseString('white', ColorStrings.HEX.match, ColorStrings.HEX.parse)341 ).toEqual(false)342 })343 test('should convent to hex', () => {344 expect(345 ColorStrings.HEX.to({346 r: 255,347 g: 0,348 b: 0,349 a: 1350 })351 ).toEqual('#ff0000')352 })353 })354 describe('TRANSPARENT', () => {355 test('should parse transparent', () => {356 expect(357 parseString(358 'transparent',359 ColorStrings.TRANSPARENT.match,360 ColorStrings.TRANSPARENT.parse361 )362 ).toEqual({363 r: 0,364 g: 0,365 b: 0,366 a: 0367 })368 expect(369 parseString(370 'TRANSPARENT',371 ColorStrings.TRANSPARENT.match,372 ColorStrings.TRANSPARENT.parse373 )374 ).toEqual({375 r: 0,376 g: 0,377 b: 0,378 a: 0379 })380 expect(381 parseString(382 'rgb(100, 150, 200)',383 ColorStrings.TRANSPARENT.match,384 ColorStrings.TRANSPARENT.parse385 )386 ).toEqual(false)387 expect(388 parseString(389 'rgba(100, 150, 200, 0.1)',390 ColorStrings.TRANSPARENT.match,391 ColorStrings.TRANSPARENT.parse392 )393 ).toEqual(false)394 expect(395 parseString(396 'hsl(0, 100%, 50%)',397 ColorStrings.TRANSPARENT.match,398 ColorStrings.TRANSPARENT.parse399 )400 ).toEqual(false)401 expect(402 parseString(403 'hsla(0, 100%, 50%, 0.1)',404 ColorStrings.TRANSPARENT.match,405 ColorStrings.TRANSPARENT.parse406 )407 ).toEqual(false)408 expect(409 parseString(410 '#ff0000',411 ColorStrings.TRANSPARENT.match,412 ColorStrings.TRANSPARENT.parse413 )414 ).toEqual(false)415 expect(416 parseString(417 'white',418 ColorStrings.TRANSPARENT.match,419 ColorStrings.TRANSPARENT.parse420 )421 ).toEqual(false)422 })423 test('should convent to transparent', () => {424 expect(425 ColorStrings.TRANSPARENT.to({426 r: 0,427 g: 0,428 b: 0,429 a: 0430 })431 ).toEqual('transparent')432 })433 })434 describe('NAME', () => {435 test('should parse color name', () => {436 expect(437 parseString('white', ColorStrings.NAME.match, ColorStrings.NAME.parse)438 ).toEqual({439 r: 255,440 g: 255,441 b: 255,442 a: 1443 })444 expect(445 parseString('yellow', ColorStrings.NAME.match, ColorStrings.NAME.parse)446 ).toEqual({447 r: 255,448 g: 255,449 b: 0,450 a: 1451 })452 expect(453 parseString(454 'rgb(100, 150, 200)',455 ColorStrings.NAME.match,456 ColorStrings.NAME.parse457 )458 ).toEqual(false)459 expect(460 parseString(461 'rgba(100, 150, 200, 0.1)',462 ColorStrings.NAME.match,463 ColorStrings.NAME.parse464 )465 ).toEqual(false)466 expect(467 parseString(468 'hsl(0, 100%, 50%)',469 ColorStrings.NAME.match,470 ColorStrings.NAME.parse471 )472 ).toEqual(false)473 expect(474 parseString(475 'hsla(0, 100%, 50%, 0.1)',476 ColorStrings.NAME.match,477 ColorStrings.NAME.parse478 )479 ).toEqual(false)480 expect(481 parseString('#ff0000', ColorStrings.NAME.match, ColorStrings.NAME.parse)482 ).toEqual(false)483 })484 test('should convent to name', () => {485 expect(486 ColorStrings.NAME.to({487 r: 255,488 g: 255,489 b: 255,490 a: 1491 })492 ).toEqual('white')493 })494 })495})

Full Screen

Full Screen

localDateTest.js

Source:localDateTest.js Github

copy

Full Screen

...3const expect = chai.expect;4describe('LocalDate', () => {5 describe('#constructor()', () => {6 it('should parse string', () => {7 const localDate = LocalDate.parseString('2021-06-12');8 assert.equal(localDate.year, 2021);9 assert.equal(localDate.month, 6);10 assert.equal(localDate.day, 12);11 });12 it('should parse object', () => {13 const localDate = LocalDate.parseProperties({14 year: 2020,15 month: 5,16 day: 2517 });18 assert.equal(localDate.year, 2020);19 assert.equal(localDate.month, 5);20 assert.equal(localDate.day, 25);21 });22 it('should parse null', () => {23 const localDate = LocalDate.parseProperties(null);24 assert.equal(localDate.year, 0);25 assert.equal(localDate.month, 0);26 assert.equal(localDate.day, 0);27 });28 it('should parse blank string', () => {29 const localDate = LocalDate.parseString(' \t \n ');30 assert.equal(localDate.year, 0);31 assert.equal(localDate.month, 0);32 assert.equal(localDate.day, 0);33 });34 it('should fail on invalid string', () => {35 expect(() => {36 LocalDate.parseString('202-01-A')37 }).to.throw("The value '202-01-A' is not a valid LocalDate. The correct syntax is 'YYYY-MM-DD'.");38 });39 });40 describe('#isBefore()', () => {41 it('should work with non-null dates', () => {42 assert.equal(LocalDate.parseString('2021-02-01').isBefore(LocalDate.parseString('2021-05-01')), true);43 assert.equal(LocalDate.parseString('2020-12-01').isBefore(LocalDate.parseString('2021-05-01')), true);44 assert.equal(LocalDate.parseString('2020-12-01').isBefore(LocalDate.parseString('2020-12-06')), true);45 assert.equal(LocalDate.parseString('2020-12-01').isBefore(LocalDate.parseString('2020-10-01')), false);46 assert.equal(LocalDate.parseString('2021-10-01').isBefore(LocalDate.parseString('2020-10-01')), false);47 assert.equal(LocalDate.parseString('2021-10-25').isBefore(LocalDate.parseString('2021-10-01')), false);48 });49 });50 describe('#isAfter()', () => {51 it('should work with non-null dates', () => {52 assert.equal(LocalDate.parseString('2021-02-01').isAfter(LocalDate.parseString('2021-05-01')), false);53 assert.equal(LocalDate.parseString('2020-12-01').isAfter(LocalDate.parseString('2021-05-01')), false);54 assert.equal(LocalDate.parseString('2020-12-01').isAfter(LocalDate.parseString('2020-12-06')), false);55 assert.equal(LocalDate.parseString('2020-12-01').isAfter(LocalDate.parseString('2020-10-01')), true);56 assert.equal(LocalDate.parseString('2021-10-01').isAfter(LocalDate.parseString('2020-10-01')), true);57 assert.equal(LocalDate.parseString('2021-10-25').isAfter(LocalDate.parseString('2021-10-01')), true);58 });59 });60 describe('#equals()', () => {61 it('should work with non-null dates', () => {62 assert.equal(LocalDate.parseString('2021-02-01').equals(LocalDate.parseString('2021-02-01')), true);63 assert.equal(LocalDate.parseString('2021-02-01').equals(LocalDate.parseString('2021-02-25')), false);64 assert.equal(LocalDate.parseString('2021-02-01').equals(LocalDate.parseString('2021-07-01')), false);65 assert.equal(LocalDate.parseString('2021-02-01').equals(LocalDate.parseString('2019-02-01')), false);66 });67 });68 describe('#toString()', () => {69 it('should work with non-null dates', () => {70 assert.equal(LocalDate.parseString('2021-02-01').toString(), '2021-02-01');71 assert.equal(LocalDate.parseString('2021-09-15').toString(), '2021-09-15');72 assert.equal(LocalDate.parseString('2020-10-30').toString(), '2020-10-30');73 assert.equal(LocalDate.parseString('2020-12-31').toString(), '2020-12-31');74 });75 });76 describe('#nbDaysUntil()', () => {77 it('should work with non-null dates', () => {78 assert.equal(79 LocalDate.parseString('2021-02-01').nbDaysUntil(LocalDate.parseString('2021-02-01')),80 0);81 assert.equal(82 LocalDate.parseString('2021-02-01').nbDaysUntil(LocalDate.parseString('2021-02-02')),83 1);84 assert.equal(85 LocalDate.parseString('2021-02-02').nbDaysUntil(LocalDate.parseString('2021-02-01')),86 -1);87 assert.equal(88 LocalDate.parseString('2021-02-01').nbDaysUntil(LocalDate.parseString('2021-02-21')),89 20);90 assert.equal(91 LocalDate.parseString('2021-02-01').nbDaysUntil(LocalDate.parseString('2021-03-01')),92 28);93 assert.equal(94 LocalDate.parseString('2021-01-01').nbDaysUntil(LocalDate.parseString('2021-03-20')),95 31 + 28 + 19);96 assert.equal(97 LocalDate.parseString('2020-01-01').nbDaysUntil(LocalDate.parseString('2021-01-01')),98 366);99 assert.equal(100 LocalDate.parseString('2019-01-01').nbDaysUntil(LocalDate.parseString('2021-02-10')),101 365 * 2 + 31 + 10);102 });103 });104 describe('#nbYearsUntil()', () => {105 it('should work with non-null dates', () => {106 assert.equal(107 LocalDate.parseString('2021-02-01').nbYearsUntil(LocalDate.parseString('2021-02-01')),108 0);109 assert.equal(110 LocalDate.parseString('2021-02-01').nbYearsUntil(LocalDate.parseString('2022-02-01')),111 1);112 assert.equal(113 LocalDate.parseString('2020-01-01').nbYearsUntil(LocalDate.parseString('2019-01-01')),114 -1);115 assert.equal(116 LocalDate.parseString('2021-02-01').nbYearsUntil(LocalDate.parseString('2023-02-01')),117 2);118 });119 });120 describe('#findClosestAvailableLocalDate()', () => {121 it('should work with non-null dates', () => {122 const availableLocalDates = [123 LocalDate.parseString('2021-01-31'),124 LocalDate.parseString('2021-02-28'),125 LocalDate.parseString('2021-03-31'),126 LocalDate.parseString('2021-04-30'),127 LocalDate.parseString('2021-05-15'),128 LocalDate.parseString('2021-05-16'),129 LocalDate.parseString('2021-05-18'),130 ];131 assert.equal(132 LocalDate.findClosestAvailableLocalDate(133 availableLocalDates, LocalDate.parseString('2021-02-28')).toString(),134 '2021-02-28');135 assert.equal(136 LocalDate.findClosestAvailableLocalDate(137 availableLocalDates, LocalDate.parseString('2021-02-20')).toString(),138 '2021-02-28');139 assert.equal(140 LocalDate.findClosestAvailableLocalDate(141 availableLocalDates, LocalDate.parseString('2021-03-01')).toString(),142 '2021-02-28');143 assert.equal(144 LocalDate.findClosestAvailableLocalDate(145 availableLocalDates, LocalDate.parseString('1999-01-01')).toString(),146 '2021-01-31');147 assert.equal(148 LocalDate.findClosestAvailableLocalDate(149 availableLocalDates, LocalDate.parseString('2021-06-13')).toString(),150 '2021-05-18');151 assert.equal(152 LocalDate.findClosestAvailableLocalDate(153 availableLocalDates, LocalDate.parseString('2021-05-17')).toString(),154 '2021-05-16');155 assert.equal(156 LocalDate.findClosestAvailableLocalDate(157 availableLocalDates, LocalDate.parseString('2021-05-05')).toString(),158 '2021-04-30');159 assert.equal(160 LocalDate.findClosestAvailableLocalDate(161 availableLocalDates, LocalDate.parseString('2021-05-15')).toString(),162 '2021-05-15');163 });164 });165 describe('#toClosestYearMonth()', () => {166 it('should work with non-null dates', () => {167 assert.equal(LocalDate.parseString('2021-02-01').toClosestYearMonth().toString(), '2021-02');168 assert.equal(LocalDate.parseString('2021-02-10').toClosestYearMonth().toString(), '2021-02');169 assert.equal(LocalDate.parseString('2021-02-14').toClosestYearMonth().toString(), '2021-02');170 assert.equal(LocalDate.parseString('2021-02-15').toClosestYearMonth().toString(), '2021-03');171 assert.equal(LocalDate.parseString('2021-02-16').toClosestYearMonth().toString(), '2021-03');172 assert.equal(LocalDate.parseString('2021-02-28').toClosestYearMonth().toString(), '2021-03');173 assert.equal(LocalDate.parseString('2021-12-05').toClosestYearMonth().toString(), '2021-12');174 assert.equal(LocalDate.parseString('2021-12-30').toClosestYearMonth().toString(), '2022-01');175 });176 });177 describe('#compareAsc()', () => {178 it('should work with multiple dates', () => {179 const dates = [180 LocalDate.parseString('2021-05-14'),181 LocalDate.parseString('2021-05-12'),182 LocalDate.parseString('2021-04-28'),183 LocalDate.parseString('2021-06-28'),184 LocalDate.parseString('2020-10-01'),185 ];186 const sortedDates = dates.sort(LocalDate.compareAsc);187 assert.equal(sortedDates.length, 5);188 assert.equal(sortedDates[0].toString(), '2020-10-01');189 assert.equal(sortedDates[1].toString(), '2021-04-28');190 assert.equal(sortedDates[2].toString(), '2021-05-12');191 assert.equal(sortedDates[3].toString(), '2021-05-14');192 assert.equal(sortedDates[4].toString(), '2021-06-28');193 });194 });...

Full Screen

Full Screen

TestCombinatorParser.js

Source:TestCombinatorParser.js Github

copy

Full Screen

...96TestCombinatorParser.prototype.tearDown = function() {97}98// Test cases99TestCombinatorParser.prototype.testWord1 = function() {100 assertEquals("testWord1", word.parseString("a1234"), ["a1234"]);101}102TestCombinatorParser.prototype.testWord2 = function() {103 assertEquals("testWord2", word.parseString("a1234*"), null);104}105TestCombinatorParser.prototype.testText1 = function() {106 assertEquals("testText1", dot.parseString("."), ["."]);107}108TestCombinatorParser.prototype.testText2 = function() {109 assertEquals("testText2", dot.parseString(".*"), null);110}111TestCombinatorParser.prototype.testText3 = function() {112 assertEquals("testText3", text.parseString("text."), ["text", "."]);113}114TestCombinatorParser.prototype.testText4 = function() {115 assertEquals("testText4", dotf.parseString("."), ["."]);116}117TestCombinatorParser.prototype.testText5 = function() {118 assertEquals("testText5", dot2.parseString(".."), [".","."]);119}120TestCombinatorParser.prototype.testInteger1 = function() {121 assertEquals("testInteger1", num.parseString("1234"), [1234]);122}123TestCombinatorParser.prototype.testInteger2 = function() {124 assertEquals("testInteger2", num.parseString("1234*"), null);125}126TestCombinatorParser.prototype.testInteger3 = function() {127 assertEquals("testInteger3", nump.parseString("(333)"), ["(",333,")"]);128}129TestCombinatorParser.prototype.testInteger4 = function() {130 assertEquals("testInteger4", numq.parseString("(444)"), [444]);131}132TestCombinatorParser.prototype.testInteger5 = function() {133 assertEquals("testInteger5", numo.parseString("(555)"), ["(",555,")"]);134}135TestCombinatorParser.prototype.testInteger6 = function() {136 assertEquals("testInteger6", numo.parseString(""), [null]);137}138TestCombinatorParser.prototype.testInteger7 = function() {139 assertEquals("testInteger7", numo.parseString("x"), null);140}141TestCombinatorParser.prototype.testConst1 = function() {142 assertEquals("testConst1", con1.parseString(""), [11]);143}144TestCombinatorParser.prototype.testConst2 = function() {145 assertEquals("testConst2", con2.parseString(""), [22]);146}147TestCombinatorParser.prototype.testConst3 = function() {148 assertEquals("testConst3", con3.parseString(""), []);149}150TestCombinatorParser.prototype.testConst4 = function() {151 assertEquals("testConst4", con1.parseString("x"), null);152}153TestCombinatorParser.prototype.testVal1 = function() {154 assertEquals("testVal1", val.parseString("1"), [1]);155}156TestCombinatorParser.prototype.testVal2 = function() {157 assertEquals("testVal2", val.parseString("abc"), ["abc"]);158}159TestCombinatorParser.prototype.testPrim1 = function() {160 assertEquals("testPrim1", prim.parseString("1"), [1]);161}162TestCombinatorParser.prototype.testPrim2 = function() {163 assertEquals("testPrim2", prim.parseString("(22)"), ["(",22,")"]);164}165TestCombinatorParser.prototype.testFact1 = function() {166 assertEquals("testFact1", fact.parseString("1"), [1]);167}168TestCombinatorParser.prototype.testFact2 = function() {169 assertEquals("testFact2", fact.parseString("(22)"), [["(",22,")"]]);170}171TestCombinatorParser.prototype.testExpr1 = function() {172 assertEquals("testExpr1", expr.parseString("1+2*3."), [1,"+",2,"*",3,"."]);173}174TestCombinatorParser.prototype.testExpr2 = function() {175 assertEquals("testExpr2", expr.parseString("(1+2)*3."), [["(",1,"+",2,")"],"*",3,"."]);176}177TestCombinatorParser.prototype.testExpr3 = function() {178 assertEquals("testExpr3", expr.parseString("(1+2)*3"), null);179}180TestCombinatorParser.prototype.testExpr4 = function() {181 assertEquals("testExpr4", expr.parseString("(1+2)!3."), null);182}183TestCombinatorParser.prototype.testGen_delims1 = function() {184 assertEquals("testGen_delims1", gen_delims.parseString(":"), [":"]);185}186TestCombinatorParser.prototype.testGen_delims2 = function() {187 assertEquals("testGen_delims2", gen_delims.parseString("/"), ["/"]);188}189TestCombinatorParser.prototype.testGen_delims3 = function() {190 assertEquals("testGen_delims3", gen_delims.parseString("?"), ["?"]);191}192TestCombinatorParser.prototype.testGen_delims4 = function() {193 assertEquals("testGen_delims4", gen_delims.parseString("#"), ["#"]);194}195TestCombinatorParser.prototype.testGen_delims5 = function() {196 assertEquals("testGen_delims5", gen_delims.parseString("["), ["["]);197}198TestCombinatorParser.prototype.testGen_delims6 = function() {199 assertEquals("testGen_delims6", gen_delims.parseString("]"), ["]"]);200}201TestCombinatorParser.prototype.testGen_delims7 = function() {202 assertEquals("testGen_delims7", gen_delims.parseString("@"), ["@"]);203}204TestCombinatorParser.prototype.testSub_delims1 = function() {205 assertEquals("testSub_delims1", sub_delims.parseString("!"), ["!"]);206}207TestCombinatorParser.prototype.testSub_delims2 = function() {208 assertEquals("testSub_delims2", sub_delims.parseString("$"), ["$"]);209}210TestCombinatorParser.prototype.testSub_delims3 = function() {211 assertEquals("testSub_delims3", sub_delims.parseString("&"), ["&"]);212}213TestCombinatorParser.prototype.testSub_delims4 = function() {214 assertEquals("testSub_delims4", sub_delims.parseString("'"), ["'"]);215}216TestCombinatorParser.prototype.testSub_delims5 = function() {217 assertEquals("testSub_delims5", sub_delims.parseString("("), ["("]);218}219TestCombinatorParser.prototype.testSub_delims6 = function() {220 assertEquals("testSub_delims6", sub_delims.parseString(")"), [")"]);221}222TestCombinatorParser.prototype.testSub_delims7 = function() {223 assertEquals("testSub_delims7", sub_delims.parseString("*"), ["*"]);224}225TestCombinatorParser.prototype.testSub_delims8 = function() {226 assertEquals("testSub_delims8", sub_delims.parseString("+"), ["+"]);227}228TestCombinatorParser.prototype.testSub_delims9 = function() {229 assertEquals("testSub_delims9", sub_delims.parseString(","), [","]);230}231TestCombinatorParser.prototype.testSub_delims10 = function() {232 assertEquals("testSub_delims10", sub_delims.parseString(";"), [";"]);233}234TestCombinatorParser.prototype.testSub_delims11 = function() {235 assertEquals("testSub_delims11", sub_delims.parseString("="), ["="]);236}237TestCombinatorParser.prototype.testUnreserved1 = function() {238 assertEquals("testUnreserved1", unreserved.parseString("a"), ["a"]);239}240TestCombinatorParser.prototype.testUnreserved2 = function() {241 assertEquals("testUnreserved2", unreserved.parseString("Z"), ["Z"]);242}243TestCombinatorParser.prototype.testUnreserved3 = function() {244 assertEquals("testUnreserved3", unreserved.parseString("3"), ["3"]);245}246TestCombinatorParser.prototype.testUnreserved4 = function() {247 assertEquals("testUnreserved4", unreserved.parseString("-"), ["-"]);248}249TestCombinatorParser.prototype.testUnreserved5 = function() {250 assertEquals("testUnreserved5", unreserved.parseString("."), ["."]);251}252TestCombinatorParser.prototype.testUnreserved6 = function() {253 assertEquals("testUnreserved6", unreserved.parseString("~"), ["~"]);254}255TestCombinatorParser.prototype.testXXX = function() {256 assertEquals("testXXX", 4, 2+2);257}258// Expose functions at global level of frame for JSUnit259// JSUnit page setup260function setUpPage() {261 info("setUpPage", "TestCombinatorParser");262 setUpPageForJSUnit(TestCombinatorParser, this);263}264// Return list of tests for JSunit265exposeTestFunctionNames = TestCombinatorParser.exposeTestFunctionNames;...

Full Screen

Full Screen

yearMonthTest.js

Source:yearMonthTest.js Github

copy

Full Screen

...3const expect = chai.expect;4describe('YearMonth', () => {5 describe('#constructor()', () => {6 it('should parse string', () => {7 const yearMonth = YearMonth.parseString('2021-06');8 assert.equal(yearMonth.year, 2021);9 assert.equal(yearMonth.month, 6);10 });11 it('should parse object', () => {12 const yearMonth = YearMonth.parseStringOrProperties({13 year: 2020,14 month: 515 });16 assert.equal(yearMonth.year, 2020);17 assert.equal(yearMonth.month, 5);18 });19 it('should parse null', () => {20 const yearMonth = YearMonth.parseProperties(null);21 assert.equal(yearMonth.year, 0);22 assert.equal(yearMonth.month, 0);23 });24 it('should parse blank string', () => {25 const yearMonth = YearMonth.parseString(' \t \n ');26 assert.equal(yearMonth.year, 0);27 assert.equal(yearMonth.month, 0);28 });29 it('should fail on invalid string', () => {30 expect(() => {31 YearMonth.parseString('202-01')32 }).to.throw("The value '202-01' is not a valid YearMonth. The correct syntax is 'YYYY-MM'.");33 });34 });35 describe('#generateRangeBetween()', () => {36 it('should work within the same year', () => {37 const yearMonths = YearMonth.generateRangeBetween(38 YearMonth.parseString('2021-02'), YearMonth.parseString('2021-06'));39 assert.equal(yearMonths.length, 5);40 assert.equal(yearMonths[0].year, 2021);41 assert.equal(yearMonths[0].month, 2);42 assert.equal(yearMonths[1].year, 2021);43 assert.equal(yearMonths[1].month, 3);44 assert.equal(yearMonths[2].year, 2021);45 assert.equal(yearMonths[2].month, 4);46 assert.equal(yearMonths[3].year, 2021);47 assert.equal(yearMonths[3].month, 5);48 assert.equal(yearMonths[4].year, 2021);49 assert.equal(yearMonths[4].month, 6);50 });51 it('should work across years', () => {52 const yearMonths = YearMonth.generateRangeBetween(53 YearMonth.parseString('2020-10'), YearMonth.parseString('2021-02'));54 assert.equal(yearMonths.length, 5);55 assert.equal(yearMonths[0].year, 2020);56 assert.equal(yearMonths[0].month, 10);57 assert.equal(yearMonths[1].year, 2020);58 assert.equal(yearMonths[1].month, 11);59 assert.equal(yearMonths[2].year, 2020);60 assert.equal(yearMonths[2].month, 12);61 assert.equal(yearMonths[3].year, 2021);62 assert.equal(yearMonths[3].month, 1);63 assert.equal(yearMonths[4].year, 2021);64 assert.equal(yearMonths[4].month, 2);65 });66 });67 describe('#compareAsc()', () => {68 it('should work with multiple dates', () => {69 const yearMonths = [70 YearMonth.parseString('2021-02'),71 YearMonth.parseString('2021-05'),72 YearMonth.parseString('2020-12'),73 YearMonth.parseString('2020-10'),74 ];75 const sortedYearMonths = yearMonths.sort(YearMonth.compareAsc);76 assert.equal(sortedYearMonths.length, 4);77 assert.equal(sortedYearMonths[0].year, 2020);78 assert.equal(sortedYearMonths[0].month, 10);79 assert.equal(sortedYearMonths[1].year, 2020);80 assert.equal(sortedYearMonths[1].month, 12);81 assert.equal(sortedYearMonths[2].year, 2021);82 assert.equal(sortedYearMonths[2].month, 2);83 assert.equal(sortedYearMonths[3].year, 2021);84 assert.equal(sortedYearMonths[3].month, 5);85 });86 });87 describe('#compareDesc()', () => {88 it('should work with multiple dates', () => {89 const yearMonths = [90 YearMonth.parseString('2021-02'),91 YearMonth.parseString('2021-05'),92 YearMonth.parseString('2020-12'),93 YearMonth.parseString('2020-10'),94 ];95 const sortedYearMonths = yearMonths.sort(YearMonth.compareDesc);96 assert.equal(sortedYearMonths.length, 4);97 assert.equal(sortedYearMonths[0].year, 2021);98 assert.equal(sortedYearMonths[0].month, 5);99 assert.equal(sortedYearMonths[1].year, 2021);100 assert.equal(sortedYearMonths[1].month, 2);101 assert.equal(sortedYearMonths[2].year, 2020);102 assert.equal(sortedYearMonths[2].month, 12);103 assert.equal(sortedYearMonths[3].year, 2020);104 assert.equal(sortedYearMonths[3].month, 10);105 });106 });107 describe('#isBefore()', () => {108 it('should work with non-null dates', () => {109 assert.equal(YearMonth.parseString('2021-02').isBefore(YearMonth.parseString('2021-05')), true);110 assert.equal(YearMonth.parseString('2020-12').isBefore(YearMonth.parseString('2021-05')), true);111 assert.equal(YearMonth.parseString('2020-12').isBefore(YearMonth.parseString('2020-10')), false);112 assert.equal(YearMonth.parseString('2021-10').isBefore(YearMonth.parseString('2020-10')), false);113 });114 });115 describe('#isAfter()', () => {116 it('should work with non-null dates', () => {117 assert.equal(YearMonth.parseString('2021-02').isAfter(YearMonth.parseString('2021-05')), false);118 assert.equal(YearMonth.parseString('2020-12').isAfter(YearMonth.parseString('2021-05')), false);119 assert.equal(YearMonth.parseString('2020-12').isAfter(YearMonth.parseString('2020-10')), true);120 assert.equal(YearMonth.parseString('2021-10').isAfter(YearMonth.parseString('2020-10')), true);121 });122 });123 describe('#equals()', () => {124 it('should work with non-null dates', () => {125 assert.equal(YearMonth.parseString('2021-02').equals(YearMonth.parseString('2021-02')), true);126 assert.equal(YearMonth.parseString('2020-12').equals(YearMonth.parseString('2021-12')), false);127 assert.equal(YearMonth.parseString('2021-12').equals(YearMonth.parseString('2021-01')), false);128 assert.equal(YearMonth.parseString('2020-12').equals(YearMonth.parseString('2021-01')), false);129 });130 });131 describe('#nbMonthsBetween()', () => {132 it('should work with non-null dates', () => {133 assert.equal(YearMonth.nbMonthsBetween(YearMonth.parseString('2021-02'), YearMonth.parseString('2021-02')), 0);134 assert.equal(YearMonth.nbMonthsBetween(YearMonth.parseString('2020-12'), YearMonth.parseString('2021-12')), 12);135 assert.equal(YearMonth.nbMonthsBetween(YearMonth.parseString('2021-12'), YearMonth.parseString('2021-01')), -11);136 assert.equal(YearMonth.nbMonthsBetween(YearMonth.parseString('2020-12'), YearMonth.parseString('2021-01')), 1);137 });138 });139 describe('#toString()', () => {140 it('should work with non-null dates', () => {141 assert.equal(YearMonth.parseString('2021-02').toString(), '2021-02');142 assert.equal(YearMonth.parseString('2021-09').toString(), '2021-09');143 assert.equal(YearMonth.parseString('2020-10').toString(), '2020-10');144 assert.equal(YearMonth.parseString('2020-12').toString(), '2020-12');145 });146 });147 describe('#nbDaysInMonth()', () => {148 it('should work with non-null dates', () => {149 assert.equal(YearMonth.parseString('2021-01').nbDaysInMonth(), 31);150 assert.equal(YearMonth.parseString('2021-02').nbDaysInMonth(), 28);151 assert.equal(YearMonth.parseString('2021-03').nbDaysInMonth(), 31);152 assert.equal(YearMonth.parseString('2021-04').nbDaysInMonth(), 30);153 assert.equal(YearMonth.parseString('2021-05').nbDaysInMonth(), 31);154 assert.equal(YearMonth.parseString('2021-06').nbDaysInMonth(), 30);155 assert.equal(YearMonth.parseString('2021-07').nbDaysInMonth(), 31);156 assert.equal(YearMonth.parseString('2021-08').nbDaysInMonth(), 31);157 assert.equal(YearMonth.parseString('2021-09').nbDaysInMonth(), 30);158 assert.equal(YearMonth.parseString('2021-10').nbDaysInMonth(), 31);159 assert.equal(YearMonth.parseString('2021-11').nbDaysInMonth(), 30);160 assert.equal(YearMonth.parseString('2021-12').nbDaysInMonth(), 31);161 assert.equal(YearMonth.parseString('2000-02').nbDaysInMonth(), 29);162 });163 });164 describe('#atDay()', () => {165 it('should work with non-null day', () => {166 assert.equal(YearMonth.parseString('2021-05').atDay(11).toString(), '2021-05-11');167 });168 });169 describe('#nbYearsUntil()', () => {170 it('should work with non-null day', () => {171 assert.equal(YearMonth.parseString('2021-05').nbYearsUntil(YearMonth.parseString('2021-05')), 0);172 assert.equal(YearMonth.parseString('2020-05').nbYearsUntil(YearMonth.parseString('2021-05')), 1);173 assert.equal(YearMonth.parseString('2021-05').nbYearsUntil(YearMonth.parseString('2020-05')), -1);174 assert.equal(YearMonth.parseString('2021-01').nbYearsUntil(YearMonth.parseString('2021-07')), 0.5);175 });176 });177 describe('#nextMonth()', () => {178 it('should work with non-null dates', () => {179 assert.equal(YearMonth.parseString('2021-05').nextMonth().toString(), '2021-06');180 assert.equal(YearMonth.parseString('2021-11').nextMonth().toString(), '2021-12');181 assert.equal(YearMonth.parseString('2021-12').nextMonth().toString(), '2022-01');182 });183 });...

Full Screen

Full Screen

linkparser.js

Source:linkparser.js Github

copy

Full Screen

1import { module, test } from "qunit";2import { parseString } from "utils/linkparser";3module( "utils/linkparser", function() {4 test( "invalid URLs", function( assert ) {5 assert.propEqual( parseString( undefined ), { texts: [ "" ], links: [] }, "undefined" );6 assert.propEqual( parseString( null ), { texts: [ "" ], links: [] }, "null" );7 assert.propEqual( parseString( false ), { texts: [ "" ], links: [] }, "false" );8 assert.propEqual( parseString( true ), { texts: [ "" ], links: [] }, "true" );9 assert.propEqual( parseString( {} ), { texts: [ "[object Object]" ], links: [] }, "obj" );10 });11 test( "URL boundaries", function( assert ) {12 assert.propEqual(13 parseString( "foohttps://google.com" ),14 {15 texts: [ "foohttps://google.com" ],16 links: []17 },18 "invalid starting boundary"19 );20 assert.propEqual(21 parseString( "https://google.comfoo" ),22 {23 texts: [ "https://google.comfoo" ],24 links: []25 },26 "invalid ending boundary"27 );28 assert.propEqual(29 parseString( "https://google.com" ),30 {31 texts: [ "", "" ],32 links: [ { url: "https://google.com", text: "https://google.com" } ]33 },34 "just the url"35 );36 assert.propEqual(37 parseString( "!https://google.com" ),38 {39 texts: [ "!", "" ],40 links: [ { url: "https://google.com", text: "https://google.com" } ]41 },42 "valid starting boundary"43 );44 assert.propEqual(45 parseString( "<https://google.com>" ),46 {47 texts: [ "<", ">" ],48 links: [ { url: "https://google.com", text: "https://google.com" } ]49 },50 "valid ending boundary (no path)"51 );52 assert.propEqual(53 parseString( "foo https://google.com bar" ),54 {55 texts: [ "foo ", " bar" ],56 links: [ { url: "https://google.com", text: "https://google.com" } ]57 },58 "between text"59 );60 });61 test( "URL schemes", function( assert ) {62 assert.propEqual(63 parseString( "http://google.com" ),64 {65 texts: [ "", "" ],66 links: [ { url: "http://google.com", text: "google.com" } ]67 },68 "Remove http protocol from link text"69 );70 assert.propEqual(71 parseString( "google.com" ),72 {73 texts: [ "", "" ],74 links: [ { url: "http://google.com", text: "google.com" } ]75 },76 "Implicit http protocol"77 );78 });79 test( "URL netlocs", function( assert ) {80 assert.propEqual(81 parseString( "cat.jpg" ),82 {83 texts: [ "cat.jpg" ],84 links: []85 },86 "Invalid TLD"87 );88 assert.propEqual(89 parseString( "google.de" ),90 {91 texts: [ "", "" ],92 links: [ { url: "http://google.de", text: "google.de" } ]93 },94 "country code domains"95 );96 assert.propEqual(97 parseString( "google.co.uk" ),98 {99 texts: [ "", "" ],100 links: [ { url: "http://google.co.uk", text: "google.co.uk" } ]101 },102 "second level domains"103 );104 assert.propEqual(105 parseString( "foo.我爱你" ),106 {107 texts: [ "", "" ],108 links: [ { url: "http://foo.我爱你", text: "foo.我爱你" } ]109 },110 "internationalized TLDs"111 );112 assert.propEqual(113 parseString( "foo.xn--7ba0bs.xn--6QQ986B3XL" ),114 {115 texts: [ "", "" ],116 links: [ { url: "http://foo.xn--7ba0bs.xn--6QQ986B3XL", text: "foo.ÄÖÜ.我爱你" } ]117 },118 "internationalized domains"119 );120 assert.propEqual(121 parseString( "https://www.google.com" ),122 {123 texts: [ "", "" ],124 links: [ { url: "https://www.google.com", text: "https://www.google.com" } ]125 },126 "subdomains"127 );128 assert.propEqual(129 parseString( "https://foo.bar.baz.com" ),130 {131 texts: [ "", "" ],132 links: [ { url: "https://foo.bar.baz.com", text: "https://foo.bar.baz.com" } ]133 },134 "multiple subdomains"135 );136 assert.deepEqual(137 parseString( "foo.com:8080" ),138 {139 texts: [ "", "" ],140 links: [ { url: "http://foo.com:8080", text: "foo.com:8080" } ]141 },142 "port number"143 );144 });145 test( "URL paths", function( assert ) {146 assert.propEqual(147 parseString( "foo.com/" ),148 {149 texts: [ "", "" ],150 links: [ { url: "http://foo.com/", text: "foo.com/" } ]151 },152 "empty path"153 );154 assert.propEqual(155 parseString( "https://foo.com/bar" ),156 {157 texts: [ "", "" ],158 links: [ { url : "https://foo.com/bar", text: "https://foo.com/bar" } ]159 },160 "non-empty path"161 );162 assert.propEqual(163 parseString( "<https://foo.com/>" ),164 {165 texts: [ "<", "" ],166 links: [ { url: "https://foo.com/>", text: "https://foo.com/>" } ]167 },168 "empty path with URL wrappers"169 );170 assert.propEqual(171 parseString( "<https://foo.com/bar>" ),172 {173 texts: [ "<", "" ],174 links: [ { url: "https://foo.com/bar>", text: "https://foo.com/bar>" } ]175 },176 "non-empty path with URL wrappers"177 );178 assert.propEqual(179 parseString( "foo.com:8080/bar" ),180 {181 texts: [ "", "" ],182 links: [ { url: "http://foo.com:8080/bar", text: "foo.com:8080/bar" } ]183 },184 "port number"185 );186 });187 test( "URLs misc", function( assert ) {188 assert.propEqual(189 parseString( "GOOGLE.COM" ),190 {191 texts: [ "", "" ],192 links: [ { url : "http://GOOGLE.COM", text: "GOOGLE.COM" } ]193 },194 "Ignore case"195 );196 assert.propEqual(197 parseString( "http://sub.host.com/path/subpath?a=b&c#d" ),198 {199 texts: [ "", "" ],200 links: [{201 url : "http://sub.host.com/path/subpath?a=b&c#d",202 text: "sub.host.com/path/subpath?a=b&c#d"203 }]204 },205 "Path + query + hash"206 );207 assert.propEqual(208 parseString( "foo bar.com baz.com qux.com quux" ),209 {210 texts: [ "foo ", " ", " ", " quux" ],211 links: [212 { url: "http://bar.com", text: "bar.com" },213 { url: "http://baz.com", text: "baz.com" },214 { url: "http://qux.com", text: "qux.com" }215 ]216 },217 "Multiple matches"218 );219 });220 test( "Twitter", function( assert ) {221 assert.propEqual(222 parseString( "@foo" ),223 {224 texts: [ "", "" ],225 links: [ { url: "https://twitter.com/foo", text: "@foo" } ]226 },227 "Simple test"228 );229 assert.propEqual(230 parseString( "name@mail.com" ),231 {232 texts: [ "name@mail.com" ],233 links: []234 },235 "Email test"236 );237 assert.propEqual(238 parseString( "!@foo..." ),239 {240 texts: [ "!", "..." ],241 links: [ { url: "https://twitter.com/foo", text: "@foo" } ]242 },243 "Special char boundaries"244 );245 assert.propEqual(246 parseString( "@myusernameiswaytoolongfortwitter" ),247 {248 texts: [ "@myusernameiswaytoolongfortwitter" ],249 links: []250 },251 "Username length"252 );253 assert.propEqual(254 parseString( "foo @bar @baz @qux quux" ),255 {256 texts: [ "foo ", " ", " ", " quux" ],257 links: [258 { url: "https://twitter.com/bar", text: "@bar" },259 { url: "https://twitter.com/baz", text: "@baz" },260 { url: "https://twitter.com/qux", text: "@qux" }261 ]262 },263 "Multiple matches"264 );265 });266 test( "Subreddit", function( assert ) {267 assert.propEqual(268 parseString( "/r/all /r/all/" ),269 {270 texts: [ "", " ", "" ],271 links: [272 { url: "https://www.reddit.com/r/all", text: "/r/all" },273 { url: "https://www.reddit.com/r/all", text: "/r/all" }274 ]275 },276 "Implicit subreddit match"277 );278 assert.propEqual(279 parseString( "https://www.reddit.com/r/all https://www.reddit.com/r/all/" ),280 {281 texts: [ "", " ", "" ],282 links: [283 { url: "https://www.reddit.com/r/all", text: "/r/all" },284 { url: "https://www.reddit.com/r/all", text: "/r/all" }285 ]286 },287 "Explicit subreddit match"288 );289 assert.propEqual(290 parseString( "https://www.reddit.com https://www.reddit.com/r/subreddit/comments/abcdef" ),291 {292 texts: [ "", " ", "" ],293 links: [294 {295 url: "https://www.reddit.com",296 text: "https://www.reddit.com"297 },298 {299 url: "https://www.reddit.com/r/subreddit/comments/abcdef",300 text: "https://www.reddit.com/r/subreddit/comments/abcdef"301 }302 ]303 },304 "Non-matching subreddit links"305 );306 });307 test( "Reddit user", function( assert ) {308 assert.propEqual(309 parseString( "/u/name /u/name/" ),310 {311 texts: [ "", " ", "" ],312 links: [313 { url: "https://www.reddit.com/u/name", text: "/u/name" },314 { url: "https://www.reddit.com/u/name", text: "/u/name" }315 ]316 },317 "Implicit reddit user match (short)"318 );319 assert.propEqual(320 parseString( "/user/name /user/name" ),321 {322 texts: [ "", " ", "" ],323 links: [324 { url: "https://www.reddit.com/u/name", text: "/u/name" },325 { url: "https://www.reddit.com/u/name", text: "/u/name" }326 ]327 },328 "Implicit reddit user match (long)"329 );330 assert.propEqual(331 parseString( "https://www.reddit.com/u/name https://www.reddit.com/u/name/" ),332 {333 texts: [ "", " ", "" ],334 links: [335 { url: "https://www.reddit.com/u/name", text: "/u/name" },336 { url: "https://www.reddit.com/u/name", text: "/u/name" }337 ]338 },339 "Explicit reddit user match"340 );341 });342 test( "All parsers", function( assert ) {343 assert.propEqual(344 parseString( "Follow @foo and visit bar.com or follow /u/baz and visit /r/qux" ),345 {346 texts: [ "Follow ", " and visit ", " or follow ", " and visit ", "" ],347 links: [348 { url: "https://twitter.com/foo", text: "@foo" },349 { url: "http://bar.com", text: "bar.com" },350 { url: "https://www.reddit.com/u/baz", text: "/u/baz" },351 { url: "https://www.reddit.com/r/qux", text: "/r/qux" }352 ]353 },354 "Multiple matches"355 );356 });...

Full Screen

Full Screen

attributes.js

Source:attributes.js Github

copy

Full Screen

1'use strict'2const {3 parseDate, parseString, parseBoolean,4 parseArray, parseArrayOfStrings5} = require('./parse')6module.exports = {7 '_kMDItemOwnerUserID': parseInt,8 kMDItemAcquisitionMake: parseString,9 kMDItemAcquisitionModel: parseString,10 kMDItemAlbum: parseString,11 kMDItemAperture: parseString,12 kMDItemAppleLoopDescriptors: parseArrayOfStrings,13 kMDItemAppleLoopsKeyFilterType: parseString,14 kMDItemAppleLoopsLoopMode: parseString,15 kMDItemAppleLoopsRootKey: parseString,16 kMDItemAttributeChangeDate: parseDate,17 kMDItemAudiences: parseArrayOfStrings,18 kMDItemAudioBitRate: parseFloat,19 kMDItemAudioChannelCount: parseInt,20 kMDItemAudioEncodingApplication: parseString,21 kMDItemAudioSampleRate: parseFloat,22 kMDItemAudioTrackNumber: parseInt,23 kMDItemAuthors: parseArrayOfStrings,24 kMDItemAuthorAddresses: parseArrayOfStrings,25 kMDItemBitsPerSample: parseInt,26 kMDItemCity: parseString,27 kMDItemCodecs: parseArrayOfStrings,28 kMDItemColorSpace: parseString,29 kMDItemComment: parseString,30 kMDItemComposer: parseString,31 kMDItemContactKeywords: parseArrayOfStrings,32 kMDItemContentCreationDate: parseDate,33 kMDItemContentModificationDate: parseDate,34 kMDItemContentType: parseString,35 kMDItemContentTypeTree: parseArrayOfStrings,36 kMDItemContributors: parseArrayOfStrings,37 kMDItemCopyright: parseString,38 kMDItemCountry: parseString,39 kMDItemCoverage: parseString,40 kMDItemCreator: parseString,41 kMDItemDateAdded: parseDate,42 kMDItemDeliveryType: parseString,43 kMDItemDescription: parseString,44 kMDItemDisplayName: parseString,45 kMDItemDownloadedDate: parseArray(parseDate),46 kMDItemDueDate: parseDate,47 kMDItemDurationSeconds: parseFloat,48 kMDItemEmailAddresses: parseArrayOfStrings,49 kMDItemEncodingApplications: parseArrayOfStrings,50 kMDItemEXIFVersion: parseString,51 kMDItemExposureMode: parseInt,52 kMDItemExposureProgram: parseString,53 kMDItemExposureTimeSeconds: parseFloat,54 kMDItemExposureTimeString: parseString,55 kMDItemFinderComment: parseString,56 kMDItemFlashOnOff: parseBoolean,57 kMDItemFNumber: parseFloat,58 kMDItemFocalLength: parseFloat,59 kMDItemFonts: parseArrayOfStrings,60 kMDItemFSContentChangeDate: parseDate,61 kMDItemFSCreationDate: parseDate,62 kMDItemFSCreatorCode: parseString,63 kMDItemFSFinderFlags: parseInt,64 kMDItemFSHasCustomIcon: parseInt,65 kMDItemFSInvisible: parseBoolean,66 kMDItemFSIsExtensionHidden: parseBoolean,67 kMDItemFSIsStationery: parseBoolean,68 kMDItemFSLabel: parseInt,69 kMDItemFSName: parseString,70 kMDItemFSNodeCount: parseInt,71 kMDItemFSOwnerGroupID: parseInt,72 kMDItemFSOwnerUserID: parseInt,73 kMDItemFSSize: parseInt,74 kMDItemFSTypeCode: parseString,75 kMDItemHasAlphaChannel: parseBoolean,76 kMDItemHeadline: parseString,77 kMDItemIdentifier: parseString,78 kMDItemInstantMessageAddresses: parseArrayOfStrings,79 kMDItemInstructions: parseArrayOfStrings,80 kMDItemIsGeneralMIDISequence: parseBoolean,81 kMDItemISOSpeed: parseInt,82 kMDItemKeySignature: parseString,83 kMDItemKeywords: parseArrayOfStrings,84 kMDItemKind: parseString,85 kMDItemLanguages: parseArrayOfStrings,86 kMDItemLastUsedDate: parseDate,87 kMDItemLayerNames: parseArrayOfStrings,88 kMDItemLogicalSize: parseInt,89 kMDItemLyricist: parseString,90 kMDItemMaxAperture: parseFloat,91 kMDItemMediaTypes: parseArrayOfStrings,92 kMDItemMeteringMode: parseString,93 kMDItemMusicalGenre: parseString,94 kMDItemMusicalInstrumentCategory: parseString,95 kMDItemMusicalInstrumentName: parseString,96 kMDItemNamedLocation: parseString,97 kMDItemNumberOfPages: parseInt,98 kMDItemOrganizations: parseArrayOfStrings,99 kMDItemOrientation: parseInt,100 kMDItemPageHeight: parseFloat,101 kMDItemPageWidth: parseFloat,102 kMDItemParticipants: parseArrayOfStrings,103 kMDItemPath: parseString,104 kMDItemPhoneNumbers: parseArrayOfStrings,105 kMDItemPhysicalSize: parseInt,106 kMDItemPixelCount: parseInt,107 kMDItemPixelHeight: parseInt,108 kMDItemPixelWidth: parseInt,109 kMDItemProfileName: parseString,110 kMDItemProjects: parseArrayOfStrings,111 kMDItemPublishers: parseArrayOfStrings,112 kMDItemRecipients: parseArrayOfStrings,113 kMDItemRecipientAddresses: parseArrayOfStrings,114 kMDItemRecordingDate: parseDate,115 kMDItemRecordingYear: parseInt,116 kMDItemRedEyeOnOff: parseBoolean,117 kMDItemResolutionHeightDPI: parseFloat,118 kMDItemResolutionWidthDPI: parseFloat,119 kMDItemRights: parseString,120 kMDItemSecurityMethod: parseString,121 kMDItemStarRating: parseFloat,122 kMDItemStateOrProvince: parseString,123 kMDItemStreamable: parseBoolean,124 kMDItemTempo: parseFloat,125 kMDItemTextContent: parseString,126 kMDItemTimeSignature: parseString,127 kMDItemTitle: parseString,128 kMDItemTotalBitRate: parseFloat,129 kMDItemUseCount: parseInt,130 kMDItemUsedDates: parseArray(parseDate),131 kMDItemUserCreatedDate: parseArray(parseDate),132 kMDItemUserCreatedUserHandle: parseArray((s) => parseInt(s)),133 kMDItemVersion: parseString,134 kMDItemVideoBitRate: parseFloat,135 kMDItemWhereFroms: parseArrayOfStrings,136 kMDItemWhiteBalance: parseInt...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1var express = require('express');2var app = module.exports = express();3var request = require('request');4var parseString = require('xml2js').parseString;5var cors = require('cors');6var whitelist = [7 "http://bgg-middleware.azurewebsites.net",8 "http://bgg-middleware-staging.azurewebsites.net",9 "http://bgg-middleware-stage.azurewebsites.net",10 "http://bgg-middleware.herokuapp.com"11];12var corsOptions = {13 origin: function(origin, callback){14 var originIsWhitelisted = whitelist.indexOf(origin) !== -1;15 callback(null, originIsWhitelisted);16 },17 allowedHeaders: [18 "auth-token"19 ]20};21app.use(cors());22// Analytics Setup23var ua = require('universal-analytics');24var visitor = ua('UA-51022207-6');25visitor.pageview("/").send();26// Port Setup27app.set('port', (process.env.PORT || 1337));28app.use(express.static(__dirname + '/public'));29//LOAD THEM ROUTES, BOYYYYYY30require('./routes/search')(app, request, parseString);31require('./routes/mostActive')(app, request, parseString);32require('./routes/game')(app, request, parseString);33require('./routes/gameImages')(app, request);34require('./routes/forumlist')(app, request, parseString);35require('./routes/threadList')(app, request, parseString);36require('./routes/thread')(app, request, parseString);37require('./routes/mechanics')(app, request, parseString);38require('./routes/categories')(app, request);39require('./routes/featured')(app, request, parseString);40require('./routes/featured-image')(app, request, parseString);41require('./routes/top100')(app, request, parseString);42require('./routes/announcements')(app, request);43require('./routes/apps')(app, request);44require('./routes/featured/game')(app, request);45//USER SPECIFIC ROUTES46require('./routes/user/collection')(app, request, parseString);47require('./routes/user/playsCollection')(app, request, parseString);48require('./routes/user/recentPlays')(app, request, parseString);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 const html = await page.content();7 console.log(html);8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseString } = require('playwright/lib/utils/utils');2const { Playwright } = require('playwright');3const pw = new Playwright();4const browser = await pw.chromium.launch();5const context = await browser.newContext();6const page = await context.newPage();7const result = await parseString(page, 'Hello World!');8console.log(result);9await browser.close();10const { parseString } = require('playwright/lib/utils/utils');11const { Playwright } = require('playwright');12const pw = new Playwright();13const browser = await pw.chromium.launch();14const context = await browser.newContext();15const page = await context.newPage();16const result = await parseString(page, 'Hello World!');17console.log(result);18await browser.close();19const { parseString } = require('playwright/lib/utils/utils');20const { Playwright } = require('playwright');21const pw = new Playwright();22const browser = await pw.chromium.launch();23const context = await browser.newContext();24const page = await context.newPage();25const result = await parseString(page, 'Hello World!');26console.log(result);27await browser.close();28const { parseString } = require('playwright/lib/utils/utils');29const { Playwright } = require('playwright');30const pw = new Playwright();31const browser = await pw.chromium.launch();32const context = await browser.newContext();33const page = await context.newPage();34const result = await parseString(page, 'Hello World!');35console.log(result);36await browser.close();37const { parseString } = require('playwright/lib/utils/utils');38const { Playwright } = require('playwright');39const pw = new Playwright();40const browser = await pw.chromium.launch();41const context = await browser.newContext();42const page = await context.newPage();43const result = await parseString(page, 'Hello World!');44console.log(result);45await browser.close();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseString } = require('playwright/lib/utils/utils');2(async () => {3 const result = await parseString('{"foo": "bar"}');4 console.log(result);5})();6{ foo: 'bar' }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseString } = require('@playwright/test/lib/utils/parseTest');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await parseString('test', page);5});6const { parseString } = require('@playwright/test/lib/utils/parseTest');7const { test } = require('@playwright/test');8test('test', async ({ page }) => {9 await parseString('test', page);10});11const { parseString } = require('@playwright/test/lib/utils/parseTest');12const { test } = require('@playwright/test');13test('test', async ({ page }) => {14 await parseString('test', page);15});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseString } = require('playwright-core/lib/utils/parseUtils');2const result = parseString('{"foo": "bar"}');3console.log(result);4{ foo: 'bar' }5The parseString() method is used to parse the JSON string to the JavaScript object. It is not recommended to use this method in your code as the Playwright team may change it in the future. This method may break your code. The parseString() method can be used in the following way:6const { parseString } = require('playwright-core/lib/utils/parseUtils');7const result = parseString('{"foo": "bar"}');8console.log(result);9{ foo: 'bar' }10The parseString() method is used to parse the JSON string to the JavaScript object. It is not recommended to use this method in your code as the Playwright team may change it in the future. This method may break your code. The parseString() method can be used in the following way:11const { parseString } = require('playwright-core/lib/utils/parseUtils');12const result = parseString('{"foo": "bar"}');13console.log(result);14{ foo: 'bar' }15The parseString() method is used to parse the JSON string to the JavaScript object. It is not recommended to use this method in your code as the Playwright team may change it in the future. This method may break your code. The parseString() method can be used in the following way:16const { parseString } = require('playwright-core/lib/utils/parseUtils');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseString } = require('playwright-core/lib/utils/parseQuery');2const parsed = parseString('text=foo');3console.log(parsed);4const { parseSelector } = require('playwright-core/lib/utils/parseQuery');5const parsed = parseSelector('text=foo');6console.log(parsed);7const { parseSelector } = require('playwright-core/lib/utils/parseQuery');8const parsed = parseSelector('text=foo');9console.log(parsed);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseString } = require('playwright-internal');2const result = parseString('{"x": 5}');3console.log(result);4const { parseString } = require('playwright-internal');5const result = parseString('{"x": 5}');6console.log(result);7const { parseString } = require('playwright-internal');8const result = parseString('{"x": 5}');9console.log(result);10{ x: 5, '$': {} }11{ x: 5, '$': { '$': {} } }

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful