Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(text-minimessage): Show ANSI rendering of parsed components in tests #1042

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion text-minimessage/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ description = "A string-based, user-friendly format for representing Minecraft:

dependencies {
api(projects.adventureApi)
testImplementation(project(":adventure-text-serializer-plain"))
testImplementation(projects.adventureTextSerializerPlain)
testImplementation(projects.adventureTextSerializerAnsi)
annotationProcessor(projects.adventureAnnotationProcessors)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer;
import net.kyori.ansi.ColorLevel;
import net.kyori.examination.string.MultiLineStringExaminer;
import org.jetbrains.annotations.NotNull;

import static org.junit.jupiter.api.Assertions.assertEquals;

public abstract class AbstractTest {
protected static final MiniMessage PARSER = MiniMessage.builder().debug(System.out::print).build();
protected static final ANSIComponentSerializer ANSI = ANSIComponentSerializer.builder()
.colorLevel(ColorLevel.TRUE_COLOR)
.build();

protected void assertSerializedEquals(final @NotNull String expected, final @NotNull ComponentLike input) {
final String string = PARSER.serialize(input.asComponent());
Expand All @@ -52,16 +57,14 @@ protected void assertParsedEquals(final @NotNull Component expected, final @NotN
this.assertParsedEquals(PARSER, expected, input, args);
}

protected void assertParsedEquals(final MiniMessage miniMessage, final Component expected, final String input) {
final String expectedSerialized = this.prettyPrint(expected.compact());
final String actual = this.prettyPrint(miniMessage.deserialize(input).compact());
assertEquals(expectedSerialized, actual);
}

protected void assertParsedEquals(final MiniMessage miniMessage, final Component expected, final String input, final @NotNull TagResolver... args) {
final String expectedSerialized = this.prettyPrint(expected.compact());
final String actual = this.prettyPrint(miniMessage.deserialize(input, TagResolver.resolver(args)).compact());
assertEquals(expectedSerialized, actual);
final Component expectedCompacted = expected.compact();
final String expectedSerialized = this.prettyPrint(expectedCompacted);
final Component actualCompacted = miniMessage.deserialize(input, TagResolver.resolver(args)).compact();
final String actual = this.prettyPrint(actualCompacted);
assertEquals(expectedSerialized, actual, () -> "Expected parsed value did not match actual:\n"
+ " Expected: " + ANSI.serialize(expectedCompacted) + '\n'
+ " Actual: " + ANSI.serialize(actualCompacted));
}

protected final String prettyPrint(final Component component) {
Expand Down