How to use createRegExp method in Best

Best JavaScript code snippet using best

FieldRegexpFactoryTests.js

Source:FieldRegexpFactoryTests.js Github

copy

Full Screen

1var assert = require('assert');2var ns = require('../FieldRegexpFactory');3var FieldRegexpFactory = ns.FieldRegexpFactory;4describe('FieldRegexpFactory', function(){5 var factory = new FieldRegexpFactory();6 it('throws if there are more fields than patterns', function(){7 assert.throws(function(){8 factory.createRegexp("35x", "(Account)(xxx)");9 });10 });11 it('one field', function(){12 var r = factory.createRegexp("35x", "(Account)");13 assert.equal(r, "^(?<Account>.{1,35})$");14 });15 it('unnamed field', function(){16 var r = factory.createRegexp("35x", "");17 assert.equal(r, "^(?<Value>.{1,35})$");18 });19 it('one field optional', function(){20 var r = factory.createRegexp("[35x]", "(Account)");21 assert.equal(r, "^(?<Account>.{1,35})?$");22 });23 it('one field exact', function(){24 var r = factory.createRegexp("6!n", "(Date)");25 assert.equal(r, "^(?<Date>.{6})$");26 });27 it('one field exact optional', function(){28 var r = factory.createRegexp("[6!n]", "(Date)");29 assert.equal(r, "^(?<Date>.{6})?$");30 });31 it('two fields', function(){32 var r = factory.createRegexp("3!a15d", "(Type)(Quantity)");33 assert.equal(r, "^(?<Type>.{3})(?<Quantity>.{1,15})$");34 });35 it('two optional fields', function(){36 var r = factory.createRegexp("[3!a][15d]", "(Type)(Quantity)");37 assert.equal(r, "^(?<Type>.{3})?(?<Quantity>.{1,15})?$");38 });39 it('one multiline field', function(){40 var r = factory.createRegexp("5*35x", "(Narrative)");41 assert.equal(r, "^(?<Narrative>.{1,35}(\r\n.{1,35}){0,4})$");42 });43 it('more multiline field', function(){44 var r = factory.createRegexp("4!c//4*35x", "(Qualifier)(Narrative)");45 assert.equal(r, "^(?<Qualifier>.{4})//(?<Narrative>.{1,35}(\r\n.{1,35}){0,3})$");46 });47 it('two separated fields', function(){48 var r = factory.createRegexp("4!c//8!n", "(Qualifier)(Date)");49 assert.equal(r, "^(?<Qualifier>.{4})//(?<Date>.{8})$");50 });51 it('two separated optional fields', function(){52 var r = factory.createRegexp("5n[/2n]", "(PageNumber)(Indicator)");53 assert.equal(r, "^(?<PageNumber>.{1,5})(/(?<Indicator>.{1,2}))?$");54 });55 it('multiple separated fields', function(){56 var r = factory.createRegexp(":4!c//3!a/3!a/15d", "(Qualifier)(FirstCurrencyCode)(SecondCurrencyCode)(Rate)");57 assert.equal(r, "^:?(?<Qualifier>.{4})//(?<FirstCurrencyCode>.{3})/(?<SecondCurrencyCode>.{3})/(?<Rate>.{1,15})$");58 });59 it('leading colon', function(){60 var r = factory.createRegexp(":4!c//8!n", "(Qualifier)(Date)");61 assert.equal(r, "^:?(?<Qualifier>.{4})//(?<Date>.{8})$");62 });63 it('empty field names', function(){64 var r = factory.createRegexp("3!n", "");65 assert.equal(r, "^(?<Value>.{3})$");66 });67//field merging68 it('merged fields', function(){69 var r = factory.createRegexp(":4!c//4!a2!a2!c[3!c]", "(Qualifier)(IdentifierCode)");70 assert.equal(r, "^:?(?<Qualifier>.{4})//(?<IdentifierCode>.{4}.{2}.{2}(.{3})?)$");71 });72//sign73 it('named sign', function(){74 var r = factory.createRegexp("[N]3!n", "(Sign)(Number)");75 assert.equal(r, "^(?<Sign>N)?(?<Number>.{3})$");76 });77//isin78 it('ISIN', function(){79 var r = factory.createRegexp("[ISIN1!e12!c]", "(IdentificationOfSecurity)");80 assert.equal(r, "^(ISIN {1}(?<IdentificationOfSecurity>.{12}))?$");81 });82//multiline83 it('multiline pattern with mandatory parts', function(){84 var r = factory.createRegexp("3!a$5!a", "(First)$(Second)");85 assert.equal(r, "^(?<First>.{3})\r\n(?<Second>.{5})$");86 });87 it('multiline pattern with optional first part', function(){88 var r = factory.createRegexp("[3!a]$5!a", "(First)$(Second)");89 assert.equal(r, "^(?<First>.{3})?(\r\n)?(?<Second>.{5})$");90 });91 it('multiline pattern with optional second part', function(){92 var r = factory.createRegexp("3!a$[5!a]", "(First)$(Second)");93 assert.equal(r, "^(?<First>.{3})(\r\n)?(?<Second>.{5})?$");94 });95 it('multiline pattern with optional both parts', function(){96 var r = factory.createRegexp("[3!a]$[5!a]", "(First)$(Second)");97 assert.equal(r, "^(?<First>.{3})?(\r\n)?(?<Second>.{5})?$");98 });99 it('multiline pattern with multiple fields', function(){100 var r = factory.createRegexp("[/1!a][/34x]$4!a2!a2!c[3!c]", "(PartyIdentifier)$(IdentifierCode)");101 assert.equal(r, "^(?<PartyIdentifier>(/.{1})?(/.{1,34})?)(\r\n)?(?<IdentifierCode>.{4}.{2}.{2}(.{3})?)$");102 });103 it('multiline pattern with multiline field', function(){104 var r = factory.createRegexp("[/1!a][/34x]$4*35x", "(PartyIdentifier)$(NameAndAddress)");105 assert.equal(r, "^(?<PartyIdentifier>(/.{1})?(/.{1,34})?)(\r\n)?(?<NameAndAddress>.{1,35}(\r\n.{1,35}){0,3})$");106 });107 it('multiline pattern with three lines', function(){108 var r = factory.createRegexp("3!n$6!n$[4!n6!n]", "(MTNumber)$(Date)$(SessionNumber)(ISN)");109 assert.equal(r, "^(?<MTNumber>.{3})\r\n(?<Date>.{6})(\r\n)?((?<SessionNumber>.{4})(?<ISN>.{6}))?$");110 });111//narrative112 it('charset z', function(){113 var r = factory.createRegexp("8000z", "(Narrative)");114 assert.equal(r, "^(?<Narrative>[\\s\\S]{1,8000})$");115 });116});117describe('FieldNamesParser', function(){118 it('parses empty string', function(){119 var result = ns.FieldNamesParser.parseFieldNames("");120 assert.deepEqual(result, []);121 });122 it('parses one field', function(){123 var result = ns.FieldNamesParser.parseFieldNames("(field)");124 assert.deepEqual(result, ["field"]);125 });126 it('parses multiple fields', function(){127 var result = ns.FieldNamesParser.parseFieldNames("(field1)(field2)(field 3 with space)");128 assert.deepEqual(result, ["field1", "field2", "field_3_with_space"]);129 });130 it('parses multiline fields', function(){131 var result = ns.FieldNamesParser.parseFieldNames("(field1)$(field2)(field3)");132 assert.deepEqual(result, ["field1", "field2", "field3"]);133 });134});135describe('FieldContentParser', function(){136 var factory = new FieldRegexpFactory();137 it('parses one field', function(){138 var r = factory.createRegexp("6!n", "(Date)");139 var fieldParser = new ns.FieldContentParser(r, new ns.FieldNames("(Date)"));140 var result = fieldParser.parse("123456");141 assert.deepEqual(result, {Date:"123456"});142 });143 it('parses complex field with colon', function(){144 var r = factory.createRegexp(":4!c//8!n6!n[,3n][/[N]2!n[2!n]]", "(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)");145 var fieldParser = new ns.FieldContentParser(r, new ns.FieldNames("(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)"));146 var result = fieldParser.parse(":QUAL//20140418010323,555/N9912");147 assert.deepEqual(result, {Qualifier:"QUAL", Date:"20140418", Time:"010323", Decimals:"555", 'UTC Sign': "N", 'UTC Indicator':"9912"});148 });149 it('parses complex field without colon', function(){150 var r = factory.createRegexp(":4!c//8!n6!n[,3n][/[N]2!n[2!n]]", "(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)");151 var fieldParser = new ns.FieldContentParser(r, new ns.FieldNames("(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)"));152 var result = fieldParser.parse("QUAL//20140418010323,555/N9912");153 assert.deepEqual(result, {Qualifier:"QUAL", Date:"20140418", Time:"010323", Decimals:"555", 'UTC Sign': "N", 'UTC Indicator':"9912"});154 });155});156describe('FieldParser', function() {157 var parser;158 before(function(){159 parser = new ns.FieldParser(patterns);160 });161 it('unnamed field', function(){162 var result = parser.parse('12', 'ABC');163 assert.deepEqual(result, {Value:"ABC"});164 });165 it('named field', function(){166 var result = parser.parse('19', '123456789');167 assert.deepEqual(result, {Amount:"123456789"});168 });169 it('optional part present', function(){170 var result = parser.parse('28', '1234/56');171 assert.deepEqual(result, {'Page Number':"1234", Indicator:"56"});172 });173 it('optional part missing', function(){174 var result = parser.parse('28', '1234');175 assert.deepEqual(result, {'Page Number':"1234"});176 });177 it('multiple fields with separator', function(){178 var result = parser.parse('92B', 'ABCD//CZK/USD/,0123456789');179 assert.deepEqual(result, {Qualifier:"ABCD", 'First Currency Code':"CZK","Second Currency Code":"USD", Rate:",0123456789"});180 });181 it('leading colon', function(){182 var result = parser.parse('92B', ':ABCD//CZK/USD/,0123456789');183 assert.deepEqual(result, {Qualifier:"ABCD", 'First Currency Code':"CZK","Second Currency Code":"USD", Rate:",0123456789"});184 });185 it('merged fields with optional present', function(){186 var result = parser.parse('95P', ':MERE//CRESCHZZEEO');187 assert.deepEqual(result, {Qualifier:"MERE", 'Identifier Code':"CRESCHZZEEO"});188 });189 it('merged fields with optional missing', function(){190 var result = parser.parse('95P', ':MERE//CRESCHZZ');191 assert.deepEqual(result, {Qualifier:"MERE", 'Identifier Code':"CRESCHZZ"});192 });193 it('sign missing', function(){194 var result = parser.parse('19A', 'ABCD//CZK123,456');195 assert.deepEqual(result, {Qualifier:"ABCD", 'Currency Code':"CZK", Amount:"123,456"});196 });197 it('sign present', function(){198 var result = parser.parse('19A', 'ABCD//NCZK123,456');199 assert.deepEqual(result, {Qualifier:"ABCD", Sign:"N", 'Currency Code':"CZK", Amount:"123,456"});200 });201 it('handling of 98E - mandatory only', function(){202 var result = parser.parse('98E', 'ABCD//20140427133200');203 assert.deepEqual(result, {Qualifier:"ABCD", Date:"20140427", Time:"133200"});204 });205 it('handling of 98E - with decimals', function(){206 var result = parser.parse('98E', 'ABCD//20140427133200,123');207 assert.deepEqual(result, {Qualifier:"ABCD", Date:"20140427", Time:"133200", Decimals:"123"});208 });209 it('handling of 98E - with sign', function(){210 var result = parser.parse('98E', 'ABCD//20140427133200/N0102');211 assert.deepEqual(result, {Qualifier:"ABCD", Date:"20140427", Time:"133200", "UTC Sign":"N", "UTC Indicator":"0102"});212 });213 it('narrative single line', function(){214 var narrative = '++ ADDITIONAL INFORMATION ++SHS DEL';215 var result = parser.parse('70G', "ADTX//" + narrative);216 assert.deepEqual(result, {Qualifier:"ADTX", Narrative:narrative});217 });218 it('narrative multiline', function(){219 var narrative = '++ ADDITIONAL INFORMATION ++SHS DEL\r\nTO YOU UPON RECEIPT PLUS\r\nHKD80.64';220 var result = parser.parse('70G', "ADTX//" + narrative);221 assert.deepEqual(result, {Qualifier:"ADTX", Narrative:narrative});222 });223 it('narrative charset z', function(){224 var narrative = "+------------- REPURCHASE OFFER / -------------+\r\n+------------ CONSENT SOLICITATION ------------+\r\n.\r\nCONTINUATION OF SWIFT MT564/568 SENT WITH CORP.\r\nREF. 294166.\r\n.\r\nPROCEEDS:\r\n.\r\n1/(A) TOTAL CONSIDERATION:\r\nHOLDERS WHO VALIDLY TENDER THEIR NOTES BEFORE\r\nTHE EARLY TENDER DEADLINE AND WHOSE NOTES ARE\r\nACCEPTED FOR PURCHASE WILL RECEIVE USD 1'170.87\r\nFOR EACH USD 1'000 PRINCIPAL AMOUNT.\r\n(THE TOTAL CONSIDERATION INCLUDES A CONSENT\r\nPAYMENT OF USD 30.00 PER USD 1'000 PRINCIPAL\r\nAMOUNT)\r\n.\r\n1/(B) OFFER CONSIDERATION:\r\nHOLDERS WHO VALIDLY TENDER THEIR NOTES AFTER THE\r\nEARLY TENDER DEADLINE AND WHOSE NOTES ARE\r\nACCEPTED FOR PURCHASE WILL RECEIVE USD 1'140.87\r\nFOR EACH USD 1'000 PRINCIPAL AMOUNT.\r\n.\r\n2/ IN ADDITION, AN AMOUNT IN CASH FOR ACCRUED\r\nAND UNPAID INTEREST WILL BE PAID, WHICH WILL BE\r\nHANDLED BY OUR INCOME DEPARTMENT.\r\n.\r\nTHE CONSENT PAYMENT IS N-O-T IRS REPORTABLE WITH\r\nINCOME CODE 50.\r\n.\r\nPOSSIBLE EFFECTS ON UNTENDERED NOTES:\r\nAS SOON AS REASONABLY PRACTICABLE FOLLOWING THE\r\nFINANCING, THE COMPANY CURRENTLY INTENDS, BUT IS\r\nNOT OBLIGATED, TO CALL FOR REDEMPTION ALL OF THE\r\nNOTES THAT REMAIN OUTSTANDING FOLLOWING THE\r\nCONSUMMATION OF THE FINANCING IN ACCORDANCE WITH\r\nTHE PROVISIONS OF THE INDENTURE, AND AT THAT\r\nTIME TO SATISFY AND DISCHARGE THE INDENTURE IN\r\nACCORDANCE WITH ITS TERMS. PLEASE FIND FURTHER\r\nINFORMATION TO UNTENDERED NOTES ON PAGES 6, 10\r\nAND 20-21 IN THE 'PROSPECTUS'.\r\n.\r\nCONDITIONS OF THE OFFER:\r\nTHE OFFER IS NOT CONDITIONED UPON ANY MINIMUM\r\nAMOUNT OF NOTES BEING TENDERED OR ANY OF THE\r\nPROPOSED AMENDMENTS BECOMING OPERATIVE. THE\r\nOFFER IS HOWEVER SUBJECT TO THE SATISFACITON OF\r\nTHE FINANCING CONDITION AND THE GENERAL\r\nCONDITIONS.\r\n.\r\nADOPTION OF THE PROPOSED AMENDMENTS ARE SUBJECT\r\nTO COMPANY'S RECEIPT OF THE RELEVANT REQUISITE\r\nCONSENTS, SATISFACTION OF THE FINANCING\r\nCONDITION AND CONSUMMATION OF THE OFFER.\r\n.\r\nPLEASE FIND FULL DESCRIPTION OF THE OFFER\r\nCONDITIONS ON PAGES III AND 11-13 IN THE\r\n'PROSPECTUS'.\r\n.\r\nTIMETABLE:\r\nWITHDRAWAL DEADLINE: PLEASE FULLY REFER TO PAGE\r\nIV IN THE 'PROSPECTUS'\r\n.\r\nRESTRICTIONS: NONE\r\nINVESTORS MUST VERIFY THAT THEY ARE NOT ACTING\r\nAGAINST THEIR COUNTRY'S REGULATIONS.\r\n.\r\nWITH YOUR INSTRUCTION YOU CONFIRM YOUR\r\nELIGIBILITY TO PARTICIPATE IN THE OFFER.\r\n.\r\nTHE 'PROSPECTUS' IS AVAILABLE IN CAES OR AT SIX\r\nSIS UPON REQUEST.\r\n.\r\n+++++++++ EARLY RESULTS AND SETTLEMENT +++++++++\r\n.\r\nAS OF THE EARLY TENDER DEADLINE USD 598'620'000\r\nAGGREGATE PRINCIPAL AMOUNT, OR APPROXIMATELY\r\n99.8 PCT OF THE NOTES HAVE BEEN VALIDLY TENDERED\r\nAND THE RELATED CONSENTS HAVE BEEN VALIDLY\r\nDELIVERED.\r\n.\r\nWITH THE RECEIPT OF THE REQUISITE CONSENTS, THE\r\nCOMPANY HAS EXECUTED A SUPPLEMENTAL INDENTURE\r\nGOVERNING THE NOTES, WHICH WILL AMEND THE\r\nINDENTURE UNDER WHICH THE NOTES WERE ISSUED TO\r\nELIMINATE SUBSTANTIALLY ALL OF THE RESTRICTIVE\r\nCOVENANTS AND EVENTS OF DEFAULT AND RELATED\r\nPROVISIONS IN THE INDENTURE. THE AMENDMENTS TO\r\nTHE INDENTURE WILL BECOME OPERATIVE UPON PAYMENT\r\nFOR NOTES VALIDLY TENDERED PRIOR TO THE EARLY\r\nTENDER DEADLINE MADE BY THE COMPANY.\r\n.\r\nHOLDERS WHO PARTICIPATED IN THE OFFER AND WHOSE\r\nNOTES HAVE BEEN ACCEPTED WILL BE CREDITED TODAY,\r\nWITH VALUE DATE 08.02.2013, WITH THE FOLLOWING\r\nCASH AMOUNT (FOR EACH USD 1'000 P.A.):\r\n.\r\nPURCHASE PRICE: USD 1'140.87\r\nCONSENT PAYMENT: USD 30.00\r\nACCRUED INTEREST: USD 23.631944\r\n(RATE: 10.25 PCT / DAYS: 83/360)\r\n.\r\nTHE 'EARLY RESULTS ANNOUNCEMENT' IS AVAILABLE IN\r\nCAES OR AT SIX SIS UPON REQUEST.\r\n.\r\nSTATUS: COMPLETE\r\n.\r\nFOR ANY QUERIES PLEASE CONTACT:\r\nCABO.GROUP(AT)ISIS.SISCLEAR.COM";225 var result = parser.parse('70F', "ADTX//" + narrative);226 assert.deepEqual(result, {Qualifier:"ADTX", Narrative:narrative});227 });228 it('identification of security with ISIN and description', function(){229 var result = parser.parse('35B', "ISIN US8175651046\r\n/CH/969683\r\nSERVICE CORP INTL SHS");230 assert.deepEqual(result, {'Identification of Security':"US8175651046", 'Description of Security':"/CH/969683\r\nSERVICE CORP INTL SHS"});231 });232 it('identification of security without ISIN', function(){233 var content = "/CH/969683\r\nSERVICE CORP INTL SHS";234 var result = parser.parse('35B', content);235 assert.deepEqual(result, {'Description of Security':content});236 });237 it('identification of security with ISIN only', function(){238 var result = parser.parse('35B', "ISIN US8175651046");239 assert.deepEqual(result, {'Identification of Security':"US8175651046"});240 });241 it('multiline pattern - first line present', function(){242 var result = parser.parse('53D', '/X/123456\r\nname\r\naddres\r\naddress2');243 assert.deepEqual(result, {"Party Identifier":"/X/123456", "Name and Address":"name\r\naddres\r\naddress2"});244 });245 it('multiline pattern - first line missing', function(){246 var result = parser.parse('53D', 'name\r\naddres\r\naddress2');247 assert.deepEqual(result, {"Name and Address":"name\r\naddres\r\naddress2", 'Party Identifier':""}); //the fully optional party matches an empty string248 });249 it('handling of 77E not supported', function(){250 assert.throws(function(){251 parser.parse('77E', 'ABCD//20140427133200');252 });253 });254});255var patterns = {256 "12": {257 "pattern": "3!n",258 "fieldNames": ""259 },260 "19": {261 "pattern": "17d",262 "fieldNames": "(Amount)"263 },264 "28": {265 "pattern": "5n[/2n]",266 "fieldNames": "(Page Number)(Indicator)"267 },268 "92B": {269 "pattern": ":4!c//3!a/3!a/15d",270 "fieldNames": "(Qualifier)(First Currency Code)(Second Currency Code)(Rate)"271 },272 "95P": {273 "pattern": ":4!c//4!a2!a2!c[3!c]",274 "fieldNames": "(Qualifier)(Identifier Code)"275 },276 "19A": {277 "pattern": ":4!c//[N]3!a15d",278 "fieldNames": "(Qualifier)(Sign)(Currency Code)(Amount)"279 },280 "98E": {281 "pattern": ":4!c//8!n6!n[,3n][/[N]2!n[2!n]]",282 "fieldNames": "(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)"283 },284 "70G": {285 "pattern": ":4!c//10*35z",286 "fieldNames": "(Qualifier)(Narrative)"287 },288 "70F": {289 "pattern": ":4!c//8000z",290 "fieldNames": "(Qualifier)(Narrative)"291 },292 "35B": {293 "pattern": "[ISIN1!e12!c]$[4*35x]",294 "fieldNames": "(Identification of Security)$(Description of Security)"295 },296 "53D": {297 "pattern": "[/1!a][/34x]$4*35x",298 "fieldNames": "(Party Identifier)$(Name and Address)"299 },300 "77E": {301 "pattern": "73x$[n*78x]",302 "fieldNames": "(Text)$(Text)"303 }...

Full Screen

Full Screen

fieldRegexpFactory.test.js

Source:fieldRegexpFactory.test.js Github

copy

Full Screen

1const assert = require('assert');2const ns = require('../lib/FieldRegexpFactory');3const { FieldRegexpFactory } = ns;4const patterns = {5 12: {6 pattern: '3!n',7 fieldNames: '(Value)',8 },9 '15A': {10 pattern: '',11 fieldNames: '',12 },13 19: {14 pattern: '17d',15 fieldNames: '(Amount)',16 },17 28: {18 pattern: '5n[/2n]',19 fieldNames: '(Page Number)(Indicator)',20 },21 '92B': {22 pattern: ':4!c//3!a/3!a/15d',23 fieldNames: '(Qualifier)(First Currency Code)(Second Currency Code)(Rate)',24 },25 '95P': {26 pattern: ':4!c//4!a2!a2!c[3!c]',27 fieldNames: '(Qualifier)(Identifier Code)',28 },29 '19A': {30 pattern: ':4!c//[N]3!a15d',31 fieldNames: '(Qualifier)(Sign)(Currency Code)(Amount)',32 },33 '98E': {34 pattern: ':4!c//8!n6!n[,3n][/[N]2!n[2!n]]',35 fieldNames: '(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)',36 },37 '70G': {38 pattern: ':4!c//10*35z',39 fieldNames: '(Qualifier)(Narrative)',40 },41 '70F': {42 pattern: ':4!c//8000z',43 fieldNames: '(Qualifier)(Narrative)',44 },45 '35B': {46 pattern: '[ISIN1!e12!c]$[4*35x]',47 fieldNames: '(Identification of Security)$(Description of Security)',48 },49 '53D': {50 pattern: '[/1!a][/34x]$4*35x',51 fieldNames: '(Party Identifier)$(Name and Address)',52 },53 '77E': {54 pattern: '73x$[n*78x]',55 fieldNames: '(Text)$(Text)',56 },57};58describe('FieldRegexpFactory', () => {59 const factory = new FieldRegexpFactory();60 it('throws if there are more fields than patterns', () => {61 assert.throws(() => {62 factory.createRegexp('35x', '(Account)(xxx)');63 });64 });65 it('one field', () => {66 const r = factory.createRegexp('35x', '(Account)');67 assert.equal(r, '^(?<Account>.{1,35})$');68 });69 it('unnamed field', () => {70 const r = factory.createRegexp('35x', '');71 assert.equal(r, '^.{1,35}$');72 });73 it('one field optional', () => {74 const r = factory.createRegexp('[35x]', '(Account)');75 assert.equal(r, '^(?<Account>.{1,35})?$');76 });77 it('one field exact', () => {78 const r = factory.createRegexp('6!n', '(Date)');79 assert.equal(r, '^(?<Date>.{6})$');80 });81 it('one field exact optional', () => {82 const r = factory.createRegexp('[6!n]', '(Date)');83 assert.equal(r, '^(?<Date>.{6})?$');84 });85 it('two fields', () => {86 const r = factory.createRegexp('3!a15d', '(Type)(Quantity)');87 assert.equal(r, '^(?<Type>.{3})(?<Quantity>.{1,15})$');88 });89 it('two optional fields', () => {90 const r = factory.createRegexp('[3!a][15d]', '(Type)(Quantity)');91 assert.equal(r, '^(?<Type>.{3})?(?<Quantity>.{1,15})?$');92 });93 it('one multiline field', () => {94 const r = factory.createRegexp('5*35x', '(Narrative)');95 assert.equal(r, '^(?<Narrative>.{1,35}(\n.{1,35}){0,4})$');96 });97 it('more multiline field', () => {98 const r = factory.createRegexp('4!c//4*35x', '(Qualifier)(Narrative)');99 assert.equal(r, '^(?<Qualifier>.{4})//(?<Narrative>.{1,35}(\n.{1,35}){0,3})$');100 });101 it('two separated fields', () => {102 const r = factory.createRegexp('4!c//8!n', '(Qualifier)(Date)');103 assert.equal(r, '^(?<Qualifier>.{4})//(?<Date>.{8})$');104 });105 it('two separated optional fields', () => {106 const r = factory.createRegexp('5n[/2n]', '(PageNumber)(Indicator)');107 assert.equal(r, '^(?<PageNumber>.{1,5})(/(?<Indicator>.{1,2}))?$');108 });109 it('multiple separated fields', () => {110 const r = factory.createRegexp(':4!c//3!a/3!a/15d', '(Qualifier)(FirstCurrencyCode)(SecondCurrencyCode)(Rate)');111 assert.equal(r, '^:?(?<Qualifier>.{4})//(?<FirstCurrencyCode>.{3})/(?<SecondCurrencyCode>.{3})/(?<Rate>.{1,15})$');112 });113 it('leading colon', () => {114 const r = factory.createRegexp(':4!c//8!n', '(Qualifier)(Date)');115 assert.equal(r, '^:?(?<Qualifier>.{4})//(?<Date>.{8})$');116 });117 it('empty field names', () => {118 const r = factory.createRegexp('3!n', '');119 assert.equal(r, '^.{3}$');120 });121 // field merging122 it('merged fields', () => {123 const r = factory.createRegexp(':4!c//4!a2!a2!c[3!c]', '(Qualifier)(IdentifierCode)');124 assert.equal(r, '^:?(?<Qualifier>.{4})//(?<IdentifierCode>.{4}.{2}.{2}(.{3})?)$');125 });126 // sign127 it('named sign', () => {128 const r = factory.createRegexp('[N]3!n', '(Sign)(Number)');129 assert.equal(r, '^(?<Sign>N)?(?<Number>.{3})$');130 });131 // isin132 it('ISIN', () => {133 const r = factory.createRegexp('[ISIN1!e12!c]', '(IdentificationOfSecurity)');134 assert.equal(r, '^(ISIN {1}(?<IdentificationOfSecurity>.{12}))?$');135 });136 // multiline137 it('multiline pattern with mandatory parts', () => {138 const r = factory.createRegexp('3!a$5!a', '(First)$(Second)');139 assert.equal(r, '^(?<First>.{3})\n(?<Second>.{5})$');140 });141 it('multiline pattern with optional first part', () => {142 const r = factory.createRegexp('[3!a]$5!a', '(First)$(Second)');143 assert.equal(r, '^(?<First>.{3})?(\n)?(?<Second>.{5})$');144 });145 it('multiline pattern with optional second part', () => {146 const r = factory.createRegexp('3!a$[5!a]', '(First)$(Second)');147 assert.equal(r, '^(?<First>.{3})(\n)?(?<Second>.{5})?$');148 });149 it('multiline pattern with optional both parts', () => {150 const r = factory.createRegexp('[3!a]$[5!a]', '(First)$(Second)');151 assert.equal(r, '^(?<First>.{3})?(\n)?(?<Second>.{5})?$');152 });153 it('multiline pattern with multiple fields', () => {154 const r = factory.createRegexp('[/1!a][/34x]$4!a2!a2!c[3!c]', '(PartyIdentifier)$(IdentifierCode)');155 assert.equal(r, '^(?<PartyIdentifier>(/.{1})?(/.{1,34})?)(\n)?(?<IdentifierCode>.{4}.{2}.{2}(.{3})?)$');156 });157 it('multiline pattern with multiline field', () => {158 const r = factory.createRegexp('[/1!a][/34x]$4*35x', '(PartyIdentifier)$(NameAndAddress)');159 assert.equal(r, '^(?<PartyIdentifier>(/.{1})?(/.{1,34})?)(\n)?(?<NameAndAddress>.{1,35}(\n.{1,35}){0,3})$');160 });161 it('multiline pattern with three lines', () => {162 const r = factory.createRegexp('3!n$6!n$[4!n6!n]', '(MTNumber)$(Date)$(SessionNumber)(ISN)');163 assert.equal(r, '^(?<MTNumber>.{3})\n(?<Date>.{6})(\n)?((?<SessionNumber>.{4})(?<ISN>.{6}))?$');164 });165 // narrative166 it('charset z', () => {167 const r = factory.createRegexp('8000z', '(Narrative)');168 assert.equal(r, '^(?<Narrative>[\\s\\S]{1,8000})$');169 });170});171describe('FieldNamesParser', () => {172 it('parses empty string', () => {173 const result = ns.FieldNamesParser.parseFieldNames('');174 assert.deepEqual(result, []);175 });176 it('parses one field', () => {177 const result = ns.FieldNamesParser.parseFieldNames('(field)');178 assert.deepEqual(result, ['field']);179 });180 it('parses multiple fields', () => {181 const result = ns.FieldNamesParser.parseFieldNames('(field1)(field2)(field 3 with space)');182 assert.deepEqual(result, ['field1', 'field2', 'field_3_with_space']);183 });184 it('parses multiline fields', () => {185 const result = ns.FieldNamesParser.parseFieldNames('(field1)$(field2)(field3)');186 assert.deepEqual(result, ['field1', 'field2', 'field3']);187 });188});189describe('FieldContentParser', () => {190 const factory = new FieldRegexpFactory();191 it('parses one field', () => {192 const r = factory.createRegexp('6!n', '(Date)');193 const fieldParser = new ns.FieldContentParser(r, new ns.FieldNames('(Date)'));194 const result = fieldParser.parse('123456');195 assert.deepEqual(result, { Date: '123456' });196 });197 it('parses complex field with colon', () => {198 const r = factory.createRegexp(':4!c//8!n6!n[,3n][/[N]2!n[2!n]]', '(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)');199 const fieldParser = new ns.FieldContentParser(r, new ns.FieldNames('(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)'));200 const result = fieldParser.parse(':QUAL//20140418010323,555/N9912');201 assert.deepEqual(result, {202 Qualifier: 'QUAL', Date: '20140418', Time: '010323', Decimals: '555', 'UTC Sign': 'N', 'UTC Indicator': '9912',203 });204 });205 it('parses complex field without colon', () => {206 const r = factory.createRegexp(':4!c//8!n6!n[,3n][/[N]2!n[2!n]]', '(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)');207 const fieldParser = new ns.FieldContentParser(r, new ns.FieldNames('(Qualifier)(Date)(Time)(Decimals)(UTC Sign)(UTC Indicator)'));208 const result = fieldParser.parse('QUAL//20140418010323,555/N9912');209 assert.deepEqual(result, {210 Qualifier: 'QUAL', Date: '20140418', Time: '010323', Decimals: '555', 'UTC Sign': 'N', 'UTC Indicator': '9912',211 });212 });213});214describe('FieldParser', () => {215 let parser;216 before(() => {217 parser = new ns.FieldParser(patterns);218 });219 it('unnamed field', () => {220 const result = parser.parse('12', 'ABC');221 assert.deepEqual(result, { Value: 'ABC' });222 });223 it('named field', () => {224 const result = parser.parse('19', '123456789');225 assert.deepEqual(result, { Amount: '123456789' });226 });227 it('sequence field', () => {228 const result = parser.parse('15A', '');229 assert.deepEqual(result, {});230 });231 it('optional part present', () => {232 const result = parser.parse('28', '1234/56');233 assert.deepEqual(result, { 'Page Number': '1234', Indicator: '56' });234 });235 it('optional part missing', () => {236 const result = parser.parse('28', '1234');237 assert.deepEqual(result, { 'Page Number': '1234' });238 });239 it('multiple fields with separator', () => {240 const result = parser.parse('92B', 'ABCD//CZK/USD/,0123456789');241 assert.deepEqual(result, {242 Qualifier: 'ABCD', 'First Currency Code': 'CZK', 'Second Currency Code': 'USD', Rate: ',0123456789',243 });244 });245 it('leading colon', () => {246 const result = parser.parse('92B', ':ABCD//CZK/USD/,0123456789');247 assert.deepEqual(result, {248 Qualifier: 'ABCD', 'First Currency Code': 'CZK', 'Second Currency Code': 'USD', Rate: ',0123456789',249 });250 });251 it('merged fields with optional present', () => {252 const result = parser.parse('95P', ':MERE//CRESCHZZEEO');253 assert.deepEqual(result, { Qualifier: 'MERE', 'Identifier Code': 'CRESCHZZEEO' });254 });255 it('merged fields with optional missing', () => {256 const result = parser.parse('95P', ':MERE//CRESCHZZ');257 assert.deepEqual(result, { Qualifier: 'MERE', 'Identifier Code': 'CRESCHZZ' });258 });259 it('sign missing', () => {260 const result = parser.parse('19A', 'ABCD//CZK123,456');261 assert.deepEqual(result, { Qualifier: 'ABCD', 'Currency Code': 'CZK', Amount: '123,456' });262 });263 it('sign present', () => {264 const result = parser.parse('19A', 'ABCD//NCZK123,456');265 assert.deepEqual(result, {266 Qualifier: 'ABCD', Sign: 'N', 'Currency Code': 'CZK', Amount: '123,456',267 });268 });269 it('handling of 98E - mandatory only', () => {270 const result = parser.parse('98E', 'ABCD//20140427133200');271 assert.deepEqual(result, { Qualifier: 'ABCD', Date: '20140427', Time: '133200' });272 });273 it('handling of 98E - with decimals', () => {274 const result = parser.parse('98E', 'ABCD//20140427133200,123');275 assert.deepEqual(result, {276 Qualifier: 'ABCD', Date: '20140427', Time: '133200', Decimals: '123',277 });278 });279 it('handling of 98E - with sign', () => {280 const result = parser.parse('98E', 'ABCD//20140427133200/N0102');281 assert.deepEqual(result, {282 Qualifier: 'ABCD', Date: '20140427', Time: '133200', 'UTC Sign': 'N', 'UTC Indicator': '0102',283 });284 });285 it('narrative single line', () => {286 const narrative = '++ ADDITIONAL INFORMATION ++SHS DEL';287 const result = parser.parse('70G', `ADTX//${narrative}`);288 assert.deepEqual(result, { Qualifier: 'ADTX', Narrative: narrative });289 });290 it('narrative multiline', () => {291 const narrative = '++ ADDITIONAL INFORMATION ++SHS DEL\nTO YOU UPON RECEIPT PLUS\nHKD80.64';292 const result = parser.parse('70G', `ADTX//${narrative}`);293 assert.deepEqual(result, { Qualifier: 'ADTX', Narrative: narrative });294 });295 it('narrative charset z', () => {296 const narrative = "+------------- REPURCHASE OFFER / -------------+\n+------------ CONSENT SOLICITATION ------------+\n.\nCONTINUATION OF SWIFT MT564/568 SENT WITH CORP.\nREF. 294166.\n.\nPROCEEDS:\n.\n1/(A) TOTAL CONSIDERATION:\nHOLDERS WHO VALIDLY TENDER THEIR NOTES BEFORE\nTHE EARLY TENDER DEADLINE AND WHOSE NOTES ARE\nACCEPTED FOR PURCHASE WILL RECEIVE USD 1'170.87\nFOR EACH USD 1'000 PRINCIPAL AMOUNT.\n(THE TOTAL CONSIDERATION INCLUDES A CONSENT\nPAYMENT OF USD 30.00 PER USD 1'000 PRINCIPAL\nAMOUNT)\n.\n1/(B) OFFER CONSIDERATION:\nHOLDERS WHO VALIDLY TENDER THEIR NOTES AFTER THE\nEARLY TENDER DEADLINE AND WHOSE NOTES ARE\nACCEPTED FOR PURCHASE WILL RECEIVE USD 1'140.87\nFOR EACH USD 1'000 PRINCIPAL AMOUNT.\n.\n2/ IN ADDITION, AN AMOUNT IN CASH FOR ACCRUED\nAND UNPAID INTEREST WILL BE PAID, WHICH WILL BE\nHANDLED BY OUR INCOME DEPARTMENT.\n.\nTHE CONSENT PAYMENT IS N-O-T IRS REPORTABLE WITH\nINCOME CODE 50.\n.\nPOSSIBLE EFFECTS ON UNTENDERED NOTES:\nAS SOON AS REASONABLY PRACTICABLE FOLLOWING THE\nFINANCING, THE COMPANY CURRENTLY INTENDS, BUT IS\nNOT OBLIGATED, TO CALL FOR REDEMPTION ALL OF THE\nNOTES THAT REMAIN OUTSTANDING FOLLOWING THE\nCONSUMMATION OF THE FINANCING IN ACCORDANCE WITH\nTHE PROVISIONS OF THE INDENTURE, AND AT THAT\nTIME TO SATISFY AND DISCHARGE THE INDENTURE IN\nACCORDANCE WITH ITS TERMS. PLEASE FIND FURTHER\nINFORMATION TO UNTENDERED NOTES ON PAGES 6, 10\nAND 20-21 IN THE 'PROSPECTUS'.\n.\nCONDITIONS OF THE OFFER:\nTHE OFFER IS NOT CONDITIONED UPON ANY MINIMUM\nAMOUNT OF NOTES BEING TENDERED OR ANY OF THE\nPROPOSED AMENDMENTS BECOMING OPERATIVE. THE\nOFFER IS HOWEVER SUBJECT TO THE SATISFACITON OF\nTHE FINANCING CONDITION AND THE GENERAL\nCONDITIONS.\n.\nADOPTION OF THE PROPOSED AMENDMENTS ARE SUBJECT\nTO COMPANY'S RECEIPT OF THE RELEVANT REQUISITE\nCONSENTS, SATISFACTION OF THE FINANCING\nCONDITION AND CONSUMMATION OF THE OFFER.\n.\nPLEASE FIND FULL DESCRIPTION OF THE OFFER\nCONDITIONS ON PAGES III AND 11-13 IN THE\n'PROSPECTUS'.\n.\nTIMETABLE:\nWITHDRAWAL DEADLINE: PLEASE FULLY REFER TO PAGE\nIV IN THE 'PROSPECTUS'\n.\nRESTRICTIONS: NONE\nINVESTORS MUST VERIFY THAT THEY ARE NOT ACTING\nAGAINST THEIR COUNTRY'S REGULATIONS.\n.\nWITH YOUR INSTRUCTION YOU CONFIRM YOUR\nELIGIBILITY TO PARTICIPATE IN THE OFFER.\n.\nTHE 'PROSPECTUS' IS AVAILABLE IN CAES OR AT SIX\nSIS UPON REQUEST.\n.\n+++++++++ EARLY RESULTS AND SETTLEMENT +++++++++\n.\nAS OF THE EARLY TENDER DEADLINE USD 598'620'000\nAGGREGATE PRINCIPAL AMOUNT, OR APPROXIMATELY\n99.8 PCT OF THE NOTES HAVE BEEN VALIDLY TENDERED\nAND THE RELATED CONSENTS HAVE BEEN VALIDLY\nDELIVERED.\n.\nWITH THE RECEIPT OF THE REQUISITE CONSENTS, THE\nCOMPANY HAS EXECUTED A SUPPLEMENTAL INDENTURE\nGOVERNING THE NOTES, WHICH WILL AMEND THE\nINDENTURE UNDER WHICH THE NOTES WERE ISSUED TO\nELIMINATE SUBSTANTIALLY ALL OF THE RESTRICTIVE\nCOVENANTS AND EVENTS OF DEFAULT AND RELATED\nPROVISIONS IN THE INDENTURE. THE AMENDMENTS TO\nTHE INDENTURE WILL BECOME OPERATIVE UPON PAYMENT\nFOR NOTES VALIDLY TENDERED PRIOR TO THE EARLY\nTENDER DEADLINE MADE BY THE COMPANY.\n.\nHOLDERS WHO PARTICIPATED IN THE OFFER AND WHOSE\nNOTES HAVE BEEN ACCEPTED WILL BE CREDITED TODAY,\nWITH VALUE DATE 08.02.2013, WITH THE FOLLOWING\nCASH AMOUNT (FOR EACH USD 1'000 P.A.):\n.\nPURCHASE PRICE: USD 1'140.87\nCONSENT PAYMENT: USD 30.00\nACCRUED INTEREST: USD 23.631944\n(RATE: 10.25 PCT / DAYS: 83/360)\n.\nTHE 'EARLY RESULTS ANNOUNCEMENT' IS AVAILABLE IN\nCAES OR AT SIX SIS UPON REQUEST.\n.\nSTATUS: COMPLETE\n.\nFOR ANY QUERIES PLEASE CONTACT:\nCABO.GROUP(AT)ISIS.SISCLEAR.COM";297 const result = parser.parse('70F', `ADTX//${narrative}`);298 assert.deepEqual(result, { Qualifier: 'ADTX', Narrative: narrative });299 });300 it('identification of security with ISIN and description', () => {301 const result = parser.parse('35B', 'ISIN US8175651046\n/CH/969683\nSERVICE CORP INTL SHS');302 assert.deepEqual(result, { 'Identification of Security': 'US8175651046', 'Description of Security': '/CH/969683\nSERVICE CORP INTL SHS' });303 });304 it('identification of security without ISIN', () => {305 const content = '/CH/969683\nSERVICE CORP INTL SHS';306 const result = parser.parse('35B', content);307 assert.deepEqual(result, { 'Description of Security': content });308 });309 it('identification of security with ISIN only', () => {310 const result = parser.parse('35B', 'ISIN US8175651046');311 assert.deepEqual(result, { 'Identification of Security': 'US8175651046' });312 });313 it('multiline pattern - first line present', () => {314 const result = parser.parse('53D', '/X/123456\nname\naddres\naddress2');315 assert.deepEqual(result, { 'Party Identifier': '/X/123456', 'Name and Address': 'name\naddres\naddress2' });316 });317 it('multiline pattern - first line missing', () => {318 const result = parser.parse('53D', 'name\naddres\naddress2');319 assert.deepEqual(result, { 'Name and Address': 'name\naddres\naddress2', 'Party Identifier': '' }); // the fully optional party matches an empty string320 });321 it('handling of 77E not supported', () => {322 assert.throws(() => {323 parser.parse('77E', 'ABCD//20140427133200');324 });325 });...

Full Screen

Full Screen

cache-helpers.spec.js

Source:cache-helpers.spec.js Github

copy

Full Screen

...64 });65 });66 describe('-> createRegExp', () => {67 it('should create a regexp from a string', () => {68 const re = createRegExp('/houses/2');69 expect(re).to.eql(/\/houses\/2/);70 });71 it('should support * to .* rewrite', () => {72 const re = createRegExp('/houses/2*');73 expect(re).to.eql(/\/houses\/2.*/);74 });75 it('should support ? to \\? rewrite', () => {76 const re = createRegExp('/houses/2?hallo');77 expect(re).to.eql(/\/houses\/2\?hallo/);78 });79 it('should support . to \\. rewrite', () => {80 const re = createRegExp('/houses/2.hallo');81 expect(re).to.eql(/\/houses\/2\.hallo/);82 });83 it('should support [ to \\[ rewrite', () => {84 const re = createRegExp('/houses/2hallo[');85 expect(re).to.eql(/\/houses\/2hallo\[/);86 });87 it('should support ] to \\] rewrite', () => {88 const re = createRegExp('/houses/2hallo]');89 expect(re).to.eql(/\/houses\/2hallo\]/);90 });91 it('should support ^ to \\^ rewrite', () => {92 const re = createRegExp('/houses/2hallo^');93 expect(re).to.eql(/\/houses\/2hallo\^/);94 });95 it('should support $ to \\$ rewrite', () => {96 const re = createRegExp('/houses/2hallo$');97 expect(re).to.eql(/\/houses\/2hallo\$/);98 });99 it('should rewrite urls', () => {100 const re = createRegExp('http://localhost.no/?param1=yo&param2=yo');101 expect(re).to.eql(/http:\/\/localhost\.no\/\?param1=yo&param2=yo/);102 });103 });...

