From fdf9a021abe0ada3737e8ffa3924a81caad6fd83 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 6 Oct 2020 13:54:01 +0530 Subject: [PATCH] more tests --- libs/remix-astwalker/tests/newTests.ts | 60 +++++++++++++++----------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/libs/remix-astwalker/tests/newTests.ts b/libs/remix-astwalker/tests/newTests.ts index 86d7536d0c..cb30b5f36a 100644 --- a/libs/remix-astwalker/tests/newTests.ts +++ b/libs/remix-astwalker/tests/newTests.ts @@ -6,8 +6,9 @@ import legacyNode from "./resources/legacyAST"; tape("New ASTWalker", (t: tape.Test) => { // New Ast Object const astWalker = new AstWalker(); - const latestAST = node.ast + const latestASTNode = JSON.parse(JSON.stringify(node.ast)) t.test("ASTWalker.walk && .walkastList", (st: tape.Test) => { + const latestAST = JSON.parse(JSON.stringify(latestASTNode)) st.plan(24); // EventListener astWalker.on("node", node => { @@ -21,7 +22,7 @@ tape("New ASTWalker", (t: tape.Test) => { }); // Callback pattern - astWalker.walk(node.ast, (node: AstNode) => { + astWalker.walk(latestAST, (node: AstNode) => { if (node.nodeType === "ContractDefinition") { checkContract(st, node); } @@ -39,10 +40,10 @@ tape("New ASTWalker", (t: tape.Test) => { return true; }; // Calling walk function with cb - astWalker.walk(node.ast, callback); + astWalker.walk(latestAST, callback); // Calling walk function without cb - astWalker.walk(node.ast); + astWalker.walk(latestAST); // Calling WALKASTLIST function astWalker.walkAstList(node); @@ -54,40 +55,47 @@ tape("New ASTWalker", (t: tape.Test) => { st.end(); }); - // t.test("ASTWalker.getASTNodeChildren", (st: tape.Test) => { - // st.plan(11); - // st.equal(node.ast.nodeType, 'SourceUnit') + t.test("ASTWalker.getASTNodeChildren", (st: tape.Test) => { + const latestAST = JSON.parse(JSON.stringify(latestASTNode)) + st.plan(14); + st.equal(latestAST.nodeType, 'SourceUnit') - // let subNodes1 = astWalker.getASTNodeChildren(node.ast) + let subNodes1 = astWalker.getASTNodeChildren(latestAST) - // st.equal(subNodes1.length, 3) - // st.equal(subNodes1[0].nodeType, 'PragmaDirective') - // st.equal(subNodes1[1].nodeType, 'ImportDirective') - // st.equal(subNodes1[2].nodeType, 'ContractDefinition') + st.equal(subNodes1.length, 3) + st.equal(subNodes1[0].nodeType, 'PragmaDirective') + st.equal(subNodes1[1].nodeType, 'ImportDirective') + st.equal(subNodes1[2].nodeType, 'ContractDefinition') - // let subNodes2 = astWalker.getASTNodeChildren(subNodes1[0]) - // st.equal(subNodes2.length, 0) + let subNodes2 = astWalker.getASTNodeChildren(subNodes1[0]) + st.equal(subNodes2.length, 0) - // subNodes2 = astWalker.getASTNodeChildren(subNodes1[1]) - // st.equal(subNodes2.length, 0) - // console.log('subNodes-1-->', subNodes1[2]) + subNodes2 = astWalker.getASTNodeChildren(subNodes1[1]) + st.equal(subNodes2.length, 0) - // subNodes2 = astWalker.getASTNodeChildren(subNodes1[2]) - // console.log('subNodes-3-->', subNodes2) - // st.equal(subNodes2.length, 4) - // st.equal(subNodes2[1].nodeType, 'VariableDeclaration') - // st.equal(subNodes2[2].nodeType, 'FunctionDefinition') - // st.equal(subNodes2[3].nodeType, 'FunctionDefinition') + subNodes2 = astWalker.getASTNodeChildren(subNodes1[2]) + st.equal(subNodes2.length, 4) + st.equal(subNodes2[0].nodeType, 'VariableDeclaration') + st.equal(subNodes2[1].nodeType, 'FunctionDefinition') + st.equal(subNodes2[2].nodeType, 'FunctionDefinition') + st.equal(subNodes2[3].nodeType, 'InheritanceSpecifier') - // st.end(); - // }); + let subNodes3 = astWalker.getASTNodeChildren(subNodes2[0]) + + st.equal(subNodes3.length, 1) + st.equal(subNodes3[0].nodeType, 'ElementaryTypeName') + + subNodes3 = astWalker.getASTNodeChildren(subNodes2[1]) + + st.end(); + }); t.test("ASTWalkFull", (st: tape.Test) => { + const latestAST = JSON.parse(JSON.stringify(latestASTNode)) const astNodeCount = 26; st.plan(2 + astNodeCount); let count: number = 0; astWalker.walkFull(latestAST, (node: AstNode) => { - // console.log('nodes inside walkfull-------------------------->>>', node) st.ok(isAstNode(node), "passed an ast node"); count += 1; });