Best JavaScript code snippet using wpt
cff_parser_spec.js
Source:cff_parser_spec.js
...60 afterAll(function () {61 fontData = null;62 });63 beforeEach(function () {64 parser = new CFFParser(fontData, {}, SEAC_ANALYSIS_ENABLED);65 cff = parser.parse();66 });67 afterEach(function () {68 parser = cff = null;69 });70 it("parses header", function () {71 const header = cff.header;72 expect(header.major).toEqual(1);73 expect(header.minor).toEqual(0);74 expect(header.hdrSize).toEqual(4);75 expect(header.offSize).toEqual(1);76 });77 it("parses name index", function () {78 const names = cff.names;79 expect(names.length).toEqual(1);80 expect(names[0]).toEqual("ABCDEF+Times-Roman");81 });82 it("parses string index", function () {83 const strings = cff.strings;84 expect(strings.count).toEqual(3);85 expect(strings.get(0)).toEqual(".notdef");86 expect(strings.get(391)).toEqual("001.007");87 });88 it("parses top dict", function () {89 const topDict = cff.topDict;90 // 391 version 392 FullName 393 FamilyName 389 Weight 28416 UniqueID91 // -168 -218 1000 898 FontBBox 94 CharStrings 45 102 Private92 expect(topDict.getByName("version")).toEqual(391);93 expect(topDict.getByName("FullName")).toEqual(392);94 expect(topDict.getByName("FamilyName")).toEqual(393);95 expect(topDict.getByName("Weight")).toEqual(389);96 expect(topDict.getByName("UniqueID")).toEqual(28416);97 expect(topDict.getByName("FontBBox")).toEqual([-168, -218, 1000, 898]);98 expect(topDict.getByName("CharStrings")).toEqual(94);99 expect(topDict.getByName("Private")).toEqual([45, 102]);100 });101 it("refuses to add topDict key with invalid value (bug 1068432)", function () {102 const topDict = cff.topDict;103 const defaultValue = topDict.getByName("UnderlinePosition");104 topDict.setByKey(/* [12, 3] = */ 3075, [NaN]);105 expect(topDict.getByName("UnderlinePosition")).toEqual(defaultValue);106 });107 it(108 "ignores reserved commands in parseDict, and refuses to add privateDict " +109 "keys with invalid values (bug 1308536)",110 function () {111 const bytes = new Uint8Array([112 64, 39, 31, 30, 252, 114, 137, 115, 79, 30, 197, 119, 2, 99, 127, 6,113 ]);114 parser.bytes = bytes;115 const topDict = cff.topDict;116 topDict.setByName("Private", [bytes.length, 0]);117 const parsePrivateDict = function () {118 parser.parsePrivateDict(topDict);119 };120 expect(parsePrivateDict).not.toThrow();121 const privateDict = topDict.privateDict;122 expect(privateDict.getByName("BlueValues")).toBeNull();123 }124 );125 it("parses a CharString having cntrmask", function () {126 // prettier-ignore127 const bytes = new Uint8Array([0, 1, // count128 1, // offsetSize129 0, // offset[0]130 38, // end131 149, 149, 149, 149, 149, 149, 149, 149,132 149, 149, 149, 149, 149, 149, 149, 149,133 1, // hstem134 149, 149, 149, 149, 149, 149, 149, 149,135 149, 149, 149, 149, 149, 149, 149, 149,136 3, // vstem137 20, // cntrmask138 22, 22, // fail if misparsed as hmoveto139 14 // endchar140 ]);141 parser.bytes = bytes;142 const charStringsIndex = parser.parseIndex(0).obj;143 const charStrings = parser.parseCharStrings({144 charStrings: charStringsIndex,145 privateDict: privateDictStub,146 }).charStrings;147 expect(charStrings.count).toEqual(1);148 // shouldn't be sanitized149 expect(charStrings.get(0).length).toEqual(38);150 });151 it("parses a CharString endchar with 4 args w/seac enabled", function () {152 const cffParser = new CFFParser(153 fontData,154 {},155 /* seacAnalysisEnabled = */ true156 );157 cffParser.parse(); // cff158 // prettier-ignore159 const bytes = new Uint8Array([0, 1, // count160 1, // offsetSize161 0, // offset[0]162 237, 247, 22, 247, 72, 204, 247, 86, 14]);163 cffParser.bytes = bytes;164 const charStringsIndex = cffParser.parseIndex(0).obj;165 const result = cffParser.parseCharStrings({166 charStrings: charStringsIndex,167 privateDict: privateDictStub,168 });169 expect(result.charStrings.count).toEqual(1);170 expect(result.charStrings.get(0).length).toEqual(1);171 expect(result.seacs.length).toEqual(1);172 expect(result.seacs[0].length).toEqual(4);173 expect(result.seacs[0][0]).toEqual(130);174 expect(result.seacs[0][1]).toEqual(180);175 expect(result.seacs[0][2]).toEqual(65);176 expect(result.seacs[0][3]).toEqual(194);177 });178 it("parses a CharString endchar with 4 args w/seac disabled", function () {179 const cffParser = new CFFParser(180 fontData,181 {},182 /* seacAnalysisEnabled = */ false183 );184 cffParser.parse(); // cff185 // prettier-ignore186 const bytes = new Uint8Array([0, 1, // count187 1, // offsetSize188 0, // offset[0]189 237, 247, 22, 247, 72, 204, 247, 86, 14]);190 cffParser.bytes = bytes;191 const charStringsIndex = cffParser.parseIndex(0).obj;192 const result = cffParser.parseCharStrings({193 charStrings: charStringsIndex,194 privateDict: privateDictStub,195 });196 expect(result.charStrings.count).toEqual(1);197 expect(result.charStrings.get(0).length).toEqual(9);198 expect(result.seacs.length).toEqual(0);199 });200 it("parses a CharString endchar no args", function () {201 // prettier-ignore202 const bytes = new Uint8Array([0, 1, // count203 1, // offsetSize204 0, // offset[0]205 14]);206 parser.bytes = bytes;207 const charStringsIndex = parser.parseIndex(0).obj;208 const result = parser.parseCharStrings({209 charStrings: charStringsIndex,210 privateDict: privateDictStub,211 });212 expect(result.charStrings.count).toEqual(1);213 expect(result.charStrings.get(0)[0]).toEqual(14);214 expect(result.seacs.length).toEqual(0);215 });216 it("parses predefined charsets", function () {217 const charset = parser.parseCharsets(0, 0, null, true);218 expect(charset.predefined).toEqual(true);219 });220 it("parses charset format 0", function () {221 // The first three bytes make the offset large enough to skip predefined.222 // prettier-ignore223 const bytes = new Uint8Array([0x00, 0x00, 0x00,224 0x00, // format225 0x00, 0x02 // sid/cid226 ]);227 parser.bytes = bytes;228 let charset = parser.parseCharsets(3, 2, new CFFStrings(), false);229 expect(charset.charset[1]).toEqual("exclam");230 // CID font231 charset = parser.parseCharsets(3, 2, new CFFStrings(), true);232 expect(charset.charset[1]).toEqual(2);233 });234 it("parses charset format 1", function () {235 // The first three bytes make the offset large enough to skip predefined.236 // prettier-ignore237 const bytes = new Uint8Array([0x00, 0x00, 0x00,238 0x01, // format239 0x00, 0x08, // sid/cid start240 0x01 // sid/cid left241 ]);242 parser.bytes = bytes;243 let charset = parser.parseCharsets(3, 2, new CFFStrings(), false);244 expect(charset.charset).toEqual([".notdef", "quoteright", "parenleft"]);245 // CID font246 charset = parser.parseCharsets(3, 2, new CFFStrings(), true);247 expect(charset.charset).toEqual([0, 8, 9]);248 });249 it("parses charset format 2", function () {250 // format 2 is the same as format 1 but the left is card16251 // The first three bytes make the offset large enough to skip predefined.252 // prettier-ignore253 const bytes = new Uint8Array([0x00, 0x00, 0x00,254 0x02, // format255 0x00, 0x08, // sid/cid start256 0x00, 0x01 // sid/cid left257 ]);258 parser.bytes = bytes;259 let charset = parser.parseCharsets(3, 2, new CFFStrings(), false);260 expect(charset.charset).toEqual([".notdef", "quoteright", "parenleft"]);261 // CID font262 charset = parser.parseCharsets(3, 2, new CFFStrings(), true);263 expect(charset.charset).toEqual([0, 8, 9]);264 });265 it("parses encoding format 0", function () {266 // The first two bytes make the offset large enough to skip predefined.267 // prettier-ignore268 const bytes = new Uint8Array([0x00, 0x00,269 0x00, // format270 0x01, // count271 0x08 // start272 ]);273 parser.bytes = bytes;274 const encoding = parser.parseEncoding(2, {}, new CFFStrings(), null);275 expect(encoding.encoding).toEqual(createWithNullProto({ 0x8: 1 }));276 });277 it("parses encoding format 1", function () {278 // The first two bytes make the offset large enough to skip predefined.279 // prettier-ignore280 const bytes = new Uint8Array([0x00, 0x00,281 0x01, // format282 0x01, // num ranges283 0x07, // range1 start284 0x01 // range2 left285 ]);286 parser.bytes = bytes;287 const encoding = parser.parseEncoding(2, {}, new CFFStrings(), null);288 expect(encoding.encoding).toEqual(289 createWithNullProto({ 0x7: 0x01, 0x08: 0x02 })290 );291 });292 it("parses fdselect format 0", function () {293 // prettier-ignore294 const bytes = new Uint8Array([0x00, // format295 0x00, // gid: 0 fd: 0296 0x01 // gid: 1 fd: 1297 ]);298 parser.bytes = bytes.slice();299 const fdSelect = parser.parseFDSelect(0, 2);300 expect(fdSelect.fdSelect).toEqual([0, 1]);301 expect(fdSelect.format).toEqual(0);302 });303 it("parses fdselect format 3", function () {304 // prettier-ignore305 const bytes = new Uint8Array([0x03, // format306 0x00, 0x02, // range count307 0x00, 0x00, // first gid308 0x09, // font dict 1 id309 0x00, 0x02, // next gid310 0x0a, // font dict 2 id311 0x00, 0x04 // sentinel (last gid)312 ]);313 parser.bytes = bytes.slice();314 const fdSelect = parser.parseFDSelect(0, 4);315 expect(fdSelect.fdSelect).toEqual([9, 9, 0xa, 0xa]);316 expect(fdSelect.format).toEqual(3);317 });318 it("parses invalid fdselect format 3 (bug 1146106)", function () {319 // prettier-ignore320 const bytes = new Uint8Array([0x03, // format321 0x00, 0x02, // range count322 0x00, 0x01, // first gid (invalid)323 0x09, // font dict 1 id324 0x00, 0x02, // next gid325 0x0a, // font dict 2 id326 0x00, 0x04 // sentinel (last gid)327 ]);328 parser.bytes = bytes.slice();329 const fdSelect = parser.parseFDSelect(0, 4);330 expect(fdSelect.fdSelect).toEqual([9, 9, 0xa, 0xa]);331 expect(fdSelect.format).toEqual(3);332 });333 // TODO fdArray334});335describe("CFFCompiler", function () {336 function testParser(bytes) {337 bytes = new Uint8Array(bytes);338 return new CFFParser(339 {340 getBytes: () => {341 return bytes;342 },343 },344 {},345 SEAC_ANALYSIS_ENABLED346 );347 }348 it("encodes integers", function () {349 const c = new CFFCompiler();350 // all the examples from the spec351 expect(c.encodeInteger(0)).toEqual([0x8b]);352 expect(c.encodeInteger(100)).toEqual([0xef]);...
Using AI Code Generation
1var CFFParser = require('./wptools').CFFParser;2var fs = require('fs');3var path = require('path');4var cffParser = new CFFParser();5cffParser.parseFile(path.join(__dirname, 'font.cff'), function(err, result) {6 if (err) {7 console.log('ERROR: ' + err);8 return;9 }10 console.log(result);11});12{ version: 1,13 [ { version: 391,14 private: [ 1, 0 ] } ],15 privateDictIndex: [ { blueValues: [], otherBlues: [], familyBlues: [], familyOtherBlues: [] } ] }16var charString = result.charStringsIndex[0];17var charString = result.charStringsIndex[0].toString();
Using AI Code Generation
1var wptools = require('wptools');2wptools.page('Barack Obama').then(function(page) {3 return page.getParse();4}).then(function(parse) {5 console.log(parse.json());6});7var wptools = require('wptools');8wptools.page('Barack Obama').then(function(page) {9 return page.getParse();10}).then(function(parse) {11 console.log(parse.wtf_wikipedia());12});13var wptools = require('wptools');14wptools.page('Barack Obama').then(function(page) {15 return page.getParse();16}).then(function(parse) {17 console.log(parse.wtf_wikipedia());18});19var wptools = require('wptools');20var page = wptools.page('Barack Obama', {format: 'json'});21page.getParse().then(function(parse) {22 console.log(parse.json());23});24var wptools = require('wptools');25var page = wptools.page('Barack Obama', {format: 'json'});26page.getParse().then(function(parse) {27 console.log(parse.wtf_wikipedia());28});29var wptools = require('wptools');30var page = wptools.page('Barack Obama', {format: 'json'});31page.getParse().then(function(parse) {32 console.log(parse.wtf_wikipedia());33});34var wptools = require('wptools');35var page = wptools.page('Barack Obama', {format: 'json'});36page.getParse().then(function(parse) {37 console.log(parse.wtf_wikipedia());38});39var wptools = require('wptools');40var page = wptools.page('Barack Obama', {format: 'json'});41page.getParse().then(function(parse) {42 console.log(parse.wtf_wikipedia());43});44var wptools = require('wptools');45var page = wptools.page('Barack Obama', {format: 'json'});46page.getParse().then(function(parse) {47 console.log(parse.wtf_wikipedia());48});49var wptools = require('wptools');50var page = wptools.page('Barack Obama', {format: 'json'});51page.getParse().then
Using AI Code Generation
1var parser = require('wptools').CFFParser;2var fs = require('fs');3var cff = fs.readFileSync('test.cff', 'utf8');4parser.parse(cff, function(err, data) {5 console.log(data);6});7var parser = require('wptools').CFFParser;8var fs = require('fs');9var cff = fs.readFileSync('test.cff', 'utf8');10parser.parse(cff, function(err, data) {11 console.log(data);12});13{14 {
Using AI Code Generation
1wptools.page('Wikipedia').then(function(response) {2 console.log(response);3});4wptools.page('Wikipedia', {format: 'json'}).then(function(response) {5 console.log(response);6});7wptools.page('Wikipedia', {format: 'json'}).then(function(response) {8 console.log(response.json());9});10wptools.page('Wikipedia', {format: 'json'}).then(function(response) {11 console.log(response.json().infobox);12});13wptools.page('Wikipedia', {format: 'json'}).then(function(response) {14 console.log(response.json().infobox.image);15});16wptools.page('Wikipedia', {format: 'json'}).then(function(response) {17 console.log(response.json().infobox.image.caption);18});19wptools.page('Wikipedia', {format: 'json'}).then(function(response) {20 console.log(response.json().infobox.image.caption.text);21});22wptools.page('Wikipedia', {format: 'json'}).then(function(response) {23 console.log(response.json().infobox.image.caption.text);24});25wptools.page('Wikipedia', {format: 'json'}).then(function(response) {26 console.log(response.json().infobox.image.caption.text);27});28wptools.page('Wikipedia', {format: 'json'}).then(function(response) {29 console.log(response.json().infobox.image.caption.text);30});31wptools.page('Wikipedia', {format: 'json'}).then(function(response) {
Using AI Code Generation
1const wptools = require('wptools');2const CFFParser = require('cff-parser-js');3let cff = new CFFParser().parse('test.cff');4console.log(cff);5let metadata = cff.getMetadata();6console.log(metadata);7let softwareName = cff.getSoftwareName();8console.log(softwareName);9let softwareVersion = cff.getSoftwareVersion();10console.log(softwareVersion);11let softwareTitle = cff.getSoftwareTitle();12console.log(softwareTitle);13let softwareDOI = cff.getSoftwareDOI();14console.log(softwareDOI);15let softwareURL = cff.getSoftwareURL();16console.log(softwareURL);17let softwareRepository = cff.getSoftwareRepository();18console.log(softwareRepository);19let softwareAuthors = cff.getSoftwareAuthors();20console.log(softwareAuthors);21let softwareReferences = cff.getSoftwareReferences();22console.log(softwareReferences);23let softwareKeywords = cff.getSoftwareKeywords();24console.log(softwareKeywords);25let softwareLicense = cff.getSoftwareLicense();26console.log(softwareLicense);27let softwareVersion = cff.getSoftwareVersion();28console.log(softwareVersion);29let softwareTitle = cff.getSoftwareTitle();30console.log(softwareTitle);31let softwareDOI = cff.getSoftwareDOI();32console.log(softwareDOI);33let softwareURL = cff.getSoftwareURL();34console.log(softwareURL);35let softwareRepository = cff.getSoftwareRepository();36console.log(softwareRepository);37let softwareAuthors = cff.getSoftwareAuthors();38console.log(softwareAuthors);39let softwareReferences = cff.getSoftwareReferences();40console.log(softwareReferences);41let softwareKeywords = cff.getSoftwareKeywords();42console.log(softwareKeywords);43let softwareLicense = cff.getSoftwareLicense();44console.log(softwareLicense);
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!!