Full Screen

Full Screen

check-license-headers.js

Source:check-license-headers.js Github

copy

Full Screen

...72 'strings',73 'ipynb',74 'htm',75 'toml',76].map((extension) => createRegExp(`.${extension}$`));77const GENERIC_IGNORED_PATTERNS = [78 '(^|/)\\.[^/]+(/|$)',79 //'third[_\\-. ]party/', // to be on the safe side80 '^node[_\\-. ]modules/',81 'gradlew\\.bat$',82 'gradlew$',83 'gradle/wrapper/',84 '.idea/',85 '__init__\\.py$',86 '^Setup.hs$',87 '^(readme|README|Readme)\\..*$',88 'Cargo\\.toml$',89 '^Cartfile.*$',90 '^.*\\.xcodeproj/$',...

Full Screen

Full Screen

dataGenerator.js

Source:dataGenerator.js Github

copy

Full Screen

1const {2 landingStories,3 landingPagination,4} = require('../mocks/stories');5function createRegexp (stringToGoIntoTheRegex) {6 const parsed = stringToGoIntoTheRegex.replace(/[\\?]/g, '\\$&');7 // We need to match anything other query params that go after it8 return new RegExp(`${parsed}[\\S]+`);9}10class DataMock {11 constructor (page) {12 this.page = page;13 this.handlers = [];14 this.page.on('request', req => {15 const hadHandler = this.handlers.find(handler => {16 return handler(req);17 });18 !hadHandler && req.continue();19 });20 }21 _matchesRegexp (regexp) {22 return (req) => {23 return !!(req.url().match(regexp));24 };25 };26 _handleRequest (match, response, config = {}) {27 this.handlers.push(req => {28 if (match(req)) {29 let body;30 if (config.pagination) {31 body = {32 data: response,33 ...config.pagination34 }35 } else {36 body = response;37 }38 req.respond({39 status: 200 || config.status,40 contentType: 'application/json' || config.contentType,41 body: JSON.stringify(body),42 });43 return true;44 }45 return false;46 });47 }48 mockStories (stories = landingStories, config = { pagination: landingPagination }) {49 const regexp = createRegexp(`public/story?`);50 this._handleRequest(51 req => {52 return !!(req.url().match(regexp));53 },54 stories,55 config,56 );57 }58 mockStoriesQuickSearch (filter, stories = landingStories, config = { pagination: landingPagination }) {59 const regexp = createRegexp(`public/story/quick?quickSearch=${filter}`);60 const filteredStories = stories.filter(s => {61 return !!([s.name, s.shortDescription, s.longDescription].find(val => {62 return val.toLowerCase().includes(filter.toLowerCase());63 }));64 });65 this._handleRequest(66 req => {67 return !!(req.url().match(regexp));68 },69 filteredStories,70 config71 );72 }73 mockAdminStory (story) {74 const regexp = createRegexp('api/story/[a-z0-9]+');75 this._handleRequest(76 this._matchesRegexp(regexp),77 story,78 );79 }80 mockAdminCollections (collections) {81 const regexp = createRegexp('api/collection');82 this._handleRequest(83 this._matchesRegexp(regexp),84 collections,85 );86 }87 mockAdminStories (stories) {88 const regexp = createRegexp('api/story');89 this._handleRequest(90 this._matchesRegexp(regexp),91 stories,92 );93 }94 mockAdminAttributes (attributes = []) {95 const regexp = createRegexp('api/attribute/[a-z0-9]+');96 this._handleRequest(97 this._matchesRegexp(regexp),98 attributes,99 );100 }101 mockAdminSequences (sequences = []) {102 const regexp = createRegexp('api/sequence/[a-z0-9]+?');103 this._handleRequest(104 this._matchesRegexp(regexp),105 sequences,106 );107 }108 mockAdminChapters (chapters = []) {109 const regexp = createRegexp('api/chapter/[a-z0-9]+?');110 this._handleRequest(111 this._matchesRegexp(regexp),112 chapters,113 );114 }115}...

Full Screen

Full Screen

dependencyExtractor.js

Source:dependencyExtractor.js Github

copy

Full Screen

...22const LEFT_PARENTHESIS = '\\(';23const RIGHT_PARENTHESIS = '\\)';24const WHITESPACE = '\\s*';25const OPTIONAL_COMMA = '(:?,\\s*)?';26function createRegExp(parts, flags) {27 return new RegExp(parts.join(''), flags);28}29function alternatives(...parts) {30 return `(?:${parts.join('|')})`;31}32function functionCallStart(...names) {33 return [34 NOT_A_DOT,35 WORD_SEPARATOR,36 alternatives(...names),37 WHITESPACE,38 LEFT_PARENTHESIS,39 WHITESPACE40 ];41}42const BLOCK_COMMENT_RE = /\/\*[^]*?\*\//g;43const LINE_COMMENT_RE = /\/\/.*/g;44const REQUIRE_OR_DYNAMIC_IMPORT_RE = createRegExp(45 [46 ...functionCallStart('require', 'import'),47 CAPTURE_STRING_LITERAL(1),48 WHITESPACE,49 OPTIONAL_COMMA,50 RIGHT_PARENTHESIS51 ],52 'g'53);54const IMPORT_OR_EXPORT_RE = createRegExp(55 [56 '\\b(?:import|export)\\s+(?!type(?:of)?\\s+)(?:[^\'"]+\\s+from\\s+)?',57 CAPTURE_STRING_LITERAL(1)58 ],59 'g'60);61const JEST_EXTENSIONS_RE = createRegExp(62 [63 ...functionCallStart(64 'require\\s*\\.\\s*(?:requireActual|requireMock)',65 'jest\\s*\\.\\s*(?:requireActual|requireMock|genMockFromModule)'66 ),67 CAPTURE_STRING_LITERAL(1),68 WHITESPACE,69 OPTIONAL_COMMA,70 RIGHT_PARENTHESIS71 ],72 'g'73);74function extract(code) {75 const dependencies = new Set();...

Full Screen

Full Screen

day-19.js

Source:day-19.js Github

copy

Full Screen

1"use script";2//input here data from day-19-data.txt3const inputDataStr = ``;4const data = inputDataStr5 .split('\n\n')[1]6 .split('\n');7const rules = inputDataStr8 .split("\n\n")[0]9 .split('\n')10 .reduce((arr, rule) => {11 arr[rule.split(': ')[0]] = rule12 .split(': ')[1]13 .split(' | ')14 .map(prop => prop.split(' ').map(prop => prop.match(/\D/) ? prop[1] : +(prop)))15 return arr;16 }, []);17const createRegexp = (rules, ruleIndex, isPartTwo) => {18 let rule = rules[ruleIndex];19 if (isPartTwo) {20 if (ruleIndex === 8) return `(${createRegexp(rules, 42, true)})+`;21 if (ruleIndex === 11) return `(${createRegexp(rules, 42, true)}){n}(${createRegexp(rules, 31, true)}){n}`;22 }23 let reg = rule.reduce((reg, prop) => {24 reg += '|';25 prop.forEach(operation => {26 if (typeof (operation) === 'number') reg += createRegexp(rules, operation, isPartTwo);27 else reg += operation;28 })29 return reg;30 }, '').slice(1);31 if (reg.includes('|')) reg = `(${reg})`;32 if (ruleIndex === 0) reg = `^${reg}$`;33 return reg;34};35const partOne = data.reduce((count, message) => {36 if (message.match(RegExp(createRegexp(rules, 0, false)))) count++;37 return count;38}, 0);39const partTwo = data.reduce((count, message) => {40 for (let i = 1; i < 5; i++) {41 if (message.match(RegExp(createRegexp(rules, 0, true).replace(/n/g, i)))) count++42 }43 return count;44}, 0);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...3exports.pascalify = pascalify4exports.kebabcasify = kebabcasify5exports.parseContent = (content, { componentName, ownerName }) => {6 return content7 .replace(createRegExp('componentNamePascal'), pascalify(componentName))8 .replace(createRegExp('componentName'), kebabcasify(componentName))9 .replace(createRegExp('ownerName'), ownerName)10 .replace(createRegExp('ownerNameLowerCase'), ownerName.toLowerCase())11 .replace(createRegExp('cliVersion'), require('../package.json').version)12 .replace(createRegExp('licenseYear'), new Date().getFullYear())13}14function kebabcasify(content) {15 return content16 .replace(/([a-z])([A-Z])/g, '$1-$2')17 .replace(/\s+/g, '-')18 .toLowerCase()19}20function pascalify(content) {21 const camelized = content.replace(/-([a-z])/g, c => c[1].toUpperCase())22 return camelized.charAt(0).toUpperCase() + camelized.slice(1)23}24function createRegExp(str) {25 return new RegExp(`{{\\s?${str}\\s?}}`, 'g')...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRegexp = require('../lib/bestregexp').BestRegexp;2var br = new BestRegexp();3var regexp = br.createRegExp(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']);4console.log(regexp);5var BestRegexp = require('../lib/bestregexp').BestRegexp;6var br = new BestRegexp();7var regexp = br.createRegExp(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']);8console.log(regexp);9var BestRegexp = require('../lib/bestregexp').BestRegexp;10var br = new BestRegexp();11var regexp = br.createRegExp(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']);12console.log(regexp);13var BestRegexp = require('../lib/bestregexp').BestRegexp;14var br = new BestRegexp();15var regexp = br.createRegExp(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']);16console.log(regexp);17var BestRegexp = require('../lib/bestregexp').BestRegexp;18var br = new BestRegexp();19var regexp = br.createRegExp(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']);20console.log(regexp);21var BestRegexp = require('../lib/bestregexp').BestRegexp;22var br = new BestRegexp();23var regexp = br.createRegExp(['a', 'b', 'c', 'd', 'e', '

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRegexp = require('bestregexp');2var bestRegexp = new BestRegexp();3var regexp = bestRegexp.createRegExp(['a', 'b', 'c']);4var BestRegexp = require('bestregexp');5var bestRegexp = new BestRegexp();6var regexp = bestRegexp.createRegExp(['a', 'b', 'c'], true);7var BestRegexp = require('bestregexp');8var bestRegexp = new BestRegexp();9var regexp = bestRegexp.createRegExp(['a', 'b', 'c'], false, true);10var BestRegexp = require('bestregexp');11var bestRegexp = new BestRegexp();12var regexp = bestRegexp.createRegExp(['a', 'b', 'c'], true, true);13var BestRegexp = require('bestregexp');14var bestRegexp = new BestRegexp();15var regexp = bestRegexp.createRegExp(['a', 'b', 'c'], false, false, true);16var BestRegexp = require('bestregexp');17var bestRegexp = new BestRegexp();18var regexp = bestRegexp.createRegExp(['a', 'b', 'c'], true, false, true);19var BestRegexp = require('bestregexp');20var bestRegexp = new BestRegexp();21var regexp = bestRegexp.createRegExp(['a', 'b', 'c'], false, true

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRegExp = require('./BestRegExp');2var reg = BestRegExp.createRegExp('abc');3module.exports = BestRegExp;4function BestRegExp(pattern, flags) {5 this._pattern = pattern;6 this._flags = flags;7}8BestRegExp.prototype.test = function (str) {9 return str.indexOf(this._pattern) != -1;10}11BestRegExp.createRegExp = function (pattern, flags) {12 return new BestRegExp(pattern, flags);13}14var BestRegExp = require('./BestRegExp');15var reg = new BestRegExp.createRegExp('abc');16 at Object.<anonymous> (C:\Users\Naveen\Documents\NodeJS\NodeJS-Module-Exports\test5.js:3:23)17 at Module._compile (module.js:409:26)18 at Object.Module._extensions..js (module.js:416:10)19 at Module.load (module.js:343:32)20 at Function.Module._load (module.js:300:12)21 at Function.Module.runMain (module.js:441:10)22 at startup (node.js:139:18)23module.exports = BestRegExp;24function BestRegExp(pattern, flags) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRegexp = require('bestregexp');2var bestRegexp = new BestRegexp();3var str = 'This is a string';4var regExp = bestRegexp.createRegExp(str);5console.log(regExp);6var BestRegexp = require('bestregexp');7var bestRegexp = new BestRegexp();8var str = 'This is a string';9var regExp = bestRegexp.createRegExp(str, {caseInsensitive: true});10console.log(regExp);11var BestRegexp = require('bestregexp');12var bestRegexp = new BestRegexp();13var str = 'This is a string';14var regExp = bestRegexp.createRegExp(str, {global: true});15console.log(regExp);16var BestRegexp = require('bestregexp');17var bestRegexp = new BestRegexp();18var str = 'This is a string';19var regExp = bestRegexp.createRegExp(str, {multiline: true});20console.log(regExp);21var BestRegexp = require('bestregexp');22var bestRegexp = new BestRegexp();23var str = 'This is a string';24var regExp = bestRegexp.createRegExp(str, {sticky: true});25console.log(regExp);26var BestRegexp = require('bestregexp');27var bestRegexp = new BestRegexp();28var str = 'This is a string';29var regExp = bestRegexp.createRegExp(str, {unicode: true});30console.log(regExp);31var BestRegexp = require('bestregexp');32var bestRegexp = new BestRegexp();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRegExp = require('./BestRegExp.js');2var regExp = new BestRegExp();3var pattern = regExp.createRegExp("abc");4console.log(pattern);5function BestRegExp() {6 this.createRegExp = function (str) {7 return new RegExp(str);8 };9}10module.exports = BestRegExp;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRegExp = require('./BestRegExp');2var x = new BestRegExp();3x.createRegExp('test');4console.log(x.getRegExp());5function BestRegExp() {6 this.regExp = null;7}8BestRegExp.prototype.createRegExp = function createRegExp(str) {9 this.regExp = new RegExp(str);10}11BestRegExp.prototype.getRegExp = function getRegExp() {12 return this.regExp;13}14module.exports = BestRegExp;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRegexp = require('bestregexp').BestRegexp;2var strings = ['a', 'ab', 'abc', 'abcd', 'abcde'];3var regexp = BestRegexp.createRegExp(strings);4console.log(regexp);5var BestRegexp = require('bestregexp').BestRegexp;6var strings = ['a', 'ab', 'abc', 'abcd', 'abcde'];7var regexp = BestRegexp.createRegExp(strings, {minLength: 3, maxLength: 5});8console.log(regexp);9var BestRegexp = require('bestregexp').BestRegexp;10var strings = ['a', 'ab', 'abc', 'abcd', 'abcde'];11var regexp = BestRegexp.createRegExp(strings, {minLength: 2, maxLength: 5});12console.log(regexp);13var BestRegexp = require('bestregexp').BestRegexp;14var strings = ['a', 'ab', 'abc', 'abcd', 'abcde'];15var regexp = BestRegexp.createRegExp(strings, {minLength: 2, maxLength: 4});16console.log(regexp);17var BestRegexp = require('bestregexp').BestRegexp;18var strings = ['a', 'ab', 'abc', 'abcd', 'abcde'];19var regexp = BestRegexp.createRegExp(strings, {minLength: 3, maxLength: 4});20console.log(regexp);

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run Best 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