From 9850e58de1a06102fcadd7788bd0ddd5adfcf2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Thu, 1 Aug 2024 19:14:08 +0100 Subject: [PATCH] Adds tests to AnyWeaver, improves test in AnyAst --- .../up/fe/specs/anycompiler/srl-ast.json.txt | 6 +++ .../fe/specs/anycompiler/JsonParserTest.java | 8 +++- AnyWeaver/build.gradle | 16 +++---- .../anyweaver/test/weaver/Srl.js | 7 +++ .../anyweaver/test/weaver/src/srl-ast.json | 30 ++++++++++++ .../anycompiler/weaver/AnyWeaverTester.java | 14 ++++++ .../weaver/tests/AnyWeaverTest.java | 47 +++++++++++++++++++ 7 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 AnyAst/resources/pt/up/fe/specs/anycompiler/srl-ast.json.txt create mode 100644 AnyWeaver/test-resources/anyweaver/test/weaver/Srl.js create mode 100644 AnyWeaver/test-resources/anyweaver/test/weaver/src/srl-ast.json create mode 100644 AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/AnyWeaverTester.java create mode 100644 AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/tests/AnyWeaverTest.java diff --git a/AnyAst/resources/pt/up/fe/specs/anycompiler/srl-ast.json.txt b/AnyAst/resources/pt/up/fe/specs/anycompiler/srl-ast.json.txt new file mode 100644 index 0000000..6b22195 --- /dev/null +++ b/AnyAst/resources/pt/up/fe/specs/anycompiler/srl-ast.json.txt @@ -0,0 +1,6 @@ +GenericAnyNode: STREAM::store: {args=[outputStream], id=node::1, type=STREAM::store} + GenericAnyNode: OP::+: {id=node::2, type=OP::+} + GenericAnyNode: STREAM::load: {args=[S2], id=node::3, type=STREAM::load} + GenericAnyNode: OP::*: {id=node::4, type=OP::*} + GenericAnyNode: STREAM::load: {args=[S1], id=node::5, type=STREAM::load} + GenericAnyNode: INPUT::VALUE: {args=[mult_factor], id=node::6, type=INPUT::VALUE} diff --git a/AnyAst/test/pt/up/fe/specs/anycompiler/JsonParserTest.java b/AnyAst/test/pt/up/fe/specs/anycompiler/JsonParserTest.java index c87cddf..20ea41b 100644 --- a/AnyAst/test/pt/up/fe/specs/anycompiler/JsonParserTest.java +++ b/AnyAst/test/pt/up/fe/specs/anycompiler/JsonParserTest.java @@ -13,17 +13,21 @@ package pt.up.fe.specs.anycompiler; + +import org.junit.Assert; import org.junit.Test; import pt.up.fe.specs.anycompiler.parsers.JsonParser; import pt.up.fe.specs.util.SpecsIo; +import pt.up.fe.specs.util.SpecsStrings; public class JsonParserTest { @Test public void testSrlAst() { - var code = SpecsIo.getResource(() -> "pt/up/fe/specs/anycompiler/srl-ast.json"); + var code = SpecsIo.getResource("pt/up/fe/specs/anycompiler/srl-ast.json"); var parser = new JsonParser("type", "children", true); var ast = parser.parse(code); - System.out.println("AST:" + ast.toTree()); + + Assert.assertTrue(SpecsStrings.check(SpecsIo.getResource("pt/up/fe/specs/anycompiler/srl-ast.json.txt"), ast.toTree())); } } diff --git a/AnyWeaver/build.gradle b/AnyWeaver/build.gradle index a257d0e..eb18a2a 100644 --- a/AnyWeaver/build.gradle +++ b/AnyWeaver/build.gradle @@ -57,17 +57,17 @@ sourceSets { } } - /* + test { - java { - srcDir 'test' - } + java { + srcDir 'test' + } - resources { - srcDir 'resources' - } + resources { + srcDir 'test-resources' + } } - */ + } diff --git a/AnyWeaver/test-resources/anyweaver/test/weaver/Srl.js b/AnyWeaver/test-resources/anyweaver/test/weaver/Srl.js new file mode 100644 index 0000000..5026f1d --- /dev/null +++ b/AnyWeaver/test-resources/anyweaver/test/weaver/Srl.js @@ -0,0 +1,7 @@ +laraImport("weaver.Query"); + +for (const l of Query.search("STREAM::load")) { + console.log(l.getValue("args")); +} + +console.log("Hello") \ No newline at end of file diff --git a/AnyWeaver/test-resources/anyweaver/test/weaver/src/srl-ast.json b/AnyWeaver/test-resources/anyweaver/test/weaver/src/srl-ast.json new file mode 100644 index 0000000..65e123c --- /dev/null +++ b/AnyWeaver/test-resources/anyweaver/test/weaver/src/srl-ast.json @@ -0,0 +1,30 @@ +{ + "node::1": { + "type": "STREAM::store", + "args": ["outputStream"], + "children": ["node::2"] + }, + "node::2": { + "type": "OP::+", + "children": ["node::3", "node::4"] + }, + "node::3": { + "type": "STREAM::load", + "args": ["S2"], + "children": [] + }, + "node::4": { + "type": "OP::*", + "children": ["node::5", "node::6"] + }, + "node::5": { + "type": "STREAM::load", + "args": ["S1"], + "children": [] + }, + "node::6": { + "type": "INPUT::VALUE", + "args": ["mult_factor"], + "children": [] + } +} diff --git a/AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/AnyWeaverTester.java b/AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/AnyWeaverTester.java new file mode 100644 index 0000000..896e7a8 --- /dev/null +++ b/AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/AnyWeaverTester.java @@ -0,0 +1,14 @@ +package pt.up.fe.specs.anycompiler.weaver; + + +import org.lara.interpreter.tester.WeaverTester; + +public class AnyWeaverTester extends WeaverTester { + + public AnyWeaverTester(String basePackage) { + super(AnyWeaver.class, basePackage); + + // Set custom settings + //getCustomData(). + } +} diff --git a/AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/tests/AnyWeaverTest.java b/AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/tests/AnyWeaverTest.java new file mode 100644 index 0000000..72cc463 --- /dev/null +++ b/AnyWeaver/test/pt/up/fe/specs/anycompiler/weaver/tests/AnyWeaverTest.java @@ -0,0 +1,47 @@ +/** + * Copyright 2016 SPeCS. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. under the License. + */ + +package pt.up.fe.specs.anycompiler.weaver.tests; + +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import pt.up.fe.specs.anycompiler.weaver.AnyWeaverTester; +import pt.up.fe.specs.util.SpecsSystem; + +public class AnyWeaverTest { + + @BeforeClass + public static void setupOnce() { + SpecsSystem.programStandardInit(); + AnyWeaverTester.clean(); + } + + @After + public void tearDown() { + AnyWeaverTester.clean(); + } + + private static AnyWeaverTester newTester() { + return new AnyWeaverTester("anyweaver/test/weaver/") + .setSrcPackage("src/") + .setResultPackage("results/"); + } + + @Test + public void testBasic() { + newTester().test("Srl.js", "srl-ast.json"); + } + + +}