Best JavaScript code snippet using playwright-internal
test.linkage.js
Source:test.linkage.js
...50 afterEach(function(done) {51 $containers.empty()52 done()53 })54 function genNode(id, name, type, checked, disabled, children) {55 _.each(children, function(item /*, index*/ ) {56 item.pid = id57 item.pname = name58 })59 return {60 id: id,61 pid: undefined,62 name: name,63 pname: undefined,64 value: id,65 type: type,66 checked: !!checked,67 disabled: !!disabled,68 children: children || [],69 html: function() {70 return TPL(this)71 }72 }73 }74 genNode.checkbox = function(id, checked, disabled, children) {75 return genNode(id, Random.cword(5), 'checkbox', checked, disabled, children)76 }77 genNode.radio = function(id, checked, disabled, children) {78 return genNode(id, Random.cword(5), 'radio', checked, disabled, children)79 }80 function genData(type) {81 return genNode[type]('ROOT', false, false, [82 genNode[type]('1', false, false, [83 genNode[type]('1-1', false, false, [84 genNode[type]('1-1-1', false, false, []), genNode[type]('1-1-2', false, false, []), genNode[type]('1-1-3', false, false, [])85 ]),86 genNode[type]('1-2', false, false, [87 genNode[type]('1-2-1', false, false, []), genNode[type]('1-2-2', false, false, []), genNode[type]('1-2-3', false, false, [])88 ]),89 genNode[type]('1-3', false, false, [90 genNode[type]('1-3-1', false, false, []), genNode[type]('1-3-2', false, false, []), genNode[type]('1-3-3', false, false, [])91 ])92 ]),...
fingerSpellCopy.js
Source:fingerSpellCopy.js
...122 initPhalanges(vBuffer);123 render();124}125function initPhalanges(id){126 palm = new genNode(id,1,.75,.3,0,0,0,0,-.5,0);127 thumb1 = new genNode(id,.5,.6,1,0,0,-45,1.5,-.75,0);128 // thumb2 = new genNode(id,1,1,1,0,0,0,0,0,0);129 // thumb3 = new genNode(id,1,1,1,0,0,0,0,0,0);130 palm.leftChild = thumb1;131 // thumb1.leftChild = thumb2;132 // thumb2.leftChild = thumb3;133 // index1 = new genNode(id,.1,.4,.2,0,0,0,0,0,0);134 // index2 = new genNode(id,1,1,1,0,0,0,0,0,0);135 // index3 = new genNode(id,1,1,1,0,0,0,0,0,0);136 // thumb1.rightSibling = index1;137 // index1.leftChild = index2;138 // index2.leftChild = index3;139 // middle1 = new genNode(id,.2,.4,.2,0,0,0,0,0,0);140 // middle2 = new genNode(id,1,1,1,0,0,0,0,0,0);141 // middle3 = new genNode(id,1,1,1,0,0,0,0,0,0);142 // index1.rightSibling = middle1;143 // middle1.leftChild = middle2;144 // middle2.leftChild = middle3;145 // ring1 = new genNode(id,.2,.4,.2,0,0,0,0,0,0);146 // ring2 = new genNode(id,1,1,1,0,0,0,0,0,0);147 // ring3 = new genNode(id,1,1,1,0,0,0,0,0,0);148 // middle1.rightSibling = ring1;149 // ring1.leftChild = ring2;150 // ring2.leftChild = ring3;151 // pinky1 = new genNode(id,.2,.2,.2,0,0,0,0,0,0);152 // pinky2 = new genNode(id,1,1,1,0,0,0,0,0,0);153 // pinky3 = new genNode(id,1,1,1,0,0,0,0,0,0);154 // ring1.rightSibling = pinky1;155 // pinky1.leftChild = pinky2;156 // pinky2.leftChild = pinky3;157}158//----------------------------------------------------------------------------159function base() {160 var s = scale4(palm.initialPos.xScale, palm.initialPos.yScale, palm.initialPos.zScale);161 var instanceMatrix = mult( translate( 0.0, 0.5 * palm.initialPos.yScale, 0.0 ), s);162 var t = mult(modelViewMatrix, instanceMatrix);163 gl.uniformMatrix4fv(modelViewMatrixLoc, false, flatten(t) );164 gl.drawArrays( gl.TRIANGLES, 0, newCylinderVertices.length );165}166//----------------------------------------------------------------------------167function upperArm() {...
gennode.js
Source:gennode.js
1#!/usr/bin/env node2/**3 * @fileoverview This utility reads the node source directory and parses4 * all core library objects with the help of markdown files and additional5 * metadata held in typedata.txt. This information is used to generate6 * wrappers to these libs that provide closure friendly way of writing7 * node code.8 *9 * @author guido@tapia.com.au (Guido Tapia)10 */11require('nclosure').nclosure();12goog.provide('nclosure.gennode.gennode');13// Ensure you do not add dependencies on the node. namespace as it may14// not exist as this is the class responsible for creating it.15goog.require('goog.array');16goog.require('goog.object');17goog.require('nclosure.gennode.processor');18goog.require('nclosure.gennode.utils');19/**20 * @constructor21 */22nclosure.gennode.gennode = function() {23 this.allLibFiles_ = this.getAllLibFiles_();24 this.allMarkdownFiles_ = this.getAllMarkdownFiles_();25 this.allDocs_ = this.parseAllDocs_();26 this.allTypeData_ = this.parseAllTypeData_();27 this.processGlobalObjects_();28 this.processFiles_();29};30/**31 * @private32 */33nclosure.gennode.gennode.prototype.processGlobalObjects_ = function() {34 this.writeDummyDocObjects_('node', this.allDocs_['synopsis.']);35 for (var i in nclosure.gennode.utils.REQUIRED_GLOBALS_) {36 var obj = nclosure.gennode.utils.REQUIRED_GLOBALS_[i];37 if (typeof(obj) !== 'object') continue;38 this.processObject_(i, obj, i,39 i === 'global' ? this.allDocs_['globals.'] : '');40 }41};42/**43 * @private44 * @param {string} name The name of the class to create.45 * @param {string} overview The overview of this mock class.46 */47nclosure.gennode.gennode.prototype.writeDummyDocObjects_ =48 function(name, overview) {49 var dummy = new nclosure.gennode.clazz(name);50 dummy.createNamespace(name, overview);51 nclosure.gennode.processor.dumpClassFile(name, dummy);52};53/**54 * @private55 */56nclosure.gennode.gennode.prototype.processFiles_ = function() {57 this.allLibFiles_.slice(0, 1);58 goog.array.forEach(this.allLibFiles_, this.processJSFile_, this);59};60/**61 * @private62 * @param {string} f The filename to read and process.63 */64nclosure.gennode.gennode.prototype.processJSFile_ = function(f) {65 if (f.indexOf('_') === 0) return; // Ignore privates66 var js = require('fs').readFileSync(67 nclosure.gennode.utils.NODE_LIB_DIR_ + f);68 var ctx = goog.object.clone(nclosure.gennode.utils.REQUIRED_GLOBALS_);69 var fileExports = {};70 ctx.exports = fileExports;71 try { process.binding('evals').Script.runInNewContext(js, ctx, f); }72 catch (ex) { console.error('Not parsing: ' + f + ' ex: ' + ex.message); }73 this.processObject_(f, fileExports);74};75/**76 * @private77 * @param {string} name The name of this object.78 * @param {Object} obj An instance of this object.79 * @param {string=} coreRequires If specified will not use the defaule80 * require('type') to initialise the node object.81 * @param {string=} overrideOverview Namespace documentation to override.82 */83nclosure.gennode.gennode.prototype.processObject_ =84 function(name, obj, coreRequires, overrideOverview) {85 new nclosure.gennode.processor(name, true, obj, this.allDocs_,86 this.allTypeData_, coreRequires, overrideOverview).process();87};88/**89 * @private90 * @return {Array.<string>} All the core node js files.91 */92nclosure.gennode.gennode.prototype.getAllLibFiles_ = function() {93 return require('fs').readdirSync(nclosure.gennode.utils.NODE_LIB_DIR_);94};95/**96 * @private97 * @return {Object.<string, string>} The object -> doc map for all objects in98 * the markdown docs.99 */100nclosure.gennode.gennode.prototype.parseAllDocs_ = function() {101 var map = {};102 goog.array.forEach(this.allMarkdownFiles_, function(f) {103 var contents = require('fs').readFileSync(104 nclosure.gennode.utils.NODE_DOC_DIR_ + f).105 toString();106 var fileMap = this.parseDocContents_(f, contents);107 for (var i in fileMap) {108 if (i in map) throw new Error(i +109 ' already exists in the objects->documents map');110 map[i] = fileMap[i];111 }112 }, this);113 return map;114};115/**116 * @private117 * @param {string} name The name of the file.118 * @param {string} contents The markdown to parse for object documentation.119 * @return {Object.<string, string>} The object -> doc map for this markdown120 * contents.121 */122nclosure.gennode.gennode.prototype.parseDocContents_ =123 function(name, contents) {124 var map = {};125 var classes = contents.split(/^##\s/gm);126 name = name.split('.')[0];127 goog.array.forEach(classes, function(c, i) {128 if (!c) return;129 var className = i === 1 ? name : c.substring(0, c.indexOf('\n'));130 className = className.replace('child_processes', 'child_process');131 var members = c.split(/^###\s/gm);132 goog.array.forEach(members, function(m, i) {133 var mname = m.substring(0, m.indexOf('\n'));134 if (mname.indexOf('*/') >= 0) {135 mname = mname.substring(mname.indexOf('*/') + 1);136 }137 if (mname.indexOf('(') >= 0) {138 mname = mname.substring(0, mname.indexOf('('));139 } if (mname.indexOf('.') >= 0) {140 mname = mname.split('.')[1];141 }142 m = this.formatDocs_(m);143 var id = nclosure.gennode.utils.getClassAndMemberID(144 className, i > 0 ? mname : undefined);145 map[id] = m;146 }, this);147 }, this);148 return map;149};150/**151 * @private152 * @param {string} d The document to format.153 * @return {string} The formatted document.154 */155nclosure.gennode.gennode.prototype.formatDocs_ = function(d) {156 // Remove the first line which just has the name157 d = d.substring(d.indexOf('\n')).replace(/\//g, '/');158 d = d.replace(/`([^`]+)`/g,159 '<code>$1</code>');160 d = d.replace(/___([^_]+)___/g, '<em><strong>$1</strong></em>');161 d = d.replace(/__([^_]+)__/g, '<strong>$1</strong>');162 d = d.replace(/_([^_]+)_/g, '<em>$1</em>');163 // TODO: The replace below is very inflexible164 d = d.replace(/\[([^\]]+)\]\(([^\)]+)\)/g, '<a href="node.$2">$1</a>');165 // Put code samples in <pre> tags166 var lines = d.split('\n');167 var incode = false;168 var prev;169 for (var i = 0, len = lines.length; i < len; i++) {170 var l = lines[i];171 if (!incode && l.indexOf(' ') === 0 && prev === '') {172 lines[i - 1] = '<pre>';173 incode = true;174 } else if (incode && l.indexOf(' ') !== 0 && prev === '') {175 lines[i - 1] = '</pre>';176 incode = false;177 }178 prev = l;179 }180 return goog.string.trim(lines.join('\n'));181};182/**183 * @private184 * @return {Object.<string>} All the type data in the typedata.txt file.185 */186nclosure.gennode.gennode.prototype.parseAllTypeData_ = function() {187 var contents =188 require('fs').readFileSync(__dirname + '/typedata.txt').189 toString().split('\n');190 var parsed = {};191 goog.array.forEach(contents, function(c) {192 if (!c || c.indexOf('#') === 0) return; // Ignore comments193 var idx = c.indexOf('=');194 parsed[c.substring(0, idx)] = c.substring(idx + 1);195 });196 return parsed;197};198/**199 * @private200 * @return {Array.<string>} All the markdown files in the node api dir.201 */202nclosure.gennode.gennode.prototype.getAllMarkdownFiles_ = function() {203 return require('fs').readdirSync(nclosure.gennode.utils.NODE_DOC_DIR_);204};...
clazz.js
Source:clazz.js
1/**2 * @fileoverview This file represents the metadata of a closre class. It3 * provides helpers to generate string representation of this class also.4 *5 * Note: This class is used by nclosure.gennode.gennode which is the entry6 * point to this application.7 *8 * @author guido@tapia.com.au (Guido Tapia)9 */10goog.provide('nclosure.gennode.clazz');11goog.require('goog.array');12goog.require('goog.string');13goog.require('nclosure.gennode.type');14/**15 * @constructor16 * @param {string} name The name of this class.17 * @param {string=} overview The fileOvervio of the class.18 * @param {Array.<nclosure.gennode.type>=} requireNamespaces The namespaces19 * required by this class.20 */21nclosure.gennode.clazz = function(name, overview, requireNamespaces) {22 /**23 * @private24 * @type {string}25 */26 this.clazzName_ = name;27 /**28 * @private29 * @type {Array.<string>}30 */31 this.clazzNameParts_ = this.clazzName_.split('.');32 /**33 * @type {string}34 */35 this.nodeRequire = 'require("' +36 this.clazzNameParts_[this.clazzNameParts_.length - 1] + '")';37 /**38 * @private39 * @type {string|undefined}40 */41 this.overview_ = overview;42 /**43 * @private44 * @type {Array.<nclosure.gennode.type>|undefined}45 */46 this.requireNamespaces_ = requireNamespaces;47 /**48 * @private49 * @type {string}50 */51 this.constructor_ = '';52 /**53 * @private54 * @type {string}55 */56 this.namespace_ = '';57 /**58 * @private59 * @type {Array.<string>}60 */61 this.attributes_ = [];62 /**63 * @private64 * @type {Array.<string>}65 */66 this.functions_ = [];67 /**68 * @private69 * @type {Array.<string>}70 */71 this.requires_ = [];72};73/**74 * @param {string} name The name of this namespace.75 * @param {string} desc The description of this namespace.76 */77nclosure.gennode.clazz.prototype.createNamespace = function(name, desc) {78 var jsdoc = ['@name ' + name, '@namespace'];79 if (desc) jsdoc.push(desc);80 this.namespace_ = nclosure.gennode.clazz.buildJSDoc_(jsdoc);81};82/**83 * @param {string} desc The description of this constructor.84 * @param {Array.<nclosure.gennode.type>=} args Args to this constructor.85 * @param {boolean=} priv Wether the constructor is private.86 */87nclosure.gennode.clazz.prototype.createConstructor =88 function(desc, args, priv) {89 if (this.constructor_)90 throw new Error('A class can only have one constructor');91 var jsdoc = [];92 if (priv) jsdoc.push('@private');93 if (desc) jsdoc.push(desc);94 if (args) goog.array.forEach(args, function(t) {95 jsdoc.push(typeof(t) === 'string' ? t : t.toParamString());96 });97 jsdoc.push('@constructor');98 // TODO support function args to constructor99 this.constructor_ = nclosure.gennode.clazz.buildJSDoc_(jsdoc) +100 '\n' + this.clazzName_ + ' = function() {};';101};102/**103 * @param {string} type The type that this class depends on. Will be104 * required. Safe to call multiple times.105 */106nclosure.gennode.clazz.prototype.addRequires = function(type) {107 if (this.requires_.indexOf(type) >= 0) return;108 this.requires_.push(type);109};110/**111 * @param {string} type The type of this attribute.112 * @param {string} name The attribute name.113 * @param {string} desc A description of this attribute.114 * @param {boolean} isStatic wether this attribute is a static attribute (or115 * else a class attribute).116 */117nclosure.gennode.clazz.prototype.addAttr =118 function(type, name, desc, isStatic) {119 var jsdoc = [];120 if (desc) jsdoc.push(desc);121 jsdoc.push('@type {' + type + '|null}');122 var attr = nclosure.gennode.clazz.buildJSDoc_(jsdoc) + '\n' + this.clazzName_;123 if (!isStatic) attr += '.prototype';124 attr += ('.' + name + ' = null;');125 this.attributes_.push(attr);126};127/**128 * @param {string} name The function name.129 * @param {string} desc A description of this function.130 * @param {Array.<nclosure.gennode.type>} args Args to this function.131 * @param {nclosure.gennode.type} returnType The return type of this function.132 * @param {boolean} isStatic wether this function is a static attribute (or133 * else a class attribute).134 */135nclosure.gennode.clazz.prototype.addFunct =136 function(name, desc, args, returnType, isStatic) {137 var jsdoc = [];138 if (desc) jsdoc.push(desc);139 if (args) goog.array.forEach(args, function(a) {140 jsdoc.push(a.toParamString());141 });142 if (returnType) jsdoc.push(returnType.toReturnString());143 var funct = nclosure.gennode.clazz.buildJSDoc_(jsdoc) + '\n' +144 this.clazzName_ + '.';145 if (!isStatic) funct += 'prototype' + '.';146 funct += name + ' = function(';147 if (args) goog.array.forEach(args, function(a, idx) {148 if (idx > 0) funct += ', ';149 funct += a.name;150 });151 funct += ') {\n return ' + this.clazzName_ + '.core_.' + name + '.apply(' +152 this.clazzName_ + '.core_, arguments);\n};';153 this.functions_.push(funct);154};155/**156 * @private157 * @param {Array.<string>} parts The lines of this jsdoc.158 * @return {string} The jsdoc.159 */160nclosure.gennode.clazz.buildJSDoc_ = function(parts) {161 return '/**\n * ' + parts.join('\n * ') + '\n */';162};163/**164 * @override165 * @return {string} The string representation of this class ready to be166 * written to disc.167 */168nclosure.gennode.clazz.prototype.toString = function() {169 var buffer = [];170 if (this.namespace_) buffer.push(this.namespace_);171 buffer.push('\ngoog.provide("' + this.clazzName_ + '");\n');172 if (this.overview_) {173 buffer.push(nclosure.gennode.clazz.buildJSDoc_(174 ['@fileOverview ' + this.overview_]));175 buffer.push('');176 }177 goog.array.forEach(this.requires_, function(r) {178 buffer.push('goog.require("' + r + '");');179 });180 if (this.requires_.length > 0) {181 buffer.push('');182 }183 if (this.constructor_) {184 buffer.push(this.constructor_);185 buffer.push('');186 }187 goog.array.forEach(this.attributes_, function(a) {188 buffer.push(a.toString());189 buffer.push('');190 });191 goog.array.forEach(this.functions_, function(f) {192 buffer.push(f.toString());193 buffer.push('');194 });195 buffer.push(nclosure.gennode.clazz.CORE_PREFIX_ + this.clazzName_ +196 '.core_ = ' + this.nodeRequire + ';');197 // Remove all trailing whitespaces198 return goog.array.map(buffer.join('\n').split('\n'), goog.string.trimRight).199 join('\n');200};201/**202 * @private203 * @type {string}204 * const205 */...
nodes.js
Source:nodes.js
...91 file.ast.push(token);92 file.prevToken = token;93 };94};95genNode('Feature', function(file, token) {96 file.state = 'FEATURE';97 file.on('stateChange', function(state) {98 file.prevState = file.state;99 file.state = state;100 });101});102genNode('Background', function(file, token) {103 file.emit('stateChange', 'BACKGROUND');104 file.feature.background = {105 lineno: token[1],106 steps: [],107 stepArgs: {}108 };109});110genNode('Teardown', function(file) {111 file.emit('stateChange', 'TEARDOWN')112});113genNode('Scenario', function(file, token) {114 file.emit('stateChange', 'SCENARIO');115 file.feature.scenarios.push({116 lineno: token[1],117 steps: [],118 stepArgs: {}119 });120 file.setScenarioIndex();121});122genNode('Outline', function(file, token) {123 file.emit('stateChange', 'OUTLINE');124 file.feature.scenarios.push({125 lineno: token[1],126 steps: [],127 examples: [],128 stepArgs: {},129 isOutline: true130 });131 file.setScenarioIndex();132});133genNode('Step');134genNode('Tag', function(file, token) {135 switch(token[0]) {136 case 'FEATURE_TAG':137 file.feature.tag = token[2];138 break;139 case 'SCENARIO_TAG':140 file.currentScenario().tag = token[2];141 break;142 case 'OUTLINE_TAG':143 file.currentScenario().tag = token[2];144 break;145 };146});147genNode('Serial', function(file, token) {148 console.error('The serial directive is deprecated, all tests run serially. Please remove the directive from your features.')149});150 151genNode('Timeout', function(file, token) {152 file.feature.timeout = parseInt(token[2].split(' ')[1], 10);153});154genNode('Line', function(file, token) {155 switch(token[0]) {156 case 'FEATURE_DESCRIPTION':157 file.feature.name = token[2];158 break;159 case 'BACKGROUND_DESCRIPTION':160 file.feature.background.name = token[2];161 break;162 case 'SCENARIO_DESCRIPTION':163 case 'OUTLINE_DESCRIPTION':164 file.currentScenario().name = token[2];165 break;166 case 'STEP_DESCRIPTION':167 var stepToken = [file.prevToken[2], token[1], token[2]];168 file.vars.currentStepLine = token[1];169 if (file.prevToken[2] === 'And' || file.prevToken[2] === 'But') {170 if (file.vars.prevStepType !== undefined) {171 stepToken[3] = file.vars.prevStepType;172 }173 } else {174 file.vars.prevStepType = file.prevToken[2];175 }176 if (file.state === 'BACKGROUND') {177 file.feature.background.steps.push(stepToken);178 file.setBackgroundStepIndex();179 } else if (file.state === 'TEARDOWN') {180 _(file.feature.scenarios).each(function(scenario) {181 scenario.steps.push(stepToken);182 });183 } else {184 file.currentScenario().steps.push(stepToken);185 file.setStepIndex();186 }187 break;188 case 'LINE':189 if (file.state === 'FEATURE') {190 file.feature.description += token[2] + "\n";191 }192 break;193 };194});195genNode('Pystring', function(file, token) {196 file.capturePyString(token);197});198genNode('Table', function(file, token) {199 file.captureFitTables(token);200});201genNode('Examples', function(file, token) {202 if (file.currentScenario() !== undefined) {203 if (file.currentScenario().isOutline) {204 file.captureScenarioExamples(token);205 }206 }207});208genNode('Newline');...
gennodeClazzTests.js
Source:gennodeClazzTests.js
1goog.require('goog.array');2goog.require('goog.testing.jsunit');3goog.require('nclosure.gennode.clazz');4goog.require('nclosure.gennode.type');5var coreprefix = '\n\n\n/**\n * @private\n * @type {*}\n */\n';6function testBuildJSDoc_() {7 assertEquals_('/**\n * test\n */', nclosure.gennode.clazz.buildJSDoc_(['test']));8}9function testEmptyClass() {10 var c = new nclosure.gennode.clazz('ncnode.test.className');11 var exp = '\ngoog.provide("ncnode.test.className");' +12 coreprefix + 'ncnode.test.className.core_ = require("className");';13 assertEquals_(exp, c.toString());14}15function testEmptyClassWithOverview() {16 var c = new nclosure.gennode.clazz('ncnode.test.className', 'foo');17 var exp = '\ngoog.provide("ncnode.test.className");\n\n/**\n' +18 ' * @fileOverview foo\n */' +19 coreprefix + 'ncnode.test.className.core_ = require("className");';20 assertEquals_(exp, c.toString());21}22function testConstructorWithNoDescAndNoArgs() {23 var c = new nclosure.gennode.clazz('ncnode.test.className');24 c.createConstructor();25 assertEquals_('/**\n * @constructor\n' +26 ' */\nncnode.test.className = function() {};', c.constructor_);27}28function testConstructorWithNoDesc() {29 var c = new nclosure.gennode.clazz('ncnode.test.className');30 c.createConstructor('desc');31 assertEquals_('/**\n * desc\n * @constructor\n */\n' +32 'ncnode.test.className = function() {};', c.constructor_);33}34function testConstructorWithArgs() {35 var c = new nclosure.gennode.clazz('ncnode.test.className');36 c.createConstructor(null, [37 new nclosure.gennode.type('type.ns', 'arg1'),38 new nclosure.gennode.type('type.ns2', 'arg2', 'desc')39 ]);40 assertEquals_('/**\n * @param {type.ns} arg1' +41 '\n * @param {type.ns2} arg2 desc\n * @constructor\n */\n' +42 'ncnode.test.className = function() {};', c.constructor_);43}44function testConstructorWithDescAndArgs() {45 var c = new nclosure.gennode.clazz('ncnode.test.className');46 c.createConstructor('desc', [47 new nclosure.gennode.type('type.ns', 'arg1')48 ]);49 assertEquals_('/**\n * desc\n' +50 ' * @param {type.ns} arg1\n * @constructor\n */\n' +51 'ncnode.test.className = function() {};',52 c.constructor_);53}54function testAddAttribute() {55 var c = new nclosure.gennode.clazz('c');56 var exp = '\ngoog.provide("c");\n' +57 '\n/**\n * @type {type.ns|null}\n */\nc.prototype.attr1 = null;' +58 coreprefix + 'c.core_ = require("c");';59 c.addAttr('type.ns', 'attr1');60 assertEquals_(exp, c.toString());61}62function testAddMultipleAttribute() {63 var c = new nclosure.gennode.clazz('c');64 var exp = '\ngoog.provide("c");\n' +65 '\n/**\n * @type {type.ns|null}\n */\nc.prototype.attr1 = null;\n' +66 '\n/**\n * desc\n * @type {type.ns2|null}\n */\nc.prototype.attr2 = null;\n' +67 '\n/**\n * desc3\n * @type {type.ns3|null}\n */\nc.attr3 = null;' +68 coreprefix + 'c.core_ = require("c");';69 c.addAttr('type.ns', 'attr1');70 c.addAttr('type.ns2', 'attr2', 'desc');71 c.addAttr('type.ns3', 'attr3', 'desc3', true);72 assertEquals_(exp, c.toString());73}74function testAddFunct() {75 var c = new nclosure.gennode.clazz('c');76 var exp = '\ngoog.provide("c");\n' +77 '\n/**\n *\n */\nc.prototype.functName = function() {' +78 '\n return c.core_.functName.apply(c.core_, arguments);' +79 '\n};' +80 coreprefix + 'c.core_ = require("c");';81 c.addFunct('functName');82 assertEquals_(exp, c.toString());83}84function testAddFuncts() {85 var c = new nclosure.gennode.clazz('c');86 var exp = '\ngoog.provide("c");\n' +87 '\n/**\n *\n */\nc.prototype.functName = function() {' +88 '\n return c.core_.functName.apply(c.core_, arguments);' +89 '\n};\n' +90 '\n/**\n * desc2\n */\nc.prototype.functName2 = function() {' +91 '\n return c.core_.functName2.apply(c.core_, arguments);' +92 '\n};\n' +93 '\n/**\n * desc3\n * @return {ret.type}\n */\n' +94 'c.prototype.functName3 = function() {' +95 '\n return c.core_.functName3.apply(c.core_, arguments);' +96 '\n};\n' +97 '\n/**\n * @param {type.ns} arg1\n */\nc.prototype.functName4 = ' +98 'function(arg1) {' +99 '\n return c.core_.functName4.apply(c.core_, arguments);' +100 '\n};\n' +101 '\n/**' +102 '\n * @param {type.ns} arg1' +103 '\n * @param {type.ns2} arg2 desc' +104 '\n * @return {ret.type5}' +105 '\n */\nc.functName5 = ' +106 'function(arg1, arg2) {' +107 '\n return c.core_.functName5.apply(c.core_, arguments);' +108 '\n};' +109 coreprefix + 'c.core_ = require("c");';110 c.addFunct('functName');111 c.addFunct('functName2', 'desc2');112 c.addFunct('functName3', 'desc3', null, new nclosure.gennode.type('ret.type'));113 c.addFunct('functName4', null, [new nclosure.gennode.type('type.ns', 'arg1')]);114 c.addFunct('functName5', null, [115 new nclosure.gennode.type('type.ns', 'arg1'),116 new nclosure.gennode.type('type.ns2', 'arg2', 'desc')117 ], new nclosure.gennode.type('ret.type5'), true);118 assertEquals_(exp, c.toString());119}120function testNodeRequire() {121 var c = new nclosure.gennode.clazz('c');122 c.nodeRequire = 'alternateInitialisation()';123 var exp = '\ngoog.provide("c");' +124 coreprefix + 'c.core_ = alternateInitialisation();';125 assertEquals_(exp, c.toString());126}127function assertEquals_(exp, actual) {128 // console.error(exp.split('\n'));129 // console.error(actual.split('\n'));130 assertEquals(exp, actual);...
isMatch-状态机生成.js
Source:isMatch-状态机生成.js
1/*2 * @lc app=leetcode.cn id=10 lang=javascript3 *4 * [10] æ£å表达å¼å¹é
5 */6// @lc code=start7/**8 * @param {string} s9 * @param {string} p10 * @return {boolean}11 */12 const getNodeList = (pattern) => {13 const nodeList = [];14 for(const char of pattern) {15 if(char == '*') {16 current.type = 'ANY';17 } else {18 current = {19 type: 'NORMAL',20 char: char == '.'?'EVERY':char 21 };22 nodeList.push(current);23 }24 }25 return nodeList;26}27const getGenerator = (nodeList) => {28 let start = {29 type: 'START',30 next: []31 };32 let currentList = [start];33 for(const node of nodeList) {34 if(node.type == 'ANY') {35 const genNode = {36 type: 'NORMAL',37 char: node.char,38 next: []39 };40 genNode.next.push(genNode);41 currentList.forEach(current => current.next.push(genNode));42 currentList.push(genNode);43 } else {44 const genNode = {45 ...node,46 next: []47 }48 currentList.forEach(current => current.next.push(genNode));49 currentList = [genNode];50 }51 }52 currentList.forEach(current => current.next.push({53 type: 'END'54 }))55 return start;56} 57const test = (str, generator) => {58 if(generator.type == 'END' || str.length == 0) {59 return generator.type == 'END' && str.length == 0;60 }61 let _str;62 if(generator.type == 'START') {63 _str = str;64 } else {65 if(generator.char !== 'EVERY' && generator.char !== str[0]) return false;66 _str = str.substring(1);67 }68 return generator.next.some(_gen => test(_str, _gen));69}70var isMatch = function(s, p) {71 const nodeList = getNodeList(p);72 const generatorStart = getGenerator(nodeList);73 return test(s, generatorStart);74};...
codegen.js
Source:codegen.js
1const codegen = (ast) =>{2 let js = '';3 ast.forEach((node)=>{4 js += genNode(node);5 });6 return js;7};8const genNode = (node)=>{9 if (node.type === 'identifier') {10 return node.name;11 } else if (node.type === 'number') {12 return node.value;13 } else if (node.type === 'property') {14 return node.object + "." + node.property;15 } else if(node.type === 'expression') {16 const logic = {17 'and' : '&&',18 'or' : '||'19 }20 return genNode(node.left) + ' '21 + logic[node.logic] + ' '22 + genNode(node.right);23 } else if (node.type === 'method') {24 return node.object + "." + node.method + "(); ";25 } else if (node.type === "finish"){26 return "return; ";27 } else if (node.type === 'math') {28 return genNode(node.left) + ' '29 + node.operator + ' '30 + genNode(node.right);31 } else if (node.type === 'if') {32 return 'if (' +33 genNode(node.condition) +34 ') {\n' +35 codegen(node.body) +36 '}';37 } else if(node.type === 'while') {38 return 'while (' +39 genNode(node.condition) +40 ') {\n' +41 codegen(node.body) +42 '}';43 } else if(node.type === 'comparison') {44 const operators = {45 '=' : '===',46 '<=' : '<==',47 '>=' : '>==',48 '<' : '<',49 '>' : '>',50 }51 const jsOperator = operators[node.operator];52 return genNode(node.left) + ' '53 + jsOperator + ' '54 + genNode(node.right);55 } else {56 return new Error('Unkonwn node: ' + JSON.stringify(node));57 }58};...
Using AI Code Generation
1const playwright = require('playwright');2const { genNode } = require('playwright/lib/server/dom.js');3(async () => {4 const browser = await playwright['chromium'].launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const input = await page.$('input#searchInput');8 const node = genNode(input);9 console.log('node', node);10 await browser.close();11})();12node {13 attributes: {14 },15 boundingBox: {16 },17}
Using AI Code Generation
1const { genNode } = require('playwright/lib/server/dom.js');2const { jsdom } = require('jsdom');3const { JSDOM } = jsdom;4const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');5const document = dom.window.document;6const element = document.createElement('div');7const node = genNode(element);8const { genNode } = require('puppeteer/lib/JSHandle.js');9const { jsdom } = require('jsdom');10const { JSDOM } = jsdom;11const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');12const document = dom.window.document;13const element = document.createElement('div');14const node = genNode(element);15const { JSHandle } = require('puppeteer/lib/JSHandle.js');16const { jsdom } = require('jsdom');17const { JSDOM } = jsdom;18const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');19const document = dom.window.document;20const element = document.createElement('div');21const node = new JSHandle(element).asElement()._remoteObject.objectId;
Using AI Code Generation
1const { genNode } = require('playwright');2const node = genNode();3console.log(node);4const { Playwright } = require('playwright');5const node = Playwright.genNode();6console.log(node);7const { Playwright } = require('playwright');8const node = Playwright.genNode();9console.log(node);10const { Playwright } = require('playwright');11const node = Playwright.genNode();12console.log(node);13const { Playwright } = require('playwright');14const node = Playwright.genNode();15console.log(node);16const { Playwright } = require('playwright');17const node = Playwright.genNode();18console.log(node);19const { Playwright } = require('playwright');20const node = Playwright.genNode();21console.log(node);22const { Playwright } = require('playwright');23const node = Playwright.genNode();24console.log(node);25const { Playwright } = require('playwright');26const node = Playwright.genNode();27console.log(node);28const { Playwright } = require('playwright');29const node = Playwright.genNode();30console.log(node);31const { Playwright } = require('playwright');32const node = Playwright.genNode();33console.log(node);34const { Playwright } = require('playwright');35const node = Playwright.genNode();36console.log(node);37const { Playwright } = require('playwright');38const node = Playwright.genNode();39console.log(node);40const { Playwright } = require('playwright');41const node = Playwright.genNode();42console.log(node);43const { Playwright } = require('play
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const newButton = await page.evaluateHandle(() => {7 return window.playwright._internal.genNode('button', 'newButton');8 });9 await page.evaluate((newButton) => {10 document.body.appendChild(newButton);11 }, newButton);12 await page.screenshot({ path: 'test.png' });13 await browser.close();14})();15I am using the latest version of Playwright (1.12.3)16const { chromium } = require('playwright');17(async () => {18 const browser = await chromium.launch();19 const context = await browser.newContext();20 const page = await context.newPage();21 const newButton = await page.evaluateHandle(() => {22 const button = document.createElement('button');23 button.id = 'newButton';24 return button;25 });26 await page.evaluate((newButton) => {27 document.body.appendChild(newButton);28 }, newButton);29 await page.screenshot({ path: 'test.png' });30 await browser.close();31})();
Using AI Code Generation
1const playwright = require('@playwright/test');2const { genNode } = require('@playwright/test/lib/server/registry');3(async () => {4 const node = await genNode({ name: 'Node1', type: 'chromium' });5 const browser = await node.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'example.png' });9 await browser.close();10})();11{12 "scripts": {13 },14 "dependencies": {15 }16}
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.
Get 100 minutes of automation test minutes FREE!!