From 3e66a05c21fe209875781729b982b52bbc124ec2 Mon Sep 17 00:00:00 2001 From: RGoyalmc <76780190+RGoyalmc@users.noreply.github.com> Date: Mon, 30 May 2022 22:51:44 +0530 Subject: [PATCH] feat(minimessage): tests for progress and repeat tags --- .../tag/standard/ProgressTagTest.java | 81 ++++++++++++++++ .../tag/standard/RepeatTagTest.java | 93 +++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ProgressTagTest.java create mode 100644 text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RepeatTagTest.java diff --git a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ProgressTagTest.java b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ProgressTagTest.java new file mode 100644 index 0000000000..2e5c054a5d --- /dev/null +++ b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ProgressTagTest.java @@ -0,0 +1,81 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * 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 NONINFRINGEMENT. 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 net.kyori.adventure.text.minimessage.tag.standard; + +import java.util.function.Supplier; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.AbstractTest; +import net.kyori.adventure.text.minimessage.tag.resolver.Formatter; +import org.junit.jupiter.api.Test; + +import static net.kyori.adventure.text.Component.empty; +import static net.kyori.adventure.text.Component.text; +import static net.kyori.adventure.text.format.NamedTextColor.BLUE; +import static net.kyori.adventure.text.format.NamedTextColor.GREEN; +import static net.kyori.adventure.text.format.TextColor.color; + +public class ProgressTagTest extends AbstractTest { + + @Test + void testConstantProgress() { + final String input = ""; + final Component filled = text("|", GREEN); + final Component empty = text("|", color(0x696969)); + final Component expected = empty() + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(empty) + .append(empty) + .append(empty) + .append(empty) + .append(empty); + assertParsedEquals(expected, input); + } + + @Test + void testSupplierProgress() { + final Supplier progressSupplier = () -> 0.777; + final String input = ""; + final Component filled = text("|", BLUE); + final Component empty = text("|", color(0xFF5555)); + final Component expected = empty() + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(filled) + .append(empty) + .append(empty) + .append(empty); + assertParsedEquals(expected, input, Formatter.progress("why_am_i_doing_this", progressSupplier)); + } + +} diff --git a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RepeatTagTest.java b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RepeatTagTest.java new file mode 100644 index 0000000000..907fffb2f4 --- /dev/null +++ b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RepeatTagTest.java @@ -0,0 +1,93 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * 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 NONINFRINGEMENT. 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 net.kyori.adventure.text.minimessage.tag.standard; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.AbstractTest; +import org.junit.jupiter.api.Test; + +import static net.kyori.adventure.text.Component.empty; +import static net.kyori.adventure.text.Component.newline; +import static net.kyori.adventure.text.Component.text; +import static net.kyori.adventure.text.event.ClickEvent.runCommand; +import static net.kyori.adventure.text.event.HoverEvent.showText; +import static net.kyori.adventure.text.format.NamedTextColor.GREEN; +import static net.kyori.adventure.text.format.NamedTextColor.RED; +import static net.kyori.adventure.text.format.Style.style; +import static net.kyori.adventure.text.format.TextDecoration.BOLD; +import static net.kyori.adventure.text.minimessage.tag.resolver.Placeholder.parsed; + +public class RepeatTagTest extends AbstractTest { + + @Test + void testSimpleRepeat() { + final String input = ""; + final Component expected = empty() + .append(text("Hello World!")) + .append(text("Hello World!")) + .append(text("Hello World!")) + .append(text("Hello World!")) + .append(text("Hello World!")); + assertParsedEquals(expected, input); + } + + @Test + void spaceRepeat() { + final String input = ""; + final Component expected = empty() + .append(text(" ")) + .append(text(" ")) + .append(text(" ")) + .append(text(" ")) + .append(text(" ")); + assertParsedEquals(expected, input); + } + + @Test + void fancyRepeat() { + final String input = "AMiniMessageTest'>"; + final Component toRepeat = empty() + .append(text("Mini", RED)) + .append(text("Message", GREEN)) + .append(newline()) + .append(text("Test").clickEvent(runCommand("/hello world")).hoverEvent(showText(text("AAA")))); + final Component expected = empty().append(text("A")).append( + text("cool placeholder value", style(BOLD)) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + .append(toRepeat) + ); + assertParsedEquals(expected, input, parsed("idk_what_to_name", "cool placeholder value")); + } + +}