How to use parsePseudo method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

test-css-expr.js

Source:test-css-expr.js Github

copy

Full Screen

...19 /**20 * @param {string} cssString21 * @return {string}22 */23 function parsePseudo(cssString) {24 const node = parseCss(cssString);25 if (node == null) {26 return null;27 }28 return pseudo(node);29 }30 /**31 * @param {!CssNode} n32 * @return {string}33 */34 function pseudo(n) {35 if (n instanceof ast.CssPassthroughNode) {36 return n.css_;37 }38 if (n instanceof ast.CssUrlNode) {39 return `URL<${n.url_}>`;40 }41 if (n instanceof ast.CssConcatNode) {42 return `CON<${pseudoArray(n.array_)}>`;43 }44 if (n instanceof ast.CssNumericNode) {45 return `${n.type_}<${n.num_}` +46 `${n.units_ && n.units_ != '%' ? ' ' + n.units_.toUpperCase() : ''}>`;47 }48 if (n instanceof ast.CssTranslateNode) {49 return 'TRANSLATE' +50 `${n.suffix_ ? '-' + n.suffix_.toUpperCase() : ''}` +51 `<${pseudoArray(n.args_)}>`;52 }53 if (n instanceof ast.CssDimSizeNode) {54 return `DIM<${n.dim_}` +55 `, ${n.selector_ ? '"' + n.selector_ + '"' : null}` +56 `, ${n.selectionMethod_}>`;57 }58 if (n instanceof ast.CssRandNode) {59 return `RAND<${n.left_ ? pseudo(n.left_) : null}` +60 `, ${n.right_ ? pseudo(n.right_) : null}>`;61 }62 if (n instanceof ast.CssIndexNode) {63 return 'INDEX<>';64 }65 if (n instanceof ast.CssVarNode) {66 return `VAR<${n.varName_}${n.def_ ? ', ' + pseudo(n.def_) : ''}>`;67 }68 if (n instanceof ast.CssCalcNode) {69 return `CALC<${pseudo(n.expr_)}>`;70 }71 if (n instanceof ast.CssCalcSumNode) {72 return `${n.op_ == '+' ? 'ADD' : 'SUB'}` +73 `<${pseudo(n.left_)}, ${pseudo(n.right_)}>`;74 }75 if (n instanceof ast.CssCalcProductNode) {76 return `${n.op_ == '*' ? 'MUL' : 'DIV'}` +77 `<${pseudo(n.left_)}, ${pseudo(n.right_)}>`;78 }79 if (n instanceof ast.CssFuncNode) {80 return `${n.name_.toUpperCase()}<${pseudoArray(n.args_)}>`;81 }82 throw new Error('unknown node: ' + n);83 }84 /**85 * @param {!Array<!CssNode>} array86 * @return {string}87 */88 function pseudoArray(array) {89 if (!array || array.length == 0) {90 return '';91 }92 return array.map(n => pseudo(n)).join(', ');93 }94 it('should parse empty string as null', () => {95 expect(parsePseudo('')).to.be.null;96 });97 it('should parse string', () => {98 expect(parsePseudo('"abc"')).to.equal('"abc"');99 expect(parsePseudo('\'abc\'')).to.equal('\'abc\'');100 });101 it('should parse ident', () => {102 expect(parsePseudo('abc')).to.equal('abc');103 expect(parsePseudo('-abc')).to.equal('-abc');104 expect(parsePseudo('-abc1')).to.equal('-abc1');105 expect(parsePseudo('-abc1a')).to.equal('-abc1a');106 });107 it('should parse number', () => {108 expect(parsePseudo('0')).to.equal('NUM<0>');109 expect(parsePseudo('1')).to.equal('NUM<1>');110 expect(parsePseudo('10')).to.equal('NUM<10>');111 expect(parsePseudo('0.5')).to.equal('NUM<0.5>');112 expect(parsePseudo('.5')).to.equal('NUM<0.5>');113 expect(parsePseudo('1.5')).to.equal('NUM<1.5>');114 expect(parsePseudo('-0.5')).to.equal('NUM<-0.5>');115 expect(parsePseudo('-.5')).to.equal('NUM<-0.5>');116 expect(parsePseudo('+.5')).to.equal('NUM<0.5>');117 expect(parsePseudo('+1.5')).to.equal('NUM<1.5>');118 expect(parsePseudo('1e2')).to.equal('NUM<100>');119 expect(parsePseudo('.1e2')).to.equal('NUM<10>');120 expect(parsePseudo('1e+2')).to.equal('NUM<100>');121 expect(parsePseudo('1e-2')).to.equal('NUM<0.01>');122 });123 it('should parse percent', () => {124 expect(parsePseudo('0%')).to.equal('PRC<0>');125 expect(parsePseudo('1%')).to.equal('PRC<1>');126 expect(parsePseudo('0.5%')).to.equal('PRC<0.5>');127 expect(parsePseudo('.5%')).to.equal('PRC<0.5>');128 expect(parsePseudo('1e2%')).to.equal('PRC<100>');129 });130 it('should parse length', () => {131 expect(parsePseudo('100px')).to.equal('LEN<100 PX>');132 expect(parsePseudo('-100px')).to.equal('LEN<-100 PX>');133 expect(parsePseudo('+100px')).to.equal('LEN<100 PX>');134 expect(parsePseudo('100.5px')).to.equal('LEN<100.5 PX>');135 expect(parsePseudo('0.5px')).to.equal('LEN<0.5 PX>');136 expect(parsePseudo('.5px')).to.equal('LEN<0.5 PX>');137 // Non-px units:138 expect(parsePseudo('100em')).to.equal('LEN<100 EM>');139 expect(parsePseudo('100rem')).to.equal('LEN<100 REM>');140 expect(parsePseudo('100vh')).to.equal('LEN<100 VH>');141 expect(parsePseudo('100vw')).to.equal('LEN<100 VW>');142 expect(parsePseudo('100vmin')).to.equal('LEN<100 VMIN>');143 expect(parsePseudo('100vmax')).to.equal('LEN<100 VMAX>');144 expect(parsePseudo('100cm')).to.equal('LEN<100 CM>');145 expect(parsePseudo('100mm')).to.equal('LEN<100 MM>');146 expect(parsePseudo('100q')).to.equal('LEN<100 Q>');147 expect(parsePseudo('100in')).to.equal('LEN<100 IN>');148 expect(parsePseudo('100pc')).to.equal('LEN<100 PC>');149 expect(parsePseudo('100pt')).to.equal('LEN<100 PT>');150 });151 it('should parse angle', () => {152 expect(parsePseudo('10deg')).to.equal('ANG<10 DEG>');153 expect(parsePseudo('-10deg')).to.equal('ANG<-10 DEG>');154 expect(parsePseudo('+10deg')).to.equal('ANG<10 DEG>');155 expect(parsePseudo('1.5deg')).to.equal('ANG<1.5 DEG>');156 expect(parsePseudo('0.5deg')).to.equal('ANG<0.5 DEG>');157 expect(parsePseudo('.5deg')).to.equal('ANG<0.5 DEG>');158 // Non-deg units:159 expect(parsePseudo('10rad')).to.equal('ANG<10 RAD>');160 expect(parsePseudo('10grad')).to.equal('ANG<10 GRAD>');161 });162 it('should parse time', () => {163 expect(parsePseudo('10ms')).to.equal('TME<10 MS>');164 expect(parsePseudo('10s')).to.equal('TME<10 S>');165 });166 it('should parse url', () => {167 expect(parsePseudo('url("https://acme.org/abc")'))168 .to.equal('URL<https://acme.org/abc>');169 expect(parsePseudo('url(\'https://acme.org/abc\')'))170 .to.equal('URL<https://acme.org/abc>');171 expect(parsePseudo('url(\'data:abc\')'))172 .to.equal('URL<data:abc>');173 // HTTP and relative are allowed at this stage.174 expect(parsePseudo('url(\'http://acme.org/abc\')'))175 .to.equal('URL<http://acme.org/abc>');176 expect(parsePseudo('url(\'/relative\')'))177 .to.equal('URL</relative>');178 });179 it('should parse hexcolor', () => {180 expect(parsePseudo('#123456')).to.equal('#123456');181 expect(parsePseudo('#AB3456')).to.equal('#AB3456');182 expect(parsePseudo('#ABCDEF')).to.equal('#ABCDEF');183 // Alpha-format:184 expect(parsePseudo('#ABCDEF01')).to.equal('#ABCDEF01');185 // Abbrv:186 expect(parsePseudo('#FFF')).to.equal('#FFF');187 expect(parsePseudo('#fff')).to.equal('#fff');188 });189 it('should parse a function', () => {190 expect(parsePseudo('unknown()')).to.equal('UNKNOWN<>');191 expect(parsePseudo('unknown( )')).to.equal('UNKNOWN<>');192 expect(parsePseudo('rgb(10, 20, 30)'))193 .to.equal('RGB<NUM<10>, NUM<20>, NUM<30>>');194 expect(parsePseudo('translate(100px, 200px)'))195 .to.equal('TRANSLATE<LEN<100 PX>, LEN<200 PX>>');196 });197 it('should parse a translate()', () => {198 expect(parsePseudo('translate(100px)'))199 .to.equal('TRANSLATE<LEN<100 PX>>');200 expect(parsePseudo('translate(100px, 200px)'))201 .to.equal('TRANSLATE<LEN<100 PX>, LEN<200 PX>>');202 expect(parsePseudo('translateX(100px)'))203 .to.equal('TRANSLATE-X<LEN<100 PX>>');204 expect(parsePseudo('TRANSLATEX(100px)'))205 .to.equal('TRANSLATE-X<LEN<100 PX>>');206 expect(parsePseudo('translatex(100px)'))207 .to.equal('TRANSLATE-X<LEN<100 PX>>');208 expect(parsePseudo('translateY(100px)'))209 .to.equal('TRANSLATE-Y<LEN<100 PX>>');210 expect(parsePseudo('translateZ(100px)'))211 .to.equal('TRANSLATE-Z<LEN<100 PX>>');212 expect(parsePseudo('translate3d(1px, 2px, 3px)'))213 .to.equal('TRANSLATE-3D<LEN<1 PX>, LEN<2 PX>, LEN<3 PX>>');214 });215 it('should parse a concat of functions', () => {216 expect(parsePseudo('translateX(100px) rotate(45deg)'))217 .to.equal('CON<TRANSLATE-X<LEN<100 PX>>, ROTATE<ANG<45 DEG>>>');218 });219 it('should allow two-way concatenation', () => {220 // This is currently doesn't happen in parse, but by API possible with221 // minor changes to parsing order. Thus it's re-tested separately here.222 expect(pseudo(ast.CssConcatNode.concat(223 new ast.CssConcatNode([new ast.CssPassthroughNode('A')]),224 new ast.CssConcatNode([new ast.CssPassthroughNode('B')]))))225 .to.equal('CON<A, B>');226 expect(pseudo(ast.CssConcatNode.concat(227 new ast.CssPassthroughNode('A'),228 new ast.CssConcatNode([new ast.CssPassthroughNode('B')]))))229 .to.equal('CON<A, B>');230 });231 it('should parse a dimension function', () => {232 // Current.233 expect(parsePseudo('width()'))234 .to.equal('DIM<w, null, null>');235 expect(parsePseudo('height()'))236 .to.equal('DIM<h, null, null>');237 // Query.238 expect(parsePseudo('width(".sel")'))239 .to.equal('DIM<w, ".sel", null>');240 expect(parsePseudo('WIDTH(".sel > div")'))241 .to.equal('DIM<w, ".sel > div", null>');242 expect(parsePseudo('height(".sel")'))243 .to.equal('DIM<h, ".sel", null>');244 // Closest.245 expect(parsePseudo('width(closest(".sel"))'))246 .to.equal('DIM<w, ".sel", closest>');247 expect(parsePseudo('height(closest(".sel"))'))248 .to.equal('DIM<h, ".sel", closest>');249 });250 it('should parse a rand function', () => {251 expect(parsePseudo('rand()'))252 .to.equal('RAND<null, null>');253 expect(parsePseudo('rand(10, 20)'))254 .to.equal('RAND<NUM<10>, NUM<20>>');255 expect(parsePseudo('rand(10px, 20px)'))256 .to.equal('RAND<LEN<10 PX>, LEN<20 PX>>');257 expect(parsePseudo('rand(10em, 20em)'))258 .to.equal('RAND<LEN<10 EM>, LEN<20 EM>>');259 expect(parsePseudo('rand(10px, 20em)'))260 .to.equal('RAND<LEN<10 PX>, LEN<20 EM>>');261 expect(parsePseudo('rand(10s, 20s)'))262 .to.equal('RAND<TME<10 S>, TME<20 S>>');263 expect(parsePseudo('rand(10rad, 20rad)'))264 .to.equal('RAND<ANG<10 RAD>, ANG<20 RAD>>');265 expect(parsePseudo('rand(10%, 20%)'))266 .to.equal('RAND<PRC<10>, PRC<20>>');267 expect(parsePseudo('rand(var(--x), var(--y))'))268 .to.equal('RAND<VAR<--x>, VAR<--y>>');269 expect(parsePseudo('rand(10px, var(--y))'))270 .to.equal('RAND<LEN<10 PX>, VAR<--y>>');271 });272 it('should parse an index function', () => {273 expect(parsePseudo('index()')).to.equal('INDEX<>');274 expect(parsePseudo('INDEX()')).to.equal('INDEX<>');275 });276 it('should parse a var()', () => {277 expect(parsePseudo('var(--abc)')).to.equal('VAR<--abc>');278 expect(parsePseudo('var(--abc1)')).to.equal('VAR<--abc1>');279 expect(parsePseudo('var(--abc-d)')).to.equal('VAR<--abc-d>');280 expect(parsePseudo('VAR(--abc)')).to.equal('VAR<--abc>');281 expect(parsePseudo('var(--ABC)')).to.equal('VAR<--ABC>');282 expect(parsePseudo('var(--abc, 100px)'))283 .to.equal('VAR<--abc, LEN<100 PX>>');284 expect(parsePseudo('var(--abc, var(--def))'))285 .to.equal('VAR<--abc, VAR<--def>>');286 expect(parsePseudo('var(--abc, var(--def, 200px))'))287 .to.equal('VAR<--abc, VAR<--def, LEN<200 PX>>>');288 expect(parsePseudo('var(--abc, rgb(1, 2, 3))'))289 .to.equal('VAR<--abc, RGB<NUM<1>, NUM<2>, NUM<3>>>');290 });291 it('should parse a calc()', () => {292 expect(parsePseudo('calc(100px)'))293 .to.equal('CALC<LEN<100 PX>>');294 expect(parsePseudo('calc((100px))'))295 .to.equal('CALC<LEN<100 PX>>');296 // calc_sum297 expect(parsePseudo('calc(100px + 200px)'))298 .to.equal('CALC<ADD<LEN<100 PX>, LEN<200 PX>>>');299 expect(parsePseudo('calc(100px - 200px)'))300 .to.equal('CALC<SUB<LEN<100 PX>, LEN<200 PX>>>');301 expect(parsePseudo('calc((100px + 200px))'))302 .to.equal('CALC<ADD<LEN<100 PX>, LEN<200 PX>>>');303 // calc_product304 expect(parsePseudo('calc(100px * 2)'))305 .to.equal('CALC<MUL<LEN<100 PX>, NUM<2>>>');306 expect(parsePseudo('calc(2 * 100px)'))307 .to.equal('CALC<MUL<NUM<2>, LEN<100 PX>>>');308 expect(parsePseudo('calc(100px / 2)'))309 .to.equal('CALC<DIV<LEN<100 PX>, NUM<2>>>');310 expect(parsePseudo('calc((100px * 2))'))311 .to.equal('CALC<MUL<LEN<100 PX>, NUM<2>>>');312 // precedence313 expect(parsePseudo('calc(100px + 200px + 300px)'))314 .to.equal('CALC<ADD<ADD<LEN<100 PX>, LEN<200 PX>>, LEN<300 PX>>>');315 expect(parsePseudo('calc(100px * 2 * 3)'))316 .to.equal('CALC<MUL<MUL<LEN<100 PX>, NUM<2>>, NUM<3>>>');317 expect(parsePseudo('calc(100px * 2 / 3)'))318 .to.equal('CALC<DIV<MUL<LEN<100 PX>, NUM<2>>, NUM<3>>>');319 expect(parsePseudo('calc(100px + 200px * 0.5)'))320 .to.equal('CALC<ADD<LEN<100 PX>, MUL<LEN<200 PX>, NUM<0.5>>>>');321 expect(parsePseudo('calc(100px - 200px / 0.5)'))322 .to.equal('CALC<SUB<LEN<100 PX>, DIV<LEN<200 PX>, NUM<0.5>>>>');323 expect(parsePseudo('calc((100px + 200px) * 0.5)'))324 .to.equal('CALC<MUL<ADD<LEN<100 PX>, LEN<200 PX>>, NUM<0.5>>>');325 expect(parsePseudo('calc((100px - 200px) / 0.5)'))326 .to.equal('CALC<DIV<SUB<LEN<100 PX>, LEN<200 PX>>, NUM<0.5>>>');327 expect(parsePseudo('calc(100px * 0.5 + 200px)'))328 .to.equal('CALC<ADD<MUL<LEN<100 PX>, NUM<0.5>>, LEN<200 PX>>>');329 expect(parsePseudo('calc(100px / 0.5 - 200px)'))330 .to.equal('CALC<SUB<DIV<LEN<100 PX>, NUM<0.5>>, LEN<200 PX>>>');331 expect(parsePseudo('calc(0.5 * (100px + 200px))'))332 .to.equal('CALC<MUL<NUM<0.5>, ADD<LEN<100 PX>, LEN<200 PX>>>>');333 // func334 expect(parsePseudo('calc(var(--abc, 100px) + 200px)'))335 .to.equal('CALC<ADD<VAR<--abc, LEN<100 PX>>, LEN<200 PX>>>');336 });337});338describes.sandboxed('CSS resolve', {}, () => {339 const normalize = true;340 let context;341 let contextMock;342 beforeEach(() => {343 context = new ast.CssContext();344 contextMock = sandbox.mock(context);345 });346 afterEach(() => {347 contextMock.verify();348 });...

Full Screen

Full Screen

test-css-expr-parser.js

Source:test-css-expr-parser.js Github

copy

Full Screen

...19 /**20 * @param {string} cssString21 * @return {string}22 */23 function parsePseudo(cssString) {24 const node = parseCss(cssString);25 if (node == null) {26 return null;27 }28 return pseudo(node);29 }30 /**31 * @param {!CssNode} n32 * @return {string}33 */34 function pseudo(n) {35 if (n instanceof ast.CssPassthroughNode) {36 return n.css_;37 }38 if (n instanceof ast.CssUrlNode) {39 return `URL<${n.url_}>`;40 }41 if (n instanceof ast.CssConcatNode) {42 return `CON<${pseudoArray(n.array_, n.dimensions_, ' ')}>`;43 }44 if (n instanceof ast.CssNumericNode) {45 return (46 `${n.type_}<${n.num_}` +47 `${n.units_ && n.units_ != '%' ? ' ' + n.units_.toUpperCase() : ''}>`48 );49 }50 if (n instanceof ast.CssTranslateNode) {51 return (52 'TRANSLATE' +53 `${n.suffix_ ? '-' + n.suffix_.toUpperCase() : ''}` +54 `<${pseudoArray(n.args_, n.dimensions_)}>`55 );56 }57 if (n instanceof ast.CssRectNode) {58 return (59 `RECT<${n.field_}` +60 `, ${n.selector_ ? '"' + n.selector_ + '"' : null}` +61 `, ${n.selectionMethod_}>`62 );63 }64 if (n instanceof ast.CssNumConvertNode) {65 return `NUMC<${n.value_ ? pseudo(n.value_) : null}>`;66 }67 if (n instanceof ast.CssRandNode) {68 return (69 `RAND<${n.left_ ? pseudo(n.left_) : null}` +70 `, ${n.right_ ? pseudo(n.right_) : null}>`71 );72 }73 if (n instanceof ast.CssIndexNode) {74 return 'INDEX<>';75 }76 if (n instanceof ast.CssLengthFuncNode) {77 return 'LENGTH<>';78 }79 if (n instanceof ast.CssVarNode) {80 return `VAR<${n.varName_}${n.def_ ? ', ' + pseudo(n.def_) : ''}>`;81 }82 if (n instanceof ast.CssCalcNode) {83 return `CALC<${pseudo(n.expr_)}>`;84 }85 if (n instanceof ast.CssCalcSumNode) {86 return (87 `${n.op_ == '+' ? 'ADD' : 'SUB'}` +88 `<${pseudo(n.left_)}, ${pseudo(n.right_)}>`89 );90 }91 if (n instanceof ast.CssCalcProductNode) {92 return (93 `${n.op_ == '*' ? 'MUL' : 'DIV'}` +94 `<${pseudo(n.left_)}, ${pseudo(n.right_)}>`95 );96 }97 if (n instanceof ast.CssFuncNode) {98 return `${n.name_.toUpperCase()}<${pseudoArray(n.args_, n.dimensions_)}>`;99 }100 throw new Error('unknown node: ' + n);101 }102 /**103 * @param {!Array<!CssNode>} array104 * @param {?Array<string>} dims105 * @param {string=} delim106 * @return {string}107 */108 function pseudoArray(array, dims = null, delim = ', ') {109 if (!array || array.length == 0) {110 return '';111 }112 return array113 .map((n, i) => {114 const v = pseudo(n);115 if (dims && i < dims.length) {116 return `${v}|${dims[i]}`;117 }118 return v;119 })120 .join(delim);121 }122 it('should parse empty string as null', () => {123 expect(parsePseudo('')).to.be.null;124 });125 it('should parse string', () => {126 expect(parsePseudo('"abc"')).to.equal('"abc"');127 expect(parsePseudo("'abc'")).to.equal("'abc'");128 });129 it('should parse "none" ident', () => {130 expect(parsePseudo('none')).to.equal('none');131 });132 it('should parse ident', () => {133 expect(parsePseudo('abc')).to.equal('abc');134 expect(parsePseudo('-abc')).to.equal('-abc');135 expect(parsePseudo('-abc1')).to.equal('-abc1');136 expect(parsePseudo('-abc1a')).to.equal('-abc1a');137 });138 it('should parse number', () => {139 expect(parsePseudo('0')).to.equal('NUM<0>');140 expect(parsePseudo('1')).to.equal('NUM<1>');141 expect(parsePseudo('10')).to.equal('NUM<10>');142 expect(parsePseudo('0.5')).to.equal('NUM<0.5>');143 expect(parsePseudo('.5')).to.equal('NUM<0.5>');144 expect(parsePseudo('1.5')).to.equal('NUM<1.5>');145 expect(parsePseudo('-0.5')).to.equal('NUM<-0.5>');146 expect(parsePseudo('-.5')).to.equal('NUM<-0.5>');147 expect(parsePseudo('+.5')).to.equal('NUM<0.5>');148 expect(parsePseudo('+1.5')).to.equal('NUM<1.5>');149 expect(parsePseudo('1e2')).to.equal('NUM<100>');150 expect(parsePseudo('.1e2')).to.equal('NUM<10>');151 expect(parsePseudo('1e+2')).to.equal('NUM<100>');152 expect(parsePseudo('1e-2')).to.equal('NUM<0.01>');153 });154 it('should parse percent', () => {155 expect(parsePseudo('0%')).to.equal('PRC<0>');156 expect(parsePseudo('1%')).to.equal('PRC<1>');157 expect(parsePseudo('0.5%')).to.equal('PRC<0.5>');158 expect(parsePseudo('.5%')).to.equal('PRC<0.5>');159 expect(parsePseudo('1e2%')).to.equal('PRC<100>');160 });161 it('should parse length', () => {162 expect(parsePseudo('100px')).to.equal('LEN<100 PX>');163 expect(parsePseudo('-100px')).to.equal('LEN<-100 PX>');164 expect(parsePseudo('+100px')).to.equal('LEN<100 PX>');165 expect(parsePseudo('100.5px')).to.equal('LEN<100.5 PX>');166 expect(parsePseudo('0.5px')).to.equal('LEN<0.5 PX>');167 expect(parsePseudo('.5px')).to.equal('LEN<0.5 PX>');168 // Non-px units:169 expect(parsePseudo('100em')).to.equal('LEN<100 EM>');170 expect(parsePseudo('100rem')).to.equal('LEN<100 REM>');171 expect(parsePseudo('100vh')).to.equal('LEN<100 VH>');172 expect(parsePseudo('100vw')).to.equal('LEN<100 VW>');173 expect(parsePseudo('100vmin')).to.equal('LEN<100 VMIN>');174 expect(parsePseudo('100vmax')).to.equal('LEN<100 VMAX>');175 expect(parsePseudo('100cm')).to.equal('LEN<100 CM>');176 expect(parsePseudo('100mm')).to.equal('LEN<100 MM>');177 expect(parsePseudo('100q')).to.equal('LEN<100 Q>');178 expect(parsePseudo('100in')).to.equal('LEN<100 IN>');179 expect(parsePseudo('100pc')).to.equal('LEN<100 PC>');180 expect(parsePseudo('100pt')).to.equal('LEN<100 PT>');181 });182 it('should parse angle', () => {183 expect(parsePseudo('10deg')).to.equal('ANG<10 DEG>');184 expect(parsePseudo('-10deg')).to.equal('ANG<-10 DEG>');185 expect(parsePseudo('+10deg')).to.equal('ANG<10 DEG>');186 expect(parsePseudo('1.5deg')).to.equal('ANG<1.5 DEG>');187 expect(parsePseudo('0.5deg')).to.equal('ANG<0.5 DEG>');188 expect(parsePseudo('.5deg')).to.equal('ANG<0.5 DEG>');189 // Non-deg units:190 expect(parsePseudo('10rad')).to.equal('ANG<10 RAD>');191 expect(parsePseudo('10grad')).to.equal('ANG<10 GRAD>');192 });193 it('should parse time', () => {194 expect(parsePseudo('10ms')).to.equal('TME<10 MS>');195 expect(parsePseudo('10s')).to.equal('TME<10 S>');196 });197 it('should parse url', () => {198 expect(parsePseudo('url("https://acme.org/abc")')).to.equal(199 'URL<https://acme.org/abc>'200 );201 expect(parsePseudo("url('https://acme.org/abc')")).to.equal(202 'URL<https://acme.org/abc>'203 );204 expect(parsePseudo("url('data:abc')")).to.equal('URL<data:abc>');205 // HTTP and relative are allowed at this stage.206 expect(parsePseudo("url('http://acme.org/abc')")).to.equal(207 'URL<http://acme.org/abc>'208 );209 expect(parsePseudo("url('/relative')")).to.equal('URL</relative>');210 });211 it('should parse hexcolor', () => {212 expect(parsePseudo('#123456')).to.equal('#123456');213 expect(parsePseudo('#AB3456')).to.equal('#AB3456');214 expect(parsePseudo('#ABCDEF')).to.equal('#ABCDEF');215 // Alpha-format:216 expect(parsePseudo('#ABCDEF01')).to.equal('#ABCDEF01');217 // Abbrv:218 expect(parsePseudo('#FFF')).to.equal('#FFF');219 expect(parsePseudo('#fff')).to.equal('#fff');220 });221 it('should parse a function', () => {222 expect(parsePseudo('unknown()')).to.equal('UNKNOWN<>');223 expect(parsePseudo('unknown( )')).to.equal('UNKNOWN<>');224 expect(parsePseudo('rgb(10, 20, 30)')).to.equal(225 'RGB<NUM<10>, NUM<20>, NUM<30>>'226 );227 expect(parsePseudo('translate(100px, 200px)')).to.equal(228 'TRANSLATE<LEN<100 PX>|w, LEN<200 PX>|h>'229 );230 });231 it('should parse a translate()', () => {232 expect(parsePseudo('translate(100px)')).to.equal(233 'TRANSLATE<LEN<100 PX>|w>'234 );235 expect(parsePseudo('translate(100px, 200px)')).to.equal(236 'TRANSLATE<LEN<100 PX>|w, LEN<200 PX>|h>'237 );238 expect(parsePseudo('translateX(100px)')).to.equal(239 'TRANSLATE-X<LEN<100 PX>|w>'240 );241 expect(parsePseudo('TRANSLATEX(100px)')).to.equal(242 'TRANSLATE-X<LEN<100 PX>|w>'243 );244 expect(parsePseudo('translatex(100px)')).to.equal(245 'TRANSLATE-X<LEN<100 PX>|w>'246 );247 expect(parsePseudo('translateY(100px)')).to.equal(248 'TRANSLATE-Y<LEN<100 PX>|h>'249 );250 expect(parsePseudo('translateZ(100px)')).to.equal(251 'TRANSLATE-Z<LEN<100 PX>|z>'252 );253 expect(parsePseudo('translate3d(1px, 2px, 3px)')).to.equal(254 'TRANSLATE-3D<LEN<1 PX>|w, LEN<2 PX>|h, LEN<3 PX>|z>'255 );256 });257 it('should parse a concat of functions', () => {258 expect(parsePseudo('translateX(100px) rotate(45deg)')).to.equal(259 'CON<TRANSLATE-X<LEN<100 PX>|w> ROTATE<ANG<45 DEG>>>'260 );261 });262 it('should allow two-way concatenation', () => {263 // This is currently doesn't happen in parse, but by API possible with264 // minor changes to parsing order. Thus it's re-tested separately here.265 expect(266 pseudo(267 ast.CssConcatNode.concat(268 new ast.CssConcatNode([new ast.CssPassthroughNode('A')]),269 new ast.CssConcatNode([new ast.CssPassthroughNode('B')])270 )271 )272 ).to.equal('CON<A B>');273 expect(274 pseudo(275 ast.CssConcatNode.concat(276 new ast.CssPassthroughNode('A'),277 new ast.CssConcatNode([new ast.CssPassthroughNode('B')])278 )279 )280 ).to.equal('CON<A B>');281 });282 it('should parse a rect function', () => {283 // Current.284 expect(parsePseudo('width()')).to.equal('RECT<w, null, null>');285 expect(parsePseudo('height()')).to.equal('RECT<h, null, null>');286 expect(parsePseudo('x()')).to.equal('RECT<x, null, null>');287 expect(parsePseudo('y()')).to.equal('RECT<y, null, null>');288 // Query.289 expect(parsePseudo('width(".sel")')).to.equal('RECT<w, ".sel", null>');290 expect(parsePseudo('WIDTH(".sel > div")')).to.equal(291 'RECT<w, ".sel > div", null>'292 );293 expect(parsePseudo('height(".sel")')).to.equal('RECT<h, ".sel", null>');294 expect(parsePseudo('x(".sel")')).to.equal('RECT<x, ".sel", null>');295 expect(parsePseudo('x(".sel > div")')).to.equal(296 'RECT<x, ".sel > div", null>'297 );298 expect(parsePseudo('y(".sel")')).to.equal('RECT<y, ".sel", null>');299 // Closest.300 expect(parsePseudo('width(closest(".sel"))')).to.equal(301 'RECT<w, ".sel", closest>'302 );303 expect(parsePseudo('height(closest(".sel"))')).to.equal(304 'RECT<h, ".sel", closest>'305 );306 expect(parsePseudo('x(closest(".sel"))')).to.equal(307 'RECT<x, ".sel", closest>'308 );309 expect(parsePseudo('y(closest(".sel"))')).to.equal(310 'RECT<y, ".sel", closest>'311 );312 });313 it('should parse a num-convert function', () => {314 expect(parsePseudo('num(10)')).to.equal('NUMC<NUM<10>>');315 expect(parsePseudo('num(10px)')).to.equal('NUMC<LEN<10 PX>>');316 expect(parsePseudo('num(10em)')).to.equal('NUMC<LEN<10 EM>>');317 expect(parsePseudo('num(10s)')).to.equal('NUMC<TME<10 S>>');318 expect(parsePseudo('num(10rad)')).to.equal('NUMC<ANG<10 RAD>>');319 expect(parsePseudo('num(10%)')).to.equal('NUMC<PRC<10>>');320 expect(parsePseudo('num(var(--x))')).to.equal('NUMC<VAR<--x>>');321 });322 it('should parse a rand function', () => {323 expect(parsePseudo('rand()')).to.equal('RAND<null, null>');324 expect(parsePseudo('rand(10, 20)')).to.equal('RAND<NUM<10>, NUM<20>>');325 expect(parsePseudo('rand(10px, 20px)')).to.equal(326 'RAND<LEN<10 PX>, LEN<20 PX>>'327 );328 expect(parsePseudo('rand(10em, 20em)')).to.equal(329 'RAND<LEN<10 EM>, LEN<20 EM>>'330 );331 expect(parsePseudo('rand(10px, 20em)')).to.equal(332 'RAND<LEN<10 PX>, LEN<20 EM>>'333 );334 expect(parsePseudo('rand(10s, 20s)')).to.equal(335 'RAND<TME<10 S>, TME<20 S>>'336 );337 expect(parsePseudo('rand(10rad, 20rad)')).to.equal(338 'RAND<ANG<10 RAD>, ANG<20 RAD>>'339 );340 expect(parsePseudo('rand(10%, 20%)')).to.equal('RAND<PRC<10>, PRC<20>>');341 expect(parsePseudo('rand(var(--x), var(--y))')).to.equal(342 'RAND<VAR<--x>, VAR<--y>>'343 );344 expect(parsePseudo('rand(10px, var(--y))')).to.equal(345 'RAND<LEN<10 PX>, VAR<--y>>'346 );347 });348 it('should parse an index function', () => {349 expect(parsePseudo('index()')).to.equal('INDEX<>');350 expect(parsePseudo('INDEX()')).to.equal('INDEX<>');351 });352 it('should parse a length function', () => {353 expect(parsePseudo('length()')).to.equal('LENGTH<>');354 expect(parsePseudo('LENGTH()')).to.equal('LENGTH<>');355 });356 it('should parse clip-path:inset', () => {357 // No radius.358 // inset(<all>)359 expect(parsePseudo('inset(10%)')).to.equal(360 'INSET<CON<PRC<10>|h PRC<10>|w>>'361 );362 // inset(<vert horiz>)363 expect(parsePseudo('inset(10% 10%)')).to.equal(364 'INSET<CON<PRC<10>|h PRC<10>|w>>'365 );366 // inset(<top horiz bottom>)367 expect(parsePseudo('inset(10% 20% 30%)')).to.equal(368 'INSET<CON<PRC<10>|h PRC<20>|w PRC<30>|h>>'369 );370 // inset(<top right bottom left>)371 expect(parsePseudo('inset(10% 20% 30% 40%)')).to.equal(372 'INSET<CON<PRC<10>|h PRC<20>|w PRC<30>|h PRC<40>|w>>'373 );374 // With radius.375 // inset(<all> round 50%)376 expect(parsePseudo('inset(10% round 50% 20%)')).to.equal(377 'INSET<CON<CON<PRC<10>|h PRC<10>|w> round CON<PRC<50> PRC<20>>>>'378 );379 // inset(<all> round 10px / 20px)380 expect(parsePseudo('inset(10% round 10px / 20px)')).to.equal(381 'INSET<CON<CON<PRC<10>|h PRC<10>|w> round CON<CON<LEN<10 PX>> / CON<LEN<20 PX>>>>>'382 );383 // Do not allow empty box.384 expect(() => {385 parsePseudo('inset()');386 }).to.throw(/Parse error/);387 // Do not allow more than 4 components in a box.388 expect(() => {389 parsePseudo('inset(1px 2px 3px 4px 5px)');390 }).to.throw(/must have between 1 and 4 components/);391 // Do not allow empty radius.392 expect(() => {393 parsePseudo('inset(10% round)');394 }).to.throw(/Parse error/);395 // Do not allow radius with more than 4 components.396 expect(() => {397 parsePseudo('inset(10% round 1px 2px 3px 4px 5px)');398 }).to.throw(/must have between 1 and 4 components/);399 });400 it('should parse clip-path:circle', () => {401 // No position.402 // circle()403 expect(parsePseudo('circle()')).to.equal('CIRCLE<>');404 // circle(50%)405 expect(parsePseudo('circle(50%)')).to.equal('CIRCLE<PRC<50>>');406 // circle(50px)407 expect(parsePseudo('circle(50px)')).to.equal('CIRCLE<LEN<50 PX>>');408 // circle(farthest-side)409 expect(parsePseudo('circle(farthest-side)')).to.equal(410 'CIRCLE<farthest-side>'411 );412 // With radius.413 // circle(at 10% 20%)414 expect(parsePseudo('circle(at 10% 20%)')).to.equal(415 'CIRCLE<CON<at CON<PRC<10>|w PRC<20>|h>>>'416 );417 // circle(50% at 10% 20%)418 expect(parsePseudo('circle(50% at 10% 20%)')).to.equal(419 'CIRCLE<CON<PRC<50> at CON<PRC<10>|w PRC<20>|h>>>'420 );421 // circle(50% at left top)422 expect(parsePseudo('circle(50% at left top)')).to.equal(423 'CIRCLE<CON<PRC<50> at CON<left|w top|h>>>'424 );425 // circle(50% at left 20%)426 expect(parsePseudo('circle(50% at left 20%)')).to.equal(427 'CIRCLE<CON<PRC<50> at CON<left|w PRC<20>|h>>>'428 );429 // circle(50% at 10% top)430 expect(parsePseudo('circle(50% at 10% top)')).to.equal(431 'CIRCLE<CON<PRC<50> at CON<PRC<10>|w top|h>>>'432 );433 // circle(50% at left 10% top 20%)434 expect(parsePseudo('circle(50% at left 10% top 20%)')).to.equal(435 'CIRCLE<CON<PRC<50> at CON<left|w PRC<10>|w top|h PRC<20>|h>>>'436 );437 });438 it('should parse clip-path:ellipse', () => {439 // No position.440 // ellipse()441 expect(parsePseudo('ellipse()')).to.equal('ELLIPSE<>');442 // ellipse(50%)443 expect(parsePseudo('ellipse(20% 30%)')).to.equal(444 'ELLIPSE<CON<PRC<20> PRC<30>>>'445 );446 // ellipse(50px)447 expect(parsePseudo('ellipse(20px 30px)')).to.equal(448 'ELLIPSE<CON<LEN<20 PX> LEN<30 PX>>>'449 );450 // ellipse(farthest-side)451 expect(parsePseudo('ellipse(closest-side farthest-side)')).to.equal(452 'ELLIPSE<CON<closest-side farthest-side>>'453 );454 // With radius.455 // ellipse(at 10% 20%)456 expect(parsePseudo('ellipse(at 10% 20%)')).to.equal(457 'ELLIPSE<CON<at CON<PRC<10>|w PRC<20>|h>>>'458 );459 // ellipse(30% 40% at 10% 20%)460 expect(parsePseudo('ellipse(30% 40% at 10% 20%)')).to.equal(461 'ELLIPSE<CON<CON<PRC<30> PRC<40>> at CON<PRC<10>|w PRC<20>|h>>>'462 );463 // ellipse(30% 40% at left top)464 expect(parsePseudo('ellipse(30% 40% at left top)')).to.equal(465 'ELLIPSE<CON<CON<PRC<30> PRC<40>> at CON<left|w top|h>>>'466 );467 // ellipse(30% 40% at left 20%)468 expect(parsePseudo('ellipse(30% 40% at left 20%)')).to.equal(469 'ELLIPSE<CON<CON<PRC<30> PRC<40>> at CON<left|w PRC<20>|h>>>'470 );471 // ellipse(30% 40% at 10% top)472 expect(parsePseudo('ellipse(30% 40% at 10% top)')).to.equal(473 'ELLIPSE<CON<CON<PRC<30> PRC<40>> at CON<PRC<10>|w top|h>>>'474 );475 // ellipse(30% 40% at left 10% top 20%)476 expect(parsePseudo('ellipse(30% 40% at left 10% top 20%)')).to.equal(477 'ELLIPSE<CON<CON<PRC<30> PRC<40>> at CON<left|w PRC<10>|w top|h PRC<20>|h>>>'478 );479 // ellipse(30% 40% at top 10% left 20%)480 expect(parsePseudo('ellipse(30% 40% at top 10% left 20%)')).to.equal(481 'ELLIPSE<CON<CON<PRC<30> PRC<40>> at CON<top|h PRC<10>|h left|w PRC<20>|w>>>'482 );483 });484 it('should parse clip-path:polygon', () => {485 // 1 tuple.486 expect(parsePseudo('polygon(10px 20px)')).to.equal(487 'POLYGON<CON<LEN<10 PX>|w LEN<20 PX>|h>>'488 );489 expect(parsePseudo('polygon(10% 20%)')).to.equal(490 'POLYGON<CON<PRC<10>|w PRC<20>|h>>'491 );492 // 2 tuples.493 expect(parsePseudo('polygon(10px 20px, 30px 40px)')).to.equal(494 'POLYGON<CON<LEN<10 PX>|w LEN<20 PX>|h>, CON<LEN<30 PX>|w LEN<40 PX>|h>>'495 );496 expect(parsePseudo('polygon(10% 20%, 30% 40%)')).to.equal(497 'POLYGON<CON<PRC<10>|w PRC<20>|h>, CON<PRC<30>|w PRC<40>|h>>'498 );499 });500 it('should parse a var()', () => {501 expect(parsePseudo('var(--abc)')).to.equal('VAR<--abc>');502 expect(parsePseudo('var(--abc1)')).to.equal('VAR<--abc1>');503 expect(parsePseudo('var(--abc-d)')).to.equal('VAR<--abc-d>');504 expect(parsePseudo('VAR(--abc)')).to.equal('VAR<--abc>');505 expect(parsePseudo('var(--ABC)')).to.equal('VAR<--ABC>');506 expect(parsePseudo('var(--abc, 100px)')).to.equal(507 'VAR<--abc, LEN<100 PX>>'508 );509 expect(parsePseudo('var(--abc, var(--def))')).to.equal(510 'VAR<--abc, VAR<--def>>'511 );512 expect(parsePseudo('var(--abc, var(--def, 200px))')).to.equal(513 'VAR<--abc, VAR<--def, LEN<200 PX>>>'514 );515 expect(parsePseudo('var(--abc, rgb(1, 2, 3))')).to.equal(516 'VAR<--abc, RGB<NUM<1>, NUM<2>, NUM<3>>>'517 );518 });519 it('should parse a calc()', () => {520 expect(parsePseudo('calc(100px)')).to.equal('CALC<LEN<100 PX>>');521 expect(parsePseudo('calc((100px))')).to.equal('CALC<LEN<100 PX>>');522 // calc_sum523 expect(parsePseudo('calc(100px + 200px)')).to.equal(524 'CALC<ADD<LEN<100 PX>, LEN<200 PX>>>'525 );526 expect(parsePseudo('calc(100px - 200px)')).to.equal(527 'CALC<SUB<LEN<100 PX>, LEN<200 PX>>>'528 );529 expect(parsePseudo('calc((100px + 200px))')).to.equal(530 'CALC<ADD<LEN<100 PX>, LEN<200 PX>>>'531 );532 // calc_product533 expect(parsePseudo('calc(100px * 2)')).to.equal(534 'CALC<MUL<LEN<100 PX>, NUM<2>>>'535 );536 expect(parsePseudo('calc(2 * 100px)')).to.equal(537 'CALC<MUL<NUM<2>, LEN<100 PX>>>'538 );539 expect(parsePseudo('calc(100px / 2)')).to.equal(540 'CALC<DIV<LEN<100 PX>, NUM<2>>>'541 );542 expect(parsePseudo('calc((100px * 2))')).to.equal(543 'CALC<MUL<LEN<100 PX>, NUM<2>>>'544 );545 // precedence546 expect(parsePseudo('calc(100px + 200px + 300px)')).to.equal(547 'CALC<ADD<ADD<LEN<100 PX>, LEN<200 PX>>, LEN<300 PX>>>'548 );549 expect(parsePseudo('calc(100px * 2 * 3)')).to.equal(550 'CALC<MUL<MUL<LEN<100 PX>, NUM<2>>, NUM<3>>>'551 );552 expect(parsePseudo('calc(100px * 2 / 3)')).to.equal(553 'CALC<DIV<MUL<LEN<100 PX>, NUM<2>>, NUM<3>>>'554 );555 expect(parsePseudo('calc(100px + 200px * 0.5)')).to.equal(556 'CALC<ADD<LEN<100 PX>, MUL<LEN<200 PX>, NUM<0.5>>>>'557 );558 expect(parsePseudo('calc(100px - 200px / 0.5)')).to.equal(559 'CALC<SUB<LEN<100 PX>, DIV<LEN<200 PX>, NUM<0.5>>>>'560 );561 expect(parsePseudo('calc((100px + 200px) * 0.5)')).to.equal(562 'CALC<MUL<ADD<LEN<100 PX>, LEN<200 PX>>, NUM<0.5>>>'563 );564 expect(parsePseudo('calc((100px - 200px) / 0.5)')).to.equal(565 'CALC<DIV<SUB<LEN<100 PX>, LEN<200 PX>>, NUM<0.5>>>'566 );567 expect(parsePseudo('calc(100px * 0.5 + 200px)')).to.equal(568 'CALC<ADD<MUL<LEN<100 PX>, NUM<0.5>>, LEN<200 PX>>>'569 );570 expect(parsePseudo('calc(100px / 0.5 - 200px)')).to.equal(571 'CALC<SUB<DIV<LEN<100 PX>, NUM<0.5>>, LEN<200 PX>>>'572 );573 expect(parsePseudo('calc(0.5 * (100px + 200px))')).to.equal(574 'CALC<MUL<NUM<0.5>, ADD<LEN<100 PX>, LEN<200 PX>>>>'575 );576 // func577 expect(parsePseudo('calc(var(--abc, 100px) + 200px)')).to.equal(578 'CALC<ADD<VAR<--abc, LEN<100 PX>>, LEN<200 PX>>>'579 );580 });581 it('should parse a min()/max()', () => {582 expect(parsePseudo('min(100px)')).to.equal('MIN<LEN<100 PX>>');583 expect(parsePseudo('max(100px)')).to.equal('MAX<LEN<100 PX>>');584 // 2+ components.585 expect(parsePseudo('min(100px, 200px, 300px)')).to.equal(586 'MIN<LEN<100 PX>, LEN<200 PX>, LEN<300 PX>>'587 );588 expect(parsePseudo('max(100px, 200px, 300px)')).to.equal(589 'MAX<LEN<100 PX>, LEN<200 PX>, LEN<300 PX>>'590 );591 // With calc_sum.592 expect(parsePseudo('min(100px + 200px, 100px + 300px)')).to.equal(593 'MIN<ADD<LEN<100 PX>, LEN<200 PX>>, ADD<LEN<100 PX>, LEN<300 PX>>>'594 );595 // With calc_product.596 expect(parsePseudo('min(100px * 2, 100px / 2)')).to.equal(597 'MIN<MUL<LEN<100 PX>, NUM<2>>, DIV<LEN<100 PX>, NUM<2>>>'598 );599 // With precedence.600 expect(parsePseudo('min(100px + 200px + 300px, 250px)')).to.equal(601 'MIN<ADD<ADD<LEN<100 PX>, LEN<200 PX>>, LEN<300 PX>>, LEN<250 PX>>'602 );603 expect(parsePseudo('min(100px * 2 * 3, 250px)')).to.equal(604 'MIN<MUL<MUL<LEN<100 PX>, NUM<2>>, NUM<3>>, LEN<250 PX>>'605 );606 expect(parsePseudo('max(100px * 2 / 3, 250px)')).to.equal(607 'MAX<DIV<MUL<LEN<100 PX>, NUM<2>>, NUM<3>>, LEN<250 PX>>'608 );609 expect(parsePseudo('min(100px + 200px * 0.5, 250px)')).to.equal(610 'MIN<ADD<LEN<100 PX>, MUL<LEN<200 PX>, NUM<0.5>>>, LEN<250 PX>>'611 );612 expect(parsePseudo('max((100px + 200px) * 0.5, 250px)')).to.equal(613 'MAX<MUL<ADD<LEN<100 PX>, LEN<200 PX>>, NUM<0.5>>, LEN<250 PX>>'614 );615 // With func.616 expect(parsePseudo('min(var(--abc, 100px) + 200px, 250px)')).to.equal(617 'MIN<ADD<VAR<--abc, LEN<100 PX>>, LEN<200 PX>>, LEN<250 PX>>'618 );619 // With calc.620 expect(parsePseudo('calc(0.5 * max(100px, 200px))')).to.equal(621 'CALC<MUL<NUM<0.5>, MAX<LEN<100 PX>, LEN<200 PX>>>>'622 );623 });624 it('should parse a clamp()', () => {625 expect(parsePseudo('clamp(100px, 200px, 300px)')).to.equal(626 'CLAMP<LEN<100 PX>, LEN<200 PX>, LEN<300 PX>>'627 );628 // With calc_sum.629 expect(630 parsePseudo('clamp(100px + 1px, 100px + 2px, 100px + 3px)')631 ).to.equal(632 'CLAMP<ADD<LEN<100 PX>, LEN<1 PX>>, ADD<LEN<100 PX>, LEN<2 PX>>, ADD<LEN<100 PX>, LEN<3 PX>>>'633 );634 // With calc.635 expect(parsePseudo('calc(0.5 * clamp(1px, 2px, 3px))')).to.equal(636 'CALC<MUL<NUM<0.5>, CLAMP<LEN<1 PX>, LEN<2 PX>, LEN<3 PX>>>>'637 );638 });...

Full Screen

Full Screen

crucial.js

Source:crucial.js Github

copy

Full Screen

...89const cssConfig = {mqs: {}, currentMQ: '', beforeMQ: ''};90const parseCSS = function () {91 let mqCallbacks;92 const root = document.documentElement;93 const styles = rb.parsePseudo(root) || {};94 const currentMQStyle = rb.getStyles(root, '::after');95 let currentStyle = '';96 const detectMQChange = function () {97 const nowStyle = currentMQStyle.content;98 if (currentStyle != nowStyle) {99 currentStyle = nowStyle;100 rb.cssConfig.beforeMQ = rb.cssConfig.currentMQ;101 rb.cssConfig.currentMQ = removeLeadingQuotes(currentStyle);102 if (rb.$ && rb.$.Callbacks) {103 rb.cssConfig.mqChange.fireWith(rb.cssConfig);104 }105 }106 };107 const timedDetectMQChange = (function(){...

Full Screen

Full Screen

isolateCss.js

Source:isolateCss.js Github

copy

Full Screen

...42 return true;43 }44 function parsePseudoContent(){45 for (; i < len && sym[i] != ')'; i++)46 if (parseComment() || parseBraces() || parsePseudo() || parseClassName())47 continue;48 }49 function parsePseudo(){50 if (sym[i] !== ':')51 return;52 var m = css.substr(i + 1, CSS_FNSELECTOR_MAXLEN).match(CSS_FNSELECTOR);53 if (m)54 {55 i += m[0].length + 1;56 parsePseudoContent();57 }58 return true;59 }60 function parseAtRule(){61 if (sym[i] !== '@')62 return;63 var m = css.substr(i + 1, CSS_NESTED_ATRULE_MAXLEN).match(CSS_NESTED_ATRULE);64 if (m)65 {66 i += m[0].length;67 nestedStyleSheet = true;68 }69 return true;70 }71 function parseBlock(){72 if (sym[i] !== '{')73 return;74 if (nestedStyleSheet)75 {76 i++;77 parseStyleSheet(true);78 return;79 }80 for (i++; i < len && sym[i] !== '}'; i++)81 parseComment() || parseString() || parseBraces();82 return true;83 }84 function parseClassName(){85 if (sym[i] !== '.')86 return;87 var m = css.substr(i + 1, CSS_CLASSNAME_START_MAXLEN).match(CSS_CLASSNAME_START);88 if (m)89 {90 i++;91 map[i + (result.length / 2) * prefix.length - 1] = i;92 result.push(css.substring(lastMatchPos, i), prefix);93 lastMatchPos = i;94 }95 return true;96 }97 function parseStyleSheet(nested){98 for (nestedStyleSheet = false; i < len; i++)99 {100 if (parseComment() || parseAtRule() || parsePseudo() || parseBraces() || parseString() || parseClassName())101 continue;102 if (nested && sym[i] == '}')103 return;104 parseBlock();105 }106 }107 var map = {};108 var result = [];109 var sym = css.split('');110 var len = sym.length;111 var lastMatchPos = 0;112 var i = 0;113 var nestedStyleSheet;114 if (!prefix)...

Full Screen

Full Screen

cssxpath.js

Source:cssxpath.js Github

copy

Full Screen

...12 converter.trimCss();13 if (!converter.css) break;14 previousCss = converter.css;15 converter.parseAsterisk();16 converter.parsePseudo();17 converter.parseElement();18 converter.parseAttribute();19 converter.parseCombinators();20 converter.parseDisjunction();21 }22 converter.joinXPathParts();23 handleErrors(converter.css, previousCss);24 Converter.killInstance();25 return converter.xpathResult;26}27function handleErrors(css, previousCss) {28 const converter = Converter.getInstance();29 if (css === previousCss && !converter.xpathResult.error) converter.xpathResult.error = 'Invalid CSS selector.'; // True if css has something left not parsed30 if (converter.xpathResult.error) converter.xpathResult.xpath = '';...

Full Screen

Full Screen

styled.js

Source:styled.js Github

copy

Full Screen

...28 const [systemStyles, pseudoStyles, sxStyles] = extractStyles(mergedStyles);29 return Object.assign({},30 resolveStyledProps(systemStyles),31 mapToTheme(sxStyles, theme),32 mapToTheme(parsePseudo(pseudoStyles), theme),33 );34};35const extractStyles = (styles) => {36 const {sx: sxStyles = {}, ...restStyles} = styles;37 const systemStyles = {};38 const pseudoStyles = {};39 for (const key in restStyles) {40 if (!Object.prototype.hasOwnProperty.call(restStyles, key)) continue;41 if (PSEUDO_NAMES.includes(key)) pseudoStyles[key] = restStyles[key];42 else systemStyles[key] = restStyles[key];43 }44 return [45 systemStyles,46 pseudoStyles,...

Full Screen

Full Screen

parse-pseudo.js

Source:parse-pseudo.js Github

copy

Full Screen

...8 * Styles for CSS Selector `&:active`9 */10 _active: "&:active, &[data-active]",11};12export function parsePseudo(val) {13 return R.when(14 isObject,15 parse,16 )(val);17}18const defaultArrayWith = R.o(R.defaultTo([]));19const isObject = R.is(Object);20const toObject = R.curryN(2, R.converge)(R.zipObj);21const toTranspose = R.pipe(22 R.toPairs, // {a: 1, b: 2} -> [[a, 1], [b, 2]]23 R.transpose, // [[a, 1], [b, 2]] -> [[a, b], [1, 2]]24);25const transforKey = R.pipe(26 defaultArrayWith(R.head),...

Full Screen

Full Screen

parse-body.js

Source:parse-body.js Github

copy

Full Screen

...4 ['{{ticker}}', '{{> ticker start=start format=style.tickerFormat}}']5];6module.exports = parse;7function parse (body) {8 return parsePseudo(parseMd(body));9}10function parseMd (md) {11 const renderer = new marked.Renderer();12 renderer.heading = cleanHeading;13 return marked(md, {breaks: true, renderer});14 function cleanHeading (text, level) {15 return `<h${level}>${text}</h${level}>`;16 }17}18function parsePseudo (body) {19 return translations.reduce(translate, body);20 function translate (result, [pseudo, code]) {21 return result.replace(new RegExp(pseudo, 'g'), code);22 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const XCUITestDriver = require('appium-xcuitest-driver');2const XCUITestDriver = new XCUITestDriver();3const XCUITestDriver = require('appium-xcuitest-driver');4const XCUITestDriver = new XCUITestDriver();5const XCUITestDriver = require('appium-xcuitest-driver');6const XCUITestDriver = new XCUITestDriver();7const XCUITestDriver = require('appium-xcuitest-driver');8const XCUITestDriver = new XCUITestDriver();

Full Screen

Using AI Code Generation

copy

Full Screen

1var XCUITestDriver = require('appium-xcuitest-driver').XCUITestDriver;2var driver = new XCUITestDriver();3driver.parsePseudo('name == "button" && label == "button" && enabled == true && visible == true && rect.width == 100 && rect.height == 100 && rect.x == 100 && rect.y == 100');4var XCUITestDriver = require('appium-xcuitest-driver').XCUITestDriver;5var driver = new XCUITestDriver();6driver.parsePseudo('name == "button" && label == "button" && enabled == true && visible == true && rect.width == 100 && rect.height == 100 && rect.x == 100 && rect.y == 100');7var XCUITestDriver = require('appium-xcuitest-driver').XCUITestDriver;8var driver = new XCUITestDriver();9driver.parsePseudo('name == "button" && label == "button" && enabled == true && visible == true && rect.width == 100 && rect.height == 100 && rect.x == 100 && rect.y == 100');10var XCUITestDriver = require('appium-xcuitest-driver').XCUITestDriver;11var driver = new XCUITestDriver();12driver.parsePseudo('name == "button" && label == "button" && enabled == true && visible == true && rect.width == 100 && rect.height == 100 && rect.x == 100 && rect.y == 100');13var XCUITestDriver = require('appium-xcuitest-driver').XCUITestDriver;14var driver = new XCUITestDriver();15driver.parsePseudo('name == "button" && label == "button" && enabled == true && visible == true && rect.width == 100 && rect.height == 100 && rect.x == 100 && rect.y

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');2const { parsePseudo } = require('appium-xcuitest-driver');3const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');4const { parsePseudo } = require('appium-xcuitest-driver');5const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');6const { parsePseudo } = require('appium-xcuitest-driver');7const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');8const { parsePseudo } = require('appium-xcuitest-driver');9const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');10const { parsePseudo } = require('appium-xcuitest-driver');11const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');12const { parsePseudo } = require('appium-xcuitest-driver');13const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');14const { parsePseudo } = require('appium-xcuitest-driver');15const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');16const { parsePseudo } = require('appium-xcuitest-driver');17const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');18const { parsePseudo } = require('appium-xcuitest-driver');19const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');20const { parsePseudo } = require('appium-xcuitest-driver');21const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');22const { parsePseudo } = require('appium-xcuitest-driver');23const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');24const { parsePseudo } = require('appium-xcuitest-driver');25const { parsePseudo } = require('appium-xcuitest-driver/lib/commands/execute');26const { parsePseudo } = require

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parsePseudo } = require('appium-xcuitest-driver').utils;2const pseudo = parsePseudo('type == "XCUIElementTypeButton"');3console.log(pseudo);4const { parsePseudo } = require('appium-xcuitest-driver').utils;5const pseudo = parsePseudo('type == "XCUIElementTypeButton"');6console.log(pseudo);7const { parsePseudo } = require('appium-xcuitest-driver').utils;8const pseudo = parsePseudo('type == "XCUIElementTypeButton"');9console.log(pseudo);10const { parsePseudo } = require('appium-xcuitest-driver').utils;11const pseudo = parsePseudo('type == "XCUIElementTypeButton"');12console.log(pseudo);13const { parsePseudo } = require('appium-xcuitest-driver').utils;14const pseudo = parsePseudo('type == "XCUIElementTypeButton"');15console.log(pseudo);16const { parsePseudo } = require('appium-xcuitest-driver').utils;17const pseudo = parsePseudo('type == "XCUIElementTypeButton"');18console.log(pseudo);19const { parsePseudo } = require('appium-xcuitest-driver').utils;20const pseudo = parsePseudo('type == "XCUIElementTypeButton"');21console.log(pseudo);22const { parsePseudo } = require('appium-xcuitest-driver').utils;23const pseudo = parsePseudo('type == "XCUIElementTypeButton"');24console.log(pseudo);25const { parsePseudo } = require('appium-xcuitest-driver').utils;26const pseudo = parsePseudo('type == "XCUIElementTypeButton"');27console.log(pseudo);

Full Screen

Using AI Code Generation

copy

Full Screen

1const XCUITestDriver = require('appium-xcuitest-driver');2const driver = new XCUITestDriver();3driver.parsePseudo('label == "test"');4from appium.webdriver.appium_service import AppiumService5from appium import webdriver6from appium.webdriver.common.mobileby import MobileBy7from appium.webdriver.common.touch_action import TouchAction8from appium.webdriver.common.multi_action import MultiAction9from selenium.webdriver.support.ui import WebDriverWait10from selenium.webdriver.support import expected_conditions as EC11from selenium.webdriver.common.by import By12from selenium.webdriver.common.keys import Keys13from selenium.webdriver.common.touch_actions import TouchActions14from selenium.webdriver.common.action_chains import ActionChains15from selenium.webdriver import DesiredCapabilities16from selenium.webdriver.support.ui import Select17from selenium.common.exceptions import NoSuchElementException18from selenium.common.exceptions import ElementNotVisibleException19from selenium.common.exceptions import ElementNotSelectableException20from selenium.common.exceptions import NoAlertPresentException21from selenium.common.exceptions import TimeoutException22from selenium.common.exceptions import StaleElementReferenceException23from selenium.common.exceptions import WebDriverException24from selenium.common.exceptions import InvalidElementStateException25from selenium.common.exceptions import InvalidSelectorException26from selenium.common.exceptions import InvalidSessionIdException27from selenium.common.exceptions import InvalidArgumentException28from selenium.common.exceptions import NoSuchAttributeException29from selenium.common.exceptions import MoveTargetOutOfBoundsException30from selenium.common.exceptions import ImeNotAvailableException31from selenium.common.exceptions import ImeActivationFailedException32from selenium.common.exceptions import JavaScriptException33from selenium.common.exceptions import NoSuchWindowException34from selenium.common.exceptions import NoSuchFrameException35from selenium.common.exceptions import NoSuchCookieException36from selenium.common.exceptions import UnexpectedAlertPresentException37from selenium.common.exceptions import ElementClickInterceptedException38from selenium.common.exceptions import ElementNotInteractableException39from selenium.common.exceptions import InvalidCookieDomainException40from selenium.common.exceptions import UnableToSetCookieException41from selenium.common.exceptions import UnexpectedTagNameException42from selenium.common.exceptions import NoSuchContextException43from selenium.common.exceptions import InvalidContextException44from selenium.common.exceptions import TimeoutException45from selenium.common.exceptions import ElementNotSelectableException46from selenium.common.exceptions import NoSuchAlertException47from selenium.common.exceptions import NoSuchFrameException48from selenium.common.exceptions import NoSuchWindowException49from selenium.common.exceptions import NoSuchAttributeException50from selenium.common.exceptions import NoSuchCookie

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parsePseudo } = require('./lib/commands/element.js');2const pseudo = parsePseudo('label == "foo"');3const { parsePseudo } = require('./lib/commands/element.js');4const pseudo = parsePseudo('label == "foo"');5const { parsePseudo } = require('./lib/commands/element.js');6const pseudo = parsePseudo('label == "foo"');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parsePseudo } = require(‘appium-xcuitest-driver/lib/commands/element’);2const pseudo = ‘:has(.XCUIElementTypeStaticText)’;3const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton))’;4const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeTextField)))’;5const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeTextField:has(.XCUIElementTypeStaticText))))’;6const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeTextField:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton)))))’;7const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeTextField:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeStaticText)))))))’;8const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeTextField:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton))))))))’;9const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeTextField:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeStaticText)))))))))’;10const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeTextField:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton:has(.XCUIElementTypeStaticText:has(.XCUIElementTypeButton))))))))))’;11const pseudo = ‘:has(.XCUIElementTypeStaticText:has(.XCUIElementType

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 Appium Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful