Skip to content

Commit

Permalink
tests refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 8, 2025
1 parent bdad472 commit 686463c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 45 deletions.
23 changes: 11 additions & 12 deletions eo-runtime/src/test/java/EOorg/EOeolang/EObytesEOconcatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@ final class EObytesEOconcatTest {

@Test
void concatenatesBytes() {
final Phi current = new Data.ToPhi("привет ").take("as-bytes");
final Phi provided = new Data.ToPhi("mr. ㄤㄠ!").take("as-bytes");
final Phi phi = new PhWith(
Phi.Φ.take("org.eolang.string"),
0,
new PhWith(
current.take("concat").copy(),
"b",
provided
)
);
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
new Dataized(phi).asString(),
new Dataized(
new PhWith(
Phi.Φ.take("org.eolang.string"),
0,
new PhWith(
new Data.ToPhi("привет ").take("as-bytes").take("concat").copy(),
"b",
new Data.ToPhi("mr. ㄤㄠ!").take("as-bytes")
)
)
).asString(),
Matchers.equalTo("привет mr. ㄤㄠ!")
);
}
Expand Down
49 changes: 24 additions & 25 deletions eo-runtime/src/test/java/EOorg/EOeolang/EObytesEOsliceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/
package EOorg.EOeolang; // NOPMD

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhWith;
Expand Down Expand Up @@ -70,31 +70,30 @@ void takesLegalSlice() {

@Test
void takesWrongSlice() {
final EOerror.ExError exp = Assertions.assertThrows(
EOerror.ExError.class,
() -> new Dataized(
new PhWith(
new PhWith(
new Data.ToPhi("hello, world!")
.take("as-bytes")
.take("slice")
.copy(),
"start",
new Data.ToPhi(2)
),
"len",
new Data.ToPhi(-5)
)
).asString(),
"fails on check"
);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintWriter writer = new PrintWriter(baos)) {
exp.printStackTrace(writer);
}
MatcherAssert.assertThat(
"error message is correct",
baos.toString(),
new UncheckedText(
new TextOf(
Assertions.assertThrows(
EOerror.ExError.class,
() -> new Dataized(
new PhWith(
new PhWith(
new Data.ToPhi("hello, world!")
.take("as-bytes")
.take("slice")
.copy(),
"start",
new Data.ToPhi(2)
),
"len",
new Data.ToPhi(-5)
)
).asString(),
"fails on check"
)
)
).asString(),
Matchers.containsString("the 'len' attribute (-5) must be a positive integer")
);
}
Expand Down
12 changes: 4 additions & 8 deletions eo-runtime/src/test/java/EOorg/EOeolang/EOerrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,12 @@ void makesToxicObject() {
@ParameterizedTest
@MethodSource("getTestSources")
void getsReadableError(final byte[] cnst, final String text) {
ExAbstract error = null;
try {
new Dataized(new MyError(cnst)).take();
} catch (final ExAbstract exc) {
error = exc;
}
assert error != null;
MatcherAssert.assertThat(
"Bytes must be translated to string correctly",
error.toString(),
Assertions.assertThrows(
ExAbstract.class,
() -> new Dataized(new MyError(cnst)).take()
).toString(),
Matchers.containsString(text)
);
}
Expand Down

0 comments on commit 686463c

Please sign in to comment.