diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 8464cb69cd..0000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,12 +0,0 @@ -Make sure the title of the issue explains the problem you are having. Also, the description of the issue must clearly explain what is broken, not what you want us to implement. Go through this checklist and make sure you answer "YES" to all points: - - - You have all pre-requisites listed in README.md installed - - You are sure that you are not reporting a duplicate (search all issues) - - You say "is broken" or "doesn't work" in the title - - You tell us what you are trying to do - - You explain the results you are getting - - You suggest an alternative result you would like to see - -This article will help you understand what we are looking for: http://www.yegor256.com/2014/11/24/principles-of-bug-tracking.html - -Thank you for your contribution! diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6cc83b323d..0000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,11 +0,0 @@ -Many thanks for your contribution, we truly appreciate it. We will appreciate it even more, if you make sure that you can say "YES" to each point in this short checklist: - - - You made a small amount of changes (less than 100 lines, less than 10 files) - - You made changes related to only one bug (create separate PRs for separate problems) - - You are ready to defend your changes (there will be a code review) - - You don't touch what you don't understand - - You ran the build locally and it passed - -This article will help you understand what we are looking for: http://www.yegor256.com/2015/02/09/serious-code-reviewer.html - -Thank you for your contribution! diff --git a/LICENSE.txt b/LICENSE.txt index 93682bee04..0fad6fb4d6 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 eolang.org +Copyright (c) 2016-2020 Yegor Bugayenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9af7334e64..02121c785e 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,8 @@ These things we **don't tolerate**: * NULL ([why?](http://www.yegor256.com/2014/05/13/why-null-is-bad.html)) * global variables/procedures * reflection - * constants * type casting ([why?](http://www.yegor256.com/2015/04/02/class-casting-is-anti-pattern.html)) - * scalar types + * scalar types and data primitives * annotations ([why?](http://www.yegor256.com/2016/04/12/java-annotations-are-evil.html)) * unchecked exceptions ([why?](http://www.yegor256.com/2015/07/28/checked-vs-unchecked-exceptions.html)) * operators @@ -69,21 +68,30 @@ independent. ## Quick Start -Here is a classic "Hello, world!" example: +Here is a simple program that asks for a year and tells you +whether it's leap or not: ``` -import org.eolang.cli -import org.eolang.printed -import org.eolang.string -cli: - printed: - string: - "Hello, world!" ++alias stdout org.eolang.io.Stdout ++alias stdin org.eolang.io.Stdin ++alias scanner org.eolang.txt.Scanner + +[args] > main + [y] > leap + or + and + eq (mod y 4) 0 + not (eq (mod y 100) 0) + eq (mod y 400) 0 + and + stdout "Enter a year:" + stdout + concat + (scanner stdin).nextInt > !year + " is a leap year?" + leap year:y ``` -This code will compile into a `.java` class that will compile into -a `.class` byte code that will run and print "Hello, world!". - ## How to contribute Fork repository, make changes, send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build: diff --git a/eo-archetype/LICENSE.txt b/eo-archetype/LICENSE.txt index 93682bee04..0fad6fb4d6 100644 --- a/eo-archetype/LICENSE.txt +++ b/eo-archetype/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 eolang.org +Copyright (c) 2016-2020 Yegor Bugayenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/eo-archetype/pom.xml b/eo-archetype/pom.xml index 8f63417adf..7b625b037e 100644 --- a/eo-archetype/pom.xml +++ b/eo-archetype/pom.xml @@ -2,7 +2,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/eo-compiler/src/main/resources/eo-object.xsd b/eo-compiler/src/main/resources/eo-object.xsd index 1d82bf8350..4efe300e98 100644 --- a/eo-compiler/src/main/resources/eo-object.xsd +++ b/eo-compiler/src/main/resources/eo-object.xsd @@ -2,7 +2,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/02-resolve-aliases.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/02-resolve-aliases.xsl new file mode 100644 index 0000000000..0e637371b3 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/02-resolve-aliases.xsl @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + The alias " + + " doesn't have the tail part: " + + " at line + + + + + + + org.eolang. + + + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/03-abstracts-float-up.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/03-abstracts-float-up.xsl new file mode 100644 index 0000000000..ed1a17c93f --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/03-abstracts-float-up.xsl @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/04-rename-bases.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/04-rename-bases.xsl new file mode 100644 index 0000000000..0632102fd4 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/04-rename-bases.xsl @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + Can't find ancestor of " + + " at line + + + + + + + + + + + + + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/05-wrap-method-calls.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/05-wrap-method-calls.xsl new file mode 100644 index 0000000000..ad65d745b5 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/05-wrap-method-calls.xsl @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/06-to-java.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/06-to-java.xsl new file mode 100644 index 0000000000..e963530496 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/06-to-java.xsl @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + import org.eolang.*; + + public final class + + + implements java.util.concurrent.Callable<Object> + + { + + + private final Args args; + + + public + + (final Args a) { + + + + + assert a.has(" + + "); + + + + + this.args = a; + + + } + + + + + } + + + + + + + + @Override + + + public Object call() throws Exception + + + + public Object + + (final Args a) + + { + + + + + Object + + ; + + + + + return + + + + + + + ; + + + } + + + + this.args.get(" + + ") + + + + + + = + + + + + + + + ( + + + + + + ) + + + + + + + + + + = + + new + + (new ArgsOf( + + a + + , + + + + + + + + new Entry(" + + + + + + + ", + + + + + + ) + + , + + + + + + + + + )) + + + + L + + + + + + " + + " + + + ' + + ' + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/broken-aliases.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/broken-aliases.xsl new file mode 100644 index 0000000000..fe132ae5d9 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/broken-aliases.xsl @@ -0,0 +1,48 @@ + + + + + + + + + + + + + The alias is invalid: " + + " + + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/duplicate-aliases.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/duplicate-aliases.xsl new file mode 100644 index 0000000000..d147063820 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/duplicate-aliases.xsl @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + The alias " + + " is duplicated + + + + + + + + + + + + + + The name " + + " is already in use + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/duplicate-names.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/duplicate-names.xsl new file mode 100644 index 0000000000..610c7f887c --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/duplicate-names.xsl @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + The name " + + " is already in use + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/one-body.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/one-body.xsl new file mode 100644 index 0000000000..6881809e55 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/one-body.xsl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + The object + + " + + " + + may have only one body + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/reserved-atoms.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/reserved-atoms.xsl new file mode 100644 index 0000000000..4cb6ad23eb --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/reserved-atoms.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + You can't copy " + + " as a normal object + + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/same-line-names.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/same-line-names.xsl new file mode 100644 index 0000000000..39bd0767c0 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/same-line-names.xsl @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + The name " + + " was already used on the same line + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/self-naming.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/self-naming.xsl new file mode 100644 index 0000000000..5ea60abc4a --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/self-naming.xsl @@ -0,0 +1,46 @@ + + + + + + + + + + + + The object " + + " can't copy itself + + + + + + + + + + diff --git a/eo-compiler/src/main/resources/org/eolang/compiler/errors/unknown-names.xsl b/eo-compiler/src/main/resources/org/eolang/compiler/errors/unknown-names.xsl new file mode 100644 index 0000000000..d613960b23 --- /dev/null +++ b/eo-compiler/src/main/resources/org/eolang/compiler/errors/unknown-names.xsl @@ -0,0 +1,46 @@ + + + + + + + + + + + + The object " + + " is not defined anywhere + + + + + + + + + + diff --git a/eo-compiler/src/test/java/org/eolang/compiler/MainTest.java b/eo-compiler/src/test/java/org/eolang/compiler/MainTest.java index 21a36e9f82..8350d99e1c 100644 --- a/eo-compiler/src/test/java/org/eolang/compiler/MainTest.java +++ b/eo-compiler/src/test/java/org/eolang/compiler/MainTest.java @@ -1,7 +1,7 @@ -/** +/* * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,23 +27,17 @@ import org.apache.commons.io.output.ByteArrayOutputStream; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test case for {@link Main}. - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ * @since 0.1 */ public final class MainTest { - /** - * Main can print a simple text. - * @throws Exception If some problem inside - */ @Test public void printsSimpleResponse() throws Exception { - try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { new Main(new PrintStream(baos), "--help").exec(); MatcherAssert.assertThat( new String(baos.toByteArray()), diff --git a/eo-compiler/src/test/java/org/eolang/compiler/PacksTest.java b/eo-compiler/src/test/java/org/eolang/compiler/PacksTest.java new file mode 100644 index 0000000000..973ab591f2 --- /dev/null +++ b/eo-compiler/src/test/java/org/eolang/compiler/PacksTest.java @@ -0,0 +1,103 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2020 Yegor Bugayenko + * + * 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.compiler; + +import com.jcabi.matchers.XhtmlMatchers; +import com.jcabi.xml.XML; +import com.jcabi.xml.XMLDocument; +import com.jcabi.xml.XSLChain; +import com.jcabi.xml.XSLDocument; +import java.io.ByteArrayOutputStream; +import java.util.Collection; +import java.util.Map; +import org.cactoos.io.InputOf; +import org.cactoos.io.OutputTo; +import org.cactoos.list.ListOf; +import org.cactoos.list.Mapped; +import org.hamcrest.MatcherAssert; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.yaml.snakeyaml.Yaml; + +/** + * Test case for packs. + * + * @since 1.0 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +public final class PacksTest { + + @ParameterizedTest + @MethodSource("yamlPacks") + @SuppressWarnings("unchecked") + public void testPacks(final String pack) throws Exception { + final Yaml yaml = new Yaml(); + final Map map = yaml.load( + PacksTest.class.getResourceAsStream( + String.format("packs/%s", pack) + ) + ); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final Program program = new Program( + new InputOf(String.format("%s\n", map.get("eo"))), + new OutputTo(baos) + ); + program.compile(); + final XML out = new XSLChain( + new Mapped<>( + node -> new XSLDocument( + ToJava.class.getResourceAsStream(node) + ), + (Collection) map.get("xsls") + ) + ).transform(new XMLDocument(baos.toString())); + for (final String xpath : (Collection) map.get("tests")) { + MatcherAssert.assertThat( + XhtmlMatchers.xhtml(out.toString()), + XhtmlMatchers.hasXPath(xpath) + ); + } + } + + @SuppressWarnings("PMD.UnusedPrivateMethod") + private static Collection yamlPacks() { + return new ListOf<>( + "simple.yaml", + "full-syntax.yaml", + "catches-name-duplicates.yaml", + "catches-alias-duplicates.yaml", + "catches-broken-aliases.yaml", + "catches-unknown-names.yaml", + "catches-self-naming.yaml", + "catches-reserved-atoms.yaml", + "catches-two-bodies.yaml", + "catches-same-line-name.yaml", + "adds-refs.yaml", + "flatten-abstracts.yaml", + "resolves-aliases.yaml", + "leap-year.yaml" + ); + } + +} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/ProgramTest.java b/eo-compiler/src/test/java/org/eolang/compiler/ProgramTest.java index 7ba20c923e..d7a0f7b09d 100644 --- a/eo-compiler/src/test/java/org/eolang/compiler/ProgramTest.java +++ b/eo-compiler/src/test/java/org/eolang/compiler/ProgramTest.java @@ -1,7 +1,7 @@ -/** +/* * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,269 +23,51 @@ */ package org.eolang.compiler; -import groovy.lang.GroovyClassLoader; -import groovy.lang.GroovyCodeSource; -import groovy.lang.GroovyShell; +import com.jcabi.matchers.XhtmlMatchers; import java.io.ByteArrayOutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import org.cactoos.io.DeadOutput; import org.cactoos.io.InputOf; import org.cactoos.io.OutputTo; import org.cactoos.io.ResourceOf; -import org.cactoos.list.StickyList; -import org.cactoos.text.JoinedText; -import org.cactoos.text.TextOf; import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Test case for {@link Program}. * - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ * @since 0.1 - * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) - * @checkstyle JavadocMethodCheck (500 lines) */ -@SuppressWarnings("PMD.AvoidDuplicateLiterals") public final class ProgramTest { - /** - * Compiles long EO syntax. - * @throws Exception If some problem inside - */ - @Test - public void compilesLongSyntax() throws Exception { - final Program program = new Program( - new ResourceOf("org/eolang/compiler/long-program.eo"), - s -> new DeadOutput() - ); - program.compile(); - } - - /** - * Creates Java code that really works. - * @throws Exception If some problem inside - */ @Test - public void compilesExecutableJava() throws Exception { + public void compilesSimpleCode() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Program program = new Program( - new InputOf( - new JoinedText( - "\n", - "object car as Serializable:", - " Integer @vin", - " String name():", - " \"Mercedes-Benz\"" - ).asString() - ), - s -> new OutputTo(baos) - ); - program.compile(); - try (final GroovyClassLoader loader = new GroovyClassLoader()) { - final Class type = loader.parseClass( - new GroovyCodeSource( - new TextOf(baos.toByteArray()).asString(), - "car", GroovyShell.DEFAULT_CODE_BASE - ) - ); - MatcherAssert.assertThat( - type.getMethod("name").invoke( - type.getConstructor(Integer.class).newInstance(0) - ), - Matchers.equalTo("Mercedes-Benz") - ); - } - } - - /** - * Test zero example, this object implements two interfaces. - * - * @throws Exception If some problem inside - */ - @Test - public void processZeroExample() throws Exception { - final Path dir = Files.createTempDirectory(""); - final Program program = new Program( - new ResourceOf("org/eolang/compiler/zero.eo"), dir - ); - program.compile(); - MatcherAssert.assertThat( - new TextOf(dir.resolve(Paths.get("zero.java"))).asString(), - Matchers.stringContainsInOrder( - new StickyList<>( - "public", - "final", - "class", - "zero", - "implements", - "Money", - ",", - "Int", - "{", - "private final Int amount;", - "private final Text currency;", - "}" - ) - ) - ); - } - - @Test - public void parsesFibonacciExample() throws Exception { - final Path dir = Files.createTempDirectory(""); - final Program program = new Program( - new ResourceOf("org/eolang/compiler/fibonacci.eo"), dir - ); - program.compile(); - MatcherAssert.assertThat( - new TextOf(dir.resolve(Paths.get("fibonacci.java"))).asString(), - Matchers.stringContainsInOrder( - new StickyList<>( - "public", "final", "class", - "fibonacci", "implements", "Int", "{", - "private final Int n;", - "public fibonacci()", "{", - "this(1);", - "}", - "public fibonacci(final Int n)", "{", - "this.n = n", - "}", - "public", "Int", "int", "()", "{", - "return", "new", "if", "(", - "new", "firstIsLess", "(", - "this.n", ",", "2", - ")", ",", - "1", ",", - "new", "plus", "(", - "this.n", ",", - "new", "fibonacci", "(", - "new", "minus", "(", - "this.n", ",", "1", - ")", - ")", - ")", - ");", - "}", - "}" - ) - ) - ); - } - - /** - * Program can parse a simple type with one method. - * - * @throws Exception If some problem inside - */ - @Test - public void parsesSimpleType() throws Exception { - final Path dir = Files.createTempDirectory(""); - final Program program = new Program( - new ResourceOf("org/eolang/compiler/book.eo"), dir + new ResourceOf("org/eolang/compiler/fibonacci.eo"), + new OutputTo(baos) ); program.compile(); MatcherAssert.assertThat( - new TextOf(dir.resolve(Paths.get("Book.java"))).asString(), - Matchers.allOf( - Matchers.containsString("interface Book"), - Matchers.containsString("Text text()") - ) - ); - } - - /** - * Program can parse a type with one method with parameters. - * - * @throws Exception If some problem inside - */ - @Test - public void parsesTypeWithParametrizedMethods() throws Exception { - final Path dir = Files.createTempDirectory(""); - final Program program = new Program( - new ResourceOf("org/eolang/compiler/pixel.eo"), dir - ); - program.compile(); - MatcherAssert.assertThat( - new TextOf(dir.resolve(Paths.get("Pixel.java"))).asString(), - Matchers.allOf( - Matchers.containsString("interface Pixel"), - Matchers.containsString( - "Pixel moveTo(final Integer x, final Integer y)" - ) - ) - ); - } - - /** - * Program can parse a type with multiple methods. - * - * @throws Exception If some problem inside - */ - @Test - public void parsesBigType() throws Exception { - final Path dir = Files.createTempDirectory(""); - final Program program = new Program( - new ResourceOf("org/eolang/compiler/car.eo"), dir - ); - program.compile(); - MatcherAssert.assertThat( - new TextOf(dir.resolve(Paths.get("Car.java"))).asString(), - Matchers.allOf( - Matchers.containsString("interface Car"), - Matchers.containsString("Money cost()"), - Matchers.containsString("Bytes picture()"), - Matchers.containsString("Car moveTo(final Coordinates coords)") - ) + XhtmlMatchers.xhtml( + new String(baos.toByteArray()) + ), + XhtmlMatchers.hasXPath("/program/objects/o[@name='fibo']") ); } - /** - * Program can parse multiple types in one file. - * This test verifies indentation parsing. - * - * @throws Exception If some problem inside - */ @Test - public void parsesMultipleTypes() throws Exception { - final Path dir = Files.createTempDirectory(""); - final Program program = new Program( - new ResourceOf("org/eolang/compiler/multitypes.eo"), dir - ); - program.compile(); - MatcherAssert.assertThat( - new TextOf(dir.resolve(Paths.get("Number.java"))).asString(), - Matchers.allOf( - Matchers.containsString("interface Number"), - Matchers.containsString("Decimal decimal()"), - Matchers.containsString("Integral integral()") - ) + public void failsOnBrokenSyntax() { + Assertions.assertThrows( + CompileException.class, + () -> { + final Program program = new Program( + new InputOf("this code is definitely wrong"), + new DeadOutput() + ); + program.compile(); + } ); - MatcherAssert.assertThat( - new TextOf(dir.resolve(Paths.get("Text.java"))).asString(), - Matchers.allOf( - Matchers.containsString("interface Text"), - Matchers.containsString("Number length()"), - Matchers.containsString("Collection lines()") - ) - ); - } - - /** - * Program can parse a type with multiple methods. - * @throws Exception If some problem inside - */ - @Test(expected = CompileException.class) - public void failsOnBrokenSyntax() throws Exception { - final Program program = new Program( - new InputOf("this code is definitely wrong"), - Files.createTempDirectory("") - ); - program.compile(); } } diff --git a/eo-compiler/src/test/java/org/eolang/compiler/ToJavaTest.java b/eo-compiler/src/test/java/org/eolang/compiler/ToJavaTest.java new file mode 100644 index 0000000000..52c8014fa2 --- /dev/null +++ b/eo-compiler/src/test/java/org/eolang/compiler/ToJavaTest.java @@ -0,0 +1,79 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2020 Yegor Bugayenko + * + * 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.compiler; + +import com.jcabi.xml.XMLDocument; +import java.io.ByteArrayOutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.cactoos.io.InputOf; +import org.cactoos.io.OutputTo; +import org.cactoos.io.ResourceOf; +import org.cactoos.text.TextOf; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +/** + * Test case for {@link ToJava}. + * + * @since 1.0 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +public final class ToJavaTest { + + /** + * Temp dir for tests. + * @checkstyle VisibilityModifierCheck (4 lines) + */ + @TempDir + public Path temp; + + @Test + public void compilesSimpleCodeToJava() throws Exception { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final Program program = new Program( + new ResourceOf("org/eolang/compiler/fibonacci.eo"), + new OutputTo(baos) + ); + program.compile(); + final ToJava tojava = new ToJava( + new XMLDocument(baos.toString()), + this.temp + ); + tojava.compile(); + final Path file = this.temp.resolve(Paths.get("fibo.java")); + MatcherAssert.assertThat( + Files.exists(file), + Matchers.is(true) + ); + MatcherAssert.assertThat( + new TextOf(new InputOf(file)).asString(), + Matchers.containsString("public final class fibo") + ); + } + +} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/java/JavaClassTest.java b/eo-compiler/src/test/java/org/eolang/compiler/java/JavaClassTest.java deleted file mode 100644 index a869037823..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/java/JavaClassTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.java; - -import java.util.Collection; -import org.cactoos.list.StickyList; -import org.cactoos.matchers.InputHasContent; -import org.cactoos.text.FormattedText; -import org.cactoos.text.UncheckedText; -import org.eolang.compiler.syntax.Attribute; -import org.eolang.compiler.syntax.ObjectBody; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Java class generator test. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -@SuppressWarnings("PMD.AvoidDuplicateLiterals") -public final class JavaClassTest { - - /** - * Test class code. - */ - @Test - public void classCode() { - final String name = "Cat"; - final String type = "Animal"; - MatcherAssert.assertThat( - new JavaClass( - name, - new StickyList<>(type), - new ObjectBody( - new StickyList<>(), - new StickyList<>(), - new StickyList<>() - ) - ).code(), - new InputHasContent( - Matchers.stringContainsInOrder( - new StickyList<>( - "public", - "final", - "class", - name, - "implements", - type, - "{", - "}" - ) - ) - ) - ); - } - - /** - * Test class with multiple interfaces. - */ - @Test - public void multiTypes() { - final String name = "pdf"; - final Collection types = new StickyList<>("Text", "Book"); - MatcherAssert.assertThat( - new JavaClass( - name, - types, - new ObjectBody( - new StickyList<>(), - new StickyList<>(), - new StickyList<>() - ) - ).code(), - new InputHasContent( - Matchers.stringContainsInOrder( - new StickyList<>( - "public", - "final", - "class", - name, - "implements", - "Text", ",", - "Book", - "{", "}" - ) - ) - ) - ); - } - - /** - * Test class with fields. - */ - @Test - public void fields() { - final String name = "error"; - final Collection types = new StickyList<>("Error"); - MatcherAssert.assertThat( - new JavaClass( - name, - types, - new ObjectBody( - new StickyList<>(new Attribute("Text", "msg")), - new StickyList<>(), - new StickyList<>() - ) - ).code(), - new InputHasContent( - Matchers.stringContainsInOrder( - new StickyList<>( - "public final class", - name, - "implements Error", - "{", - "private final Text msg;", - new UncheckedText( - new FormattedText("public %s(final Text msg)", name) - ).asString(), - "{", - "this.msg = msg;", - "}", - "}" - ) - ) - ) - ); - } - - /** - * Test class path. - */ - @Test - public void classPath() { - final String name = "Book"; - MatcherAssert.assertThat( - new JavaClass( - name, - new StickyList<>("Text"), - new ObjectBody( - new StickyList<>(), - new StickyList<>(), - new StickyList<>() - ) - ).path(), - Matchers.equalTo( - new UncheckedText( - new FormattedText( - "%s.java", - name - ) - ).asString() - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/java/JavaInterfaceTest.java b/eo-compiler/src/test/java/org/eolang/compiler/java/JavaInterfaceTest.java deleted file mode 100644 index f839cde9d6..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/java/JavaInterfaceTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.java; - -import org.cactoos.list.StickyList; -import org.cactoos.matchers.InputHasContent; -import org.cactoos.text.FormattedText; -import org.cactoos.text.UncheckedText; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Java interface generator test. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class JavaInterfaceTest { - - /** - * Test interface code. - */ - @Test - public void interfaceCode() { - final String name = "Cat"; - MatcherAssert.assertThat( - new JavaInterface( - name, - new StickyList<>() - ).code(), - new InputHasContent( - Matchers.stringContainsInOrder( - new StickyList<>( - "public", - "interface", - name, - "{", - "}" - ) - ) - ) - ); - } - - /** - * Test interface path. - */ - @Test - public void interfacePath() { - final String name = "Book"; - MatcherAssert.assertThat( - new JavaInterface( - name, - new StickyList<>() - ).path(), - Matchers.equalTo( - new UncheckedText( - new FormattedText( - "%s.java", - name - ) - ).asString() - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/java/PrimaryConstructorTest.java b/eo-compiler/src/test/java/org/eolang/compiler/java/PrimaryConstructorTest.java deleted file mode 100644 index 6232eff39c..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/java/PrimaryConstructorTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.java; - -import org.cactoos.list.StickyList; -import org.eolang.compiler.syntax.Attribute; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Java class primary constructor test. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class PrimaryConstructorTest { - - /** - * Generates constructor code with fields initialization. - */ - @Test - public void generatesJavaCode() { - MatcherAssert.assertThat( - new PrimaryConstructor( - "color", - new StickyList<>( - new Attribute("Byte", "alpha"), - new Attribute("Int", "rgb") - ) - ).code(), - Matchers.stringContainsInOrder( - new StickyList<>( - "public", - "color(", - "final Byte alpha", - "final Int rgb", - ")", - "{", - "this.alpha = alpha;", - "this.rgb = rgb;", - "}" - ) - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/package-info.java b/eo-compiler/src/test/java/org/eolang/compiler/package-info.java index 07c4a5e57b..d01deef22b 100644 --- a/eo-compiler/src/test/java/org/eolang/compiler/package-info.java +++ b/eo-compiler/src/test/java/org/eolang/compiler/package-info.java @@ -1,7 +1,7 @@ -/** +/* * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgCpObjectTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgCpObjectTest.java deleted file mode 100644 index a8f7904797..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgCpObjectTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for constructor argument with object copying. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class ArgCpObjectTest { - - /** - * Test generated java code. - */ - @Test - public void java() { - MatcherAssert.assertThat( - new ArgCpObject( - new CpObject( - "point", - new StickyList<>( - new Argument.Fake("42"), - new Argument.Fake("11") - ) - ) - ).java(), - Matchers.equalTo("new point(42, 11)") - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgSimpleTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgSimpleTest.java deleted file mode 100644 index 4b87077eca..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgSimpleTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for simple constructor arguments, such as text, number, bool, etc. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class ArgSimpleTest { - - /** - * Simple text. - */ - @Test - public void text() { - final String text = "\"text\""; - MatcherAssert.assertThat( - new ArgSimple(text).java(), - Matchers.equalTo(text) - ); - } - - /** - * Simple integer. - */ - @Test - public void integer() { - final int target = 42; - MatcherAssert.assertThat( - new ArgSimple(target).java(), - Matchers.equalTo("42") - ); - } - - /** - * Simple float. - */ - @Test - public void flt() { - final double target = 136.11; - MatcherAssert.assertThat( - new ArgSimple(target).java(), - Matchers.equalTo("136.11") - ); - } - - /** - * Simple bool. - */ - @Test - public void bool() { - MatcherAssert.assertThat( - new ArgSimple(true).java(), - Matchers.equalTo("true") - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgumentTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgumentTest.java deleted file mode 100644 index a01735487c..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ArgumentTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for object's constructor arguments. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class ArgumentTest { - - /** - * New object as argument. - * - * @todo #104:1h Object instantiation as constructor argument. - * We should be able to pass new object as constructor argument. - * This is not implemented now because it's not so simple to save - * constructing object and argument object - * to different java classes (different files). - * Maybe we can save argument object as nested java class. - */ - @Test - @Ignore - public void objectInstantiation() { - // not implemented - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/AttrCtorParamFormatTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/AttrCtorParamFormatTest.java deleted file mode 100644 index 4de4594e3e..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/AttrCtorParamFormatTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for constructor parameter attribute format. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class AttrCtorParamFormatTest { - - /** - * Generates constructor parameter java code. - */ - @Test - public void javaCode() { - MatcherAssert.assertThat( - new AttrCtorParamFormat().code( - "Int", - "number" - ), - Matchers.is("final Int number") - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/AttributeTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/AttributeTest.java deleted file mode 100644 index c36a3ad9bd..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/AttributeTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.text.FormattedText; -import org.cactoos.text.UncheckedText; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for object's attribute. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class AttributeTest { - - /** - * Generates java code with provided format. - */ - @Test - public void javaCode() { - MatcherAssert.assertThat( - new Attribute( - "Type", - "name" - ).java( - (type, name) -> new UncheckedText( - new FormattedText("%s:%s", type, name) - ).asString() - ), - Matchers.equalTo( - "Type:name" - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/CpObjectTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/CpObjectTest.java deleted file mode 100644 index 7f85627488..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/CpObjectTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for object copying. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class CpObjectTest { - - /** - * Test generated java code. - */ - @Test - public void java() { - MatcherAssert.assertThat( - new CpObject( - "if", - new StickyList<>( - new Argument.Fake("true"), - new Argument.Fake("1"), - new Argument.Fake("2") - ) - ).java(), - Matchers.equalTo("new if(true, 1, 2)") - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/CtorTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/CtorTest.java deleted file mode 100644 index 633fef4fc6..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/CtorTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for object's constructor. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class CtorTest { - - /** - * Test generated java code. - */ - @Test - @SuppressWarnings("PMD.AvoidDuplicateLiterals") - public void java() { - MatcherAssert.assertThat( - new Ctor( - new StickyList<>( - new Parameter("name", "Text"), - new Parameter("age", "Int") - ), - new StickyList<>( - new Argument.Fake("name"), - new Argument.Fake("age"), - new Argument.Fake("new color(\"black\")") - ) - ).java("cat"), - Matchers.stringContainsInOrder( - new StickyList<>( - "public", "cat(", - "final Text name,", - "final Int age", - ")", "{", - "this(", - "name,", - "age,", - "new color(\"black\")", - ")", - "}" - ) - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/MethodImplTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/MethodImplTest.java deleted file mode 100644 index 43cd356ffd..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/MethodImplTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for method implementation. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class MethodImplTest { - - /** - * Test generated java code for method. - */ - @Test - @SuppressWarnings("PMD.AvoidDuplicateLiterals") - public void javaCode() { - MatcherAssert.assertThat( - new MethodImpl( - new Method( - "text", - new StickyList<>( - new Parameter( - "locale", - "Locale" - ) - ), - "Text" - ), - new Argument.Fake("textEncoded") - ).java(), - Matchers.stringContainsInOrder( - new StickyList<>( - "public", "Text", "text", "(", - "final", "Locale", "locale", - ")", "{", - "return", "textEncoded", ";", - "}" - ) - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/MethodTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/MethodTest.java deleted file mode 100644 index 003a0fe5de..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/MethodTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test case for {@link Method}. - * @author Piotr Chmielowski (piotrek.chmielowski@interia.pl) - * @version $Id$ - * @since 0.1 - */ -public final class MethodTest { - - /** - * Method can generate Java file. - * @throws Exception If some problem inside - */ - @Test - public void generatesJavaFile() throws Exception { - MatcherAssert.assertThat( - new Method( - "send", - new StickyList<>( - new Parameter("receiver", "Person"), - new Parameter("content", "Content") - ), - "Message" - ).java(), - Matchers.is( - "Message send(final Person receiver, final Content content)" - ) - ); - } - -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ObjectBodyTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/ObjectBodyTest.java deleted file mode 100644 index 4a70b3f16b..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ObjectBodyTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test for object body. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class ObjectBodyTest { - - /** - * Java fields for object attributes and primary constructor. - */ - @Test - public void fieldsAndPrimaryCtorTest() { - MatcherAssert.assertThat( - new ObjectBody( - new StickyList<>( - new Attribute("Number", "amount"), - new Attribute("Decimal", "price") - ), - new StickyList<>(), - new StickyList<>() - ).java("product"), - Matchers.stringContainsInOrder( - new StickyList<>( - "private final Number amount;", - "private final Decimal price;", - "public product(final Number amount, final Decimal price)", - "{", - "this.amount = amount;", - "this.price = price;", - "}" - ) - ) - ); - } - - /** - * Test for secondary constructor. - */ - @Test - @SuppressWarnings("PMD.AvoidDuplicateLiterals") - public void secondaryConstructorTest() { - MatcherAssert.assertThat( - new ObjectBody( - new StickyList<>(), - new StickyList<>( - new Ctor( - new StickyList<>( - new Parameter("title", "Text") - ), - new StickyList<>( - new Argument.Fake("0"), - new Argument.Fake("title") - ) - ) - ), - new StickyList<>() - ).java("book"), - Matchers.stringContainsInOrder( - new StickyList<>( - "public book(final Text title)", "{", - "this(0, title);", - "}" - ) - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ParameterTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/ParameterTest.java deleted file mode 100644 index ce369093e6..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/ParameterTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test class for {@link Parameter}. - * @author John Page (johnpagedev@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class ParameterTest { - - /** - * A test that checks that Parameter generates Java code. - * @throws Exception if, well, an exception occurs. - */ - @Test - public void generatesJavaCode() throws Exception { - MatcherAssert.assertThat( - new Parameter( - "dollars", - "Cash" - ).java(), - Matchers.is( - "final Cash dollars" - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/TreeTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/TreeTest.java deleted file mode 100644 index ddd3098f49..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/TreeTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.cactoos.matchers.InputHasContent; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test case for {@link Tree}. - * - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class TreeTest { - - /** - * Tree can generate Java files. - * - * @throws Exception If some problem inside - */ - @Test - public void generatesJavaFiles() throws Exception { - MatcherAssert.assertThat( - new Tree( - new StickyList<>( - new Type( - "Car", - new StickyList<>( - new Method( - "drive", - new StickyList<>( - new Parameter("x", "Integer"), - new Parameter("y", "Long") - ), - "Int" - ) - ) - ) - ) - ).java(), - Matchers.hasEntry( - Matchers.equalTo("Car.java"), - new InputHasContent( - Matchers.stringContainsInOrder( - new StickyList<>( - "public interface Car {", - "Int drive(final Integer x, final Long y);", - "}" - ) - ) - ) - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/syntax/TypeTest.java b/eo-compiler/src/test/java/org/eolang/compiler/syntax/TypeTest.java deleted file mode 100644 index a61b3787a8..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/syntax/TypeTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.syntax; - -import org.cactoos.list.StickyList; -import org.cactoos.matchers.InputHasContent; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test case for {@link Type}. - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class TypeTest { - - /** - * Type can generate Java file. - * @throws Exception If some problem inside - */ - @Test - public void generatesJavaFile() throws Exception { - MatcherAssert.assertThat( - new Type( - "Car", - new StickyList<>( - new Method( - "drive", - new StickyList<>( - new Parameter("x", "Integer"), - new Parameter("y", "Long") - ), - "Int" - ) - ) - ).java().code(), - new InputHasContent( - Matchers.stringContainsInOrder( - new StickyList<>( - "public interface Car", "{", - "Int drive(final Integer x, final Long y);", - "}" - ) - ) - ) - ); - } - -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlAttributeTest.java b/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlAttributeTest.java deleted file mode 100644 index ab8bfa9952..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlAttributeTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.xml; - -import com.jcabi.matchers.XhtmlMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.Test; -import org.xembly.Xembler; - -/** - * Test case for {@link XmlAttribute}. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - * @checkstyle JavadocMethodCheck (500 lines) - */ -public final class XmlAttributeTest { - @Test - public void compileToXml() throws Exception { - MatcherAssert.assertThat( - XhtmlMatchers.xhtml( - new Xembler( - new XmlAttribute( - "count", - "Number" - ) - ).xml() - ), - XhtmlMatchers.hasXPath( - "/attribute[@name = 'count']/type[@name = 'Number']" - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlMethodDefTest.java b/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlMethodDefTest.java deleted file mode 100644 index 52117f5cf8..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlMethodDefTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.xml; - -import com.jcabi.matchers.XhtmlMatchers; -import org.cactoos.list.ListOf; -import org.eolang.compiler.syntax.Parameter; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; -import org.xembly.Xembler; - -/** - * Test case for {@link XmlMethodDef}. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - * @checkstyle JavadocMethodCheck (500 lines) - */ -public final class XmlMethodDefTest { - @Test - public void compileToXml() throws Exception { - MatcherAssert.assertThat( - XhtmlMatchers.xhtml( - new Xembler( - new XmlMethodDef( - "printf", - "Text", - new ListOf<>( - new Parameter( - "format", - "String" - ), - new Parameter( - "args", - "List" - ) - ) - ) - ).xml() - ), - Matchers.allOf( - XhtmlMatchers.hasXPath("/method[@name = 'printf']"), - XhtmlMatchers.hasXPath("/method/type[@name = 'Text']"), - XhtmlMatchers.hasXPath("/method/params[count(param) = 2]") - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlParamTest.java b/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlParamTest.java deleted file mode 100644 index 04f0c82746..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlParamTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.xml; - -import com.jcabi.matchers.XhtmlMatchers; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; -import org.xembly.Xembler; - -/** - * Test case for {@link XmlParam}. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - * @checkstyle JavadocMethodCheck (500 lines) - */ -public final class XmlParamTest { - @Test - public void compileToXml() throws Exception { - MatcherAssert.assertThat( - XhtmlMatchers.xhtml( - new Xembler( - new XmlParam("value", "Int") - ).xml() - ), - Matchers.allOf( - XhtmlMatchers.hasXPath("/param/name[text() = 'value']"), - XhtmlMatchers.hasXPath("/param/type[@name = 'Int']") - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlTypeDefTest.java b/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlTypeDefTest.java deleted file mode 100644 index 80b20a4cb3..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/xml/XmlTypeDefTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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.compiler.xml; - -import com.jcabi.matchers.XhtmlMatchers; -import java.util.Collections; -import org.cactoos.list.ListOf; -import org.eolang.compiler.syntax.Method; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; -import org.xembly.Xembler; - -/** - * Test case for {@link XmlTypeDef}. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - * @checkstyle JavadocMethodCheck (500 lines) - */ -public final class XmlTypeDefTest { - @Test - public void compileToXml() throws Exception { - MatcherAssert.assertThat( - XhtmlMatchers.xhtml( - new Xembler( - new XmlTypeDef( - "Book", - new ListOf<>( - "Text" - ), - new ListOf<>( - new Method( - "page", - Collections.emptyList(), - "Page" - ) - ) - ) - ).xml() - ), - Matchers.allOf( - XhtmlMatchers.hasXPath("/type[@name = 'Book']"), - XhtmlMatchers.hasXPath("/type/super/type[@name = 'Text']"), - XhtmlMatchers.hasXPath("/type/methods[count(method) = 1]") - ) - ); - } -} diff --git a/eo-compiler/src/test/java/org/eolang/compiler/xml/package-info.java b/eo-compiler/src/test/java/org/eolang/compiler/xml/package-info.java deleted file mode 100644 index 8e96d00926..0000000000 --- a/eo-compiler/src/test/java/org/eolang/compiler/xml/package-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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. - */ -/** - * XML eo objects tests. - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -package org.eolang.compiler.xml; diff --git a/eo-compiler/src/test/resources/log4j.properties b/eo-compiler/src/test/resources/log4j.properties new file mode 100644 index 0000000000..f8675dabb6 --- /dev/null +++ b/eo-compiler/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=WARN, CONSOLE + +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=com.jcabi.log.MulticolorLayout +log4j.appender.CONSOLE.layout.ConversionPattern=[%color{%p}] %c: %m%n + +log4j.logger.org.eolang=DEBUG diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/book.eo b/eo-compiler/src/test/resources/org/eolang/compiler/book.eo deleted file mode 100644 index 76f6fbd80f..0000000000 --- a/eo-compiler/src/test/resources/org/eolang/compiler/book.eo +++ /dev/null @@ -1,2 +0,0 @@ -type Book: - Text text() diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/car.eo b/eo-compiler/src/test/resources/org/eolang/compiler/car.eo deleted file mode 100644 index c012b3966c..0000000000 --- a/eo-compiler/src/test/resources/org/eolang/compiler/car.eo +++ /dev/null @@ -1,4 +0,0 @@ -type Car: - Money cost() - Bytes picture() - Car moveTo(Coordinates coords) \ No newline at end of file diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/fibonacci.eo b/eo-compiler/src/test/resources/org/eolang/compiler/fibonacci.eo index 97fd8bf851..88b6292c3c 100644 --- a/eo-compiler/src/test/resources/org/eolang/compiler/fibonacci.eo +++ b/eo-compiler/src/test/resources/org/eolang/compiler/fibonacci.eo @@ -1,17 +1,13 @@ -object fibonacci as Int: - Int @n - ctor(): - fibonacci: - 1 - Int int(): - if: - firstIsLess: - @n - 2 - 1 - plus: - @n - fibonacci: - minus: - @n - 1 \ No newline at end of file +# This is the header comment of this simple EO +# program, to be ignored. + ++meta This is just a test META ++meta2 And yet another one + +[n] > fibo + if + less n 2 + n + add + fibo (sub n 1) + fibo (sub n 2) diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/long-program.eo b/eo-compiler/src/test/resources/org/eolang/compiler/long-program.eo deleted file mode 100644 index 85543fa587..0000000000 --- a/eo-compiler/src/test/resources/org/eolang/compiler/long-program.eo +++ /dev/null @@ -1,20 +0,0 @@ -type Thing: - String name() - -type Inventory extends Thing: - Int price() - Date created() - -object book as Inventory: - Int @isbn - Int @price - Stock @stock - Int price(): - @price - Bool available(): - if: - availability: - @stock - true - false - diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/multitypes.eo b/eo-compiler/src/test/resources/org/eolang/compiler/multitypes.eo deleted file mode 100644 index 37b3e1001f..0000000000 --- a/eo-compiler/src/test/resources/org/eolang/compiler/multitypes.eo +++ /dev/null @@ -1,7 +0,0 @@ -type Number: - Integral integral() - Decimal decimal() - -type Text: - Number length() - Collection lines() \ No newline at end of file diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/adds-refs.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/adds-refs.yaml new file mode 100644 index 0000000000..e56db0dd6e --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/adds-refs.yaml @@ -0,0 +1,25 @@ +xsls: + - errors/duplicate-names.xsl + - errors/self-naming.xsl + - errors/same-line-names.xsl + - 01-add-refs.xsl +tests: + - /program/objects[count(o)=1] + - //o[@base='x' and @ref='1'] + - //o[@base='x' and @ref='4'] + - //o[@base='x' and @line='11' and @ref='4'] + - //o[@base='a' and @line='9' and @ref='12'] + - //o[@base='something' and @line='12' and @name='a' and not(@ref)] +eo: | + [x a] > first + (stdout x) + second > hello + third > x + (stdout "Hi") + one + x + two + a + three + x + something > a diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-alias-duplicates.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-alias-duplicates.yaml new file mode 100644 index 0000000000..292f1b5850 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-alias-duplicates.yaml @@ -0,0 +1,13 @@ +xsls: + - errors/duplicate-aliases.xsl +tests: + - /program/errors[count(error)=1] + - /program/errors/error[@line='2'] + - /program/metas/meta[head='alias' and tail='stdout org.eolang.io.Stdout'] +eo: | + +alias stdout org.eolang.io.Stdout + +alias stdout org.eolang.io.Stdout + +alias stding org.eolang.io.Stdin + + [] > main + (stdout "Hello, world!").print diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-broken-aliases.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-broken-aliases.yaml new file mode 100644 index 0000000000..0ac3010db2 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-broken-aliases.yaml @@ -0,0 +1,12 @@ +xsls: + - errors/broken-aliases.xsl +tests: + - /program/errors[count(error)=3] + - /program/errors/error[@line='2'] +eo: | + +alias org.eolang.io.Stdout + +alias this is some mistake + +alias + + [] > main + (stdout "Hello, world!").print diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-name-duplicates.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-name-duplicates.yaml new file mode 100644 index 0000000000..00e5b79a1c --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-name-duplicates.yaml @@ -0,0 +1,9 @@ +xsls: + - errors/duplicate-names.xsl +tests: + - /program/errors[count(error)=1] + - /program/errors/error[@line='2'] + - /program/objects/o[@name='first']/o[@name='x'] +eo: | + [x] > first + second > x diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-reserved-atoms.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-reserved-atoms.yaml new file mode 100644 index 0000000000..327f80e231 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-reserved-atoms.yaml @@ -0,0 +1,10 @@ +xsls: + - errors/reserved-atoms.xsl +tests: + - /program/errors[count(error)=2] +eo: | + [x] > first + string > x + "test" > works + float > test + 123 > string diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-same-line-name.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-same-line-name.yaml new file mode 100644 index 0000000000..c5595df2c4 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-same-line-name.yaml @@ -0,0 +1,9 @@ +xsls: + - errors/same-line-names.xsl +tests: + - /program/errors[count(error)=1] + - /program/errors/error[@line='2'] + - /program/objects/o[@name='first']/o[@name='x'] +eo: | + [x] > first + (a > x (b > x)) diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-self-naming.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-self-naming.yaml new file mode 100644 index 0000000000..5739966d7c --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-self-naming.yaml @@ -0,0 +1,9 @@ +xsls: + - errors/self-naming.xsl +tests: + - /program/errors[count(error)=1] + - /program/errors/error[@line='2'] + - /program/objects/o[@name='first']/o[@name='a'] +eo: | + [] > first + a > a diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-two-bodies.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-two-bodies.yaml new file mode 100644 index 0000000000..08ee6b74ea --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-two-bodies.yaml @@ -0,0 +1,14 @@ +xsls: + - errors/one-body.xsl +tests: + - /program/errors[count(error)=1] + - /program/errors/error[@line='1'] + - //o[@base='first' and @line='2'] + - //o[@base='second' and @line='3'] +eo: | + [] + first + second:f + third > hey + 23 + 33 diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-unknown-names.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-unknown-names.yaml new file mode 100644 index 0000000000..6aa3fad816 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/catches-unknown-names.yaml @@ -0,0 +1,9 @@ +xsls: + - errors/unknown-names.xsl +tests: + - /program/errors[count(error)=1] + - /program/errors/error[@line='2'] + - //o[@base='test' and @line='2'] +eo: | + [] + test diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/flatten-abstracts.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/flatten-abstracts.yaml new file mode 100644 index 0000000000..b37a031a1a --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/flatten-abstracts.yaml @@ -0,0 +1,20 @@ +xsls: + - 01-add-refs.xsl + - 03-abstracts-float-up.xsl + - 04-rename-bases.xsl +tests: + - /program/objects[count(o)=3] + - //o[@name='first'] + - //o[@name='first']/o[@base='test' and @as='foo'] + - //o[@name='first$second'] + - //o[@name='first$second$third'] + - //o[@name='first$second$third']/o[@base='stdout']/o[@base='a++' and @ref='1'] +eo: | + [a b] > first + test:foo + a > yes + [x b] > second + a > no + [b c] > third + no > yes + (stdout a b c x).print diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/full-syntax.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/full-syntax.yaml new file mode 100644 index 0000000000..cad6eaa319 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/full-syntax.yaml @@ -0,0 +1,41 @@ +xsls: [] +tests: + - /program/objects[count(o)=5] +eo: | + # The purpose of this test case is to make + # sure all possible syntax scenarios can + # be parsed by the ANTLR + + +alias Test Test + +foo + +bar Some text + + 500.43 > one + + # This is just a simple string + "Hello, world!" > !hello + + [x] > first + second > hello + third:foo > x + f 12 + (((t 22) r:t 8.54 "yes").print 88):hey > !a + kid + f:u + z + z 5 + z + oops + + # Comments are allowed only in front of top-level objects + [] + one.two.three.four.five + t + .two + .three > a1 + .four > a2 + .five > a3 + + test + me + now:i (f (f (f (f 1)))).f diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/leap-year.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/leap-year.yaml new file mode 100644 index 0000000000..33920637d2 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/leap-year.yaml @@ -0,0 +1,42 @@ +xsls: + - errors/reserved-atoms.xsl + - errors/self-naming.xsl + - errors/same-line-names.xsl + - errors/one-body.xsl + - errors/duplicate-aliases.xsl + - errors/broken-aliases.xsl + - errors/duplicate-names.xsl + - 01-add-refs.xsl + - 02-resolve-aliases.xsl + - errors/unknown-names.xsl + - 03-abstracts-float-up.xsl + - 04-rename-bases.xsl + - 05-wrap-method-calls.xsl + - 06-to-java.xsl +tests: + - /program/objects[count(o)=2] + - //o[@name='main$leap'] +eo: | + # This program is from the EOLANG original paper + # and must produce a working command line tool + # + # License is MIT + + +alias stdout org.eolang.io.Stdout + +alias stdin org.eolang.io.Stdin + +alias scanner org.eolang.txt.Scanner + + [args] > main + [y] > leap + or + and + eq (mod y 4) 0 + not (eq (mod y 100) 0) + eq (mod y 400) 0 + and + stdout "Enter a year:" + stdout + concat + (scanner stdin).nextInt > !year + " is a leap year?" + leap year:y diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/resolves-aliases.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/resolves-aliases.yaml new file mode 100644 index 0000000000..3828b2d3d0 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/resolves-aliases.yaml @@ -0,0 +1,19 @@ +xsls: + - 01-add-refs.xsl + - 02-resolve-aliases.xsl +tests: + - /program/objects[count(o)=1] + - /program/metas/meta[head='foo' and @line='4'] + - /program/metas[count(meta)=1] + - //o[@base='org.eolang.io.Stdout' and @line='9'] + - //o[@base='org.eolang.And' and @line='7'] +eo: | + +alias stdout org.eolang.io.Stdout + +alias stdin org.eolang.io.Stdin + +alias scanner org.eolang.txt.Scanner + +foo Some other meta + + [args] > main + and + (scanner stdin).nextLine > !line + (stdout "You entered" line).print diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/packs/simple.yaml b/eo-compiler/src/test/resources/org/eolang/compiler/packs/simple.yaml new file mode 100644 index 0000000000..a23c8ce859 --- /dev/null +++ b/eo-compiler/src/test/resources/org/eolang/compiler/packs/simple.yaml @@ -0,0 +1,11 @@ +xsls: [] +tests: + - /program/objects + - //o[not(@name) and @base='a'] + - //o[@base='a' and @line='1'] + - //o[@base='b' and @line='2'] + - //o[@base='c' and @line='3'] +eo: | + a + b + c diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/pixel.eo b/eo-compiler/src/test/resources/org/eolang/compiler/pixel.eo deleted file mode 100644 index 9fb7be3827..0000000000 --- a/eo-compiler/src/test/resources/org/eolang/compiler/pixel.eo +++ /dev/null @@ -1,2 +0,0 @@ -type Pixel: - Pixel moveTo(Integer x, Integer y) diff --git a/eo-compiler/src/test/resources/org/eolang/compiler/zero.eo b/eo-compiler/src/test/resources/org/eolang/compiler/zero.eo deleted file mode 100644 index 90133d7c5f..0000000000 --- a/eo-compiler/src/test/resources/org/eolang/compiler/zero.eo +++ /dev/null @@ -1,3 +0,0 @@ -object zero as Money, Int: - Int @amount - Text @currency diff --git a/eo-core/src/main/eo/types.eo b/eo-core/src/main/eo/types.eo deleted file mode 100644 index 2c930abac2..0000000000 --- a/eo-core/src/main/eo/types.eo +++ /dev/null @@ -1,8 +0,0 @@ -type Bool: - Boolean asBoolean() - -type Int: - Integer asInteger() - -type Text: - String asString() diff --git a/eo-core/src/main/java/diff.java b/eo-core/src/main/java/diff.java deleted file mode 100644 index 79565d4f22..0000000000 --- a/eo-core/src/main/java/diff.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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. - */ - -import eo.Int; - -/** - * EO diff object. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class diff implements Int { - - private final Int left; - private final Int right; - - public diff(final Int left, final Int right) { - this.left = left; - this.right = right; - } - - @Override - public Integer asInteger() { - return this.left.asInteger() - this.right.asInteger(); - } -} diff --git a/eo-core/src/main/java/equals.java b/eo-core/src/main/java/equals.java deleted file mode 100644 index e2343cc989..0000000000 --- a/eo-core/src/main/java/equals.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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. - */ - -import eo.Bool; - -/** - * EO equals object. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class equals implements Bool { - - private final Object left; - private final Object right; - - public equals(final Object left, final Object right) { - this.left = left; - this.right = right; - } - - @Override - public Boolean asBoolean() { - return this.left.equals(this.right); - } -} diff --git a/eo-core/src/main/java/not.java b/eo-core/src/main/java/not.java deleted file mode 100644 index 945bae731b..0000000000 --- a/eo-core/src/main/java/not.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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. - */ - -import eo.Bool; - -/** - * EO not object. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class not implements Bool { - - private final Bool source; - - public not(final Bool source) { - this.source = source; - } - - @Override - public Boolean asBoolean() { - return !source.asBoolean(); - } -} diff --git a/eo-core/src/main/java/sum.java b/eo-core/src/main/java/sum.java deleted file mode 100644 index d6ff4754f6..0000000000 --- a/eo-core/src/main/java/sum.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016 eolang.org - * - * 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. - */ - -import eo.Int; - -/** - * EO sum object. - * - * @author Kirill (g4s8.public@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class sum implements Int { - - private final Int left; - private final Int right; - - public sum(final Int left, final Int right) { - this.left = left; - this.right = right; - } - - @Override - public Integer asInteger() { - return this.left.asInteger() + this.right.asInteger(); - } -} diff --git a/eo-maven-plugin/LICENSE.txt b/eo-maven-plugin/LICENSE.txt index 93682bee04..0fad6fb4d6 100644 --- a/eo-maven-plugin/LICENSE.txt +++ b/eo-maven-plugin/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 eolang.org +Copyright (c) 2016-2020 Yegor Bugayenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml index c78d36f0b0..0af9c1bfd6 100644 --- a/eo-maven-plugin/pom.xml +++ b/eo-maven-plugin/pom.xml @@ -2,7 +2,7 @@ 4.0.0 + + com.jcabi + parent + 0.50.9 + org.eolang eo-maven-plugin-test test 1.0-SNAPSHOT jar + + + org.eolang + eo-runtime + 1.0-SNAPSHOT + + diff --git a/eo-maven-plugin/src/it/simple/src/main/eo/org/eolang/sample/pixel.eo b/eo-maven-plugin/src/it/simple/src/main/eo/org/eolang/sample/pixel.eo deleted file mode 100644 index 9fb7be3827..0000000000 --- a/eo-maven-plugin/src/it/simple/src/main/eo/org/eolang/sample/pixel.eo +++ /dev/null @@ -1,2 +0,0 @@ -type Pixel: - Pixel moveTo(Integer x, Integer y) diff --git a/eo-maven-plugin/src/it/simple/src/main/eo/pixel.eo b/eo-maven-plugin/src/it/simple/src/main/eo/pixel.eo new file mode 100644 index 0000000000..77ea6ebada --- /dev/null +++ b/eo-maven-plugin/src/it/simple/src/main/eo/pixel.eo @@ -0,0 +1,5 @@ ++alias stdout org.eolang.io.Stdout + +[] > pixel + [] > hello + stdout "Hello, world!" diff --git a/eo-maven-plugin/src/it/simple/verify.groovy b/eo-maven-plugin/src/it/simple/verify.groovy index c83448e77d..de56ddb897 100644 --- a/eo-maven-plugin/src/it/simple/verify.groovy +++ b/eo-maven-plugin/src/it/simple/verify.groovy @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,5 +22,7 @@ * SOFTWARE. */ -assert new File(basedir, 'target/generated-sources/eo/Pixel.java').exists() -assert new File(basedir, 'target/classes/eo/Pixel.class').exists() +assert new File(basedir, 'target/generated-sources/eo/pixel.java').exists() +assert new File(basedir, 'target/generated-sources/eo/pixel$hello.java').exists() +assert new File(basedir, 'target/classes/pixel.class').exists() +assert new File(basedir, 'target/classes/pixel$hello.class').exists() diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/CompileMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/CompileMojo.java index 34187794d7..501316dd2f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/CompileMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/CompileMojo.java @@ -1,7 +1,7 @@ -/** +/* * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,8 @@ package org.eolang.maven; import com.jcabi.log.Logger; +import com.jcabi.xml.XMLDocument; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -36,17 +38,18 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.cactoos.io.InputOf; +import org.cactoos.io.OutputTo; import org.cactoos.text.FormattedText; import org.cactoos.text.UncheckedText; import org.eolang.compiler.Program; +import org.eolang.compiler.ToJava; import org.slf4j.impl.StaticLoggerBinder; /** * Compile. * - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ * @since 0.1 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @Mojo( name = "compile", @@ -120,10 +123,16 @@ public void execute() throws MojoFailureException { */ private void compile(final Path file) { try { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new Program( new InputOf(file), - this.targetDirectory.toPath() + new OutputTo(baos) ).compile(); + final ToJava tojava = new ToJava( + new XMLDocument(baos.toString()), + this.targetDirectory.toPath() + ); + tojava.compile(); } catch (final IOException ex) { throw new IllegalStateException( new UncheckedText( diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/package-info.java b/eo-maven-plugin/src/main/java/org/eolang/maven/package-info.java index 8afd18a11f..e0946af6f2 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/package-info.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/package-info.java @@ -1,7 +1,7 @@ -/** +/* * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,8 +25,6 @@ /** * EO Maven Plugin. * - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ * @since 0.1 * @see project site www.eolang.org * @see GitHub project diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/CompileMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/CompileMojoTest.java index dd0cbab06f..f0af11b7b1 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/CompileMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/CompileMojoTest.java @@ -1,7 +1,7 @@ -/** +/* * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,22 +23,23 @@ */ package org.eolang.maven; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.cactoos.io.InputOf; -import org.cactoos.io.LengthOf; import org.cactoos.io.OutputTo; import org.cactoos.io.TeeInput; +import org.cactoos.scalar.LengthOf; import org.eolang.compiler.CompileException; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** * Test case for {@link CompileMojo}. - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ + * * @since 0.1 * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @@ -46,54 +47,47 @@ public final class CompileMojoTest extends AbstractMojoTestCase { /** - * Temp dir. - * @checkstyle VisibilityModifier (3 lines) + * Temp dir for tests. + * @checkstyle VisibilityModifierCheck (4 lines) */ - public final transient TemporaryFolder temp = new TemporaryFolder(); + @TempDir + public Path temp; - /** - * Main can print a simple text. - * @throws Exception If some problem inside - */ + @Test public void testSimpleCompilation() throws Exception { final CompileMojo mojo = new CompileMojo(); - this.temp.create(); - final File src = this.temp.newFolder(); - this.setVariableValueToObject(mojo, "sourceDirectory", src); + final Path src = this.temp.resolve("src"); + this.setVariableValueToObject(mojo, "sourceDirectory", src.toFile()); new LengthOf( new TeeInput( new InputOf( - "type Pixel:\n Pixel moveTo(Integer x, Integer y)" + "[args] > main\n (stdout \"Hello!\").print\n" ), - new OutputTo(new File(src, "main.eo")) + new OutputTo(src.resolve("main.eo")) ) ).value(); - final File target = this.temp.newFolder(); - this.setVariableValueToObject(mojo, "targetDirectory", target); + final Path target = this.temp.resolve("target"); + this.setVariableValueToObject(mojo, "targetDirectory", target.toFile()); this.setVariableValueToObject(mojo, "project", new MavenProjectStub()); mojo.execute(); MatcherAssert.assertThat( - new File(target, "Pixel.java").exists(), + Files.exists(target.resolve("main.java")), Matchers.is(true) ); } - /** - * Main can print a simple text. - * @throws Exception If some problem inside - */ + @Test public void testCrashOnInvalidSyntax() throws Exception { final CompileMojo mojo = new CompileMojo(); - this.temp.create(); - final File src = this.temp.newFolder(); - this.setVariableValueToObject(mojo, "sourceDirectory", src); + final Path src = this.temp.resolve("src"); + this.setVariableValueToObject(mojo, "sourceDirectory", src.toFile()); this.setVariableValueToObject( - mojo, "targetDirectory", this.temp.newFolder() + mojo, "targetDirectory", this.temp.resolve("target").toFile() ); new LengthOf( new TeeInput( new InputOf("something is wrong here"), - new OutputTo(new File(src, "f.eo")) + new OutputTo(src.resolve("f.eo")) ) ).value(); try { diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/package-info.java b/eo-maven-plugin/src/test/java/org/eolang/maven/package-info.java index fbdbababe9..25d04a7a8b 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/package-info.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/package-info.java @@ -1,7 +1,7 @@ -/** +/* * The MIT License (MIT) * - * Copyright (c) 2016 eolang.org + * Copyright (c) 2016-2020 Yegor Bugayenko * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/eo-maven-plugin/src/test/resources/META-INF/maven/plugin.xml b/eo-maven-plugin/src/test/resources/META-INF/maven/plugin.xml index 3119a0452e..b5662f6001 100644 --- a/eo-maven-plugin/src/test/resources/META-INF/maven/plugin.xml +++ b/eo-maven-plugin/src/test/resources/META-INF/maven/plugin.xml @@ -2,7 +2,7 @@