How to use parentMethod method in ng-mocks

Best JavaScript code snippet using ng-mocks

neo-js.js

Source:neo-js.js Github

copy

Full Screen

1/**2 *3 * NEO javascript bytecode compiler4 *5 * birmas <birmingh@gmail.com> - beer fund: AcYFKVerLZbAVFYRV5Yr24587rGjHdz7SK ;-)6 *7 * https://github.com/CityOfZion8 * https://github.com/birmas/9 *10 * usage: window.neoJSEngine.parse(jsSource);11 *12 * this is very much a work in progress and is not intended to be a fully functional neo bytecode compiler (yet!)13 * short term todo:14 * - implement arithmetic operations for variables15 * - implement support for neo framework calls16 * - implement appcall supports (calling subcontracts)17 *18 * comments, suggestions and improvements are most welcome19 *20 * npm dependencies:21 * "acorn": "^5.1.1",22 * "text-diff": "^1.0.1",23 */24(function (window) {25 "use strict";26 const acorn = require('acorn');27 const neoVM = require('neo-js-vm');28 const opCodes = neoVM.OpCodes.codes;29 let Diff = require('text-diff');30 if (typeof(neo) === 'undefined') {31 // neo.init();32 window.neo = neoInit();33 }34 function neoInit() {35 return {36 vm: neoVM,37 methods: {},38 stack: {},39 sourceNodes: {},40 parser: neoParser(),41 byteCode: {},42 byteCodeScript: function () {43 return this.byteCode.join("").toLowerCase();44 }45 };46 }47 function neoParser() {48 return {49 parse: function (jsSource) {50 neo.methods = {};51 neo.stack = {};52 neo.activeRange = {};53 try {54 neo.sourceNodes = acorn.parse(jsSource, {55 sourceType: "module",56 });57 this.ProcessSourceBody();58 this.ProcessSourceToByteCode();59 this.TestApplicationEngine();60 } catch (ex) {61 console.log('error parsing editor data: %s', ex.message);62 }63 },64 TestApplicationEngine: function () {65 /*66 if (tx == null) tx = new InvocationTransaction();67 tx.Version = 1;68 tx.Script = textBox6.Text.HexToBytes();69 if (tx.Attributes == null) tx.Attributes = new TransactionAttribute[0];70 if (tx.Inputs == null) tx.Inputs = new CoinReference[0];71 if (tx.Outputs == null) tx.Outputs = new TransactionOutput[0];72 if (tx.Scripts == null) tx.Scripts = new Witness[0];73 ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx);74 */75 console.log('---------------------------------------------------------------------------------');76 console.log(neo.byteCodeScript());77 let appEngine = new neo.vm.ApplicationEngine('trigger', 'container', 'table', 'service', 'gas', true);78 let engine = appEngine.Run(neo.byteCodeScript(), null);79 console.log(appEngine);80 // appEngine.CheckArraySize();81 // appEngine.AddBreakPoint(15);82 console.log('---------------------------------------------------------------------------------');83 },84 ProcessSourceBody: function () {85 if (neo.sourceNodes.body.length <= 0) {86 console.log("ProcessSourceBody() no source nodes detected");87 return;88 }89 console.log("ProcessSourceBody() %d source nodes detected (range: %s)", neo.sourceNodes.body.length, JSON.stringify(this.NodeRange(neo.sourceNodes)));90 this.ProcessFunctionDeclarations(true);91 this.ProcessFunctionDeclarations(false);92 },93 ProcessFunctionDeclarations: function (justInitFunctionDeclarations) {94 for (let i in neo.sourceNodes.body) {95 let node = neo.sourceNodes.body[i];96 switch (node.type) {97 case "FunctionDeclaration":98 console.log("ProcessSourceBody() calling FunctionDeclaration");99 this.FunctionDeclaration(node, justInitFunctionDeclarations);100 break;101 }102 }103 },104 ProcessSourceToByteCode: function () {105 let byteCode = [];106 let currentAddress = 0;107 for (let i in neo.methods) {108 console.log('ProcessSourceToByteCode(): %s', neo.methods[i].methodName);109 let fnStack = neo.methods[i].stack;110 let fn = neo.methods[i];111 let cleanStack = {112 parent: fn,113 methodName: fn.methodName,114 sourceOperations: 0,115 address: 0,116 addressConvert: {},117 stack: [],118 };119 for (let n = 0; n < fnStack.length; n++) {120 cleanStack.stack.push(fnStack[n]);121 if (typeof(fnStack[n].bytes) !== 'undefined') {122 // add any additional bytes associated with this instruction123 for (let m = 0; m < fnStack[n].bytes.length; m++) {124 cleanStack.stack.push({code: fnStack[n].bytes[m], range: fnStack[n].range});125 }126 }127 }128 neo.methods[i].byteCodeAddress = currentAddress;129 currentAddress += cleanStack.stack.length;130 console.log('current: %d / method: %d', currentAddress, neo.methods[i].byteCodeAddress);131 byteCode = byteCode.concat(cleanStack.stack);132 }133 let byteCodeOutput = [];134 let byteCodeRanges = [];135 for (let n = 0; n < byteCode.length; n++) {136 if (byteCode[n].fixAddress === true) {137 // opCodes.CALL requires address rewrite after stack is determined138 let targetAddress = neo.methods[byteCode[n].targetAddress.methodName].byteCodeAddress;139 console.error('%s target address is %s / n is %d / %d (%s)', byteCode[n].targetAddress.methodName, targetAddress, n, targetAddress - n, this.IntToHex(targetAddress - n));140 let newAddress = this.HexByteArrayNumBits([this.IntToHex(targetAddress - n, false)], 2);141 byteCode[n + 1] = {code: newAddress[0], range: byteCode[n].range};142 byteCode[n + 2] = {code: newAddress[1], range: byteCode[n].range};143 }144 byteCodeOutput.push(byteCode[n].code.replace('0x', ''));145 // console.log(byteCode[n])146 // if(typeof(byteCode[n].range) !== 'undefined') {147 byteCodeRanges.push('<span class="bc-data" data-start={0} data-end={1} title="{2}">{3}</span>'.format(148 byteCode[n].range.start,149 byteCode[n].range.end,150 (neo.vm.OpCodes.name(byteCode[n].code)).desc,151 byteCode[n].code152 )153 );154 // }155 }156 console.log('bytecode output is');157 console.log(byteCodeOutput);158 neo.byteCode = byteCodeOutput;159 let jsByteCode = byteCodeOutput.join(" ").toLowerCase();160 console.log('JS: %s', jsByteCode);161 let jsBC = $('#jsByteCode');162 let csBC = $('#csByteCode');163 let csByteCode = csBC.val().trim();164 console.log('CS: %s', csByteCode);165 jsBC.html(byteCodeRanges.join(" ").toLowerCase().replaceAll('0x', ''));166 jsBC.removeClass('is-danger');167 jsBC.removeClass('is-success');168 if (jsByteCode !== csByteCode) {169 jsBC.addClass('is-danger');170 } else {171 jsBC.addClass('is-success');172 }173 let diff = new Diff();174 let textDiff = diff.main(csByteCode, jsByteCode);175 $('#byteCodeDiff').html(diff.prettyHtml(textDiff));176 },177 FunctionDeclaration: function (node, justInitFunctionDeclarations) {178 console.log('FunctionDeclaration(%s) called: %s (range: %s)', justInitFunctionDeclarations, node.id.name, JSON.stringify(this.NodeRange(node)));179 this.SetActiveRange(node);180 let totalVarCount = 0;181 if (justInitFunctionDeclarations) {182 // only initialise the function list, this happens so that we can determine183 // defined functions in main body before processing and to also determine return type (if any)184 neo.methods[node.id.name] = {185 functionArguments: [],186 functionVariables: {},187 sourceOperations: 0,188 address: 0,189 addressConvert: {},190 methodName: node.id.name,191 totalVars: 0,192 varCount: 0,193 totalFunctionArgs: node.params.length,194 byteCodeAddress: 0,195 hasReturnStatement: false,196 firstRun: true,197 stack: [],198 };199 for (let n = 0; n < node.params.length; n++) {200 let functionParamObject = {201 name: node.params[n].name,202 pos: n,203 isFunctionArgument: true,204 wasUsed: false, // todo: wasUsed may be deprecated205 };206 neo.methods[node.id.name].functionArguments.push(functionParamObject);207 neo.methods[node.id.name].functionVariables[node.params[n].name] = functionParamObject;208 }209 } else {210 totalVarCount = neo.methods[node.id.name].varCount + neo.methods[node.id.name].totalFunctionArgs;211 console.log(neo.methods[node.id.name]);212 neo.methods[node.id.name].sourceOperations = 0;213 neo.methods[node.id.name].address = 0;214 neo.methods[node.id.name].addressConvert = {};215 neo.methods[node.id.name].varCount = 0;216 neo.methods[node.id.name].totalFunctionArgs = node.params.length;217 neo.methods[node.id.name].byteCodeAddress = 0;218 neo.methods[node.id.name].stack = [];219 neo.methods[node.id.name].firstRun = false;220 }221 let functionStack = neo.methods[node.id.name];222 //_insertBeginCode223 console.error('%s has %d vars', functionStack.methodName, functionStack.totalVars);224 console.error('%d vars', totalVarCount);225 console.log(functionStack);226 this.InsertPushNumber(functionStack, (totalVarCount));227 this.InsertPushOne(functionStack, opCodes.NEWARRAY);228 this.InsertPushOne(functionStack, opCodes.TOALTSTACK);229 for (let n = 0; n < functionStack.totalFunctionArgs; n++) {230 this.ConvertStLoc(functionStack, n);231 }232 //_insertBeginCode end233 this.BlockStatement(functionStack, node.body);234 //_insertEndCode235 this.ConvertPushOne(functionStack, opCodes.NOP, functionStack.sourceOperations++);236 this.InsertPushOne(functionStack, opCodes.FROMALTSTACK);237 this.InsertPushOne(functionStack, opCodes.DROP);238 this.ConvertPushOne(functionStack, opCodes.RET, functionStack.sourceOperations++);239 //_insertEndCode end240 //ConvertAddrInMethod241 console.log(functionStack.addressConvert);242 for (let n = 0; n < functionStack.stack.length; n++) {243 let stackItem = functionStack.stack[n];244 if (stackItem.fixAddress && stackItem.code !== opCodes.CALL) {245 let sourceAddress = stackItem.sourceAddress;// + 2;246 // let addressOffset = functionStack.addressConvert[sourceAddress] - stackItem.address;247 let addressOffset = functionStack.address - stackItem.address;248 stackItem.bytes = this.HexByteArrayNumBits([this.IntToHex(addressOffset, false)], 2);249 stackItem.fixAddress = false;250 console.log(functionStack);251 console.log(stackItem);252 console.log('ConvertAddrInMethod method.address=%s', functionStack.address);253 console.log('ConvertAddrInMethod stackItem.sourceAddress=%s', stackItem.sourceAddress);254 console.log('ConvertAddrInMethod stackItem.address=%s', stackItem.address);255 console.log('ConvertAddrInMethod functionStack.addressConvert[sourceAddress]=%s', functionStack.addressConvert[sourceAddress]);256 console.log('ConvertAddrInMethod addressOffset=%s', addressOffset);257 console.log('ConvertAddrInMethod src=%d, addr=%d, offset=%d', sourceAddress, functionStack.addressConvert[sourceAddress], addressOffset);258 }259 }260 //ConvertAddrInMethod end261 },262 SetActiveRange: function (node) {263 this.activeRange = this.NodeRange(node);264 console.log("active range set to %o", this.activeRange);265 },266 BlockStatement: function (parentMethod, node) {267 this.SetActiveRange(node);268 console.log('BlockStatement() called (range: %s)', JSON.stringify(this.NodeRange(node)));269 console.log(node);270 this.ConvertPushOne(parentMethod, opCodes.NOP, parentMethod.sourceOperations++);271 for (let i = 0; i < node.body.length; i++) {272 let childNode = node.body[i];273 this.SetActiveRange(childNode);274 switch (childNode.type) {275 case "VariableDeclaration":276 this.VariableDeclaration(parentMethod, childNode.declarations);277 break;278 case "ExpressionStatement":279 this.ExpressionStatement(parentMethod, childNode.expression);280 break;281 case "ReturnStatement":282 this.ReturnStatement(parentMethod, childNode.argument);283 break;284 case "IfStatement":285 console.error('BlockStatement() IfStatement');286 this.IfStatement(parentMethod, childNode);287 break;288 default:289 console.error('BlockStatement() unhandled: %s', childNode.type);290 console.log(childNode);291 }292 }293 },294 ParseExpression: function (parentMethod, expression, expressionType = false, nestedCall = 0, operatorType = false) {295 if (nestedCall <= 0) {296 this.IncrementMethodVarCount(parentMethod);297 }298 console.log('expression %o', expression);299 switch (expression.type) {300 case "LogicalExpression":301 console.log('ParseExpression.LogicalExpression: nestedCall: %d', nestedCall);302 this.SetActiveRange(expression);303 let operatorInt = 0;304 switch (expression.operator) {305 case "&&":306 break;307 case "||":308 operatorInt = 1;309 break;310 }311 let nestedCallIncrement = nestedCall + 1;312 // Blt313 // Bgt314 this.ParseExpression(parentMethod, expression.left, expression.type, nestedCallIncrement, expression.operator);315 let code = this.ConvertPushOne(parentMethod, opCodes.JMPIF, parentMethod.sourceOperations, [this.IntToHex(0), this.IntToHex(0)]);316 console.log('JMP target is: %s', parentMethod.sourceOperations);317 this.ParseExpression(parentMethod, expression.right, expression.type, nestedCallIncrement);318 code.fixAddress = true;319 console.log(parentMethod);320 let multipleConditionalOffset = nestedCall === 1 ? 6 : 0;321 console.log('multipleConditionalOffset: offset: %d / %s', nestedCallIncrement, parentMethod.totalVars);322 code.sourceAddress = parentMethod.sourceOperations + 2 + multipleConditionalOffset;323 if (nestedCallIncrement <= 1) {324 code = this.ConvertPushOne(parentMethod, opCodes.JMP, parentMethod.sourceOperations++, [this.IntToHex(0), this.IntToHex(0)]);325 console.log('JMP target is: %s', parentMethod.sourceOperations);326 code.fixAddress = true;327 code.sourceAddress = parentMethod.sourceOperations + 1;328 this.ConvertPushNumber(parentMethod, operatorInt, parentMethod.sourceOperations++);329 }330 break;331 case "Literal":332 this.ConvertPushOne(parentMethod, opCodes.NOP, parentMethod.sourceOperations++);333 this.ConvertPushOne(parentMethod, opCodes.NOP, parentMethod.sourceOperations++);334 break;335 case "BinaryExpression":336 this.SetActiveRange(expression);337 console.log('BinaryExpression() nestedCall: %s', nestedCall);338 console.log('BinaryExpression() expressionType: %s', expressionType);339 console.log('BinaryExpression() expressionType: %o', expression);340 this.ConvertLdLoc(parentMethod, parentMethod.functionVariables[expression.left.name].pos);341 this.ConvertLdLoc(parentMethod, parentMethod.functionVariables[expression.right.name].pos);342 let operatorOpCode = expression.operator === '>' ? opCodes.GT : opCodes.LT;343 switch (expression.operator) {344 case ">":345 operatorOpCode = opCodes.GT;346 if (operatorType === '&&') {347 operatorOpCode = opCodes.LTE;348 }349 this.ConvertPushOne(parentMethod, operatorOpCode, parentMethod.sourceOperations++);350 break;351 case ">=":352 operatorOpCode = opCodes.LT;353 if (operatorType === '||') {354 operatorOpCode = opCodes.GTE;355 }356 console.log('operatorOpCode: %s', operatorOpCode);357 console.log('operatorType: %s', operatorType);358 this.ConvertPushOne(parentMethod, operatorOpCode, parentMethod.sourceOperations++);359 if (operatorType !== '||' && operatorType !== '&&' && nestedCall <= 1) {360 this.ConvertPushNumber(parentMethod, 0, parentMethod.sourceOperations++);361 this.ConvertPushOne(parentMethod, opCodes.NUMEQUAL, parentMethod.sourceOperations++);362 }363 break;364 case "<":365 console.log('operatorOpCode: %s', operatorOpCode);366 console.log('operatorType: %s', operatorType);367 operatorOpCode = opCodes.LT;368 if (operatorType === '&&') {369 operatorOpCode = opCodes.GTE;370 }371 this.ConvertPushOne(parentMethod, operatorOpCode, parentMethod.sourceOperations++);372 break;373 case "<=":374 operatorOpCode = opCodes.GT;375 if (operatorType === '||') {376 operatorOpCode = opCodes.LTE;377 }378 console.log('operatorOpCode: %s', operatorOpCode);379 console.log('operatorType: %s', operatorType);380 this.ConvertPushOne(parentMethod, operatorOpCode, parentMethod.sourceOperations++);381 if (operatorType !== '||' && operatorType !== '&&' && nestedCall <= 1) {382 this.ConvertPushNumber(parentMethod, 0, parentMethod.sourceOperations++);383 this.ConvertPushOne(parentMethod, opCodes.NUMEQUAL, parentMethod.sourceOperations++);384 }385 break;386 }387 break;388 }389 },390 IfStatement: function (parentMethod, expression) {391 console.error("IfStatement()");392 console.log(expression);393 let testResult = this.TestConditionalStatement(parentMethod, expression.test);394 this.ParseExpression(parentMethod, expression.test);395 console.log('test result was %s', testResult);396 if (expression.consequent !== null) {397 console.error('IfStatement(): %s expression.consequent !== null', expression.test.type);398 let conditionalLocation = (parentMethod.varCount + parentMethod.totalFunctionArgs) - 1;399 console.log('conditionalLocation parentMethod.varCount %s', parentMethod.varCount);400 console.log('conditionalLocation parentMethod.totalVars %s', parentMethod.totalVars);401 console.log('conditionalLocation parentMethod.totalFunctionArgs %s', parentMethod.totalFunctionArgs);402 console.error('pushing %s', conditionalLocation);403 this.ConvertStLoc(parentMethod, conditionalLocation);404 this.ConvertLdLoc(parentMethod, conditionalLocation);405 // brfalse - JMP to this address on false (else)406 let code = this.ConvertPushOne(parentMethod, opCodes.JMPIFNOT, parentMethod.sourceOperations++, [this.IntToHex(0), this.IntToHex(0)]);407 console.log('JMP: sourceOperations is %s', parentMethod.sourceOperations);408 this.BlockStatement(parentMethod, expression.consequent);409 this.ConvertPushOne(parentMethod, opCodes.NOP, parentMethod.sourceOperations++);410 console.log('JMP target is: %s', parentMethod.sourceOperations);411 code.fixAddress = true;412 let addressIncrement = expression.alternate !== null ? 2 : 0;413 code.sourceAddress = parentMethod.sourceOperations + addressIncrement;414 }415 if (expression.alternate !== null) {416 let code = this.ConvertPushOne(parentMethod, opCodes.JMP, parentMethod.sourceOperations++, [this.IntToHex(0), this.IntToHex(0)]);417 console.log('JMP: sourceOperations is %s', parentMethod.sourceOperations);418 this.BlockStatement(parentMethod, expression.alternate);419 this.ConvertPushOne(parentMethod, opCodes.NOP, parentMethod.sourceOperations++);420 console.log('JMP target is: %s', parentMethod.sourceOperations);421 code.fixAddress = true;422 code.sourceAddress = parentMethod.sourceOperations;423 }424 console.error('leaving IfStatement');425 },426 TestConditionalStatement: function (parentMethod, conditional) {427 console.error("TestConditionalStatement()");428 console.log(conditional);429 let leftTest, rightTest;430 // testHasLeft = typeof(conditional.left) !== 'undefined';431 // testHasRight = typeof(conditional.right) !== 'undefined';432 let testCondition = false;433 if (typeof(conditional.type) !== 'undefined') {434 switch (conditional.type) {435 case "LogicalExpression":436 leftTest = this.TestConditionalStatement(parentMethod, conditional.left);437 rightTest = this.TestConditionalStatement(parentMethod, conditional.right);438 switch (conditional.operator) {439 case "&&":440 console.log('TestConditionalStatement() leftTest: %s, rightTest: %s', leftTest, rightTest);441 testCondition = leftTest && rightTest;442 break;443 case "||":444 testCondition = leftTest || rightTest;445 break;446 default:447 alert('unhandled logical expression operator: ' + conditional.operator);448 }449 console.error("LogicalExpression()");450 console.log(conditional);451 break;452 case "BinaryExpression":453 let left = parentMethod.functionVariables[conditional.left.name];454 let right = parentMethod.functionVariables[conditional.right.name];455 switch (conditional.operator) {456 case ">":457 testCondition = left.value > right.value;458 break;459 case "<":460 testCondition = left.value < right.value;461 break;462 case ">=":463 testCondition = left.value >= right.value;464 break;465 case "<=":466 testCondition = left.value <= right.value;467 break;468 }469 console.log('left: %o', left);470 console.log('right: %o', right);471 console.log('comparison: %s %s %s = %s', left.value, conditional.operator, right.value, testCondition);472 break;473 case "UnaryExpression":474 console.error("UnaryExpression()");475 console.log(conditional);476 break;477 case "Identifier":478 let conditionVar = parentMethod.functionVariables[conditional.name];479 testCondition = conditionVar.value;480 break;481 case "Literal":482 console.log("Literal - adding var count");483 testCondition = conditional.value;484 this.ConvertPushOne(parentMethod, conditional.value ? opCodes.PUSH1 : opCodes.PUSH0, parentMethod.sourceOperations++);485 console.log('var count is %d', parentMethod.varCount);// parentMethod.varCount++;486 this.ConvertStLoc(parentMethod, parentMethod.varCount++ + parentMethod.totalFunctionArgs);487 break;488 default:489 console.error('TestConditionalStatement() unhandled conditional.type: %s', conditional.type);490 }491 } else {492 // not a condition with a type, must be literal493 console.error('unhandled conditional type: %s', conditional.type);494 console.log(conditional);495 }496 console.log('test condition was: %s', testCondition);497 return testCondition;498 },499 ReturnStatement: function (parentMethod, expression) {500 console.error('ReturnStatement()');501 parentMethod.hasReturnStatement = true;502 if (expression !== null) {503 this.VariableAssignment(parentMethod, expression);504 }505 let code = this.ConvertPushOne(parentMethod, opCodes.JMP, parentMethod.sourceOperations++, [this.IntToHex(0), this.IntToHex(0)]);506 code.fixAddress = true;507 code.sourceAddress = parentMethod.sourceOperations;508 this.ConvertLdLoc(parentMethod, (parentMethod.totalFunctionArgs + parentMethod.totalVars) - 1);509 },510 IncrementMethodTotalVars: function (parentMethod) {511 if (parentMethod.firstRun) {512 console.log('IncrementMethodTotalVars: %s / %d', parentMethod.methodName, parentMethod.totalVars);513 parentMethod.totalVars++;514 }515 },516 IncrementMethodVarCount: function (parentMethod) {517 console.log('IncrementMethodVarCount: %s / %d', parentMethod.methodName, parentMethod.varCount);518 parentMethod.varCount++;519 },520 ExpressionStatement: function (parentMethod, expression) {521 console.info('ExpressionStatement() called with expression: %s', expression.type);522 switch (expression.type) {523 case "CallExpression":524 this.CallExpression(parentMethod, expression);525 break;526 case "AssignmentExpression":527 this.AssignmentExpression(parentMethod, expression);528 break;529 default:530 console.error('ExpressionStatement() unhandled: %s', expression.type);531 }532 },533 AssignmentExpression: function (parentMethod, expression) {534 console.log(expression);535 console.log(parentMethod.functionVariables);536 switch (expression.operator) {537 case "=":538 if (expression.left.type === "MemberExpression") {539 // an array or object540 let assignmentVarName = expression.left.object.name;541 parentMethod.functionVariables[assignmentVarName].value[expression.left.property.raw] = expression.right.value;542 this.ConvertLdLoc(parentMethod, parentMethod.functionVariables[assignmentVarName].pos + parentMethod.totalFunctionArgs);543 this.ConvertPushNumber(parentMethod, parseInt(expression.left.property.raw));544 }545 switch (typeof(expression.right.value)) {546 case "string":547 this.ConvertPushArray(parentMethod, this.StringToByteArray(expression.right.value));548 break;549 case "number":550 console.log("AssignmentExpression() logging number: %s", expression.right.value);551 this.ConvertPushNumber(parentMethod, expression.right.value, parentMethod.sourceOperations++);552 break;553 case "boolean":554 console.log("AssignmentExpression() logging boolean: %s", expression.right.value);555 this.ConvertPushNumber(parentMethod, expression.right.value ? 1 : 0, parentMethod.sourceOperations++);556 break;557 }558 if (expression.left.type === "Identifier") {559 parentMethod.functionVariables[expression.left.name].value = expression.right.value;560 this.ConvertPushOne(parentMethod, opCodes.FROMALTSTACK, parentMethod.sourceOperations++);561 this.ConvertPushOne(parentMethod, opCodes.DUP);562 this.ConvertPushOne(parentMethod, opCodes.TOALTSTACK);563 this.ConvertPushNumber(parentMethod, parentMethod.functionVariables[expression.left.name].pos + parentMethod.totalFunctionArgs);564 this.ConvertPushNumber(parentMethod, 2);565 this.ConvertPushOne(parentMethod, opCodes.ROLL);566 }567 this.ConvertPushOne(parentMethod, opCodes.SETITEM, parentMethod.sourceOperations++);568 break;569 default:570 console.error('ExpressionStatement() AssignmentExpression unhandled operator: %s', expression.operator);571 }572 },573 CallExpression: function (parentMethod, callExpression, assignReturnValue = false) {574 let callType = 0;575 if (typeof(neo.methods[callExpression.callee.name]) !== 'undefined') {576 // found a call to a method declared in this contract577 callType = 1;578 console.log('CallExpression(): %s', callExpression.callee.name);579 let numArgs = callExpression.arguments.length;580 if (numArgs > 0) {581 // let identifiersAdded = 0;582 for (let i = 0; i < numArgs; i++) {583 let expr = callExpression.arguments[i];584 console.error('expression args with type: %s', expr.type);585 switch (expr.type) {586 case "Identifier":587 neo.methods[callExpression.callee.name].functionArguments[i].value = parentMethod.functionVariables[expr.name].value;588 this.ConvertLdLoc(parentMethod, parentMethod.functionVariables[expr.name].pos + parentMethod.totalFunctionArgs);589 break;590 case "Literal":591 neo.methods[callExpression.callee.name].functionArguments[i].value = expr.value;592 // neo.methods[callExpression.callee.name].functionArguments.push({value: expr.value});593 switch (typeof(expr.value)) {594 case "number":595 this.ConvertPushNumber(parentMethod, expr.value);596 break;597 case "string":598 this.ConvertPushArray(parentMethod, this.StringToByteArray(expr.value));599 break;600 case "boolean":601 console.log("CallExpression() logging boolean: %s", expr.value);602 this.ConvertPushNumber(parentMethod, expr.value ? 1 : 0, parentMethod.sourceOperations++);603 break;604 default:605 console.error('CallExpression() unhandled expression value: %s', typeof(expr.value));606 }607 break;608 default:609 console.error('CallExpression() unhandled expression type: %s', typeof(expr.type));610 break;611 }612 }613 }614 // this.StackPushCode(parentMethod, opCodes.NOP, true);615 this.ConvertPushOne(parentMethod, opCodes.NOP, parentMethod.sourceOperations++);616 if (numArgs === 2) {617 this.ConvertPushOne(parentMethod, opCodes.SWAP);618 } else if (numArgs === 3) {619 this.ConvertPushNumber(parentMethod, 2);620 this.ConvertPushOne(parentMethod, opCodes.XSWAP);621 } else if (numArgs > 1) {622 for (let i = 0; i < numArgs / 2; i++) {623 let saveTo = numArgs - 1 - i;624 this.ConvertPushNumber(parentMethod, saveTo);625 this.ConvertPushOne(parentMethod, opCodes.PICK);626 this.ConvertPushNumber(parentMethod, i + 1);627 this.ConvertPushOne(parentMethod, opCodes.PICK);628 this.ConvertPushNumber(parentMethod, saveTo + 2);629 this.ConvertPushOne(parentMethod, opCodes.XSWAP);630 this.ConvertPushOne(parentMethod, opCodes.DROP);631 this.ConvertPushNumber(parentMethod, i + 1);632 this.ConvertPushOne(parentMethod, opCodes.XSWAP);633 this.ConvertPushOne(parentMethod, opCodes.DROP);634 }635 }636 let targetAddress = [this.IntToHex(5), this.IntToHex(0)];637 let code = this.ConvertPushOne(parentMethod, opCodes.CALL, parentMethod.sourceOperations++, targetAddress);638 code.fixAddress = true;639 code.targetAddress = neo.methods[callExpression.callee.name];640 if (neo.methods[callExpression.callee.name].hasReturnStatement) {641 // this method has a return statement642 if (!assignReturnValue) {643 // return value (if any) is not assigned, drop644 this.ConvertPushOne(parentMethod, opCodes.DROP, parentMethod.sourceOperations++);645 }646 } else {647 this.ConvertPushOne(parentMethod, opCodes.NOP, parentMethod.sourceOperations++)648 }649 }650 },651 VariableDeclaration: function (parentMethod, declarations) {652 console.error('VariableDeclaration() called with %d declarations', declarations.length);653 console.log(declarations);654 for (let i = 0; i < declarations.length; i++) {655 this.SetActiveRange(declarations[i]);656 let varPosition = parentMethod.varCount;657 let returnValue = this.VariableAssignment(parentMethod, declarations[i].init, declarations[i].id.name);658 parentMethod.functionVariables[declarations[i].id.name] = {659 pos: varPosition,660 value: returnValue,661 isFunctionArgument: false,662 wasUsed: false,663 };664 }665 },666 VariableAssignment: function (parentMethod, variable, variableName = null) {667 console.error('VariableAssignment()');668 let returnValue = "";669 this.IncrementMethodTotalVars(parentMethod);670 if (variable === null) {671 this.IncrementMethodVarCount(parentMethod);672 return;673 }674 switch (variable.type) {675 case "Literal":676 console.log("VariableAssignment(): %s", typeof(variable.value));677 switch (typeof(variable.value)) {678 case "string":679 this.ConvertPushArray(parentMethod, this.StringToByteArray(variable.value), parentMethod.sourceOperations++);680 break;681 case "number":682 console.log("VariableAssignment() logging number: %d", variable.value);683 this.ConvertPushNumber(parentMethod, variable.value, parentMethod.sourceOperations++);684 break;685 case "boolean":686 console.log("VariableAssignment() logging boolean: %s", variable.value);687 this.ConvertPushNumber(parentMethod, variable.value ? 1 : 0, parentMethod.sourceOperations++);688 break;689 default:690 console.error('VariableAssignment() unhandled expression type: %s', typeof(variable.value));691 console.log(variable);692 }693 returnValue = variable.value;694 break;695 case "ArrayExpression":696 console.error('VariableAssignment() ArrayExpression');697 console.log(variable);698 //_ConvertNewArr699 let arrayLength = variable.elements.length;700 if (!parentMethod.firstRun) {701 arrayLength = parentMethod.functionVariables[variableName].value.length;702 }703 console.log('array length is: %d', arrayLength);704 this.ConvertPushNumber(parentMethod, variable.elements.length);705 this.ConvertPushOne(parentMethod, opCodes.NEWARRAY, parentMethod.sourceOperations++);706 console.log(variable.elements);707 returnValue = [];708 for (let n = 0; n < variable.elements.length; n++) {709 this.ConvertPushOne(parentMethod, opCodes.DUP, parentMethod.sourceOperations++);710 this.ConvertPushNumber(parentMethod, n);711 returnValue.push(variable.elements[n].value);712 console.log(parentMethod);713 console.log(variable.elements[n]);714 switch (typeof(variable.elements[n].value)) {715 case "string":716 this.ConvertPushArray(parentMethod, this.StringToByteArray(variable.elements[n].value), parentMethod.sourceOperations++);717 break;718 case "number":719 console.log("ArrayExpression() logging number: %d", variable.elements[n].value);720 this.ConvertPushNumber(parentMethod, variable.elements[n].value, parentMethod.sourceOperations++);721 break;722 case "boolean":723 console.log("ArrayExpression() logging boolean: %s", variable.elements[n].value);724 this.ConvertPushNumber(parentMethod, variable.elements[n].value ? 1 : 0, parentMethod.sourceOperations++);725 break;726 default:727 console.error('ArrayExpression() unhandled expression type: %s', typeof(variable.elements[n].value));728 console.log(variable);729 }730 this.ConvertPushOne(parentMethod, opCodes.SETITEM, parentMethod.sourceOperations++);731 // parentMethod.varCount--;732 }733 break;734 case "CallExpression":735 this.CallExpression(parentMethod, variable, true);736 break;737 case "Identifier":738 console.error("VariableAssignment().Identifier");739 let sourceVariable = parentMethod.functionVariables[variable.name];740 sourceVariable.wasUsed = true;741 returnValue = sourceVariable.value;742 if (sourceVariable.isFunctionArgument) {743 // opcodes.ldArg744 this.ConvertLdLoc(parentMethod, sourceVariable.pos);745 } else {746 // opcodes.ldloc747 this.ConvertLdLoc(parentMethod, sourceVariable.pos + parentMethod.totalFunctionArgs);748 }749 break;750 case "BinaryExpression":751 console.log(variable);752 this.BinaryExpression(parentMethod, variable);753 break;754 default:755 console.error('VariableAssignment() unhandled: %s', variable.type);756 console.log(variable);757 return;758 }759 console.log('VariableAssignment() VariableDeclarator');760 this.ConvertStLoc(parentMethod, parentMethod.varCount + parentMethod.totalFunctionArgs);761 this.IncrementMethodVarCount(parentMethod);762 return returnValue;763 },764 BinaryExpression: function (parentMethod, variable) {765 console.error(variable);766 },767 ConvertStLoc: function (parentMethod, pos) {768 this.ConvertPushOne(parentMethod, opCodes.FROMALTSTACK, parentMethod.sourceOperations++);769 this.ConvertPushOne(parentMethod, opCodes.DUP);770 this.ConvertPushOne(parentMethod, opCodes.TOALTSTACK);771 this.ConvertPushNumber(parentMethod, pos);772 this.ConvertPushNumber(parentMethod, 2);773 this.ConvertPushOne(parentMethod, opCodes.ROLL);774 this.ConvertPushOne(parentMethod, opCodes.SETITEM);775 },776 ConvertLdLoc: function (parentMethod, pos) {777 this.ConvertPushOne(parentMethod, opCodes.FROMALTSTACK, parentMethod.sourceOperations++);778 this.ConvertPushOne(parentMethod, opCodes.DUP);779 this.ConvertPushOne(parentMethod, opCodes.TOALTSTACK);780 this.ConvertPushNumber(parentMethod, pos);781 this.ConvertPushOne(parentMethod, opCodes.PICKITEM);782 },783 ConvertPushOne: function (parentMethod, mCode, mSourceOperations = null, mExtraData = null) {784 // let opCodeData = OpCodes.name(mCode);785 // console.error('ConvertPushOne() %s=%s: addr=%s', opCodeData.code, opCodeData.desc, mSourceOperations);786 // console.error('active range: %o', this.activeRange);787 let startAddress = parentMethod.address;788 let code = {789 address: parentMethod.address,790 code: mCode,791 debugCode: null,792 fixAddress: false,793 sourceAddress: 0,794 targetAddress: null,795 range: this.activeRange,796 };797 if (mSourceOperations !== null) {798 if (mCode === opCodes.JMP || mCode === opCodes.JMPIFNOT || mCode === opCodes.JMPIF) {799 console.log('ConvertPushOne() JMP/JMPIFNOT/JMPIF - sourceoperations++');800 parentMethod.sourceOperations++;801 }802 parentMethod.addressConvert[mSourceOperations] = startAddress;803 console.log('ConvertPushOne() %s %s / addressConvert: %s = %s', parentMethod.methodName, mCode, mSourceOperations, startAddress);804 }805 parentMethod.address++;806 if (mExtraData !== null) {807 console.log('ConvertPushOne() adding extraData: ' + mExtraData.join("") + " len: " + mExtraData.length);808 code.bytes = mExtraData;809 parentMethod.address += mExtraData.length;810 }811 parentMethod.stack.push(code);812 return code;813 },814 ConvertPushNumber: function (parentMethod, mValue, mSourceOperations) {815 // console.error('ConvertPushNumber() ' + mValue);816 if (mValue === 0) {817 return this.ConvertPushOne(parentMethod, opCodes.PUSH0, mSourceOperations);818 } else if (mValue === -1) {819 return this.ConvertPushOne(parentMethod, opCodes.PUSHM1, mSourceOperations);820 } else if (mValue > 0 && mValue <= 16) {821 return this.ConvertPushOne(parentMethod, this.IntToHex((0x50 + mValue)), mSourceOperations);822 } else {823 return this.ConvertPushArray(parentMethod, this.HexToByteArray(this.IntToHex(mValue)).reverse(), mSourceOperations);824 }825 },826 ConvertPushArray: function (parentMethod, mArray, mSourceOperations) {827 let prefixLen, code;828 if (mArray.length === 0) {829 return this.ConvertPushOne(parentMethod, opCodes.PUSH0, mSourceOperations);830 } else if (mArray.length <= 75) {831 return this.ConvertPushOne(parentMethod, this.IntToHex(mArray.length), mSourceOperations, mArray);832 } else if (mArray.length <= 255) {833 prefixLen = 1;834 code = opCodes.PUSHDATA1;835 } else if (mArray.length <= 65535) {836 prefixLen = 2;837 code = opCodes.PUSHDATA2;838 } else {839 prefixLen = 4;840 code = opCodes.PUSHDATA4;841 }842 let signedLength = this.HexByteArrayNumBits(this.HexToByteArray(this.IntToHex(mArray.length)).reverse(), prefixLen);843 return this.ConvertPushOne(parentMethod, code, mSourceOperations, signedLength.concat(mArray));844 },845 InsertPushOne: function (parentMethod, mCode, mComment = null, mExtraData = null) {846 let code = {847 address: parentMethod.address,848 code: mCode,849 debugCode: mComment,850 fixAddress: false,851 sourceAddress: 0,852 targetAddress: null,853 range: this.activeRange,854 };855 if (mComment !== null) {856 }857 parentMethod.address++;858 if (mExtraData !== null) {859 console.log('InsertPushOne() adding extraData: ');860 console.log(mExtraData);861 code.bytes = mExtraData;862 parentMethod.address += mExtraData.length;863 }864 parentMethod.stack.push(code);865 return code;866 },867 InsertPushNumber: function (parentMethod, mValue, mComment = null) {868 // console.log('InsertPushNumber() ' + mValue);869 if (mValue === 0) {870 return this.InsertPushOne(parentMethod, opCodes.PUSH0, mComment);871 } else if (mValue === -1) {872 return this.InsertPushOne(parentMethod, opCodes.PUSHM1, mComment);873 } else if (mValue > 0 && mValue <= 16) {874 return this.InsertPushOne(parentMethod, this.IntToHex((0x50 + mValue)), mComment);875 } else {876 return this.InsertPushArray(parentMethod, this.HexToByteArray(this.IntToHex(mValue)).reverse(), mComment);877 }878 },879 InsertPushArray: function (parentMethod, mArray, mComment = null) {880 let prefixLen, code;881 // console.log('InsertPushArray(): Length: ' + mArray.length);882 if (mArray.length === 0) {883 return this.InsertPushOne(parentMethod, opCodes.PUSH0, mComment);884 } else if (mArray.length <= 75) {885 return this.InsertPushOne(parentMethod, mArray.length, mComment, mArray);886 } else if (mArray.length <= 255) {887 prefixLen = 1;888 code = opCodes.PUSHDATA1;889 } else if (mArray.length <= 65535) {890 prefixLen = 2;891 code = opCodes.PUSHDATA2;892 } else {893 prefixLen = 4;894 code = opCodes.PUSHDATA4;895 }896 let signedLength = this.HexByteArrayNumBits(this.HexToByteArray(this.IntToHex(mArray.length)).reverse(), prefixLen);897 return this.InsertPushOne(parentMethod, code, mComment, signedLength.concat(mArray));898 },899 /**900 * helper method to determine how long a method is901 * @param node902 * @returns {{start, end, range: number}}903 * @constructor904 */905 NodeRange: function (node) {906 return {907 start: node.start,908 end: node.end,909 range: node.end - node.start910 }911 },912 ArrayToByteArray: function (mArray) {913 return mArray.map(function (c) {914 return c.charCodeAt(0).toString(16);915 });916 },917 StringToByteArray: function (mValue) {918 return this.ArrayToByteArray(mValue.split(''));919 },920 HexToByteArray: function (mString) {921 let ret = [];922 for (let i = 0; i < mString.length; i += 2) {923 ret.push(mString[i] + "" + mString[i + 1]);924 }925 return ret;926 },927 HexByteArrayNumBits: function (mArray, bits = 0) {928 if (typeof(mArray[0]) === 'object') {929 mArray = mArray[0];930 }931 for (let i = 0; i < mArray.length; i++) {932 if (mArray[i].length > 2) {933 mArray[i + 1] = mArray[i].substr(0, 2);934 mArray[i] = mArray[i].substr(2, 4);935 }936 }937 for (let i = mArray.length; i < bits; i++) {938 mArray.push("00");939 }940 return mArray;941 },942 /**943 * @return {string}944 */945 IntToHex: function (mNumber, useMSB = true) {946 // worst way to do twos complement D:947 if (mNumber < 0) {948 return this.HexToByteArray((65535 + mNumber + 1).toString(16)).reverse();949 }950 let h = mNumber.toString(16);951 let val = h.length % 2 ? '0' + h : h;952 let msb = {8: 1, 9: 1, a: 1, b: 1, c: 1, d: 1, e: 1, f: 1};953 if (useMSB && mNumber > 127 && typeof(msb[val.substr(0, 1)]) !== 'undefined') {954 val = '00' + val;955 }956 return val;957 },958 }959 }...

Full Screen

Full Screen

router_utils_test.js

Source:router_utils_test.js Github

copy

Full Screen

...23 var c = new Child;24 // override method25 test.equal(c.toString(), 'Child');26 // inherit method27 test.equal(c.parentMethod(), 'parentMethod');28 // new methods29 test.equal(c.childMethod(), 'childMethod');30 // constructors31 test.isTrue(childCtorCalled, 'child ctor not called');32 test.isTrue(parentCtorCalled, 'parent ctor not called');33 // class property copy34 test.isTrue(Child.classProperty, 'class property not inherited');35});36Tinytest.add('Utils - extend', function (test) {37 var parentCtorCalled = false38 , childCtorCalled = false;39 function Parent () {40 parentCtorCalled = true;41 }42 Parent.prototype = {43 constructor: Parent,44 toString: function () { return 'Parent'; },45 parentMethod: function () { return 'parentMethod'; }46 };47 Parent.classProperty = true;48 var Child = RouterUtils.extend(Parent, {49 constructor: function () {50 childCtorCalled = true;51 Child.__super__.constructor.apply(this, arguments);52 },53 toString: function () { return 'Child'; },54 childMethod: function () { return 'childMethod'; }55 });56 var c = new Child;57 // override method58 test.equal(c.toString(), 'Child');59 // inherit method60 test.equal(c.parentMethod(), 'parentMethod');61 // new methods62 test.equal(c.childMethod(), 'childMethod');63 // constructors64 test.isTrue(childCtorCalled, 'child ctor not called');65 test.isTrue(parentCtorCalled, 'parent ctor not called');66 // class property copy67 test.isTrue(Child.classProperty, 'class property not inherited');68});69Tinytest.add('Utils - capitalize', function (test) {70 var str = 'lower';71 test.equal(RouterUtils.capitalize(str), 'Lower');72});73Tinytest.add('Utils - classify', function (test) {74 test.equal(RouterUtils.classify('postsShow'), 'PostsShow');...

Full Screen

Full Screen

JSInheritence.js

Source:JSInheritence.js Github

copy

Full Screen

1/*!2 * FooClass should not have childMethod3 * parentMethod's argument should be type String4 * FooClass#overrideMethod should have only one argument5 * FooClass#overrideMethod's argument should be type String6 * FooClass#cheese should be type String|Number7 * FooClass#prop should be a String8 * BarClass should have both parentMethod and childMethod9 * childMethod's argument should be type Number10 * BarClass#parentMethod should be documented as inherited11 * BarClass#overrideMethod should be documented as an override12 * BarClass#overrideMethod should have two arguments13 * BarClass#overrideMethod's arguments should both be type Number14 * BarClass#cheese should be type Number|String15 * BargeClass should have one method, parentMethod16 * BargeClass#parentMethod's argument is called able17 * BilgeClass is a child class of BargeClass18 * BilgeClass should have two method, parentMethod and childMethod19 * BilgeClass#childMethod's argument is called baker20 * simpleFun should have no members or properties21 * TODO simpleFun should have two String arguments22*/23function FooClass (able, baker) {24 if (arguments.length != 2)25 return this.apply (this, defaultArgs);26 this.prop = 'prop';27}28FooClass.prototype.parentMethod = function (cheese) { this.cheese = cheese; };29FooClass.prototype.overrideMethod = function (able) { };30function BarClass (able, baker) {31 FooClass.apply (this, arguments);32}33function dummy(){}34dummy.prototype = FooClass.prototype;35BarClass.prototype = new dummy();36BarClass.prototype.childMethod = function (cheese) { this.cheese = cheese; };37BarClass.prototype.overrideMethod = function (able, baker) {38 FooClass.prototype.overrideMethod ("four");39};40var bar = new BarClass();41bar.parentMethod ("four");42bar.childMethod (4);43bar.overrideMethod (4, 4);44function simpleFun(){45 return this.apply (this, [ 'foo', 'bar' ]);46}47function BargeClass(){}48BargeClass.prototype.parentMethod = function (able) {};49function BilgeClass(){}50BilgeClass.prototype = Object.create (BargeClass.prototype);51BilgeClass.prototype.childMethod = function (baker) {};52module.exports = {53 FooClass: FooClass,54 BarClass: BarClass,55 BargeClass: BargeClass,56 BilgeClass: BilgeClass,57 simpleFun: simpleFun...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parentMethod } from 'ng-mocks';2describe('TestComponent', () => {3 let component: TestComponent;4 let fixture: ComponentFixture<TestComponent>;5 beforeEach(async(() => {6 TestBed.configureTestingModule({7 imports: [RouterTestingModule],8 {9 useValue: {10 navigateByUrl: () => {11 return new Promise(resolve => resolve(true));12 },13 },14 },15 }).compileComponents();16 }));17 beforeEach(() => {18 fixture = TestBed.createComponent(TestComponent);19 component = fixture.componentInstance;20 fixture.detectChanges();21 });22 it('should navigate to /test', async () => {23 const router = TestBed.get(Router);24 const spy = spyOn(router, 'navigateByUrl');25 component.navigateToTest();26 expect(spy).toHaveBeenCalledWith('/test');27 });28 it('should navigate to /test via parentMethod', async () => {29 const router = TestBed.get(Router);30 const spy = spyOn(router, 'navigateByUrl');31 parentMethod(component, 'navigateToTest');32 expect(spy).toHaveBeenCalledWith('/test');33 });34});35import { Component } from '@angular/core';36import { Router } from '@angular/router';37@Component({38})39export class TestComponent {40 constructor(private router: Router) {}41 navigateToTest() {42 this.router.navigateByUrl('/test');43 }44}45p {46 color: red;47}48import { async, ComponentFixture, TestBed } from '@angular/core/testing';49import { TestComponent } from './test.component';50describe('TestComponent', () => {51 let component: TestComponent;52 let fixture: ComponentFixture<TestComponent>;53 beforeEach(async(() => {54 TestBed.configureTestingModule({55 }).compileComponents();56 }));57 beforeEach(() => {58 fixture = TestBed.createComponent(TestComponent);59 component = fixture.componentInstance;60 fixture.detectChanges();61 });62 it('should create', () => {63 expect(component).toBeTruthy();64 });65});66import {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parentMethod } from 'ng-mocks';2describe('TestComponent', () => {3 let component: TestComponent;4 let fixture: ComponentFixture<TestComponent>;5 beforeEach(() => {6 TestBed.configureTestingModule({7 }).compileComponents();8 });9 beforeEach(() => {10 fixture = TestBed.createComponent(TestComponent);11 component = fixture.componentInstance;12 fixture.detectChanges();13 });14 it('should create', () => {15 expect(component).toBeTruthy();16 });17 it('should call parentMethod', () => {18 const spy = spyOn(component, 'parentMethod');19 parentMethod(fixture, 'parentMethod');20 expect(spy).toHaveBeenCalled();21 });22});23import { Component, OnInit } from '@angular/core';24@Component({25})26export class TestComponent implements OnInit {27 constructor() {}28 ngOnInit(): void {}29 parentMethod() {30 console.log('Parent method called');31 }32}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parentMethod } from 'ng-mocks';2import { childMethod } from 'ng-mocks';3import { ngMocksUniverse } from 'ng-mocks';4import { ngMocksFormat } from 'ng-mocks';5import { ngMocksGuts } from 'ng-mocks';6import { ngMocksGlobal } from 'ng-mocks';7import { ngMocksThrow } from 'ng-mocks';8import { ngMocksDefault } from 'ng-mocks';9import { ngMocksFind } from 'ng-mocks';10import { ngMocksFlush } from 'ng-mocks';11import { ngMocksGet } from 'ng-mocks';12import { ngMocksMock } from 'ng-mocks';13import { ngMocksRef } from 'ng-mocks';14import { ngMocksRender } from 'ng-mocks';15import { ngMocksStabilize } from 'ng-mocks';16import { ngMocksToken } from 'ng-mocks';17import { ngMocksTouch } from 'ng-mocks';18import { ngMocksUnmock } from 'ng-mocks';19import { ngMocksUpgrade } from 'ng-mocks';20import { ngMocksWarn } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parentMethod } from 'ng-mocks';2import { MyComponent } from './my-component';3import { MyService } from './my-service';4describe('MyComponent', () => {5 let component: MyComponent;6 let service: MyService;7 beforeEach(() => {8 service = parentMethod(MyService);9 component = new MyComponent(service);10 });11 it('should create', () => {12 expect(component).toBeTruthy();13 });14});15export class MyComponent {16 constructor(private service: MyService) {}17}18export class MyService {}19import { MyService } from './my-service';20describe('MyService', () => {21 let service: MyService;22 beforeEach(() => {23 service = new MyService();24 });25 it('should create', () => {26 expect(service).toBeTruthy();27 });28});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parentMethod } from 'ng-mocks';2import { parentMethod } from 'ng-mocks';3import { parentMethod } from 'ng-mocks';4import { parentMethod } from 'ng-mocks';5import { parentMethod } from 'ng-mocks';6import { parentMethod } from 'ng-mocks';7import { parentMethod } from 'ng-mocks';8import { parentMethod } from 'ng-mocks';9import { parentMethod } from 'ng-mocks';10import { parentMethod } from 'ng-mocks';11import { parentMethod } from 'ng-mocks';12import { parentMethod } from 'ng-mocks';13import { parentMethod } from 'ng-mocks';14import { parentMethod } from 'ng-mocks';15import { parentMethod } from 'ng-mocks';16import { parentMethod } from 'ng-mocks';17import { parentMethod } from 'ng-mocks';18import { parentMethod } from 'ng-mocks';19import { parentMethod } from 'ng-mocks';20import { parentMethod } from 'ng

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parentMethod } from 'ng-mocks';2@Component({3})4export class MyComponent {5}6describe('MyComponent', () => {7 let fixture: ComponentFixture<MyComponent>;8 let component: MyComponent;9 beforeEach(() => {10 fixture = TestBed.configureTestingModule({11 }).createComponent(MyComponent);12 component = fixture.componentInstance;13 });14 it('should call parentMethod', () => {15 const spy = spyOnProperty(component, 'parentMethod');16 component.parentMethod();17 expect(spy).toHaveBeenCalled();18 });19});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parentMethod } from 'ng-mocks';2import { childMethod } from 'ng-mocks';3const parent = { id: 1, name: 'parent' };4const child = { id: 2, name: 'child' };5parentMethod(parent, 'name');6childMethod(child, 'name');7import { parentMethod } from 'ng-mocks';8import { childMethod } from 'ng-mocks';9const parent = { id: 1, name: 'parent' };10const child = { id: 2, name: 'child' };11describe('parentMethod', () => {12 it('should return parent', () => {13 expect(parentMethod(parent, 'name')).toBe('parent');14 });15});16describe('childMethod', () => {17 it('should return child', () => {18 expect(childMethod(child, 'name')).toBe('child');19 });20});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks 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