-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(minimessage): tests for progress and repeat tags
- Loading branch information
Showing
2 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...sage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ProgressTagTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "<progress:0.5:|:10:green:#696969>"; | ||
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<Double> progressSupplier = () -> 0.777; | ||
final String input = "<why_am_i_doing_this:|:12:blue:#FF5555>"; | ||
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)); | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...essage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RepeatTagTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "<repeat:5:'Hello World!'>"; | ||
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 = "<repeat:5:' '>"; | ||
final Component expected = empty() | ||
.append(text(" ")) | ||
.append(text(" ")) | ||
.append(text(" ")) | ||
.append(text(" ")) | ||
.append(text(" ")); | ||
assertParsedEquals(expected, input); | ||
} | ||
|
||
@Test | ||
void fancyRepeat() { | ||
final String input = "A<idk_what_to_name><repeat:12:'<red>Mini</red><green>Message</green><newline><click:run_command:'/hello world'><hover:show_text:'AAA'>Test</hover></click>'>"; | ||
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", "<bold>cool placeholder value")); | ||
} | ||
|
||
} |