From 5cca3f1c102ae1d19507df552893a1915a1352f5 Mon Sep 17 00:00:00 2001 From: graur Date: Tue, 31 Oct 2023 11:18:56 +0300 Subject: [PATCH 1/3] #2535 - added tests and puzzles --- eo-maven-plugin/pom.xml | 2 +- .../org/eolang/maven/PhiTranslatorMojo.java | 59 ++++++++++++ .../test/java/org/eolang/maven/FakeMaven.java | 17 ++++ .../eolang/maven/PhiTranslatorMojoTest.java | 95 +++++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/PhiTranslatorMojo.java create mode 100644 eo-maven-plugin/src/test/java/org/eolang/maven/PhiTranslatorMojoTest.java diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml index a7fc72cb40..0483f57220 100644 --- a/eo-maven-plugin/pom.xml +++ b/eo-maven-plugin/pom.xml @@ -436,7 +436,7 @@ SOFTWARE. CLASS MISSEDCOUNT - 7 + 8 diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiTranslatorMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiTranslatorMojo.java new file mode 100644 index 0000000000..ea008ad67e --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiTranslatorMojo.java @@ -0,0 +1,59 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; + +/** + * Read XMIR file and translate it to the phi-calculus expression. + * + * @since 0.32 + * @todo #2536:30min We need to implement exec() method. + * The main idea is to read program written in EO and translate it to Phi-calculus. + * To store this result we suggest to create a new folder: xmir-to-phi. + * Let's store it to this folder one file by one. + */ +@Mojo( + name = "xmir-to-phi", + defaultPhase = LifecyclePhase.PROCESS_SOURCES, + threadSafe = true +) +public final class PhiTranslatorMojo extends SafeMojo { + + /** + * The directory where to generate to. + */ + public static final String DIR = "xmir-to-phi"; + + /** + * Extension of the file where we put phi-calculus expression (.txt). + */ + public static final String EXT = "txt"; + + @Override + public void exec() { + //tbd + } +} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java index 6a476629a0..91c5e68e12 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java @@ -683,6 +683,23 @@ public Iterator> iterator() { } } + /** + * Translates EO program to Phi-calculus expression. + * + * @since 0.32 + */ + static final class PhiTranslator implements Iterable> { + + @Override + public Iterator> iterator() { + return Arrays.>asList( + ParseMojo.class, + OptimizeMojo.class, + PhiTranslatorMojo.class + ).iterator(); + } + } + /** * Plan all eo dependencies full pipeline. * diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/PhiTranslatorMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/PhiTranslatorMojoTest.java new file mode 100644 index 0000000000..0b787237b8 --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/PhiTranslatorMojoTest.java @@ -0,0 +1,95 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import java.nio.file.Path; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +/** + * Test case for {@link PhiTranslatorMojo}. + * + * @since 0.32 + * @todo #2535:30min Enable tests: {@link PhiTranslatorMojoTest#checksExistence(java.nio.file.Path)} + * and {@link PhiTranslatorMojoTest#checksPhiCalculusExpression(java.nio.file.Path)}. + * Also it's better to add more test cases in different EO programs with corresponding Phi-calculus + * expressions. + */ +class PhiTranslatorMojoTest { + + /** + * Generate phi-calculus expression by XMIR. + * + * @param temp Temporary directory. + * @throws Exception + */ + @Test + @Disabled + void checksExistence(@TempDir final Path temp) throws Exception { + MatcherAssert.assertThat( + new FakeMaven(temp) + .withProgram( + "[] > cart", + " memory 0 > total", + " [i] > add", + " total.write > @", + " total.plus i" + ) + .execute(new FakeMaven.PhiTranslator()) + .result(), + Matchers.hasKey( + String.format("target/%s/cart.%s", PhiTranslatorMojo.DIR, PhiTranslatorMojo.EXT) + ) + ); + } + + @Test + @Disabled + void checksPhiCalculusExpression(@TempDir final Path temp) throws Exception { + MatcherAssert.assertThat( + new FakeMaven(temp) + .withProgram( + "[] > holder", + " 103 > storage" + ) + .execute(new FakeMaven.PhiTranslator()) + .result() + .get( + String.format( + "target/%s/holder.%s", + PhiTranslatorMojo.DIR, + PhiTranslatorMojo.EXT + ) + ) + .toFile() + .toString(), + Matchers.equalTo( + "holder ↦ ⟦ storage ↦ 103 ⟧" + ) + ); + } +} From 21b22ac3a7da23da95b55efb51aef3b0d12b8d6e Mon Sep 17 00:00:00 2001 From: graur Date: Wed, 1 Nov 2023 11:19:35 +0300 Subject: [PATCH 2/3] #2535 - fixed name --- ...latorMojo.java => TranslateToPhiMojo.java} | 2 +- .../test/java/org/eolang/maven/FakeMaven.java | 4 +-- ...oTest.java => TranslateToPhiMojoTest.java} | 26 ++++++++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) rename eo-maven-plugin/src/main/java/org/eolang/maven/{PhiTranslatorMojo.java => TranslateToPhiMojo.java} (97%) rename eo-maven-plugin/src/test/java/org/eolang/maven/{PhiTranslatorMojoTest.java => TranslateToPhiMojoTest.java} (80%) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiTranslatorMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/TranslateToPhiMojo.java similarity index 97% rename from eo-maven-plugin/src/main/java/org/eolang/maven/PhiTranslatorMojo.java rename to eo-maven-plugin/src/main/java/org/eolang/maven/TranslateToPhiMojo.java index ea008ad67e..30bd1300b2 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiTranslatorMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/TranslateToPhiMojo.java @@ -40,7 +40,7 @@ defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true ) -public final class PhiTranslatorMojo extends SafeMojo { +public final class TranslateToPhiMojo extends SafeMojo { /** * The directory where to generate to. diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java index 91c5e68e12..10e75434e0 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java @@ -688,14 +688,14 @@ public Iterator> iterator() { * * @since 0.32 */ - static final class PhiTranslator implements Iterable> { + static final class TranslateToPhi implements Iterable> { @Override public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, - PhiTranslatorMojo.class + TranslateToPhiMojo.class ).iterator(); } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/PhiTranslatorMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java similarity index 80% rename from eo-maven-plugin/src/test/java/org/eolang/maven/PhiTranslatorMojoTest.java rename to eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java index 0b787237b8..09f111b801 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/PhiTranslatorMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java @@ -31,18 +31,18 @@ import org.junit.jupiter.api.io.TempDir; /** - * Test case for {@link PhiTranslatorMojo}. + * Test case for {@link TranslateToPhiMojo}. * * @since 0.32 - * @todo #2535:30min Enable tests: {@link PhiTranslatorMojoTest#checksExistence(java.nio.file.Path)} - * and {@link PhiTranslatorMojoTest#checksPhiCalculusExpression(java.nio.file.Path)}. + * @todo #2535:30min Enable tests: {@link TranslateToPhiMojoTest#checksExistence(java.nio.file.Path)} + * and {@link TranslateToPhiMojoTest#checksPhiCalculusExpression(java.nio.file.Path)}. * Also it's better to add more test cases in different EO programs with corresponding Phi-calculus * expressions. */ -class PhiTranslatorMojoTest { +class TranslateToPhiMojoTest { /** - * Generate phi-calculus expression by XMIR. + * Checks that file exist. * * @param temp Temporary directory. * @throws Exception @@ -59,14 +59,20 @@ void checksExistence(@TempDir final Path temp) throws Exception { " total.write > @", " total.plus i" ) - .execute(new FakeMaven.PhiTranslator()) + .execute(new FakeMaven.TranslateToPhi()) .result(), Matchers.hasKey( - String.format("target/%s/cart.%s", PhiTranslatorMojo.DIR, PhiTranslatorMojo.EXT) + String.format("target/%s/cart.%s", TranslateToPhiMojo.DIR, TranslateToPhiMojo.EXT) ) ); } + /** + * Generate phi-calculus expression by XMIR. + * + * @param temp Temporary directory. + * @throws Exception + */ @Test @Disabled void checksPhiCalculusExpression(@TempDir final Path temp) throws Exception { @@ -76,13 +82,13 @@ void checksPhiCalculusExpression(@TempDir final Path temp) throws Exception { "[] > holder", " 103 > storage" ) - .execute(new FakeMaven.PhiTranslator()) + .execute(new FakeMaven.TranslateToPhi()) .result() .get( String.format( "target/%s/holder.%s", - PhiTranslatorMojo.DIR, - PhiTranslatorMojo.EXT + TranslateToPhiMojo.DIR, + TranslateToPhiMojo.EXT ) ) .toFile() From 7474b0134c66c3ac2ab1357dd6430afb46b2a8b6 Mon Sep 17 00:00:00 2001 From: graur Date: Wed, 1 Nov 2023 13:21:51 +0300 Subject: [PATCH 3/3] #2535 - fixed long link name --- .../src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java index 09f111b801..897670a745 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java @@ -34,7 +34,8 @@ * Test case for {@link TranslateToPhiMojo}. * * @since 0.32 - * @todo #2535:30min Enable tests: {@link TranslateToPhiMojoTest#checksExistence(java.nio.file.Path)} + * @todo #2535:30min Enable tests: + * {@link TranslateToPhiMojoTest#checksExistence(java.nio.file.Path)} * and {@link TranslateToPhiMojoTest#checksPhiCalculusExpression(java.nio.file.Path)}. * Also it's better to add more test cases in different EO programs with corresponding Phi-calculus * expressions.