Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Nov 1, 2023
2 parents 6545c3f + 7474b01 commit 98a8659
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 1 deletion.
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 ⟧"
)
);
}
}

2 comments on commit 98a8659

@0pdd
Copy link

@0pdd 0pdd commented on 98a8659 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2536-4ef72508 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/TranslateToPhiMojo.java) and submitted as #2572. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 98a8659 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2535-77ae0c2e discovered in eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java) and submitted as #2573. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.