Best JavaScript code snippet using wpt
parser_spec.js
Source:parser_spec.js
1/* globals expect, it, describe, StringStream, Lexer, Name, Linearization */2'use strict';3describe('parser', function() {4 describe('Lexer', function() {5 it('should stop parsing numbers at the end of stream', function() {6 var input = new StringStream('11.234');7 var lexer = new Lexer(input);8 var result = lexer.getNumber();9 expect(result).toEqual(11.234);10 });11 it('should parse PostScript numbers', function() {12 var numbers = ['-.002', '34.5', '-3.62', '123.6e10', '1E-5', '-1.', '0.0',13 '123', '-98', '43445', '0', '+17'];14 for (var i = 0, ii = numbers.length; i < ii; i++) {15 var num = numbers[i];16 var input = new StringStream(num);17 var lexer = new Lexer(input);18 var result = lexer.getNumber();19 expect(result).toEqual(parseFloat(num));20 }21 });22 it('should ignore double negative before number', function() {23 var input = new StringStream('--205.88');24 var lexer = new Lexer(input);25 var result = lexer.getNumber();26 expect(result).toEqual(-205.88);27 });28 it('should handle glued numbers and operators', function() {29 var input = new StringStream('123ET');30 var lexer = new Lexer(input);31 var value = lexer.getNumber();32 expect(value).toEqual(123);33 // The lexer must not have consumed the 'E'34 expect(lexer.currentChar).toEqual(0x45); // 'E'35 });36 it('should stop parsing strings at the end of stream', function() {37 var input = new StringStream('(1$4)');38 input.getByte = function(super_getByte) {39 // simulating end of file using null (see issue 2766)40 var ch = super_getByte.call(input);41 return (ch === 0x24 /* '$' */ ? -1 : ch);42 }.bind(input, input.getByte);43 var lexer = new Lexer(input);44 var result = lexer.getString();45 expect(result).toEqual('1');46 });47 it('should not throw exception on bad input', function() {48 // '8 0 2 15 5 2 2 2 4 3 2 4'49 // should be parsed as50 // '80 21 55 22 24 32'51 var input = new StringStream('<7 0 2 15 5 2 2 2 4 3 2 4>');52 var lexer = new Lexer(input);53 var result = lexer.getHexString();54 expect(result).toEqual('p!U"$2');55 });56 it('should ignore escaped CR and LF', function() {57 // '(\101\<CR><LF>\102)'58 // should be parsed as59 // "AB"60 var input = new StringStream('(\\101\\\r\n\\102\\\r\\103\\\n\\104)');61 var lexer = new Lexer(input);62 var result = lexer.getString();63 expect(result).toEqual('ABCD');64 });65 it('should handle Names with invalid usage of NUMBER SIGN (#)', function() {66 var inputNames = ['/# 680 0 R', '/#AQwerty', '/#A<</B'];67 var expectedNames = ['#', '#AQwerty', '#A'];68 for (var i = 0, ii = inputNames.length; i < ii; i++) {69 var input = new StringStream(inputNames[i]);70 var lexer = new Lexer(input);71 var result = lexer.getName();72 expect(result).toEqual(Name.get(expectedNames[i]));73 }74 });75 });76 describe('Linearization', function() {77 it('should not find a linearization dictionary', function () {78 // Not an actual linearization dictionary.79 var stream1 = new StringStream(80 '3 0 obj\n' +81 '<<\n' +82 '/Length 4622\n' +83 '/Filter /FlateDecode\n' +84 '>>\n' +85 'endobj'86 );87 expect(Linearization.create(stream1)).toEqual(null);88 // Linearization dictionary with invalid version number.89 var stream2 = new StringStream(90 '1 0 obj\n' +91 '<<\n' +92 '/Linearized 0\n' +93 '>>\n' +94 'endobj'95 );96 expect(Linearization.create(stream2)).toEqual(null);97 });98 it('should accept a valid linearization dictionary', function () {99 var stream = new StringStream(100 '131 0 obj\n' +101 '<<\n' +102 '/Linearized 1\n' +103 '/O 133\n' +104 '/H [ 1388 863 ]\n' +105 '/L 90\n' +106 '/E 43573\n' +107 '/N 18\n' +108 '/T 193883\n' +109 '>>\n' +110 'endobj'111 );112 var expectedLinearizationDict = {113 length: 90,114 hints: [1388, 863],115 objectNumberFirst: 133,116 endFirst: 43573,117 numPages: 18,118 mainXRefEntriesOffset: 193883,119 pageFirst: 0,120 };121 expect(Linearization.create(stream)).toEqual(expectedLinearizationDict);122 });123 it('should reject a linearization dictionary with invalid ' +124 'integer parameters', function () {125 // The /L parameter should be equal to the stream length.126 var stream1 = new StringStream(127 '1 0 obj\n' +128 '<<\n' +129 '/Linearized 1\n' +130 '/O 133\n' +131 '/H [ 1388 863 ]\n' +132 '/L 196622\n' +133 '/E 43573\n' +134 '/N 18\n' +135 '/T 193883\n' +136 '>>\n' +137 'endobj'138 );139 expect(function () {140 return Linearization.create(stream1);141 }).toThrow(new Error('The "L" parameter in the linearization ' +142 'dictionary does not equal the stream length.'));143 // The /E parameter should not be zero.144 var stream2 = new StringStream(145 '1 0 obj\n' +146 '<<\n' +147 '/Linearized 1\n' +148 '/O 133\n' +149 '/H [ 1388 863 ]\n' +150 '/L 84\n' +151 '/E 0\n' +152 '/N 18\n' +153 '/T 193883\n' +154 '>>\n' +155 'endobj'156 );157 expect(function () {158 return Linearization.create(stream2);159 }).toThrow(new Error('The "E" parameter in the linearization ' +160 'dictionary is invalid.'));161 // The /O parameter should be an integer.162 var stream3 = new StringStream(163 '1 0 obj\n' +164 '<<\n' +165 '/Linearized 1\n' +166 '/O /abc\n' +167 '/H [ 1388 863 ]\n' +168 '/L 89\n' +169 '/E 43573\n' +170 '/N 18\n' +171 '/T 193883\n' +172 '>>\n' +173 'endobj'174 );175 expect(function () {176 return Linearization.create(stream3);177 }).toThrow(new Error('The "O" parameter in the linearization ' +178 'dictionary is invalid.'));179 });180 it('should reject a linearization dictionary with invalid hint parameters',181 function () {182 // The /H parameter should be an array.183 var stream1 = new StringStream(184 '1 0 obj\n' +185 '<<\n' +186 '/Linearized 1\n' +187 '/O 133\n' +188 '/H 1388\n' +189 '/L 80\n' +190 '/E 43573\n' +191 '/N 18\n' +192 '/T 193883\n' +193 '>>\n' +194 'endobj'195 );196 expect(function () {197 return Linearization.create(stream1);198 }).toThrow(new Error('Hint array in the linearization dictionary ' +199 'is invalid.'));200 // The hint array should contain two, or four, elements.201 var stream2 = new StringStream(202 '1 0 obj\n' +203 '<<\n' +204 '/Linearized 1\n' +205 '/O 133\n' +206 '/H [ 1388 ]\n' +207 '/L 84\n' +208 '/E 43573\n' +209 '/N 18\n' +210 '/T 193883\n' +211 '>>\n' +212 'endobj'213 );214 expect(function () {215 return Linearization.create(stream2);216 }).toThrow(new Error('Hint array in the linearization dictionary ' +217 'is invalid.'));218 // The hint array should not contain zero.219 var stream3 = new StringStream(220 '1 0 obj\n' +221 '<<\n' +222 '/Linearized 1\n' +223 '/O 133\n' +224 '/H [ 1388 863 0 234]\n' +225 '/L 93\n' +226 '/E 43573\n' +227 '/N 18\n' +228 '/T 193883\n' +229 '>>\n' +230 'endobj'231 );232 expect(function () {233 return Linearization.create(stream3);234 }).toThrow(new Error('Hint (2) in the linearization dictionary ' +235 'is invalid.'));236 });237 });...
linear.js
Source:linear.js
...122 plot(linearizationToleranceBoard, userFunction, {strokecolor: "blue"});123}124function setLinearizationPoint() {125 linearizationPoint = parseFloat(document.getElementById("linearizationPoint").value);126 plotLinearization();127}128function plotLinearization() {129 linearizationToleranceBoard.clear();130 function linearization(x) {131 return userFunction(linearizationPoint)132 + derivative(linearizationPoint)*(x - linearizationPoint);133 }134 function linearizationUpperBound(x) {135 return linearization(x) + linearizationTolerance;136 }137 function linearizationLowerBound(x) {138 return linearization(x) - linearizationTolerance;139 }140 plotUserFunction();141 plot(userFunctionBoard, linearization, {strokecolor: "magenta"});142 userFunctionBoard.board.create143 ("point", [linearizationPoint, userFunction(linearizationPoint)], {name:""});144 plot(linearizationToleranceBoard, linearization, {strokecolor: "magenta"});145 plot(linearizationToleranceBoard, linearizationUpperBound, {strokecolor: "green"});146 plot(linearizationToleranceBoard, linearizationLowerBound, {strokecolor: "green"});147 linearizationToleranceBoard.board.create148 ("point", [linearizationPoint, userFunction(linearizationPoint)], {name:""});149 plotSecondDerivative();150}151function clearLinearizationPlots() {152 linearizationToleranceBoard.clear();153 plotCurrentFunctions();154}155function plotSecondDerivative() {156 secondDerivativeBoard.clear();157 plot(secondDerivativeBoard, absSecondDerivative, {strokecolor: "blue"});158 secondDerivativeBoard.board.create("line", [159 [linearizationPoint - linearizationIntervalRadius, -1000],160 [linearizationPoint - linearizationIntervalRadius, 1000],161 ], {strokecolor: "red", strokewidth:1});162 secondDerivativeBoard.board.create("line", [163 [linearizationPoint + linearizationIntervalRadius, -1000],164 [linearizationPoint + linearizationIntervalRadius, 1000],165 ], {strokecolor: "red", strokewidth:1});166}167function setLinearizationTolerance() {168 linearizationTolerance = parseFloat(document.getElementById("linearizationTolerance").value);169 plotLinearization();170}171function resetLinearizationTolerance() {172 linearizationTolerance = 1.0;173 document.getElementById("linearizationTolerance").value = "1.0";174 plotLinearization();175}176function setLinearizationIntervalRadius() {177 linearizationIntervalRadius = Math.abs(parseFloat(178 document.getElementById("linearizationIntervalRadius").value));179 plotSecondDerivative();180}181function resetLinearizationIntervalRadius() {182 linearizationIntervalRadius = 1.0;183 document.getElementById("linearizationIntervalRadius").value = "1.0";...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3}, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var test = new wpt('www.webpagetest.org');9}, function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('webpagetest');14var test = new wpt('www.webpagetest.org');15}, function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('webpagetest');20var test = new wpt('www.webpagetest.org');21}, function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('webpagetest');26var test = new wpt('www.webpagetest.org');27}, function(err
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const page = wptools.page('Barack Obama');4page.get((err, page) => {5 fs.writeFile('output.json', JSON.stringify(page.data), (err) => {6 if (err) throw err;7 console.log('It\'s saved!');8 });9});10{11 "extract": "Barack Hussein Obama II (/bəˈrɑːk huːˈseɪn oʊˈbɑːmə/; born August 4, 1961) is an American politician who served as the 44th President of the United States from 2009 to 2017. A member of the Democratic Party, he was the first African American to be elected to the presidency. He previously served as a U.S. senator from Illinois from 2005 to 2008 and an Illinois state senator from 1997 to 2004. Obama was born in Honolulu, Hawaii. After graduating from Columbia University in 1983, he worked as a community organizer in Chicago. In 1988, he enrolled in Harvard Law School, where he was the first black president of the Harvard Law Review. He was a civil rights attorney and taught constitutional law at the University of Chicago Law School from 1992 to 2004. He served three terms representing the 13th District in the Illinois Senate from 1997 until 2004, when he ran for the U.S. Senate.",
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var wp = new wptoolkit();3var options = {4};5wp.linearize(options, function(err, result) {6 if (err) {7 console.log(err);8 } else {9 console.log(result);10 }11});12var wptoolkit = require('wptoolkit');13var wp = new wptoolkit();14var options = {15};16wp.linearize(options, function(err, result) {17 if (err) {18 console.log(err);19 } else {20 console.log(result);21 }22});23var wptoolkit = require('wptoolkit');24var wp = new wptoolkit();25var options = {26};27wp.linearize(options, function(err, result) {28 if (err) {29 console.log(err);30 } else {31 console.log(result);32 }33});34var wptoolkit = require('wptoolkit');35var wp = new wptoolkit();36var options = {37};38wp.linearize(options, function(err, result) {39 if (err) {40 console.log(err);41 } else {42 console.log(result);43 }44});45var wptoolkit = require('wptoolkit');46var wp = new wptoolkit();47var options = {
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var wp = new wptoolkit();3var wptoolkit = require('wptoolkit');4var wp = new wptoolkit();5 console.log(data);6});7var wptoolkit = require('wptoolkit');8var wp = new wptoolkit();9 console.log(data);10}, 10000);11var wptoolkit = require('wptoolkit');12var wp = new wptoolkit();13 console.log(data);
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var data = wptoolkit.linearize('json', 'json', 'json');3console.log(data);4var wptoolkit = require('wptoolkit');5var data = wptoolkit.json('json', 'json', 'json');6console.log(data);7var wptoolkit = require('wptoolkit');8var data = wptoolkit.xml('json', 'json', 'json');9console.log(data);10var wptoolkit = require('wptoolkit');11var data = wptoolkit.csv('json', 'json', 'json');12console.log(data);13var wptoolkit = require('wptoolkit');14var data = wptoolkit.xml('json', 'json', 'json');15console.log(data);16var wptoolkit = require('wptoolkit');17var data = wptoolkit.csv('json', 'json', 'json');18console.log(data);19var wptoolkit = require('wptoolkit');20var data = wptoolkit.xml('json', 'json', 'json');21console.log(data);22var wptoolkit = require('wptoolkit');23var data = wptoolkit.csv('json', 'json', 'json');24console.log(data);25var wptoolkit = require('wptoolkit');26var data = wptoolkit.xml('json', 'json', 'json');27console.log(data);28var wptoolkit = require('wptoolkit');29var data = wptoolkit.csv('json', 'json',
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var pdf = new wptoolkit.PDF();3pdf.linearize('test.pdf', 'test_linearized.pdf', function(err, data){4 if(err){5 console.log(err);6 }7 else{8 console.log('Linearized');9 }10});11var wptoolkit = require('wptoolkit');12var pdf = new wptoolkit.PDF();13pdf.linearize('test.pdf', 'test_linearized.pdf', function(err, data){14 if(err){15 console.log(err);16 }17 else{18 console.log('Linearized');19 }20});
Using AI Code Generation
1var wptk = require('wptoolkit');2var obj = {};3wptk.linearize(obj);4var proto = {};5var obj = {};6wptk.linearize(obj, proto);7var proto = {};8var obj = {};9var constr = function(){};10wptk.linearize(obj, proto, constr);11var obj = {};12var constr = function(){};13wptk.linearize(obj, null, constr);14var obj = {};15var constr = function(){};16wptk.linearize(obj, null, constr, 'test');17var obj = {};18wptk.linearize(obj, null, null, 'test');19var obj = {};20var proto = {};21var constr = function(){};22wptk.linearize(obj, proto, constr, 'test');23var obj = {};24var proto = {};25wptk.linearize(obj, proto, null, 'test');26var obj = {};27var constr = function(){};28wptk.linearize(obj, null, constr, 'test');29var obj = {};30var proto = {};31var constr = function(){};32var parent = {};33wptk.linearize(obj, proto, constr, 'test', parent);34var obj = {};35var proto = {};36var constr = function(){};37var parent = {};38wptk.linearize(obj, proto, constr, null, parent);39var obj = {};40var proto = {};41var constr = function(){};42var parent = {};43wptk.linearize(obj, proto, null, 'test', parent);44var obj = {};45var proto = {};46var constr = function(){};
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!