Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#2535): added tests and puzzles for XMIR to phi-calculus translator #2569

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ SOFTWARE.
<limit>
<counter>CLASS</counter>
<value>MISSEDCOUNT</value>
<maximum>7</maximum>
<maximum>8</maximum>
</limit>
</limits>
</rule>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 TranslateToPhiMojo 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
}
}
17 changes: 17 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,23 @@ public Iterator<Class<? extends AbstractMojo>> iterator() {
}
}

/**
* Translates EO program to Phi-calculus expression.
*
* @since 0.32
*/
static final class TranslateToPhi implements Iterable<Class<? extends AbstractMojo>> {

@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
TranslateToPhiMojo.class
).iterator();
}
}

/**
* Plan all eo dependencies full pipeline.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* 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 TranslateToPhiMojo}.
*
* @since 0.32
* @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 TranslateToPhiMojoTest {

/**
* Checks that file exist.
*
* @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.TranslateToPhi())
.result(),
Matchers.hasKey(
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 {
MatcherAssert.assertThat(
new FakeMaven(temp)
.withProgram(
"[] > holder",
" 103 > storage"
)
.execute(new FakeMaven.TranslateToPhi())
.result()
.get(
String.format(
"target/%s/holder.%s",
TranslateToPhiMojo.DIR,
TranslateToPhiMojo.EXT
)
)
.toFile()
.toString(),
Matchers.equalTo(
"holder ↦ ⟦ storage ↦ 103 ⟧"
)
);
}
}
Loading