How to use DimensionToken method in Playwright Internal

Best JavaScript code snippet using playwright-internal

ios.js

Source:ios.js Github

copy

Full Screen

...457 case "number":458 create(new NumberToken()), 45 == code ? digit(next()) ? consume() && currtoken.append([ 45, code ]) && switchto("number-rest") : 46 == next(1) && digit(next(2)) ? consume(2) && currtoken.append([ 45, 46, code ]) && switchto("number-fraction") : switchto("data") && reconsume() : 43 == code ? digit(next()) ? consume() && currtoken.append([ 43, code ]) && switchto("number-rest") : 46 == next(1) && digit(next(2)) ? consume(2) && currtoken.append([ 43, 46, code ]) && switchto("number-fraction") : switchto("data") && reconsume() : digit(code) ? currtoken.append(code) && switchto("number-rest") : 46 == code && digit(next()) ? consume() && currtoken.append([ 46, code ]) && switchto("number-fraction") : switchto("data") && reconsume();459 break;460 case "number-rest":461 digit(code) ? currtoken.append(code) : 46 == code ? digit(next()) ? consume() && currtoken.append([ 46, code ]) && switchto("number-fraction") : emit() && switchto("data") && reconsume() : 37 == code ? emit(new PercentageToken(currtoken)) && switchto("data") : 69 == code || 101 == code ? digit(next()) ? consume() && currtoken.append([ 37, code ]) && switchto("sci-notation") : 43 != next(1) && 45 != next(1) || !digit(next(2)) ? create(new DimensionToken(currtoken, code)) && switchto("dimension") : currtoken.append([ 37, next(1), next(2) ]) && consume(2) && switchto("sci-notation") : 45 == code ? namestartchar(next()) ? consume() && create(new DimensionToken(currtoken, [ 45, code ])) && switchto("dimension") : 92 == next(1) && badescape(next(2)) ? parseerror() && emit() && switchto("data") && reconsume() : 92 == next(1) ? consume() && create(new DimensionToken(currtoken, [ 45, consumeEscape() ])) && switchto("dimension") : emit() && switchto("data") && reconsume() : namestartchar(code) ? create(new DimensionToken(currtoken, code)) && switchto("dimension") : 92 == code ? badescape(next) ? parseerror() && emit() && switchto("data") && reconsume() : create(new DimensionToken(currtoken, consumeEscape)) && switchto("dimension") : emit() && switchto("data") && reconsume();462 break;463 case "number-fraction":464 currtoken.type = "number", digit(code) ? currtoken.append(code) : 37 == code ? emit(new PercentageToken(currtoken)) && switchto("data") : 69 == code || 101 == code ? digit(next()) ? consume() && currtoken.append([ 101, code ]) && switchto("sci-notation") : 43 != next(1) && 45 != next(1) || !digit(next(2)) ? create(new DimensionToken(currtoken, code)) && switchto("dimension") : currtoken.append([ 101, next(1), next(2) ]) && consume(2) && switchto("sci-notation") : 45 == code ? namestartchar(next()) ? consume() && create(new DimensionToken(currtoken, [ 45, code ])) && switchto("dimension") : 92 == next(1) && badescape(next(2)) ? parseerror() && emit() && switchto("data") && reconsume() : 92 == next(1) ? consume() && create(new DimensionToken(currtoken, [ 45, consumeEscape() ])) && switchto("dimension") : emit() && switchto("data") && reconsume() : namestartchar(code) ? create(new DimensionToken(currtoken, code)) && switchto("dimension") : 92 == code ? badescape(next) ? parseerror() && emit() && switchto("data") && reconsume() : create(new DimensionToken(currtoken, consumeEscape())) && switchto("dimension") : emit() && switchto("data") && reconsume();465 break;466 case "dimension":467 namechar(code) ? currtoken.append(code) : 92 == code ? badescape(next()) ? parseerror() && emit() && switchto("data") && reconsume() : currtoken.append(consumeEscape()) : emit() && switchto("data") && reconsume();468 break;469 case "sci-notation":470 currtoken.type = "number", digit(code) ? currtoken.append(code) : emit() && switchto("data") && reconsume();471 break;472 case "url":473 eof() ? parseerror() && emit(new BadURLToken()) && switchto("data") : 34 == code ? switchto("url-double-quote") : 39 == code ? switchto("url-single-quote") : 41 == code ? emit(new URLToken()) && switchto("data") : whitespace(code) ? donothing() : switchto("url-unquoted") && reconsume();474 break;475 case "url-double-quote":476 currtoken instanceof URLToken || create(new URLToken()), eof() ? parseerror() && emit(new BadURLToken()) && switchto("data") : 34 == code ? switchto("url-end") : newline(code) ? parseerror() && switchto("bad-url") : 92 == code ? newline(next()) ? consume() : badescape(next()) ? parseerror() && emit(new BadURLToken()) && switchto("data") && reconsume() : currtoken.append(consumeEscape()) : currtoken.append(code);477 break;478 case "url-single-quote":479 currtoken instanceof URLToken || create(new URLToken()), eof() ? parseerror() && emit(new BadURLToken()) && switchto("data") : 39 == code ? switchto("url-end") : newline(code) ? parseerror() && switchto("bad-url") : 92 == code ? newline(next()) ? consume() : badescape(next()) ? parseerror() && emit(new BadURLToken()) && switchto("data") && reconsume() : currtoken.append(consumeEscape()) : currtoken.append(code);480 break;481 case "url-end":482 eof() ? parseerror() && emit(new BadURLToken()) && switchto("data") : whitespace(code) ? donothing() : 41 == code ? emit() && switchto("data") : parseerror() && switchto("bad-url") && reconsume();483 break;484 case "url-unquoted":485 currtoken instanceof URLToken || create(new URLToken()), eof() ? parseerror() && emit(new BadURLToken()) && switchto("data") : whitespace(code) ? switchto("url-end") : 41 == code ? emit() && switchto("data") : 34 == code || 39 == code || 40 == code || nonprintable(code) ? parseerror() && switchto("bad-url") : 92 == code ? badescape(next()) ? parseerror() && switchto("bad-url") : currtoken.append(consumeEscape()) : currtoken.append(code);486 break;487 case "bad-url":488 eof() ? parseerror() && emit(new BadURLToken()) && switchto("data") : 41 == code ? emit(new BadURLToken()) && switchto("data") : 92 == code ? badescape(next()) ? donothing() : consumeEscape() : donothing();489 break;490 case "unicode-range":491 for (var start = [ code ], end = [ code ], total = 1; 6 > total && hexdigit(next()); total++) consume(), 492 start.push(code), end.push(code);493 if (63 == next()) {494 for (;6 > total && 63 == next(); total++) consume(), start.push("0".charCodeAt(0)), 495 end.push("f".charCodeAt(0));496 emit(new UnicodeRangeToken(start, end)) && switchto("data");497 } else if (45 == next(1) && hexdigit(next(2))) {498 consume(), consume(), end = [ code ];499 for (var total = 1; 6 > total && hexdigit(next()); total++) consume(), end.push(code);500 emit(new UnicodeRangeToken(start, end)) && switchto("data");501 } else emit(new UnicodeRangeToken(start)) && switchto("data");502 break;503 default:504 catchfire("Unknown state '" + state + "'");505 }506 }507 }508 function stringFromCodeArray(arr) {509 return String.fromCharCode.apply(null, arr.filter(function(e) {510 return e;511 }));512 }513 function CSSParserToken() {514 return this;515 }516 function BadStringToken() {517 return this;518 }519 function BadURLToken() {520 return this;521 }522 function WhitespaceToken() {523 return this;524 }525 function CDOToken() {526 return this;527 }528 function CDCToken() {529 return this;530 }531 function ColonToken() {532 return this;533 }534 function SemicolonToken() {535 return this;536 }537 function OpenCurlyToken() {538 return this;539 }540 function CloseCurlyToken() {541 return this;542 }543 function OpenSquareToken() {544 return this;545 }546 function CloseSquareToken() {547 return this;548 }549 function OpenParenToken() {550 return this;551 }552 function CloseParenToken() {553 return this;554 }555 function EOFToken() {556 return this;557 }558 function DelimToken(code) {559 return this.value = String.fromCharCode(code), this;560 }561 function StringValuedToken() {562 return this;563 }564 function IdentifierToken(val) {565 this.value = [], this.append(val);566 }567 function FunctionToken(val) {568 this.value = val.finish().value;569 }570 function AtKeywordToken(val) {571 this.value = [], this.append(val);572 }573 function HashToken(val) {574 this.value = [], this.append(val);575 }576 function StringToken(val) {577 this.value = [], this.append(val);578 }579 function URLToken(val) {580 this.value = [], this.append(val);581 }582 function NumberToken(val) {583 this.value = [], this.append(val), this.type = "integer";584 }585 function PercentageToken(val) {586 val.finish(), this.value = val.value, this.repr = val.repr;587 }588 function DimensionToken(val, unit) {589 val.finish(), this.num = val.value, this.unit = [], this.repr = val.repr, this.append(unit);590 }591 function UnicodeRangeToken(start, end) {592 return start = parseInt(stringFromCodeArray(start), 16), end = void 0 === end ? start + 1 : parseInt(stringFromCodeArray(end), 16), 593 start > maximumallowedcodepoint && (end = start), start > end && (end = start), 594 end > maximumallowedcodepoint && (end = maximumallowedcodepoint), this.start = start, 595 this.end = end, this;596 }597 var between = function(num, first, last) {598 return num >= first && last >= num;599 }, maximumallowedcodepoint = 1114111;600 CSSParserToken.prototype.finish = function() {601 return this;602 }, CSSParserToken.prototype.toString = function() {...

Full Screen

Full Screen

CSSTokenizerTests.js

Source:CSSTokenizerTests.js Github

copy

Full Screen

1// Copyright 2020 Breakside Inc.2//3// Licensed under the Breakside Public License, Version 1.0 (the "License");4// you may not use this file except in compliance with the License.5// If a copy of the License was not distributed with this file, you may6// obtain a copy at7//8// http://breakside.io/licenses/LICENSE-1.0.txt9//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS,12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13// See the License for the specific language governing permissions and14// limitations under the License.15// #import CSSOM16// #import TestKit17"use strict";18JSClass("CSSTokenizerTests", TKTestSuite, {19 testIdentifier: function(){20 var css = "test";21 var tokenizer = CSSTokenizer.init();22 var tokens = tokenizer.tokenize(css);23 TKAssertEquals(tokens.length, 1);24 TKAssertInstance(tokens[0], CSSTokenizer.IdentifierToken);25 TKAssertEquals(tokens[0].name, "test");26 css = "test Test _test -test --test";27 tokenizer = CSSTokenizer.init();28 tokens = tokenizer.tokenize(css);29 TKAssertEquals(tokens.length, 9);30 TKAssertInstance(tokens[0], CSSTokenizer.IdentifierToken);31 TKAssertInstance(tokens[1], CSSTokenizer.WhitespaceToken);32 TKAssertInstance(tokens[2], CSSTokenizer.IdentifierToken);33 TKAssertInstance(tokens[3], CSSTokenizer.WhitespaceToken);34 TKAssertInstance(tokens[4], CSSTokenizer.IdentifierToken);35 TKAssertInstance(tokens[5], CSSTokenizer.WhitespaceToken);36 TKAssertInstance(tokens[6], CSSTokenizer.IdentifierToken);37 TKAssertInstance(tokens[7], CSSTokenizer.WhitespaceToken);38 TKAssertInstance(tokens[8], CSSTokenizer.IdentifierToken);39 TKAssertEquals(tokens[0].name, "test");40 TKAssertEquals(tokens[2].name, "Test");41 TKAssertEquals(tokens[4].name, "_test");42 TKAssertEquals(tokens[6].name, "-test");43 TKAssertEquals(tokens[8].name, "--test");44 TKAssertEquals(tokens[0].toString(), "test");45 TKAssertEquals(tokens[2].toString(), "Test");46 TKAssertEquals(tokens[8].toString(), "--test");47 },48 testWhitespace: function(){49 var css = "\n\n\ttest \t \r\nTest\r_test \f \f\t \n";50 var tokenizer = CSSTokenizer.init();51 var tokens = tokenizer.tokenize(css);52 TKAssertEquals(tokens.length, 7);53 TKAssertInstance(tokens[0], CSSTokenizer.WhitespaceToken);54 TKAssertInstance(tokens[1], CSSTokenizer.IdentifierToken);55 TKAssertInstance(tokens[2], CSSTokenizer.WhitespaceToken);56 TKAssertInstance(tokens[3], CSSTokenizer.IdentifierToken);57 TKAssertInstance(tokens[4], CSSTokenizer.WhitespaceToken);58 TKAssertInstance(tokens[5], CSSTokenizer.IdentifierToken);59 TKAssertInstance(tokens[6], CSSTokenizer.WhitespaceToken);60 TKAssertEquals(tokens[1].name, "test");61 TKAssertEquals(tokens[3].name, "Test");62 TKAssertEquals(tokens[5].name, "_test");63 TKAssertEquals(tokens[0].whitespace, "\n\n\t");64 TKAssertEquals(tokens[2].whitespace, " \t \r\n");65 TKAssertEquals(tokens[4].whitespace, "\r");66 TKAssertEquals(tokens[6].whitespace, " \f \f\t \n");67 TKAssertEquals(tokens[0].toString(), "\n\n\t");68 TKAssertEquals(tokens[2].toString(), " \t \r\n");69 TKAssertEquals(tokens[6].toString(), " \f \f\t \n");70 },71 testComment: function(){72 var css = "/*\n this is a comment\n two lines\n*/\n/**/Test/*comment*/_test/* comment */";73 var tokenizer = CSSTokenizer.init();74 var tokens = tokenizer.tokenize(css);75 TKAssertEquals(tokens.length, 7);76 TKAssertInstance(tokens[0], CSSTokenizer.CommentToken);77 TKAssertInstance(tokens[1], CSSTokenizer.WhitespaceToken);78 TKAssertInstance(tokens[2], CSSTokenizer.CommentToken);79 TKAssertInstance(tokens[3], CSSTokenizer.IdentifierToken);80 TKAssertInstance(tokens[4], CSSTokenizer.CommentToken);81 TKAssertInstance(tokens[5], CSSTokenizer.IdentifierToken);82 TKAssertInstance(tokens[6], CSSTokenizer.CommentToken);83 TKAssertEquals(tokens[3].name, "Test");84 TKAssertEquals(tokens[5].name, "_test");85 TKAssertEquals(tokens[1].whitespace, "\n");86 TKAssertEquals(tokens[0].text, "\n this is a comment\n two lines\n");87 TKAssertEquals(tokens[2].text, "");88 TKAssertEquals(tokens[4].text, "comment");89 TKAssertEquals(tokens[6].text, " comment ");90 TKAssertEquals(tokens[0].toString(), "/*\n this is a comment\n two lines\n*/");91 TKAssertEquals(tokens[2].toString(), "/**/");92 TKAssertEquals(tokens[4].toString(), "/*comment*/");93 TKAssertEquals(tokens[6].toString(), "/* comment */");94 },95 testString: function(){96 var css = "'test' 'tes\\'t' \"Test\" \"Tes\\\"t\" 'te\\\nst'";97 var tokenizer = CSSTokenizer.init();98 var tokens = tokenizer.tokenize(css);99 TKAssertEquals(tokens.length, 9);100 TKAssertInstance(tokens[0], CSSTokenizer.StringToken);101 TKAssertInstance(tokens[1], CSSTokenizer.WhitespaceToken);102 TKAssertInstance(tokens[2], CSSTokenizer.StringToken);103 TKAssertInstance(tokens[3], CSSTokenizer.WhitespaceToken);104 TKAssertInstance(tokens[4], CSSTokenizer.StringToken);105 TKAssertInstance(tokens[5], CSSTokenizer.WhitespaceToken);106 TKAssertInstance(tokens[6], CSSTokenizer.StringToken);107 TKAssertInstance(tokens[7], CSSTokenizer.WhitespaceToken);108 TKAssertInstance(tokens[8], CSSTokenizer.StringToken);109 TKAssertEquals(tokens[0].quote, "'");110 TKAssertEquals(tokens[0].value, "test");111 TKAssertEquals(tokens[2].quote, "'");112 TKAssertEquals(tokens[2].value, "tes't");113 TKAssertEquals(tokens[4].quote, '"');114 TKAssertEquals(tokens[4].value, 'Test');115 TKAssertEquals(tokens[6].quote, '"');116 TKAssertEquals(tokens[6].value, 'Tes"t');117 TKAssertEquals(tokens[8].quote, "'");118 TKAssertEquals(tokens[8].value, "test");119 TKAssertEquals(tokens[0].toString(), "'test'");120 TKAssertEquals(tokens[2].toString(), "'tes\\'t'");121 TKAssertEquals(tokens[4].toString(), '"Test"');122 TKAssertEquals(tokens[6].toString(), '"Tes\\"t"');123 TKAssertEquals(tokens[0].toString(), "'test'");124 },125 testNumbers: function(){126 var css = "1,12,123,1.23,.123,1e23";127 var tokenizer = CSSTokenizer.init();128 var tokens = tokenizer.tokenize(css);129 TKAssertEquals(tokens.length, 11);130 TKAssertInstance(tokens[0], CSSTokenizer.NumberToken);131 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);132 TKAssertInstance(tokens[2], CSSTokenizer.NumberToken);133 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);134 TKAssertInstance(tokens[4], CSSTokenizer.NumberToken);135 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);136 TKAssertInstance(tokens[6], CSSTokenizer.NumberToken);137 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);138 TKAssertInstance(tokens[8], CSSTokenizer.NumberToken);139 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);140 TKAssertInstance(tokens[10], CSSTokenizer.NumberToken);141 TKAssertExactEquals(tokens[0].value, 1);142 TKAssertExactEquals(tokens[2].value, 12);143 TKAssertExactEquals(tokens[4].value, 123);144 TKAssertFloatEquals(tokens[6].value, 1.23);145 TKAssertFloatEquals(tokens[8].value, 0.123);146 TKAssertFloatEquals(tokens[10].value, 1e23);147 TKAssertEquals(tokens[0].toString(), "1");148 TKAssertEquals(tokens[2].toString(), "12");149 TKAssertEquals(tokens[4].toString(), "123");150 TKAssertEquals(tokens[6].toString(), "1.23");151 TKAssertEquals(tokens[8].toString(), "0.123"); // rewritten with leading 0152 TKAssertEquals(tokens[10].toString(), "1e+23"); // rewritten with + exponent153 css = "+1,+12,+123,+1.23,+.123,+1e23";154 tokenizer = CSSTokenizer.init();155 tokens = tokenizer.tokenize(css);156 TKAssertEquals(tokens.length, 11);157 TKAssertInstance(tokens[0], CSSTokenizer.NumberToken);158 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);159 TKAssertInstance(tokens[2], CSSTokenizer.NumberToken);160 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);161 TKAssertInstance(tokens[4], CSSTokenizer.NumberToken);162 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);163 TKAssertInstance(tokens[6], CSSTokenizer.NumberToken);164 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);165 TKAssertInstance(tokens[8], CSSTokenizer.NumberToken);166 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);167 TKAssertInstance(tokens[10], CSSTokenizer.NumberToken);168 TKAssertExactEquals(tokens[0].value, 1);169 TKAssertExactEquals(tokens[2].value, 12);170 TKAssertExactEquals(tokens[4].value, 123);171 TKAssertFloatEquals(tokens[6].value, 1.23);172 TKAssertFloatEquals(tokens[8].value, 0.123);173 TKAssertFloatEquals(tokens[10].value, 1e23);174 // all rewritten without leading plus175 TKAssertEquals(tokens[0].toString(), "1");176 TKAssertEquals(tokens[2].toString(), "12");177 TKAssertEquals(tokens[4].toString(), "123");178 TKAssertEquals(tokens[6].toString(), "1.23");179 TKAssertEquals(tokens[8].toString(), "0.123"); // rewritten with leading 0180 TKAssertEquals(tokens[10].toString(), "1e+23"); // rewritten with + exponent181 css = "-1,-12,-123,-1.23,-.123,-1e23";182 tokenizer = CSSTokenizer.init();183 tokens = tokenizer.tokenize(css);184 TKAssertEquals(tokens.length, 11);185 TKAssertInstance(tokens[0], CSSTokenizer.NumberToken);186 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);187 TKAssertInstance(tokens[2], CSSTokenizer.NumberToken);188 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);189 TKAssertInstance(tokens[4], CSSTokenizer.NumberToken);190 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);191 TKAssertInstance(tokens[6], CSSTokenizer.NumberToken);192 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);193 TKAssertInstance(tokens[8], CSSTokenizer.NumberToken);194 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);195 TKAssertInstance(tokens[10], CSSTokenizer.NumberToken);196 TKAssertExactEquals(tokens[0].value, -1);197 TKAssertExactEquals(tokens[2].value, -12);198 TKAssertExactEquals(tokens[4].value, -123);199 TKAssertFloatEquals(tokens[6].value, -1.23);200 TKAssertFloatEquals(tokens[8].value, -0.123);201 TKAssertFloatEquals(tokens[10].value, -1e23);202 TKAssertEquals(tokens[0].toString(), "-1");203 TKAssertEquals(tokens[2].toString(), "-12");204 TKAssertEquals(tokens[4].toString(), "-123");205 TKAssertEquals(tokens[6].toString(), "-1.23");206 TKAssertEquals(tokens[8].toString(), "-0.123"); // rewritten with leading 0207 TKAssertEquals(tokens[10].toString(), "-1e+23"); // rewritten with + exponent208 },209 testDimensions: function(){210 var css = "1px,12em,123abc,1.23test,.123_abc,1e23ABC";211 var tokenizer = CSSTokenizer.init();212 var tokens = tokenizer.tokenize(css);213 TKAssertEquals(tokens.length, 11);214 TKAssertInstance(tokens[0], CSSTokenizer.DimensionToken);215 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);216 TKAssertInstance(tokens[2], CSSTokenizer.DimensionToken);217 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);218 TKAssertInstance(tokens[4], CSSTokenizer.DimensionToken);219 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);220 TKAssertInstance(tokens[6], CSSTokenizer.DimensionToken);221 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);222 TKAssertInstance(tokens[8], CSSTokenizer.DimensionToken);223 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);224 TKAssertInstance(tokens[10], CSSTokenizer.DimensionToken);225 TKAssertExactEquals(tokens[0].value, 1);226 TKAssertExactEquals(tokens[2].value, 12);227 TKAssertExactEquals(tokens[4].value, 123);228 TKAssertFloatEquals(tokens[6].value, 1.23);229 TKAssertFloatEquals(tokens[8].value, 0.123);230 TKAssertFloatEquals(tokens[10].value, 1e23);231 TKAssertEquals(tokens[0].units, "px");232 TKAssertEquals(tokens[2].units, "em");233 TKAssertEquals(tokens[4].units, "abc");234 TKAssertEquals(tokens[6].units, "test");235 TKAssertEquals(tokens[8].units, "_abc");236 TKAssertEquals(tokens[10].units, "ABC");237 TKAssertEquals(tokens[0].toString(), "1px");238 TKAssertEquals(tokens[2].toString(), "12em");239 TKAssertEquals(tokens[4].toString(), "123abc");240 TKAssertEquals(tokens[6].toString(), "1.23test");241 TKAssertEquals(tokens[8].toString(), "0.123_abc"); // rewritten with leading 0242 TKAssertEquals(tokens[10].toString(), "1e+23ABC"); // rewritten with + exponent243 css = "+1px,+12em,+123abc,+1.23test,+.123_abc,+1e23ABC";244 tokenizer = CSSTokenizer.init();245 tokens = tokenizer.tokenize(css);246 TKAssertEquals(tokens.length, 11);247 TKAssertInstance(tokens[0], CSSTokenizer.DimensionToken);248 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);249 TKAssertInstance(tokens[2], CSSTokenizer.DimensionToken);250 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);251 TKAssertInstance(tokens[4], CSSTokenizer.DimensionToken);252 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);253 TKAssertInstance(tokens[6], CSSTokenizer.DimensionToken);254 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);255 TKAssertInstance(tokens[8], CSSTokenizer.DimensionToken);256 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);257 TKAssertInstance(tokens[10], CSSTokenizer.DimensionToken);258 TKAssertExactEquals(tokens[0].value, 1);259 TKAssertExactEquals(tokens[2].value, 12);260 TKAssertExactEquals(tokens[4].value, 123);261 TKAssertFloatEquals(tokens[6].value, 1.23);262 TKAssertFloatEquals(tokens[8].value, 0.123);263 TKAssertFloatEquals(tokens[10].value, 1e23);264 TKAssertEquals(tokens[0].units, "px");265 TKAssertEquals(tokens[2].units, "em");266 TKAssertEquals(tokens[4].units, "abc");267 TKAssertEquals(tokens[6].units, "test");268 TKAssertEquals(tokens[8].units, "_abc");269 TKAssertEquals(tokens[10].units, "ABC");270 // all rewritten without leading plus271 TKAssertEquals(tokens[0].toString(), "1px");272 TKAssertEquals(tokens[2].toString(), "12em");273 TKAssertEquals(tokens[4].toString(), "123abc");274 TKAssertEquals(tokens[6].toString(), "1.23test");275 TKAssertEquals(tokens[8].toString(), "0.123_abc"); // rewritten with leading 0276 TKAssertEquals(tokens[10].toString(), "1e+23ABC"); // rewritten with + exponent277 css = "-1px,-12em,-123abc,-1.23test,-.123_abc,-1e23ABC";278 tokenizer = CSSTokenizer.init();279 tokens = tokenizer.tokenize(css);280 TKAssertEquals(tokens.length, 11);281 TKAssertInstance(tokens[0], CSSTokenizer.DimensionToken);282 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);283 TKAssertInstance(tokens[2], CSSTokenizer.DimensionToken);284 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);285 TKAssertInstance(tokens[4], CSSTokenizer.DimensionToken);286 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);287 TKAssertInstance(tokens[6], CSSTokenizer.DimensionToken);288 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);289 TKAssertInstance(tokens[8], CSSTokenizer.DimensionToken);290 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);291 TKAssertInstance(tokens[10], CSSTokenizer.DimensionToken);292 TKAssertExactEquals(tokens[0].value, -1);293 TKAssertExactEquals(tokens[2].value, -12);294 TKAssertExactEquals(tokens[4].value, -123);295 TKAssertFloatEquals(tokens[6].value, -1.23);296 TKAssertFloatEquals(tokens[8].value, -0.123);297 TKAssertFloatEquals(tokens[10].value, -1e23);298 TKAssertEquals(tokens[0].units, "px");299 TKAssertEquals(tokens[2].units, "em");300 TKAssertEquals(tokens[4].units, "abc");301 TKAssertEquals(tokens[6].units, "test");302 TKAssertEquals(tokens[8].units, "_abc");303 TKAssertEquals(tokens[10].units, "ABC");304 TKAssertEquals(tokens[0].toString(), "-1px");305 TKAssertEquals(tokens[2].toString(), "-12em");306 TKAssertEquals(tokens[4].toString(), "-123abc");307 TKAssertEquals(tokens[6].toString(), "-1.23test");308 TKAssertEquals(tokens[8].toString(), "-0.123_abc"); // rewritten with leading 0309 TKAssertEquals(tokens[10].toString(), "-1e+23ABC"); // rewritten with + exponent310 },311 testPercentages: function(){312 var css = "1%,12%,123%,1.23%,.123%,1e23%";313 var tokenizer = CSSTokenizer.init();314 var tokens = tokenizer.tokenize(css);315 TKAssertEquals(tokens.length, 11);316 TKAssertInstance(tokens[0], CSSTokenizer.PercentageToken);317 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);318 TKAssertInstance(tokens[2], CSSTokenizer.PercentageToken);319 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);320 TKAssertInstance(tokens[4], CSSTokenizer.PercentageToken);321 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);322 TKAssertInstance(tokens[6], CSSTokenizer.PercentageToken);323 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);324 TKAssertInstance(tokens[8], CSSTokenizer.PercentageToken);325 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);326 TKAssertInstance(tokens[10], CSSTokenizer.PercentageToken);327 TKAssertExactEquals(tokens[0].value, 1);328 TKAssertExactEquals(tokens[2].value, 12);329 TKAssertExactEquals(tokens[4].value, 123);330 TKAssertFloatEquals(tokens[6].value, 1.23);331 TKAssertFloatEquals(tokens[8].value, 0.123);332 TKAssertFloatEquals(tokens[10].value, 1e23);333 TKAssertEquals(tokens[0].toString(), "1%");334 TKAssertEquals(tokens[2].toString(), "12%");335 TKAssertEquals(tokens[4].toString(), "123%");336 TKAssertEquals(tokens[6].toString(), "1.23%");337 TKAssertEquals(tokens[8].toString(), "0.123%"); // rewritten with leading 0338 TKAssertEquals(tokens[10].toString(), "1e+23%"); // rewritten with + exponent339 css = "+1%,+12%,+123%,+1.23%,+.123%,+1e23%";340 tokenizer = CSSTokenizer.init();341 tokens = tokenizer.tokenize(css);342 TKAssertEquals(tokens.length, 11);343 TKAssertInstance(tokens[0], CSSTokenizer.PercentageToken);344 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);345 TKAssertInstance(tokens[2], CSSTokenizer.PercentageToken);346 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);347 TKAssertInstance(tokens[4], CSSTokenizer.PercentageToken);348 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);349 TKAssertInstance(tokens[6], CSSTokenizer.PercentageToken);350 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);351 TKAssertInstance(tokens[8], CSSTokenizer.PercentageToken);352 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);353 TKAssertInstance(tokens[10], CSSTokenizer.PercentageToken);354 TKAssertExactEquals(tokens[0].value, 1);355 TKAssertExactEquals(tokens[2].value, 12);356 TKAssertExactEquals(tokens[4].value, 123);357 TKAssertFloatEquals(tokens[6].value, 1.23);358 TKAssertFloatEquals(tokens[8].value, 0.123);359 TKAssertFloatEquals(tokens[10].value, 1e23);360 // all rewritten without leading plus361 TKAssertEquals(tokens[0].toString(), "1%");362 TKAssertEquals(tokens[2].toString(), "12%");363 TKAssertEquals(tokens[4].toString(), "123%");364 TKAssertEquals(tokens[6].toString(), "1.23%");365 TKAssertEquals(tokens[8].toString(), "0.123%"); // rewritten with leading 0366 TKAssertEquals(tokens[10].toString(), "1e+23%"); // rewritten with + exponent367 css = "-1%,-12%,-123%,-1.23%,-.123%,-1e23%";368 tokenizer = CSSTokenizer.init();369 tokens = tokenizer.tokenize(css);370 TKAssertEquals(tokens.length, 11);371 TKAssertInstance(tokens[0], CSSTokenizer.PercentageToken);372 TKAssertInstance(tokens[1], CSSTokenizer.CommaToken);373 TKAssertInstance(tokens[2], CSSTokenizer.PercentageToken);374 TKAssertInstance(tokens[3], CSSTokenizer.CommaToken);375 TKAssertInstance(tokens[4], CSSTokenizer.PercentageToken);376 TKAssertInstance(tokens[5], CSSTokenizer.CommaToken);377 TKAssertInstance(tokens[6], CSSTokenizer.PercentageToken);378 TKAssertInstance(tokens[7], CSSTokenizer.CommaToken);379 TKAssertInstance(tokens[8], CSSTokenizer.PercentageToken);380 TKAssertInstance(tokens[9], CSSTokenizer.CommaToken);381 TKAssertInstance(tokens[10], CSSTokenizer.PercentageToken);382 TKAssertExactEquals(tokens[0].value, -1);383 TKAssertExactEquals(tokens[2].value, -12);384 TKAssertExactEquals(tokens[4].value, -123);385 TKAssertFloatEquals(tokens[6].value, -1.23);386 TKAssertFloatEquals(tokens[8].value, -0.123);387 TKAssertFloatEquals(tokens[10].value, -1e23);388 TKAssertEquals(tokens[0].toString(), "-1%");389 TKAssertEquals(tokens[2].toString(), "-12%");390 TKAssertEquals(tokens[4].toString(), "-123%");391 TKAssertEquals(tokens[6].toString(), "-1.23%");392 TKAssertEquals(tokens[8].toString(), "-0.123%"); // rewritten with leading 0393 TKAssertEquals(tokens[10].toString(), "-1e+23%"); // rewritten with + exponent394 },395 testHash: function(){396 var css = "#";397 var tokenizer = CSSTokenizer.init();398 var tokens = tokenizer.tokenize(css);399 TKAssertEquals(tokens.length, 1);400 TKAssertInstance(tokens[0], CSSTokenizer.DelimToken);401 TKAssertEquals(tokens[0].char, "#");402 TKAssertEquals(tokens[0].toString(), "#");403 css = "#test";404 tokenizer = CSSTokenizer.init();405 tokens = tokenizer.tokenize(css);406 TKAssertEquals(tokens.length, 1);407 TKAssertInstance(tokens[0], CSSTokenizer.HashToken);408 TKAssertEquals(tokens[0].name, "test");409 TKAssertEquals(tokens[0].type, "id");410 TKAssertEquals(tokens[0].toString(), "#test");411 css = "#9test";412 tokenizer = CSSTokenizer.init();413 tokens = tokenizer.tokenize(css);414 TKAssertEquals(tokens.length, 1);415 TKAssertInstance(tokens[0], CSSTokenizer.HashToken);416 TKAssertEquals(tokens[0].name, "9test");417 TKAssertNull(tokens[0].type);418 TKAssertEquals(tokens[0].toString(), "#9test");419 },420 testAt: function(){421 var css = "@";422 var tokenizer = CSSTokenizer.init();423 var tokens = tokenizer.tokenize(css);424 TKAssertEquals(tokens.length, 1);425 TKAssertInstance(tokens[0], CSSTokenizer.DelimToken);426 TKAssertEquals(tokens[0].char, "@");427 TKAssertEquals(tokens[0].toString(), "@");428 css = "@test";429 tokenizer = CSSTokenizer.init();430 tokens = tokenizer.tokenize(css);431 TKAssertEquals(tokens.length, 1);432 TKAssertInstance(tokens[0], CSSTokenizer.AtKeywordToken);433 TKAssertEquals(tokens[0].name, "test");434 TKAssertEquals(tokens[0].toString(), "@test");435 css = "@9test";436 tokenizer = CSSTokenizer.init();437 tokens = tokenizer.tokenize(css);438 TKAssertEquals(tokens.length, 2);439 TKAssertInstance(tokens[0], CSSTokenizer.DelimToken);440 TKAssertEquals(tokens[0].char, "@");441 TKAssertInstance(tokens[1], CSSTokenizer.DimensionToken);442 TKAssertEquals(tokens[1].value, 9);443 TKAssertEquals(tokens[1].units, "test");444 TKAssertEquals(tokens[0].toString(), "@");445 TKAssertEquals(tokens[1].toString(), "9test");446 },447 testDelimiters: function(){448 var css = "()[]{},:;<><!---->.";449 var tokenizer = CSSTokenizer.init();450 var tokens = tokenizer.tokenize(css);451 TKAssertEquals(tokens.length, 14);452 TKAssertInstance(tokens[0], CSSTokenizer.OpenParenToken);453 TKAssertInstance(tokens[1], CSSTokenizer.CloseParenToken);454 TKAssertInstance(tokens[2], CSSTokenizer.OpenSquareToken);455 TKAssertInstance(tokens[3], CSSTokenizer.CloseSquareToken);456 TKAssertInstance(tokens[4], CSSTokenizer.OpenCurlyToken);457 TKAssertInstance(tokens[5], CSSTokenizer.CloseCurlyToken);458 TKAssertInstance(tokens[6], CSSTokenizer.CommaToken);459 TKAssertInstance(tokens[7], CSSTokenizer.ColonToken);460 TKAssertInstance(tokens[8], CSSTokenizer.SemicolonToken);461 TKAssertInstance(tokens[9], CSSTokenizer.DelimToken);462 TKAssertEquals(tokens[9].char, "<");463 TKAssertInstance(tokens[10], CSSTokenizer.DelimToken);464 TKAssertEquals(tokens[10].char, ">");465 TKAssertInstance(tokens[11], CSSTokenizer.CDOToken);466 TKAssertInstance(tokens[12], CSSTokenizer.CDCToken);467 TKAssertInstance(tokens[13], CSSTokenizer.DelimToken);468 TKAssertEquals(tokens[13].char, ".");469 TKAssertEquals(tokens[0].toString(), "(");470 TKAssertEquals(tokens[1].toString(), ")");471 TKAssertEquals(tokens[2].toString(), "[");472 TKAssertEquals(tokens[3].toString(), "]");473 TKAssertEquals(tokens[4].toString(), "{");474 TKAssertEquals(tokens[5].toString(), "}");475 TKAssertEquals(tokens[6].toString(), ",");476 TKAssertEquals(tokens[7].toString(), ":");477 TKAssertEquals(tokens[8].toString(), ";");478 TKAssertEquals(tokens[9].toString(), "<");479 TKAssertEquals(tokens[10].toString(), ">");480 TKAssertEquals(tokens[11].toString(), "<!--");481 TKAssertEquals(tokens[12].toString(), "-->");482 TKAssertEquals(tokens[13].toString(), ".");483 },484 testFunctions: function(){485 var css = "test()";486 var tokenizer = CSSTokenizer.init();487 var tokens = tokenizer.tokenize(css);488 TKAssertEquals(tokens.length, 2);489 TKAssertInstance(tokens[0], CSSTokenizer.FunctionToken);490 TKAssertEquals(tokens[0].name, "test");491 TKAssertInstance(tokens[1], CSSTokenizer.CloseParenToken);492 TKAssertEquals(tokens[0].toString(), "test(");493 TKAssertEquals(tokens[1].toString(), ")");494 css = "--test('one',2, 3.4)";495 tokenizer = CSSTokenizer.init();496 tokens = tokenizer.tokenize(css);497 TKAssertEquals(tokens.length, 8);498 TKAssertInstance(tokens[0], CSSTokenizer.FunctionToken);499 TKAssertInstance(tokens[1], CSSTokenizer.StringToken);500 TKAssertInstance(tokens[2], CSSTokenizer.CommaToken);501 TKAssertInstance(tokens[3], CSSTokenizer.NumberToken);502 TKAssertInstance(tokens[4], CSSTokenizer.CommaToken);503 TKAssertInstance(tokens[5], CSSTokenizer.WhitespaceToken);504 TKAssertInstance(tokens[6], CSSTokenizer.NumberToken);505 TKAssertInstance(tokens[7], CSSTokenizer.CloseParenToken);506 TKAssertEquals(tokens[0].name, "--test");507 TKAssertEquals(tokens[1].value, "one");508 TKAssertEquals(tokens[3].value, 2);509 TKAssertFloatEquals(tokens[6].value, 3.4);510 TKAssertEquals(tokens[0].toString(), "--test(");511 TKAssertEquals(tokens[1].toString(), "'one'");512 TKAssertEquals(tokens[2].toString(), ",");513 TKAssertEquals(tokens[3].toString(), "2");514 TKAssertEquals(tokens[4].toString(), ",");515 TKAssertEquals(tokens[5].toString(), " ");516 TKAssertEquals(tokens[6].toString(), "3.4");517 TKAssertEquals(tokens[7].toString(), ")");518 },519 testURL: function(){520 var css = "url(one)";521 var tokenizer = CSSTokenizer.init();522 var tokens = tokenizer.tokenize(css);523 TKAssertEquals(tokens.length, 1);524 TKAssertInstance(tokens[0], CSSTokenizer.URLToken);525 TKAssertEquals(tokens[0].url, "one");526 TKAssertEquals(tokens[0].toString(), "url(one)");527 css = "url( one/there#hash )";528 tokenizer = CSSTokenizer.init();529 tokens = tokenizer.tokenize(css);530 TKAssertEquals(tokens.length, 1);531 TKAssertInstance(tokens[0], CSSTokenizer.URLToken);532 TKAssertEquals(tokens[0].url, "one/there#hash");533 TKAssertEquals(tokens[0].toString(), "url(one/there#hash)"); // rewritten without whitespace534 css = "url('one/there#hash')";535 tokenizer = CSSTokenizer.init();536 tokens = tokenizer.tokenize(css);537 TKAssertEquals(tokens.length, 3);538 TKAssertInstance(tokens[0], CSSTokenizer.FunctionToken);539 TKAssertEquals(tokens[0].name, "url");540 TKAssertInstance(tokens[1], CSSTokenizer.StringToken);541 TKAssertEquals(tokens[1].value, "one/there#hash");542 TKAssertInstance(tokens[2], CSSTokenizer.CloseParenToken);543 TKAssertEquals(tokens[0].toString(), "url(");544 TKAssertEquals(tokens[1].toString(), "'one/there#hash'");545 TKAssertEquals(tokens[2].toString(), ")");546 css = "url( \"one/there#hash\" )";547 tokenizer = CSSTokenizer.init();548 tokens = tokenizer.tokenize(css);549 TKAssertEquals(tokens.length, 4);550 TKAssertInstance(tokens[0], CSSTokenizer.FunctionToken);551 TKAssertEquals(tokens[0].name, "url");552 TKAssertInstance(tokens[1], CSSTokenizer.StringToken);553 TKAssertEquals(tokens[1].value, "one/there#hash");554 TKAssertInstance(tokens[2], CSSTokenizer.WhitespaceToken);555 TKAssertEquals(tokens[2].whitespace, " ");556 TKAssertInstance(tokens[3], CSSTokenizer.CloseParenToken);557 TKAssertEquals(tokens[0].toString(), "url(");558 TKAssertEquals(tokens[1].toString(), "\"one/there#hash\"");559 TKAssertEquals(tokens[2].toString(), " ");560 TKAssertEquals(tokens[3].toString(), ")");561 },...

Full Screen

Full Screen

tokenizer.js

Source:tokenizer.js Github

copy

Full Screen

...304 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');305 else if(code == 0x45 || code == 0x65) {306 if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');307 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');308 else create(new DimensionToken(currtoken,code)) && switchto('dimension');309 }310 else if(code == 0x2d) {311 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');312 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();313 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');314 else emit() && switchto('data') && reconsume();315 }316 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');317 else if(code == 0x5c) {318 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();319 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');320 }321 else emit() && switchto('data') && reconsume();322 break;323 case "number-fraction":324 currtoken.type = "number";325 if(digit(code)) currtoken.append(code);326 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');327 else if(code == 0x45 || code == 0x65) {328 if(digit(next())) consume() && currtoken.append([0x65,code]) && switchto('sci-notation');329 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x65,next(1),next(2)]) && consume(2) && switchto('sci-notation');330 else create(new DimensionToken(currtoken,code)) && switchto('dimension');331 }332 else if(code == 0x2d) {333 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');334 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();335 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');336 else emit() && switchto('data') && reconsume();337 }338 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');339 else if(code == 0x5c) {340 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();341 else create(new DimensionToken(currtoken,consumeEscape())) && switchto('dimension');342 }343 else emit() && switchto('data') && reconsume();344 break;345 case "dimension":346 if(namechar(code)) currtoken.append(code);347 else if(code == 0x5c) {348 if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();349 else currtoken.append(consumeEscape());350 }351 else emit() && switchto('data') && reconsume();352 break;353 case "sci-notation":354 currtoken.type = "number";355 if(digit(code)) currtoken.append(code);356 else emit() && switchto('data') && reconsume();357 break;358 case "url":359 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');360 else if(code == 0x22) switchto('url-double-quote');361 else if(code == 0x27) switchto('url-single-quote');362 else if(code == 0x29) emit(new URLToken) && switchto('data');363 else if(whitespace(code)) donothing();364 else switchto('url-unquoted') && reconsume();365 break;366 case "url-double-quote":367 if(! (currtoken instanceof URLToken)) create(new URLToken);368 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');369 else if(code == 0x22) switchto('url-end');370 else if(newline(code)) parseerror() && switchto('bad-url');371 else if(code == 0x5c) {372 if(newline(next())) consume();373 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();374 else currtoken.append(consumeEscape());375 }376 else currtoken.append(code);377 break;378 case "url-single-quote":379 if(! (currtoken instanceof URLToken)) create(new URLToken);380 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');381 else if(code == 0x27) switchto('url-end');382 else if(newline(code)) parseerror() && switchto('bad-url');383 else if(code == 0x5c) {384 if(newline(next())) consume();385 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();386 else currtoken.append(consumeEscape());387 }388 else currtoken.append(code);389 break;390 case "url-end":391 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');392 else if(whitespace(code)) donothing();393 else if(code == 0x29) emit() && switchto('data');394 else parseerror() && switchto('bad-url') && reconsume();395 break;396 case "url-unquoted":397 if(! (currtoken instanceof URLToken)) create(new URLToken);398 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');399 else if(whitespace(code)) switchto('url-end');400 else if(code == 0x29) emit() && switchto('data');401 else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');402 else if(code == 0x5c) {403 if(badescape(next())) parseerror() && switchto('bad-url');404 else currtoken.append(consumeEscape());405 }406 else currtoken.append(code);407 break;408 case "bad-url":409 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');410 else if(code == 0x29) emit(new BadURLToken) && switchto('data');411 else if(code == 0x5c) {412 if(badescape(next())) donothing();413 else consumeEscape();414 }415 else donothing();416 break;417 case "unicode-range":418 // We already know that the current code is a hexdigit.419 var start = [code], end = [code];420 for(var total = 1; total < 6; total++) {421 if(hexdigit(next())) {422 consume();423 start.push(code);424 end.push(code);425 }426 else break;427 }428 if(next() == 0x3f) {429 for(;total < 6; total++) {430 if(next() == 0x3f) {431 consume();432 start.push("0".charCodeAt(0));433 end.push("f".charCodeAt(0));434 }435 else break;436 }437 emit(new UnicodeRangeToken(start,end)) && switchto('data');438 }439 else if(next(1) == 0x2d && hexdigit(next(2))) {440 consume();441 consume();442 end = [code];443 for(var total = 1; total < 6; total++) {444 if(hexdigit(next())) {445 consume();446 end.push(code);447 }448 else break;449 }450 emit(new UnicodeRangeToken(start,end)) && switchto('data');451 }452 else emit(new UnicodeRangeToken(start)) && switchto('data');453 break;454 default:455 catchfire("Unknown state '" + state + "'");456 }457 }458}459function stringFromCodeArray(arr) {460 return String.fromCharCode.apply(null,arr.filter(function(e){return e;}));461}462function CSSParserToken(options) { return this; }463CSSParserToken.prototype.finish = function() { return this; }464CSSParserToken.prototype.toString = function() { return this.tokenType; }465CSSParserToken.prototype.toSourceString = CSSParserToken.prototype.toString;466CSSParserToken.prototype.toJSON = function() { return this.toString(); }467function BadStringToken() { return this; }468BadStringToken.prototype = new CSSParserToken;469BadStringToken.prototype.tokenType = "BADSTRING";470function BadURLToken() { return this; }471BadURLToken.prototype = new CSSParserToken;472BadURLToken.prototype.tokenType = "BADURL";473function WhitespaceToken() { return this; }474WhitespaceToken.prototype = new CSSParserToken;475WhitespaceToken.prototype.tokenType = "WHITESPACE";476WhitespaceToken.prototype.toString = function() { return "WS"; }477WhitespaceToken.prototype.toSourceString = function() { return " "; }478function CDOToken() { return this; }479CDOToken.prototype = new CSSParserToken;480CDOToken.prototype.tokenType = "CDO";481function CDCToken() { return this; }482CDCToken.prototype = new CSSParserToken;483CDCToken.prototype.tokenType = "CDC";484function ColonToken() { return this; }485ColonToken.prototype = new CSSParserToken;486ColonToken.prototype.tokenType = ":";487function SemicolonToken() { return this; }488SemicolonToken.prototype = new CSSParserToken;489SemicolonToken.prototype.tokenType = ";";490function OpenCurlyToken() { return this; }491OpenCurlyToken.prototype = new CSSParserToken;492OpenCurlyToken.prototype.tokenType = "{";493function CloseCurlyToken() { return this; }494CloseCurlyToken.prototype = new CSSParserToken;495CloseCurlyToken.prototype.tokenType = "}";496function OpenSquareToken() { return this; }497OpenSquareToken.prototype = new CSSParserToken;498OpenSquareToken.prototype.tokenType = "[";499function CloseSquareToken() { return this; }500CloseSquareToken.prototype = new CSSParserToken;501CloseSquareToken.prototype.tokenType = "]";502function OpenParenToken() { return this; }503OpenParenToken.prototype = new CSSParserToken;504OpenParenToken.prototype.tokenType = "(";505function CloseParenToken() { return this; }506CloseParenToken.prototype = new CSSParserToken;507CloseParenToken.prototype.tokenType = ")";508function EOFToken() { return this; }509EOFToken.prototype = new CSSParserToken;510EOFToken.prototype.tokenType = "EOF";511function DelimToken(code) {512 this.value = String.fromCharCode(code);513 return this;514}515DelimToken.prototype = new CSSParserToken;516DelimToken.prototype.tokenType = "DELIM";517DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }518DelimToken.prototype.toSourceString = function() { return this.value; }519function StringValuedToken() { return this; }520StringValuedToken.prototype = new CSSParserToken;521StringValuedToken.prototype.append = function(val) {522 if(val instanceof Array) {523 for(var i = 0; i < val.length; i++) {524 this.value.push(val[i]);525 }526 } else {527 this.value.push(val);528 }529 return true;530}531StringValuedToken.prototype.finish = function() {532 this.value = this.valueAsString();533 return this;534}535StringValuedToken.prototype.ASCIImatch = function(str) {536 return this.valueAsString().toLowerCase() == str.toLowerCase();537}538StringValuedToken.prototype.valueAsString = function() {539 if(typeof this.value == 'string') return this.value;540 return stringFromCodeArray(this.value);541}542StringValuedToken.prototype.valueAsCodes = function() {543 if(typeof this.value == 'string') {544 var ret = [];545 for(var i = 0; i < this.value.length; i++)546 ret.push(this.value.charCodeAt(i));547 return ret;548 }549 return this.value.filter(function(e){return e;});550}551function IdentifierToken(val) {552 this.value = [];553 this.append(val);554}555IdentifierToken.prototype = new StringValuedToken;556IdentifierToken.prototype.tokenType = "IDENT";557IdentifierToken.prototype.toString = function() { return "IDENT("+this.value+")"; }558IdentifierToken.prototype.toSourceString = function() { return this.value; }559function FunctionToken(val) {560 // These are always constructed by passing an IdentifierToken561 this.value = val.finish().value;562}563FunctionToken.prototype = new StringValuedToken;564FunctionToken.prototype.tokenType = "FUNCTION";565FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }566FunctionToken.prototype.toSourceString = function() { return this.value; }567function AtKeywordToken(val) {568 this.value = [];569 this.append(val);570}571AtKeywordToken.prototype = new StringValuedToken;572AtKeywordToken.prototype.tokenType = "AT-KEYWORD";573AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }574AtKeywordToken.prototype.toSourceString = function() { return "@"+this.value; }575function HashToken(val) {576 this.value = [];577 this.append(val);578}579HashToken.prototype = new StringValuedToken;580HashToken.prototype.tokenType = "HASH";581HashToken.prototype.toString = function() { return "HASH("+this.value+")"; }582HashToken.prototype.toSourceString = function() { return "#"+this.value; }583function StringToken(val) {584 this.value = [];585 this.append(val);586}587StringToken.prototype = new StringValuedToken;588StringToken.prototype.tokenType = "STRING";589StringToken.prototype.toString = function() { return "\""+this.value+"\""; }590StringToken.prototype.toSourceString = StringToken.prototype.toString;591function URLToken(val) {592 this.value = [];593 this.append(val);594}595URLToken.prototype = new StringValuedToken;596URLToken.prototype.tokenType = "URL";597URLToken.prototype.toString = function() { return "URL("+this.value+")"; }598URLToken.prototype.toSourceString = function() { return "url('"+this.value+"')"; }599function NumberToken(val) {600 this.value = [];601 this.append(val);602 this.type = "integer";603}604NumberToken.prototype = new StringValuedToken;605NumberToken.prototype.tokenType = "NUMBER";606NumberToken.prototype.toString = function() {607 if(this.type == "integer")608 return "INT("+this.value+")";609 return "NUMBER("+this.value+")";610}611NumberToken.prototype.toSourceString = function() {612 if(this.type == "integer")613 return this.value;614 return this.value;615}616NumberToken.prototype.finish = function() {617 this.repr = this.valueAsString();618 this.value = this.repr * 1;619 if(Math.abs(this.value) % 1 != 0) this.type = "number";620 return this;621}622function PercentageToken(val) {623 // These are always created by passing a NumberToken as val624 val.finish();625 this.value = val.value;626 this.repr = val.repr;627}628PercentageToken.prototype = new CSSParserToken;629PercentageToken.prototype.tokenType = "PERCENTAGE";630PercentageToken.prototype.toString = function() { return "PERCENTAGE("+this.value+")"; }631PercentageToken.prototype.toSourceString = function() { return this.value+'%'; }632function DimensionToken(val,unit) {633 // These are always created by passing a NumberToken as the val634 val.finish();635 this.num = val.value;636 this.unit = [];637 this.repr = val.repr;638 this.append(unit);639}640DimensionToken.prototype = new CSSParserToken;641DimensionToken.prototype.tokenType = "DIMENSION";642DimensionToken.prototype.toString = function() { return "DIM("+this.num+","+this.unit+")"; }643DimensionToken.prototype.toSourceString = function() { return this.num+this.unit; }644DimensionToken.prototype.append = function(val) {645 if(val instanceof Array) {646 for(var i = 0; i < val.length; i++) {...

