How to use parseTag method in Playwright Internal

Best JavaScript code snippet using playwright-internal

bcp47.js

Source:bcp47.js Github

copy

Full Screen

...191 } else if( parsedTag.type == 'grandfathered' ) {192 // Do fancy processing to parse equivalent tag193 var preferredValue = this.getPreferredValue( parsedTag.tag );194 if( preferredValue ) {195 parsedTag = this.parseTag( preferredValue );196 } else {197 // No 'Preferred-Value'198 parsedTag = {199 tag: parsedTag.tag,200 type: parsedTag.type,201 };202 }203 }204 return parsedTag;205 },206 makeTag: function( parsedTag ) {207 // All valid parsed tags should have a 'tag' and a 'type'.208 if( !parsedTag.tag || !parsedTag.type ) {209 return false;210 }211 // Private-use and grandfathered tags are atomic.212 if( ( parsedTag.type == 'private' ) || ( parsedTag.type == 'grandfathered' ) ) {213 return parsedTag.tag;214 }215 var tag = parsedTag.language;216 if( parsedTag.extlangs.length > 0 ) {217 tag += '-' + parsedTag.extlangs.join( '-' );218 }219 if( parsedTag.script !== null ) {220 tag += '-' + parsedTag.script;221 }222 if( parsedTag.region !== null ) {223 tag += '-' + parsedTag.region;224 }225 if( parsedTag.variants.length > 0 ) {226 tag += '-' + parsedTag.variants.join( '-' );227 }228 if( parsedTag.extensions.length > 0 ) {229 for( var i = 'a'; i <= 'z'; i++ ) {230 if( i == 'x' ) {231 continue;232 }233 if( ( parsedTag.extensions[i] != undefined ) && ( parsedTag.extensions[i].length > 0 ) ) {234 tag += '-' + i + '-' + parsedTag.extensions[i].join( '-' );235 }236 }237 }238 if( parsedTag.privateUse.length > 0 ) {239 tag += '-x-' + parsedTag.privateUse.join( '-' );240 }241 return tag;242 },243 lookup: function( priorityList, availableList ) {244 // First check for exact matches.245 for( var i = 0; i < priorityList.length; i++ ) {246 priorityList = priorityList.concat( this.getRelatedTags( priorityList[i] ) );247 if( availableList.indexOf( priorityList[i] ) > -1 ) {248 return priorityList[i];249 }250 }251 // No exact match, so do Lookup matching.252 for( var i = 0; i < priorityList.length; i++ ) {253/* var tag = this.parseTag( priorityList[i] );254 // Private-use and grandfathered tags are atomic.255 if( ( tag.type == 'private' ) || ( tag.type == 'grandfathered' ) ) {256 continue;257 }258 while( tag.privateUse.length > 0 ) {259 tag.privateUse.pop();260 tag = this.makeTag( tag );261 if( availableList.indexOf( tag.tag ) > -1 ) {262 return tag.tag;263 }264 }265 while( tag.extensions.length > 0 ) {266 for( var j = 'a'; j <= 'z'; j++ ) {267 if( j == 'x' ) {268 continue;269 }270 if( tag.extensions[j] != undefined ) {271 while( tag.extensions[j].length > 0 ) {272 tag.extensions[j].pop();273 tag = this.makeTag( tag );274 if( availableList.indexOf( tag.tag ) > -1 ) {275 return tag.tag;276 }277 }278 }279 }280 }*/281 var tag = priorityList[i].split( '-' );282 while( tag.length > 0 ) {283 tag.pop();284 var newTag = tag.join( '-' );285 priorityList = priorityList.concat( this.getRelatedTags( newTag ) );286 if( availableList.indexOf( newTag ) > -1 ) {287 return newTag;288 }289 }290 }291 // XXX: This is the default. We might want to handle this differently.292 return 'en-US';293 },294 parseAcceptLanguage: function( acceptLanguage ) {295 var languages = acceptLanguage.split( ',' );296 var acceptLangs = [];297 for( var i = 0; i < languages.length; i++ ) {298 var langSplit = languages[i].split( ';' );299 var langTag = langSplit[0];300 acceptLangs[i] = { tag: langTag, q: 1.000 };301 for( var j = 1; j < langSplit.length; j++ ) {302 var langParam = langSplit[j].split( '=' );303 if( langParam[0] == 'q' ) {304 acceptLangs[i] = { tag: langTag, q: parseFloat( langParam[j] ) };305 }306 }307 }308 // Ensure language tags are sorted by quality value309 function compareQualityValues( a, b ) {310 if( a.q > b.q ) {311 return -1;312 }313 if( a.q < b.q ) {314 return 1;315 }316 return 0;317 }318 return acceptLangs.sort( compareQualityValues );319 },320 runTests: function () {321 // Tests322 console.log( this.parseTag( 'sr-Latn-RS' ), this.parseTag( 'es-419' ), this.parseTag( 'sr-Cyrl-RS' ) );323 // - Valid324 console.log( 'Simple language subtag:', this.parseTag( 'de' ), this.parseTag( 'fr' ), this.parseTag( 'ja' ), this.parseTag( 'i-enochian' ) );325 console.log( 'Language subtag plus Script subtag:', this.parseTag( 'zh-Hant' ), this.parseTag( 'zh-Hans' ), this.parseTag( 'sr-Cyrl' ), this.parseTag( 'sr-Latn' ) );326 console.log( 'Extended language subtags and their primary language subtag counterparts:', this.parseTag( 'zh-cmn-Hans-CN' ), this.parseTag( 'cmn-Hans-CN' ), this.parseTag( 'zh-yue-HK' ), this.parseTag( 'yue-HK' ) );327 console.log( 'Language-Script-Region:', this.parseTag( 'zh-Hans-CN' ), this.parseTag( 'sr-Latn-RS' ) );328 console.log( 'Language-Variant:', this.parseTag( 'sl-rozaj' ), this.parseTag( 'sl-rozaj-biske' ), this.parseTag( 'sl-nedis' ) );329 console.log( 'Language-Region-Variant:', this.parseTag( 'de-CH-1901' ), this.parseTag( 'sl-IT-nedis' ) );330 console.log( 'Language-Script-Region-Variant:', this.parseTag( 'hy-Latn-IT-arevela' ) );331 console.log( 'Language-Region:', this.parseTag( 'de-DE' ), this.parseTag( 'en-US' ), this.parseTag( 'es-419' ) );332 console.log( 'Private use subtags:', this.parseTag( 'de-CH-x-phonebk' ), this.parseTag( 'az-Arab-x-AZE-derbend' ) );333 console.log( 'Private use registry values:', this.parseTag( 'x-whatever' ), this.parseTag( 'qaa-Qaaa-QM-x-southern' ), this.parseTag( 'de-Qaaa' ), this.parseTag( 'sr-Latn-QM' ), this.parseTag( 'sr-Qaaa-RS' ) );334 console.log( 'Tags that use extensions:', this.parseTag( 'en-US-u-islamcal' ), this.parseTag( 'zh-CN-a-myext-x-private' ), this.parseTag( 'en-a-myext-b-another' ) );335 // - Invalid336 console.log( 'Some Invalid Tags:', this.parseTag( 'de-419-DE' ), this.parseTag( 'a-DE' ), this.parseTag( 'ar-a-aaa-b-bbb-a-ccc' ) );337 console.log( this.parseTag( 'zh-gan-hak-Hans-CN-1901-rozaj-2abc-t-fonipa-u-islamcal-myext-testing-x-private-testing' ) );338 console.log( this.parseTag( 'en-GB-oed' ) );339 console.log( this.parseTag( 'zh-min-nan' ) );340 console.log( this.parseTag( 'x-whatever' ) );341 }342};343var BCP47Parser = new BCP47Parser;344function BCP47() {};345BCP47.prototype = {346 IsStructurallyValidLanguageTag: function(locale) {347 return !!BCP47Parser.parseTag(locale);348 },349 CanonicalizeLanguageTag: function(locale) {350 return BCP47Parser.makeTag(BCP47Parser.parseTag(locale));351 },352 DefaultLocale: function() {353 return window.navigator.language;354 },355 CanonicalizeLocaleList: function(locales) {356 if (locales === undefined) {357 return [];358 }359 let seen = [];360 if (typeof locales === 'string') {361 locales = [ locales ];362 }363 let O = Object(locales);364 // ToUint32(lenValue)...

Full Screen

Full Screen

tag.js

Source:tag.js Github

copy

Full Screen

2import { parseTag } from '../../src/parser/tag.js';3describe('tag parser', () => {4 it('should parse b,i,u,s', () => {5 ['b', 'i', 'u', 's'].forEach((tag) => {6 expect(parseTag(`${tag}0`)).to.deep.equal({ [tag]: 0 });7 expect(parseTag(`${tag}1`)).to.deep.equal({ [tag]: 1 });8 });9 });10 it('should parse fn', () => {11 expect(parseTag('fnArial')).to.deep.equal({ fn: 'Arial' });12 expect(parseTag('fnNoto Sans')).to.deep.equal({ fn: 'Noto Sans' });13 expect(parseTag('fn黑体')).to.deep.equal({ fn: '黑体' });14 expect(parseTag('fn@微软雅黑')).to.deep.equal({ fn: '@微软雅黑' });15 });16 it('should parse fe', () => {17 expect(parseTag('fe0')).to.deep.equal({ fe: 0 });18 expect(parseTag('fe134')).to.deep.equal({ fe: 134 });19 });20 it('should parse k,K,kf,ko,kt', () => {21 ['k', 'K', 'kf', 'ko', 'kt'].forEach((tag) => {22 expect(parseTag(`${tag}0`)).to.deep.equal({ [tag]: 0 });23 expect(parseTag(`${tag}100`)).to.deep.equal({ [tag]: 100 });24 });25 });26 it('should parse q', () => {27 expect(parseTag('q0')).to.deep.equal({ q: 0 });28 expect(parseTag('q1')).to.deep.equal({ q: 1 });29 expect(parseTag('q2')).to.deep.equal({ q: 2 });30 expect(parseTag('q3')).to.deep.equal({ q: 3 });31 });32 it('should parse p', () => {33 expect(parseTag('p0')).to.deep.equal({ p: 0 });34 expect(parseTag('p1')).to.deep.equal({ p: 1 });35 });36 it('should parse pbo', () => {37 expect(parseTag('pbo0')).to.deep.equal({ pbo: 0 });38 expect(parseTag('pbo10')).to.deep.equal({ pbo: 10 });39 });40 it('should parse an,a', () => {41 for (let i = 1; i <= 11; i++) {42 expect(parseTag(`an${i}`)).to.deep.equal({ an: i });43 expect(parseTag(`a${i}`)).to.deep.equal({ a: i });44 }45 });46 it('should parse r', () => {47 expect(parseTag('r')).to.deep.equal({ r: '' });48 expect(parseTag('rDefault')).to.deep.equal({ r: 'Default' });49 });50 it('should parse be,blur', () => {51 expect(parseTag('be1')).to.deep.equal({ be: 1 });52 expect(parseTag('be2.33')).to.deep.equal({ be: 2.33 });53 expect(parseTag('blur1')).to.deep.equal({ blur: 1 });54 expect(parseTag('blur2.33')).to.deep.equal({ blur: 2.33 });55 });56 it('should parse fs', () => {57 expect(parseTag('fs15')).to.deep.equal({ fs: '15' });58 expect(parseTag('fs+6')).to.deep.equal({ fs: '+6' });59 expect(parseTag('fs-6')).to.deep.equal({ fs: '-6' });60 });61 it('should parse fsp', () => {62 expect(parseTag('fsp0')).to.deep.equal({ fsp: 0 });63 expect(parseTag('fsp5')).to.deep.equal({ fsp: 5 });64 });65 it('should parse fscx,fscy,fax,fay,frx,fry,frz,fr', () => {66 ['fscx', 'fscy', 'fax', 'fay', 'frx', 'fry', 'frz', 'fr'].forEach((tag) => {67 expect(parseTag(`${tag}0`)).to.deep.equal({ [tag]: 0 });68 expect(parseTag(`${tag}2.33`)).to.deep.equal({ [tag]: 2.33 });69 expect(parseTag(`${tag}-30`)).to.deep.equal({ [tag]: -30 });70 });71 });72 it('should parse bord,xbord,ybord,shad,xshad,yshad', () => {73 ['bord', 'xbord', 'ybord', 'shad', 'xshad', 'yshad'].forEach((tag) => {74 expect(parseTag(`${tag}0`)).to.deep.equal({ [tag]: 0 });75 expect(parseTag(`${tag}2.33`)).to.deep.equal({ [tag]: 2.33 });76 expect(parseTag(`${tag}-3`)).to.deep.equal({ [tag]: -3 });77 });78 });79 it('should parse c', () => {80 expect(parseTag('1c&HFFFFFF&')).to.deep.equal({ c1: 'FFFFFF' });81 expect(parseTag('2c&HFFFFFF&')).to.deep.equal({ c2: 'FFFFFF' });82 expect(parseTag('3c&HFFFFFF&')).to.deep.equal({ c3: 'FFFFFF' });83 expect(parseTag('4c&HFFFFFF&')).to.deep.equal({ c4: 'FFFFFF' });84 expect(parseTag('c&HFFFFFF&')).to.deep.equal({ c1: 'FFFFFF' });85 expect(parseTag('1c&HFFF&')).to.deep.equal({ c1: '000FFF' });86 expect(parseTag('1c&HFFFFFF')).to.deep.equal({ c1: 'FFFFFF' });87 expect(parseTag('1c&FFFFFF')).to.deep.equal({ c1: 'FFFFFF' });88 expect(parseTag('1cFFFFFF')).to.deep.equal({ c1: 'FFFFFF' });89 expect(parseTag('1cHFFFFFF')).to.deep.equal({ c1: 'FFFFFF' });90 expect(parseTag('1c')).to.deep.equal({ c1: '' });91 });92 it('should parse alpha', () => {93 expect(parseTag('1a&HFF&')).to.deep.equal({ a1: 'FF' });94 expect(parseTag('2a&HFF&')).to.deep.equal({ a2: 'FF' });95 expect(parseTag('3a&HFF&')).to.deep.equal({ a3: 'FF' });96 expect(parseTag('4a&HFF&')).to.deep.equal({ a4: 'FF' });97 expect(parseTag('a&HFF&')).to.deep.equal({});98 expect(parseTag('1a&HFF')).to.deep.equal({ a1: 'FF' });99 expect(parseTag('1a&FF')).to.deep.equal({ a1: 'FF' });100 expect(parseTag('1aFF')).to.deep.equal({ a1: 'FF' });101 expect(parseTag('1aHFF')).to.deep.equal({ a1: 'FF' });102 expect(parseTag('alphaFF')).to.deep.equal({ alpha: 'FF' });103 expect(parseTag('alpha&HFF&')).to.deep.equal({ alpha: 'FF' });104 expect(parseTag('alpha&HFF')).to.deep.equal({ alpha: 'FF' });105 expect(parseTag('alpha&FF')).to.deep.equal({ alpha: 'FF' });106 expect(parseTag('alphaHFF')).to.deep.equal({ alpha: 'FF' });107 expect(parseTag('alpha&HF')).to.deep.equal({ alpha: '0F' });108 expect(parseTag('alpha&H1234')).to.deep.equal({ alpha: '34' });109 expect(parseTag('alpha&H12X34')).to.deep.equal({ alpha: '12' });110 });111 it('should parse pos,org,move,fad,fade', () => {112 ['pos', 'org', 'move', 'fad', 'fade'].forEach((tag) => {113 expect(parseTag(`${tag}(0,1 ,2, 3)`)).to.deep.equal({114 [tag]: [0, 1, 2, 3],115 });116 expect(parseTag(`${tag}( 233,-42 )`)).to.deep.equal({117 [tag]: [233, -42],118 });119 });120 });121 it('should parse clip,iclip', () => {122 expect(parseTag('clip(0,1,2,3)')).to.deep.equal({123 clip: {124 inverse: false,125 scale: 1,126 drawing: null,127 dots: [0, 1, 2, 3],128 },129 });130 expect(parseTag('iclip(0,1,2,3)')).to.deep.equal({131 clip: {132 inverse: true,133 scale: 1,134 drawing: null,135 dots: [0, 1, 2, 3],136 },137 });138 expect(parseTag('clip(m 0 0 l 1 0 1 1 0 1)')).to.deep.equal({139 clip: {140 inverse: false,141 scale: 1,142 drawing: [143 ['m', '0', '0'],144 ['l', '1', '0', '1', '1', '0', '1'],145 ],146 dots: null,147 },148 });149 expect(parseTag('iclip(2, m 0 0 l 1 0 1 1 0 1)')).to.deep.equal({150 clip: {151 inverse: true,152 scale: 2,153 drawing: [154 ['m', '0', '0'],155 ['l', '1', '0', '1', '1', '0', '1'],156 ],157 dots: null,158 },159 });160 });161 it('should parse t', () => {162 expect(parseTag('t()')).to.deep.equal({});163 expect(parseTag('t(\\fs20)')).to.deep.equal({164 t: { t1: 0, t2: 0, accel: 1, tags: [{ fs: '20' }] },165 });166 expect(parseTag('t(\\frx30\\fry60)')).to.deep.equal({167 t: { t1: 0, t2: 0, accel: 1, tags: [{ frx: 30 }, { fry: 60 }] },168 });169 expect(parseTag('t(2,\\fs20 )')).to.deep.equal({170 t: { t1: 0, t2: 0, accel: 2, tags: [{ fs: '20' }] },171 });172 expect(parseTag('t( 0,1000,\\fs20)')).to.deep.equal({173 t: { t1: 0, t2: 1000, accel: 1, tags: [{ fs: '20' }] },174 });175 expect(parseTag('t(0, 1000 ,2,\\fs20)')).to.deep.equal({176 t: { t1: 0, t2: 1000, accel: 2, tags: [{ fs: '20' }] },177 });178 expect(parseTag('t(\\clip(0,1,2,3)\\fs20)')).to.deep.equal({179 t: {180 t1: 0,181 t2: 0,182 accel: 1,183 tags: [184 {185 clip: {186 inverse: false,187 scale: 1,188 drawing: null,189 dots: [0, 1, 2, 3],190 },191 },192 { fs: '20' },193 ],194 },195 });196 });197 it('should support ignoring closing parentheses', () => {198 ['pos', 'org', 'move', 'fad', 'fade'].forEach((tag) => {199 expect(parseTag(`${tag}(0,1,2,3`)).to.deep.equal({200 [tag]: [0, 1, 2, 3],201 });202 });203 const clip = {204 inverse: false,205 scale: 1,206 drawing: null,207 dots: [0, 1, 2, 3],208 };209 expect(parseTag('clip(0,1,2,3')).to.deep.equal({ clip });210 expect(parseTag('clip(m 0 0 l 1 0 1 1 0 1')).to.deep.equal({211 clip: {212 inverse: false,213 scale: 1,214 drawing: [215 ['m', '0', '0'],216 ['l', '1', '0', '1', '1', '0', '1'],217 ],218 dots: null,219 },220 });221 expect(parseTag('t(2,\\fs20')).to.deep.equal({222 t: { t1: 0, t2: 0, accel: 2, tags: [{ fs: '20' }] },223 });224 expect(parseTag('t(\\clip(0,1,2,3\\fs20').t.tags).to.deep.equal([225 { clip },226 { fs: '20' },227 ]);228 expect(parseTag('t(\\fs20\\clip(0,1,2,3').t.tags).to.deep.equal([229 { fs: '20' },230 { clip },231 ]);232 });233 it('should ignore tags without content', () => {234 ['pos', 'org', 'move', 'fad', 'fade', 'clip', 'iclip', 't'].forEach((tag) => {235 expect(parseTag(`${tag}`)).to.deep.equal({});236 expect(parseTag(`${tag}(`)).to.deep.equal({});237 expect(parseTag(`${tag}()`)).to.deep.equal({});238 });239 });...

Full Screen

Full Screen

bcp47-parse.test.js

Source:bcp47-parse.test.js Github

copy

Full Screen

...47 expect(cleanAndCheckTag('abc-def-', 'force')).toBe('x-abc-def-');48});49//parseTag50test('parse rejects a blank tag', ()=>{51 expect(()=>{parseTag('')}).toThrow('No language tag provided');52});53test('parse can be forced to parse a blank tag', ()=>{54 expect(parseTag('','force')).toEqual({privateUse:'x-null-tag'});55});56test('parse rejects no argument', ()=>{57 expect(()=>{parseTag()}).toThrow('No language tag provided');58});59test('parse can be forced to parse a blank tag', ()=>{60 expect(parseTag(undefined,'force')).toEqual({privateUse:'x-not-a-string'});61});62test(`parse is eliminates case sensitivity`, ()=>{63 expect(parseTag('AB-CDE-EFG')).toEqual(parseTag('ab-cde-efg'));64})65test(`parse identifies private-use tags as 'languages'`, ()=>{66 expect(parseTag('x-greg-is-good')).toEqual({privateUse:'x-greg-is-good'});67});68test(`parse identifies grandfathered tags with uppercase in all lowercase`, ()=>{69 expect(parseTag('en-GB-oed')).toEqual({grandfathered:'en-gb-oed'});70})71test(`parse identifies grandfathered tags without case sensitivity`, ()=>{72 //listed in BCP 47 as 'en-GB-oed'73 expect(parseTag('en-gb-oed')).toEqual({grandfathered:'en-gb-oed'});74})75test(`parse identifies regular grandfathered tags as 'languages'`, ()=>{76 expect(parseTag('art-lojban')).toEqual({grandfathered:'art-lojban'});77})78test(`parse identifies irregular grandfathered tags as 'languages'`, ()=>{79 expect(parseTag('i-klingon')).toEqual({grandfathered:'i-klingon'});80})81test('parse rejects tag with uninterpretable content', ()=>{82 //expect(parseTag('en-CA-wut')).toEqual({language:'en'});83 //Throw('End of tag could not be interpreted');84 expect(()=>{parseTag('en-CA-wut')}).toThrow('End of tag could not be interpreted');85});86test('parse can be forced to ignore uninterpretable content', ()=>{87 expect(parseTag('en-CA-wut','force')).toMatchObject({language: 'en', region: 'ca'});88});...

Full Screen

Full Screen

parser.test.js

Source:parser.test.js Github

copy

Full Screen

1import { parse } from './parser';2const parseTag = (quasis, ...expressions) => parse(quasis, expressions);3it('supports parsing expressions with quantifiers', () => {4 let ast;5 ast = parseTag`${1}?`;6 expect(ast).toHaveProperty('0.quantifier', '?');7 ast = parseTag`${1}+`;8 expect(ast).toHaveProperty('0.quantifier', '+');9 ast = parseTag`${1}*`;10 expect(ast).toHaveProperty('0.quantifier', '*');11});12it('supports top-level alternations', () => {13 let ast;14 ast = parseTag`${1} | ${2}`;15 expect(ast).toHaveProperty('length', 1);16 expect(ast).toHaveProperty('0.expression', 1);17 expect(ast).toHaveProperty('alternation.0.expression', 2);18 ast = parseTag`${1}? | ${2}?`;19 expect(ast).toHaveProperty('0.quantifier', '?');20});21it('supports groups with quantifiers', () => {22 let ast;23 ast = parseTag`(${1} ${2})`;24 expect(ast).toHaveProperty('length', 1);25 expect(ast).toHaveProperty('0.sequence.length', 2);26 expect(ast).toHaveProperty('0.sequence.0.expression', 1);27 expect(ast).toHaveProperty('0.sequence.1.expression', 2);28 ast = parseTag`(${1} ${2}?)?`;29 expect(ast).toHaveProperty('length', 1);30 expect(ast).toHaveProperty('0.quantifier', '?');31 expect(ast).toHaveProperty('0.sequence.0.quantifier', undefined);32});33describe('non-capturing syntax', () => {34 it('supports regex-like syntax', () => {35 const ast = parseTag`(?: ${1})`;36 expect(ast).toHaveProperty('length', 1);37 expect(ast).toHaveProperty('0.capture', ':');38 expect(ast).toHaveProperty('0.sequence.length', 1);39 });40 it('supports shorthand', () => {41 let ast = parseTag`:${1}`;42 expect(ast).toHaveProperty('length', 1);43 expect(ast).toHaveProperty('0.capture', ':');44 expect(ast).toHaveProperty('0.expression', 1);45 ast = parseTag`:(${1})`;46 expect(ast).toHaveProperty('length', 1);47 expect(ast).toHaveProperty('0.capture', ':');48 expect(ast).toHaveProperty('0.sequence.length', 1);49 });50 it('fails on invalid usage', () => {51 expect(() => parseTag`${1} : ${2}`).toThrow();52 expect(() => parseTag`${1} :|${2}`).toThrow();53 });54});55describe('positive lookaheads syntax', () => {56 it('supports regex-like syntax', () => {57 const ast = parseTag`(?= ${1})`;58 expect(ast).toHaveProperty('length', 1);59 expect(ast).toHaveProperty('0.capture', '=');60 expect(ast).toHaveProperty('0.sequence.length', 1);61 });62 it('supports shorthand', () => {63 let ast = parseTag`=${1}`;64 expect(ast).toHaveProperty('length', 1);65 expect(ast).toHaveProperty('0.capture', '=');66 expect(ast).toHaveProperty('0.expression', 1);67 ast = parseTag`=(${1})`;68 expect(ast).toHaveProperty('length', 1);69 expect(ast).toHaveProperty('0.capture', '=');70 expect(ast).toHaveProperty('0.sequence.length', 1);71 });72});73describe('negative lookaheads syntax', () => {74 it('supports regex-like syntax', () => {75 const ast = parseTag`(?! ${1})`;76 expect(ast).toHaveProperty('length', 1);77 expect(ast).toHaveProperty('0.capture', '!');78 expect(ast).toHaveProperty('0.sequence.length', 1);79 });80 it('supports shorthand', () => {81 let ast = parseTag`!${1}`;82 expect(ast).toHaveProperty('length', 1);83 expect(ast).toHaveProperty('0.capture', '!');84 expect(ast).toHaveProperty('0.expression', 1);85 ast = parseTag`!(${1})`;86 expect(ast).toHaveProperty('length', 1);87 expect(ast).toHaveProperty('0.capture', '!');88 expect(ast).toHaveProperty('0.sequence.length', 1);89 });90});91it('supports groups with alternates', () => {92 expect(parseTag`(${1} | ${2}) ${3}`).toMatchInlineSnapshot(`93 Array [94 Object {95 "capture": undefined,96 "sequence": Array [97 Object {98 "capture": undefined,99 "expression": 1,100 },101 ],102 },103 Object {104 "capture": undefined,105 "expression": 3,106 },107 ]108 `);...

Full Screen

Full Screen

non_block_tags.js

Source:non_block_tags.js Github

copy

Full Screen

...3 parser = require('../../parsers/tagparser.js');4describe('Self closing tags', function() {5 it ('Should return <a href="foo.html">foo</a>', function() {6 var tag = 'a(href="foo.html")'7 assert.equal('<a href="foo.html">foo</a>', parser.parseTag(tag, "foo").trim());8 });9 it ('Should return <p class="className" ng-model="foo">foo</p>', function() {10 var tag = 'p.className(ng-model="foo")'11 assert.equal('<p class="className" ng-model="foo">foo</p>', parser.parseTag(tag, "foo").trim());12 });13 it ('Should return <p class="class-name class-name-foo" id="foo bar foo-bar" ng-model="foo">foo</p>', function() {14 var tag = 'p.class-name.class-name-foo#foo-bar(ng-model="foo"): foo'15 assert.equal('<p id="foo-bar" class="class-name class-name-foo" ng-model="foo">foo</p>', parser.parseTag(tag, "foo").trim());16 });17 it ('Should return <script src="foo-bar.js">alert(-1)</script>', function() {18 var tag = 'script(src="foo-bar.js")'19 assert.equal('<script src="foo-bar.js">alert(-1)</script>', parser.parseTag(tag, "alert(-1)").trim());20 });21 it ('Should return <script src="foo-bar.js"></script>', function() {22 var tag = 'script(src="foo-bar.js")'23 assert.equal('<script src="foo-bar.js"></script>', parser.parseTag(tag).trim());24 });25 it ('Should return <link rel="stylesheet" href="/foo/foo-bar.css" />', function() {26 var tag = 'link(rel="stylesheet" href="/foo/foo-bar.css")'27 assert.equal('<link rel="stylesheet" href="/foo/foo-bar.css" />', parser.parseTag(tag).trim());28 });29 it ('Should return <button id="foo" class="className1 className2">{{foo.bar}}</button>', function() {30 var tag = 'button#foo.className1.className2'31 assert.equal('<button id="foo" class="className1 className2">{{foo.bar}}</button>', parser.parseTag(tag, "{{foo.bar}}").trim());32 });33 it ('Should return empty string', function() {34 var tag = '';35 assert.equal('', parser.parseTag(tag, 'foo bar').trim());36 });37 it ('Should return empty string', function() {38 var tag = '.foo#bar(href="index.html")';39 assert.equal('', parser.parseTag(tag, 'foo bar').trim());40 });...

Full Screen

Full Screen

news.js

Source:news.js Github

copy

Full Screen

...23 * @param {string} description — короткое описание новости24 */25export class News {26 constructor(item) {27 this.id = this.parseTag('id', item) | 028 this.title = this.parseTag('title', item)29 this.date = this.parseTag('timestamp', item) * 100030 this.image = this.parseTag('image', item)31 this.link = this.parseTag('link', item)32 this.content = (this.parseTag('text', item).match(regexp.CDATA) || [])[1]33 this.description = (this.parseTag('description', item).match(regexp.CDATA) || [])[1]34 }3536 parseTag(tag, str) {37 var regexp = new RegExp(`(?:<${tag}>)(.+?)(?:<\/${tag}>)`, 'i')38 return str.match(regexp)[1]39 }40}4142/**43 * Список новостей, распарсенных с RSS44 * @return <array{string}> — список распарсенных новостей с RSS45 */46function parseRSSNews({ data }) {47 return data.replace(/\s/g, ' ')48 .match(regexp.item)49 .map( item => new News(item) )50}

Full Screen

Full Screen

Factories.WITH_TYPE_AND_NAME.test.js

Source:Factories.WITH_TYPE_AND_NAME.test.js Github

copy

Full Screen

2var { assert, multiline } = require('megadoc-test-utils');3var Parser = subject.Parser;4describe('Parser.FACTORIES.withNameAndType', function() {5 var parser;6 function parseTag(str) {7 var docstring = multiline(str);8 return parser.createTag(subject.parseTag(docstring.trim()));9 }10 beforeEach(function() {11 parser = new Parser();12 parser.defineTag('param', Parser.FACTORIES.withNameAndType);13 });14 it('works with only a type', function() {15 var tag = parseTag(function() {16 // @param {string}17 });18 assert.ok(tag.hasOwnProperty('typeInfo'));19 assert.equal(tag.typeInfo.types.length, 1);20 assert.equal(tag.name, '');21 assert.equal(tag.description, '');22 });23 it('works with a type and name', function() {24 var tag = parseTag(function() {25 // @param {string} foo26 });27 assert.ok(tag.hasOwnProperty('typeInfo'));28 assert.equal(tag.typeInfo.types.length, 1);29 assert.equal(tag.name, 'foo');30 assert.equal(tag.description, '');31 });32 it('works with a type, name, and description', function() {33 var tag = parseTag(function() {34 // @param {string} foo35 // Hello.36 });37 assert.ok(tag.hasOwnProperty('typeInfo'));38 assert.equal(tag.typeInfo.types.length, 1);39 assert.equal(tag.name, 'foo');40 assert.equal(tag.description, 'Hello.');41 });42 it('detects an optional thingy ([foo])', function() {43 var tag = parseTag(function() {44 // @param {string} [foo]45 // Hello.46 });47 assert.equal(tag.typeInfo.optional, true);48 assert.equal(tag.name, 'foo');49 });50 it('detects a default value ([foo=5])', function() {51 var tag = parseTag(function() {52 // @param {string} [foo=5]53 // Hello.54 });55 assert.equal(tag.typeInfo.optional, true);56 assert.equal(tag.name, 'foo');57 });...

Full Screen

Full Screen

parser.js

Source:parser.js Github

copy

Full Screen

1const {parseTag} = require('../src/parseTag')2const {parseTagScenarios} = require('./__data__/parser')3describe('parseTag',()=>{4 test.each(parseTagScenarios)(5 '.parseTag("%s", "%s") returns %s', 6 (strategy, release, expected) => {7 let {tag, error} = parseTag(strategy, release)8 expect(tag).toMatch(expected)9 expect(error).toBeUndefined()10 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseTag } = require('playwright/lib/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const elementHandle = await page.$('text=Get started');7 const html = await elementHandle.innerHTML();8 const parsed = parseTag(html);9 console.log(parsed);10 await browser.close();11})();12{ name: 'a',13 attributes: { href: '/docs/intro' },14 children: [ { type: 'text', text: 'Get started' } ] }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseTag } = require('playwright/lib/utils/utils');2const { parseTag } = require('playwright/lib/utils/utils');3const { test, expect } = require('@playwright/test');4test('test', async ({ page }) => {5 const parsedTag = parseTag('button');6 const parsedTagWithAttributes = parseTag('button[aria-label="Submit"]');7 const parsedTagWithAttributesAndText = parseTag('button[aria-label="Submit"]:has-text("Submit")');8 await page.click(parsedTag);9 await page.click(parsedTagWithAttributes);10 await page.click(parsedTagWithAttributesAndText);11});12[Apache 2.0](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseTag } = require('playwright-core/lib/server/supplements/recorder/recorderApp');2const { parse } = require('playwright-core/lib/server/supplements/recorder/recorderApp');3const { parseSelector } = require('playwright-core/lib/server/supplements/recorder/recorderApp');4const tag = parseTag(selector);5console.log(tag);6const tag = parse(selector);7console.log(tag);8const tag = parseSelector(selector);9console.log(tag);10const { parseTag } = require('playwright-core/lib/server/supplements/recorder/recorderApp');11const { parse } = require('playwright-core/lib/server/supplements/recorder/recorderApp');12const { parseSelector } = require('playwright-core/lib/server/supplements/recorder/recorderApp');13const tag = parseTag(selector);14console.log(tag);15const tag = parse(selector);16console.log(tag);17const tag = parseSelector(selector);18console.log(tag);19const { parseTag } = require('playwright-core/lib/server/supplements/recorder/recorderApp');20const { parse } = require('playwright

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseTag } = require('@playwright/test/lib/test')2const { test } = require('@playwright/test')3test('test', async ({ page }) => {4 const tag = parseTag('test')5 console.log(tag)6})

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseTag } = require('playwright/lib/utils/parseTag');2const tag = parseTag('div');3console.log(tag);4const { parseTag } = require('playwright/lib/utils/parseTag');5const tag = parseTag('div#my-div');6await page.setContent(tag);7const { parseSelector } = require('playwright/lib/utils/parseSelector');8const selector = parseSelector('div#my-div');9await page.setContent(selector);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseTag } = require('playwright/lib/utils/selectorParser');2const selector = parseTag('input', { id: 'foo' });3console.log(selector);4const { parseTag } = require('playwright/lib/utils/selectorParser');5const selector = parseTag('input', { id: 'foo' });6console.log(selector);7const { parseTag } = require('playwright/lib/utils/selectorParser');8const selector = parseTag('input', { id: 'foo' });9console.log(selector);10const { parseTag } = require('playwright/lib/utils/selectorParser');11const selector = parseTag('input', { id: 'foo' });12console.log(selector);13const { parseTag } = require('playwright/lib/utils/selectorParser');14const selector = parseTag('input', { id: 'foo' });15console.log(selector);16const { parseTag } = require('playwright/lib/utils/selectorParser');17const selector = parseTag('input', { id: 'foo' });18console.log(selector);19const { parseTag } = require('playwright/lib/utils/selectorParser');20const selector = parseTag('input', { id: 'foo' });21console.log(selector);22const { parseTag } = require('playwright/lib/utils/selectorParser');23const selector = parseTag('input', { id: 'foo' });24console.log(selector);

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