From 9244bd768c802de63ed03ab30c3b76b0e67ba248 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Wed, 10 Nov 2021 16:52:08 +0800 Subject: [PATCH] fix: fix tests fix dependency bugs in tests --- build.gradle | 1 + .../bdware/sc/engine/test/MockUtilTest.java | 4 +- .../org/bdware/sc/parser/YJSParserTest.java | 69 +++++++++---------- src/test/resources/function.yjs | 9 ++- 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/build.gradle b/build.gradle index 82f22b2..b838c23 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,7 @@ jar { } tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE) +tasks.processTestResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE) task copyLibs(type: Copy, dependsOn: ":common:jar") { into "./build/output/libs/" diff --git a/src/test/java/org/bdware/sc/engine/test/MockUtilTest.java b/src/test/java/org/bdware/sc/engine/test/MockUtilTest.java index 54262ee..90b2448 100644 --- a/src/test/java/org/bdware/sc/engine/test/MockUtilTest.java +++ b/src/test/java/org/bdware/sc/engine/test/MockUtilTest.java @@ -2,8 +2,8 @@ package org.bdware.sc.engine.test; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import org.bdware.sc.engine.MockUtil; -import org.bdware.sc.util.MockSchemaParser; +import org.bdware.mockjava.MockSchemaParser; +import org.bdware.mockjava.MockUtil; public class MockUtilTest { public static void main(String[] args) { diff --git a/src/test/java/org/bdware/sc/parser/YJSParserTest.java b/src/test/java/org/bdware/sc/parser/YJSParserTest.java index ee652ad..1f7ac9c 100644 --- a/src/test/java/org/bdware/sc/parser/YJSParserTest.java +++ b/src/test/java/org/bdware/sc/parser/YJSParserTest.java @@ -1,27 +1,27 @@ package org.bdware.sc.parser; import com.google.gson.Gson; -import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.bdware.sc.ContractResult; -import org.bdware.sc.bean.ContractRequest; import org.bdware.sc.compiler.YJSCompiler; import org.bdware.sc.compiler.YJSErrorListener; import org.bdware.sc.engine.DesktopEngine; import org.bdware.sc.node.ContractNode; import org.junit.Test; -import java.io.*; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; public class YJSParserTest { @Test - public void YJSParserElseTest(){ + public void elseTest() throws IOException { InputStream resource = YJSParserTest.class.getClassLoader().getResourceAsStream("module1.yjs"); - JavaScriptLexer lexer = null; - try { - lexer = new JavaScriptLexer(new ANTLRInputStream(resource)); - + JavaScriptLexer lexer; + assert resource != null; + lexer = new JavaScriptLexer(CharStreams.fromStream(resource)); lexer.setUseStrictDefault(true); CommonTokenStream cts = new CommonTokenStream(lexer); YJSErrorListener errorListener = new YJSErrorListener(); @@ -31,45 +31,42 @@ public class YJSParserTest { parser.addErrorListener(errorListener); parser.addErrorListener(new DiagnosticErrorListener()); YJSParser.ProgramContext tree = parser.program(); - for (String str:errorListener.getResultList()) + for (String str : errorListener.getResultList()) System.out.println(str); - } catch (IOException e) { - e.printStackTrace(); - } } @Test - public void functionTest(){ + public void functionTest() throws IOException { InputStream resource = YJSParserTest.class.getClassLoader().getResourceAsStream("function.yjs"); - JavaScriptLexer lexer = null; - try { - lexer = new JavaScriptLexer(new ANTLRInputStream(resource)); - - lexer.setUseStrictDefault(true); - CommonTokenStream cts = new CommonTokenStream(lexer); - YJSErrorListener errorListener = new YJSErrorListener(); - // 语法分析 - YJSParser parser = new YJSParser(cts); - parser.removeErrorListeners(); - parser.addErrorListener(errorListener); - parser.addErrorListener(new DiagnosticErrorListener()); - YJSParser.ProgramContext tree = parser.program(); - for (String str:errorListener.getResultList()) - System.out.println(str); - } catch (IOException e) { - e.printStackTrace(); + JavaScriptLexer lexer; + assert resource != null; + lexer = new JavaScriptLexer(CharStreams.fromStream(resource)); + lexer.setUseStrictDefault(true); + CommonTokenStream cts = new CommonTokenStream(lexer); + YJSErrorListener errorListener = new YJSErrorListener(); + // 语法分析 + YJSParser parser = new YJSParser(cts); + parser.removeErrorListeners(); + parser.addErrorListener(errorListener); + parser.addErrorListener(new DiagnosticErrorListener()); + YJSParser.ProgramContext tree = parser.program(); + for (YJSParser.ClzOrFunctionDeclarationContext clzOrFunc : tree.contractDeclar().clzOrFunctionDeclaration()) { + System.out.println(clzOrFunc.functionDeclaration().View()); + } + for (String str : errorListener.getResultList()) { + System.out.println(str); } - } @Test - public void YJSParserTest() throws FileNotFoundException {//测试执行 engine 的 executeContract方法 - InputStream resource = new FileInputStream("../front-agent/BDWareProjectDir/public/ARouteExample/ARouteExample.yjs"); + public void test() throws FileNotFoundException {//测试执行 engine 的 executeContract方法 + InputStream resource = new FileInputStream( + "../front-agent/BDWareProjectDir/public/ARouteExample/ARouteExample.yjs"); YJSCompiler compiler = new YJSCompiler(); try { ContractNode cn = compiler.compile(resource, "rrr.yjs"); - DesktopEngine engine = new DesktopEngine(); - System.out.println(new Gson().toJson(cn)); + new DesktopEngine(); + System.out.println(new Gson().toJson(cn)); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/test/resources/function.yjs b/src/test/resources/function.yjs index cfd59a5..7df7781 100644 --- a/src/test/resources/function.yjs +++ b/src/test/resources/function.yjs @@ -1,5 +1,8 @@ -contract str{ - export funccion ab(){ - +contract str { + export function ab() { + return "world!"; + } + function cd() view { + return "view!"; } } \ No newline at end of file