Full Screen

Full Screen

css-tokenizer.js

Source:css-tokenizer.js Github

copy

Full Screen

...296 else emit() && switchto('data') && reconsume();297 }298 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data') && reconsume();299 else if(code == 0x45 || code == 0x65) {300 if(!options.scientificNotation) create(new DimensionToken(currtoken,code)) && switchto('dimension');301 else if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');302 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');303 else create(new DimensionToken(currtoken,code)) && switchto('dimension');304 }305 else if(code == 0x2d) {306 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');307 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();308 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');309 else emit() && switchto('data') && reconsume();310 }311 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');312 else if(code == 0x5c) {313 if(badescape(next)) emit() && switchto('data') && reconsume();314 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');315 }316 else emit() && switchto('data') && reconsume();317 break;318 case "number-fraction":319 currtoken.type = "number";320 if(digit(code)) currtoken.append(code);321 else if(code == 0x2e) emit() && switchto('data') && reconsume();322 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data') && reconsume();323 else if(code == 0x45 || code == 0x65) {324 if(!options.scientificNotation) create(new DimensionToken(currtoken,code)) && switchto('dimension');325 else if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');326 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');327 else create(new DimensionToken(currtoken,code)) && switchto('dimension');328 }329 else if(code == 0x2d) {330 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');331 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();332 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');333 else emit() && switchto('data') && reconsume();334 }335 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');336 else if(code == 0x5c) {337 if(badescape(next)) emit() && switchto('data') && reconsume();338 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');339 }340 else emit() && switchto('data') && reconsume();341 break;342 case "dimension":343 if(namechar(code)) currtoken.append(code);344 else if(code == 0x5c) {345 if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();346 else currtoken.append(consumeEscape());347 }348 else emit() && switchto('data') && reconsume();349 break;350 case "sci-notation":351 if(digit(code)) currtoken.append(code);352 else emit() && switchto('data') && reconsume();353 break;354 case "url":355 if(code == 0x22) switchto('url-double-quote');356 else if(code == 0x27) switchto('url-single-quote');357 else if(code == 0x29) emit(new URLToken) && switchto('data');358 else if(whitespace(code)) donothing();359 else switchto('url-unquoted') && reconsume();360 break;361 case "url-double-quote":362 if(currtoken == undefined) create(new URLToken);363 if(code == 0x22) switchto('url-end');364 else if(newline(code)) parseerror() && switchto('bad-url');365 else if(code == 0x5c) {366 if(newline(next())) consume();367 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();368 else currtoken.append(consumeEscape());369 }370 else currtoken.append(code);371 break;372 case "url-single-quote":373 if(currtoken == undefined) create(new URLToken);374 if(code == 0x27) switchto('url-end');375 else if(newline(code)) parseerror() && switchto('bad-url');376 else if(code == 0x5c) {377 if(newline(next())) consume();378 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();379 else currtoken.append(consumeEscape());380 }381 else currtoken.append(code);382 break;383 case "url-end":384 if(whitespace(code)) donothing();385 else if(code == 0x29) emit() && switchto('data');386 else parseerror() && switchto('bad-url') && reconsume();387 break;388 case "url-unquoted":389 if(currtoken == undefined) create(new URLToken);390 if(whitespace(code)) switchto('url-end');391 else if(code == 0x29) emit() && switchto('data');392 else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');393 else if(code == 0x5c) {394 if(badescape(next())) parseerror() && switchto('bad-url');395 else currtoken.append(consumeEscape());396 }397 else currtoken.append(code);398 break;399 case "bad-url":400 if(code == 0x29) emit(new BadURLToken) && switchto('data');401 else if(code == 0x5c) {402 if(badescape(next())) donothing();403 else consumeEscape()404 }405 else donothing();406 break;407 case "unicode-range":408 // We already know that the current code is a hexdigit.409 var start = [code], end = [code];410 for(var total = 1; total < 6; total++) {411 if(hexdigit(next())) {412 consume();413 start.push(code);414 end.push(code);415 }416 else break;417 }418 if(next() == 0x3f) {419 for(;total < 6; total++) {420 if(next() == 0x3f) {421 consume();422 start.push("0".charCodeAt(0));423 end.push("f".charCodeAt(0));424 }425 else break;426 }427 emit(new UnicodeRangeToken(start,end)) && switchto('data');428 }429 else if(next(1) == 0x2d && hexdigit(next(2))) {430 consume();431 consume();432 end = [code];433 for(var total = 1; total < 6; total++) {434 if(hexdigit(next())) {435 consume();436 end.push(code);437 }438 else break;439 }440 emit(new UnicodeRangeToken(start,end)) && switchto('data');441 }442 else emit(new UnicodeRangeToken(start)) && switchto('data');443 break;444 default:445 console.log("Unknown state '" + state + "'");446 }447 }448}449function stringFromCodeArray(arr) {450 return String.fromCharCode.apply(null,arr.filter(function(e){return e;}));451}452function CSSParserToken(options) { return this; }453CSSParserToken.prototype.finish = function() { return this; }454CSSParserToken.prototype.toString = function() { return this.tokenType; }455CSSParserToken.prototype.toJSON = function() { return this.toString(); }456function BadStringToken() { return this; }457BadStringToken.prototype = new CSSParserToken;458BadStringToken.prototype.tokenType = "BADSTRING";459function BadURLToken() { return this; }460BadURLToken.prototype = new CSSParserToken;461BadURLToken.prototype.tokenType = "BADURL";462function WhitespaceToken() { return this; }463WhitespaceToken.prototype = new CSSParserToken;464WhitespaceToken.prototype.tokenType = "WHITESPACE";465WhitespaceToken.prototype.toString = function() { return "WS"; }466function CDOToken() { return this; }467CDOToken.prototype = new CSSParserToken;468CDOToken.prototype.tokenType = "CDO";469function CDCToken() { return this; }470CDCToken.prototype = new CSSParserToken;471CDCToken.prototype.tokenType = "CDC";472function ColonToken() { return this; }473ColonToken.prototype = new CSSParserToken;474ColonToken.prototype.tokenType = ":";475function SemicolonToken() { return this; }476SemicolonToken.prototype = new CSSParserToken;477SemicolonToken.prototype.tokenType = ";";478function OpenCurlyToken() { return this; }479OpenCurlyToken.prototype = new CSSParserToken;480OpenCurlyToken.prototype.tokenType = "{";481function CloseCurlyToken() { return this; }482CloseCurlyToken.prototype = new CSSParserToken;483CloseCurlyToken.prototype.tokenType = "}";484function OpenSquareToken() { return this; }485OpenSquareToken.prototype = new CSSParserToken;486OpenSquareToken.prototype.tokenType = "[";487function CloseSquareToken() { return this; }488CloseSquareToken.prototype = new CSSParserToken;489CloseSquareToken.prototype.tokenType = "]";490function OpenParenToken() { return this; }491OpenParenToken.prototype = new CSSParserToken;492OpenParenToken.prototype.tokenType = "(";493function CloseParenToken() { return this; }494CloseParenToken.prototype = new CSSParserToken;495CloseParenToken.prototype.tokenType = ")";496function EOFToken() { return this; }497EOFToken.prototype = new CSSParserToken;498EOFToken.prototype.tokenType = "EOF";499function DelimToken(code) {500 this.value = String.fromCharCode(code);501 return this;502}503DelimToken.prototype = new CSSParserToken;504DelimToken.prototype.tokenType = "DELIM";505DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }506function StringValuedToken() { return this; }507StringValuedToken.prototype = new CSSParserToken;508StringValuedToken.prototype.append = function(val) {509 if(val instanceof Array) {510 for(var i = 0; i < val.length; i++) {511 this.value.push(val[i]);512 }513 } else {514 this.value.push(val);515 }516 return true;517}518StringValuedToken.prototype.finish = function() {519 this.value = stringFromCodeArray(this.value);520 return this;521}522function IdentifierToken(val) {523 this.value = [];524 this.append(val);525}526IdentifierToken.prototype = new StringValuedToken;527IdentifierToken.prototype.tokenType = "IDENT";528IdentifierToken.prototype.toString = function() { return "IDENT("+this.value+")"; }529function FunctionToken(val) {530 // These are always constructed by passing an IdentifierToken531 this.value = val.finish().value;532}533FunctionToken.prototype = new CSSParserToken;534FunctionToken.prototype.tokenType = "FUNCTION";535FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }536function AtKeywordToken(val) {537 this.value = [];538 this.append(val);539}540AtKeywordToken.prototype = new StringValuedToken;541AtKeywordToken.prototype.tokenType = "AT-KEYWORD";542AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }543function HashToken(val) {544 this.value = [];545 this.append(val);546}547HashToken.prototype = new StringValuedToken;548HashToken.prototype.tokenType = "HASH";549HashToken.prototype.toString = function() { return "HASH("+this.value+")"; }550function StringToken(val) {551 this.value = [];552 this.append(val);553}554StringToken.prototype = new StringValuedToken;555StringToken.prototype.tokenType = "STRING";556StringToken.prototype.toString = function() { return "\""+this.value+"\""; }557function URLToken(val) {558 this.value = [];559 this.append(val);560}561URLToken.prototype = new StringValuedToken;562URLToken.prototype.tokenType = "URL";563URLToken.prototype.toString = function() { return "URL("+this.value+")"; }564function NumberToken(val) {565 this.value = [];566 this.append(val);567 this.type = "integer";568}569NumberToken.prototype = new StringValuedToken;570NumberToken.prototype.tokenType = "NUMBER";571NumberToken.prototype.toString = function() {572 if(this.type == "integer")573 return "INT("+this.value+")";574 return "NUMBER("+this.value+")";575}576NumberToken.prototype.finish = function() {577 this.repr = stringFromCodeArray(this.value);578 this.value = this.repr * 1;579 if(Math.abs(this.value) % 1 != 0) this.type = "number";580 return this;581}582function PercentageToken(val) {583 // These are always created by passing a NumberToken as val584 val.finish();585 this.value = val.value;586 this.repr = val.repr;587}588PercentageToken.prototype = new CSSParserToken;589PercentageToken.prototype.tokenType = "PERCENTAGE";590PercentageToken.prototype.toString = function() { return "PERCENTAGE("+this.value+")"; }591function DimensionToken(val,unit) {592 // These are always created by passing a NumberToken as the val593 val.finish();594 this.num = val.value;595 this.unit = [];596 this.repr = val.repr;597 this.append(unit);598}599DimensionToken.prototype = new CSSParserToken;600DimensionToken.prototype.tokenType = "DIMENSION";601DimensionToken.prototype.toString = function() { return "DIM("+this.num+","+this.unit+")"; }602DimensionToken.prototype.append = function(val) {603 if(val instanceof Array) {604 for(var i = 0; i < val.length; i++) {605 this.unit.push(val[i]);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { dimensionToken } = require('playwright/lib/internal/frames');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const input = await page.$('input[name="q"]');8 const token = await dimensionToken(input);9 console.log(token);10 await browser.close();11})();12{

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2test('test', async ({ page }) => {3 const title = await page.title();4 expect(title).toBe('Playwright');5});6const { test, expect } = require('@playwright/test');7test('test', async ({ page }) => {8 const title = await page.title();9 expect(title).toBe('Playwright');10});11const { test, expect } = require('@playwright/test');12test('test', async ({ page }) => {13 const title = await page.title();14 expect(title).toBe('Playwright');15});16const { test, expect } = require('@playwright/test');17test('test', async ({ page }) => {18 const title = await page.title();19 expect(title).toBe('Playwright');20});21const { test, expect } = require('@playwright/test');22test('test', async ({ page }) => {23 const title = await page.title();24 expect(title).toBe('Playwright');25});26const { test, expect } = require('@playwright/test');27test('test', async ({ page }) => {28 const title = await page.title();29 expect(title).toBe('Playwright');30});31const { test, expect } = require('@playwright/test');32test('test', async ({ page }) => {33 const title = await page.title();34 expect(title).toBe('Playwright');35});36const { test, expect } = require('@playwright/test');37test('test', async ({ page }) => {38 const title = await page.title();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {DimensionToken} = require('@playwright/test/lib/test');2const {test} = require('@playwright/test');3test('test', async ({page}) => {4 const dimensionToken = new DimensionToken(page, 'playwright.dev');5 const dimensions = await dimensionToken.getDimensions();6 console.log(dimensions);7});8{9}10const {DimensionToken} = require('@playwright/test/lib/test');11const {test} = require('@playwright/test');12test('test', async ({page}) => {13 const dimensionToken = new DimensionToken(page, 'browser');14 const dimensions = await dimensionToken.getDimensions();15 console.log(dimensions);16});17{18}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { DimensionToken } = require('@playwright/test/lib/api/test');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('text=Docs');8 const box = await element.evaluate(element => {9 const rect = element.getBoundingClientRect();10 return {11 };12 });13 console.log(box);14 await browser.close();15})();16const test = require('@playwright/test');17const { chromium } = require('playwright');18test.describe('Playwright Internal API', () => {19 test('DimensionToken', async ({ page }) => {20 const element = await page.$('text=Docs');21 const box = await element.evaluate(element => {22 const rect = element.getBoundingClientRect();23 return {24 };25 });26 console.log(box);27 });28});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DimensionToken } = require('@playwright/test/lib/utils/geometry');2const { Page } = require('@playwright/test/lib/server/page');3const { Playwright } = require('@playwright/test/lib/server/playwright');4const { BrowserContext } = require('@playwright/test/lib/server/browserContext');5const { BrowserServer } = require('@playwright/test/lib/server/browserServer');6const { BrowserType } = require('@playwright/test/lib/server/browserType');7const { Browser } = require('@playwright/test/lib/server/browser');8const { Dispatcher } = require('@playwright/test/lib/server/dispatcher');9const { DispatcherConnection } = require('@playwright/test/lib/server/dispatcher');10const { DispatcherScope } = require('@playwright/test/lib/server/dispatcher');11const { Frame } = require('@playwright/test/lib/server/frame');12const { JSHandle } = require('@playwright/test/lib/server/jsHandle');13const { Loggers } = require('@playwright/test/lib/utils/loggers');14const { Logger } = require('@playwright/test/lib/utils/logger');15const { TimeoutSettings } = require('@playwright/test/lib/utils/timeoutSettings');16const { ProgressController } = require('@playwright/test/lib/utils/progress');17const { Progress } = require('@playwright/test/lib/utils/progress');18const { ProgressController } = require('@playwright/test/lib/utils/progress');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {DimensionToken} = require('playwright/lib/internal/frames');2const {Frame} = require('playwright/lib/internal/frames');3const {DimensionToken} = require('playwright/lib/internal/frames');4const {Frame} = require('playwright/lib/internal/frames');5const {DimensionToken} = require('playwright/lib/internal/frames');6const {Frame} = require('playwright/lib/internal/frames');7const {DimensionToken} = require('playwright/lib/internal/frames');8const {Frame} = require('playwright/lib/internal/frames');9const {DimensionToken} = require('playwright/lib/internal/frames');10const {Frame} = require('playwright/lib/internal/frames');11const {DimensionToken} = require('playwright/lib/internal/frames');12const {Frame} = require('playwright/lib/internal/frames');13const {DimensionToken} = require('playwright/lib/internal/frames');14const {Frame} = require('playwright/lib/internal/frames');15const {DimensionToken} = require('playwright/lib/internal/frames');16const {Frame} = require('playwright/lib/internal/frames');17const {DimensionToken} = require('playwright/lib/internal/frames');18const {Frame} = require('playwright/lib/internal/frames');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DimensionToken } = require('playwright/lib/protocol/types');2const { parse } = require('playwright/lib/protocol/parser');3const { serialize } = require('playwright/lib/protocol/serializer');4const { createGuid } = require('playwright/lib/utils/utils');5const token = new DimensionToken({ guid: createGuid(), type: 'dimension', value: '100px' });6console.log(token);7const serialized = serialize(token);8console.log(serialized);9const parsed = parse(serialized);10console.log(parsed);11const token2 = new DimensionToken(parsed);12console.log(token2);13DimensionToken {14}15{16}17{18}19DimensionToken {20}21const { DimensionToken } = require('playwright/lib/protocol/types');22const { parse } = require('playwright/lib/protocol/parser');23const { serialize } = require('playwright/lib/protocol/serializer');24const { createGuid } = require('playwright/lib/utils/utils');25const token = new DimensionToken({ guid: createGuid(), type: 'dimension', value: '100px' });26console.log(token);27const serialized = serialize(token);28console.log(serialized);29const parsed = parse(serialized);30console.log(parsed);31const token2 = new DimensionToken(parsed);32console.log(token2);33DimensionToken {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DimensionToken } from "playwright";2const dimensions = new DimensionToken();3dimensions.width = 100;4dimensions.height = 100;5import { DimensionToken } from "playwright";6const dimensions = new DimensionToken();7dimensions.width = 100;8dimensions.height = 100;9import { DimensionToken } from "playwright";10const dimensions = new DimensionToken();11dimensions.width = 100;12dimensions.height = 100;13import { DimensionToken } from "playwright";14const dimensions = new DimensionToken();15dimensions.width = 100;16dimensions.height = 100;17import { DimensionToken } from "playwright";18const dimensions = new DimensionToken();19dimensions.width = 100;20dimensions.height = 100;21import { DimensionToken } from "playwright";22const dimensions = new DimensionToken();23dimensions.width = 100;24dimensions.height = 100;25import { DimensionToken } from "playwright";26const dimensions = new DimensionToken();27dimensions.width = 100;28dimensions.height = 100;29import { DimensionToken } from "playwright";30const dimensions = new DimensionToken();31dimensions.width = 100;32dimensions.height = 100;33import { DimensionToken } from "playwright";34const dimensions = new DimensionToken();35dimensions.width = 100;36dimensions.height = 100;37import { DimensionToken } from "playwright";38const dimensions = new DimensionToken();39dimensions.width = 100;40dimensions.height = 100;41import { DimensionToken } from "playwright";42const dimensions = new DimensionToken();43dimensions.width = 100;44dimensions.height = 100;45import { DimensionToken } from "playwright";46const dimensions = new DimensionToken();47dimensions.width = 100;48dimensions.height = 100;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');2const dimensionToken = new DimensionToken('width', 'height');3const dimension = dimensionToken.toString();4console.log(dimension);5const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');6const dimensionToken = new DimensionToken('width', 'height');7const dimension = dimensionToken.toString();8console.log(dimension);9const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');10const dimensionToken = new DimensionToken('width', 'height');11const dimension = dimensionToken.toString();12console.log(dimension);13const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');14const dimensionToken = new DimensionToken('width', 'height');15const dimension = dimensionToken.toString();16console.log(dimension);17const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');18const dimensionToken = new DimensionToken('width', 'height');19const dimension = dimensionToken.toString();20console.log(dimension);21const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');22const dimensionToken = new DimensionToken('width', 'height');23const dimension = dimensionToken.toString();24console.log(dimension);25const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');26const dimensionToken = new DimensionToken('width', 'height');27const dimension = dimensionToken.toString();28console.log(dimension);29const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');30const dimensionToken = new DimensionToken('width', 'height');31const dimension = dimensionToken.toString();32console.log(dimension);33const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');34const dimensionToken = new DimensionToken('width', 'height');35const dimension = dimensionToken.toString();36console.log(dimension);37const { DimensionToken } = require('playwright-core/lib/server/supplements/recorder/types');38const dimensionToken = new DimensionToken('width', 'height');

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const playwright = require('playwright');3const { DimensionToken } = require('playwright/lib/client/dimensionToken');4const { Page } = require('playwright/lib/client/page');5const { chromium } = playwright;6const browser = await chromium.launch();7const context = await browser.newContext();8const page = await context.newPage();9const element = await page.$('input[name=q]');10const dimension = await page.evaluate((element) => {11 return new DimensionToken(element);12}, element);13console.log(dimension);14await browser.close();15const path = require('path');16const playwright = require('playwright');17const { DimensionToken } = require('playwright/lib/client/dimensionToken');18const { Page } = require('playwright/lib/client/page');19const { chromium } = playwright;20const browser = await chromium.launch();21const context = await browser.newContext();22const page = await context.newPage();23const element = await page.$('input[name=q]');24const dimension = await page.evaluate((element) => {25 return new DimensionToken(element);26}, element);27console.log(dimension);28await browser.close();29const path = require('path');30const playwright = require('playwright');31const { DimensionToken } = require('playwright/lib/client/dimensionToken');32const { Page } = require('playwright/lib/client/page');33const { chromium } = playwright;34const browser = await chromium.launch();35const context = await browser.newContext();36const page = await context.newPage();37const element = await page.$('input[name=q]');38const dimension = await page.evaluate((element) => {39 return new DimensionToken(element);40}, element);

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