-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
eo-maven-plugin/src/main/java/org/eolang/maven/TranslateToPhiMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
eo-maven-plugin/src/test/java/org/eolang/maven/TranslateToPhiMojoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ⟧" | ||
) | ||
); | ||
} | ||
} |
98a8659
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
2536-4ef72508
discovered ineo-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.98a8659
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
2535-77ae0c2e
discovered ineo-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.