Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 11, 2024
2 parents 1bce14b + 6b317f8 commit 74d04a4
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/simian.yml
Expand Up @@ -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
4 changes: 2 additions & 2 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
Expand Up @@ -190,7 +190,7 @@ private static ConcurrentHashMap<String, String> 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()
)
Expand All @@ -200,7 +200,7 @@ private static ConcurrentHashMap<String, String> 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
Expand Down
91 changes: 59 additions & 32 deletions eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOstdoutTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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()
)
)
);
}
}
}
105 changes: 41 additions & 64 deletions eo-runtime/src/test/java/org/eolang/DataizedTest.java
Expand Up @@ -48,22 +48,7 @@ void logsCorrectly() {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> 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);
Expand All @@ -83,22 +68,7 @@ void logsWhenException() {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> 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(
Expand All @@ -125,22 +95,7 @@ void printsShortLogs() throws InterruptedException {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> 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(
() -> {
Expand Down Expand Up @@ -170,22 +125,7 @@ void printsLongLogs() throws InterruptedException {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> 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(
() -> {
Expand Down Expand Up @@ -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<LogRecord> logs;

/**
* Ctor.
*
* @param logs Logs
*/
Hnd(final List<LogRecord> 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()");
}

}

}

0 comments on commit 74d04a4

Please sign in to comment.