diff --git a/.github/workflows/simian.yml b/.github/workflows/simian.yml index 2f1afb342c..6c2e2d85e2 100644 --- a/.github/workflows/simian.yml +++ b/.github/workflows/simian.yml @@ -24,4 +24,4 @@ jobs: - run: | wget --quiet http://public.yegor256.com/simian.jar -O /tmp/simian.jar - run: | - java -jar /tmp/simian.jar -threshold=25 -excludes=**/gen -excludes=**/it **/*.java + java -jar /tmp/simian.jar -threshold=16 -excludes=**/gen -excludes=**/it **/*.java diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index bef9fcaa8b..0fa4b543f4 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -190,7 +190,7 @@ private static ConcurrentHashMap load(final String src) throws I if (result.getClass() != ConcurrentHashMap.class) { throw new ClassCastException( String.format( - "Object inside %s has wrong class %s", + "Object inside %s has wrong class %s, a ConcurrentHashMap was expected", src, result.getClass() ) @@ -200,7 +200,7 @@ private static ConcurrentHashMap load(final String src) throws I } catch (final ClassNotFoundException exc) { throw new IllegalArgumentException( String.format( - "File %s contains invalid data", + "File %s contains invalid data, a ConcurrentHashMap objects was expected", src ), exc diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java index 76224ac252..29068d53f6 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java @@ -32,9 +32,11 @@ import EOorg.EOeolang.EOtuple$EOempty; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import org.eolang.AtComposite; import org.eolang.Data; import org.eolang.Dataized; import org.eolang.PhCopy; +import org.eolang.PhDefault; import org.eolang.PhMethod; import org.eolang.PhWith; import org.eolang.Phi; @@ -96,27 +98,16 @@ public void doesNotPrintTwiceOnIntComparisonMethods(final String method) { final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final String str = "Hello world"; new Dataized( - new PhWith( + new PrintWithCmp( new PhMethod( new Data.ToPhi(1L), method ), - 0, + new Data.ToPhi(2L), new PhWith( - new EOseq(Phi.Φ), - 0, - new PhWith( - new PhWith( - new EOtuple$EOempty(Phi.Φ).attr("with").get().copy(), - 0, - new PhWith( - new EOstdout(Phi.Φ, new PrintStream(stream)), - "text", - new Data.ToPhi(str) - ) - ).attr("with").get().copy(), - 0, new Data.ToPhi(2L) - ) + new EOstdout(Phi.Φ, new PrintStream(stream)), + "text", + new Data.ToPhi(str) ) ) ).take(); @@ -132,27 +123,16 @@ public void doesNotPrintTwiceOnFloatComparisonMethods(final String method) { final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final String str = "Hello world"; new Dataized( - new PhWith( + new PrintWithCmp( new PhMethod( new Data.ToPhi(1.0), method ), - 0, + new Data.ToPhi(3.0), new PhWith( - new EOseq(Phi.Φ), - 0, - new PhWith( - new PhWith( - new EOtuple$EOempty(Phi.Φ).attr("with").get().copy(), - 0, - new PhWith( - new EOstdout(Phi.Φ, new PrintStream(stream)), - "text", - new Data.ToPhi(str) - ) - ).attr("with").get().copy(), - 0, new Data.ToPhi(3.0) - ) + new EOstdout(Phi.Φ, new PrintStream(stream)), + "text", + new Data.ToPhi(str) ) ) ).take(); @@ -161,4 +141,51 @@ public void doesNotPrintTwiceOnFloatComparisonMethods(final String method) { Matchers.equalTo(str) ); } + + /** + * PrintWithCmp Phi. + * + * @since 1.0 + */ + private static class PrintWithCmp extends PhDefault { + /** + * Ctor. + * + * @param method Comparison PhMethod ("lt", "gt", "lte", "gte") + * @param value Phi value to be compared + * @param stdout Phi object with printing a string via {@link EOstdout} object + */ + PrintWithCmp(final Phi method, final Phi value, final Phi stdout) { + super(Phi.Φ); + this.add( + "φ", + new AtComposite( + this, + self -> new Data.ToPhi( + new Dataized( + new PhWith( + method, + 0, + new PhWith( + new EOseq(Phi.Φ), + 0, + new PhWith( + new PhWith( + new EOtuple$EOempty(Phi.Φ) + .attr("with") + .get() + .copy(), + 0, + stdout + ).attr("with").get().copy(), + 0, value + ) + ) + ) + ).take() + ) + ) + ); + } + } } diff --git a/eo-runtime/src/test/java/org/eolang/DataizedTest.java b/eo-runtime/src/test/java/org/eolang/DataizedTest.java index 543c129406..65e8d24aab 100644 --- a/eo-runtime/src/test/java/org/eolang/DataizedTest.java +++ b/eo-runtime/src/test/java/org/eolang/DataizedTest.java @@ -48,22 +48,7 @@ void logsCorrectly() { final Level before = log.getLevel(); log.setLevel(Level.ALL); final List logs = new LinkedList<>(); - final Handler hnd = new Handler() { - @Override - public void publish(final LogRecord record) { - logs.add(record); - } - - @Override - public void flush() { - throw new UnsupportedOperationException("#flush()"); - } - - @Override - public void close() throws SecurityException { - throw new UnsupportedOperationException("#close()"); - } - }; + final Handler hnd = new Hnd(logs); log.addHandler(hnd); new Dataized(new Data.ToPhi(1L), log).take(); log.setLevel(before); @@ -83,22 +68,7 @@ void logsWhenException() { final Level before = log.getLevel(); log.setLevel(Level.ALL); final List logs = new LinkedList<>(); - final Handler hnd = new Handler() { - @Override - public void publish(final LogRecord record) { - logs.add(record); - } - - @Override - public void flush() { - throw new UnsupportedOperationException("#flush()"); - } - - @Override - public void close() throws SecurityException { - throw new UnsupportedOperationException("#close()"); - } - }; + final Handler hnd = new Hnd(logs); log.addHandler(hnd); final Phi wrong = new PhIncorrect(Phi.Φ); IntStream.range(0, 5).forEach( @@ -125,22 +95,7 @@ void printsShortLogs() throws InterruptedException { final Level before = log.getLevel(); log.setLevel(Level.ALL); final List logs = new LinkedList<>(); - final Handler hnd = new Handler() { - @Override - public void publish(final LogRecord record) { - logs.add(record); - } - - @Override - public void flush() { - throw new UnsupportedOperationException("#flush()"); - } - - @Override - public void close() throws SecurityException { - throw new UnsupportedOperationException("#close()"); - } - }; + final Handler hnd = new Hnd(logs); log.addHandler(hnd); final Thread thread = new Thread( () -> { @@ -170,22 +125,7 @@ void printsLongLogs() throws InterruptedException { final Level before = log.getLevel(); log.setLevel(Level.ALL); final List logs = new LinkedList<>(); - final Handler hnd = new Handler() { - @Override - public void publish(final LogRecord record) { - logs.add(record); - } - - @Override - public void flush() { - throw new UnsupportedOperationException("#flush()"); - } - - @Override - public void close() throws SecurityException { - throw new UnsupportedOperationException("#close()"); - } - }; + final Handler hnd = new Hnd(logs); log.addHandler(hnd); final Thread thread = new Thread( () -> { @@ -261,4 +201,41 @@ public static class PhiDec extends PhDefault { } } + /** + * Handler implementation for tests. + * + * @since 1.0 + */ + private static class Hnd extends Handler { + /** + * Logs. + */ + private final List logs; + + /** + * Ctor. + * + * @param logs Logs + */ + Hnd(final List logs) { + this.logs = logs; + } + + @Override + public void publish(final LogRecord record) { + this.logs.add(record); + } + + @Override + public void flush() { + throw new UnsupportedOperationException("#flush()"); + } + + @Override + public void close() throws SecurityException { + throw new UnsupportedOperationException("#close()"); + } + + } + }