Skip to content

Commit

Permalink
Fixed tests (added elevated status)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsimmo committed Oct 10, 2021
1 parent a773f52 commit 5ca9b99
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 77 deletions.
42 changes: 21 additions & 21 deletions src/test/java/io/github/mdsimmo/bomberman/messaging/ExpanderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class ExpanderTest {
fun printsBasicString() {
assertEquals(
"Hello",
expand("Hello", mapOf()).toString()
expand("Hello", mapOf(), false).toString()
)
}

@Test
fun singleColorIsAdded() {
val message = expand("hi {#red|boo}", mapOf())
val message = expand("hi {#red|boo}", mapOf(), false)
assertEquals(
"hi " + ChatColor.RED + "boo" + ChatColor.RESET,
message.toString()
Expand All @@ -26,7 +26,7 @@ class ExpanderTest {

@Test
fun embeddedColorsHandled() {
val message = expand("{#green|hello, {#yellow|fred}.} You Stink", mapOf())
val message = expand("{#green|hello, {#yellow|fred}.} You Stink", mapOf(), false)
assertEquals(
ChatColor.GREEN.toString() + "hello, " + ChatColor.YELLOW + "fred" + ChatColor.GREEN + "." + ChatColor.RESET + " You Stink",
message.toString()
Expand All @@ -35,7 +35,7 @@ class ExpanderTest {

@Test
fun argumentArePassed() {
val message = expand("One, {two}, three", mapOf(Pair("two", Message.of("hello"))))
val message = expand("One, {two}, three", mapOf(Pair("two", Message.of("hello"))), false)
assertEquals(
"One, hello, three",
message.toString()
Expand All @@ -54,22 +54,22 @@ class ExpanderTest {
Message.of("Alex")
}
})
))
), false)
assertEquals("Steve likes Alex", message.toString())
}

@Test
fun messagesEmbeddedInMessages() {
val a = expand("This is A.", mapOf())
val b = expand("{a} This is B.", mapOf(Pair("a", a)))
val c = expand("{b} This is C.", mapOf(Pair("b", b)))
val a = expand("This is A.", mapOf(), false)
val b = expand("{a} This is B.", mapOf(Pair("a", a)), false)
val c = expand("{b} This is C.", mapOf(Pair("b", b)), false)
assertEquals("This is A. This is B. This is C.", c.toString())
}

@Test
fun colorsPassedThroughMessages() {
val a = expand("A{#red|B}C", mapOf())
val b = expand("{#Green|X{a}Y}", mapOf(Pair("a", a)))
val a = expand("A{#red|B}C", mapOf(), false)
val b = expand("{#Green|X{a}Y}", mapOf(Pair("a", a)), false)
assertEquals(
ChatColor.GREEN.toString() + "XA" + ChatColor.RED + "B" + ChatColor.GREEN + "CY" + ChatColor.RESET,
b.toString()
Expand All @@ -78,8 +78,8 @@ class ExpanderTest {

@Test
fun noCachedDataRemains() {
val a = expand("A{#red|B}C", mapOf())
val b = expand("{#Green|X{a}Y}", mapOf(Pair("a", a)))
val a = expand("A{#red|B}C", mapOf(), false)
val b = expand("{#Green|X{a}Y}", mapOf(Pair("a", a)), false)
// run the test a few times with the same objects. If it fails, the cache is broken
for (i in 0..4)
assertEquals(
Expand All @@ -92,7 +92,7 @@ class ExpanderTest {
fun singleMessageThatIsSuperComplex() {
val message = expand(
"Hey, {#bold|Mr. {#Red|Red {#yellow|Bob} the {#yellow|Tob} BANG} BOOM} CRASH",
mapOf()
mapOf(), false
)
assertEquals(
"Hey, " + ChatColor.BOLD + "Mr. " + ChatColor.RED + ChatColor.BOLD +
Expand All @@ -104,7 +104,7 @@ class ExpanderTest {

@Test
fun multipleFormatsGetApplied() {
val message = expand("Hello, {#bold|{#italic|{#green|World}}}!", mapOf())
val message = expand("Hello, {#bold|{#italic|{#green|World}}}!", mapOf(), false)
// TODO lazy apply color formats
// note that the bold/italic is applied twice here because the green resets it
assertEquals("Hello, " + ChatColor.BOLD + ChatColor.ITALIC + ChatColor.GREEN
Expand All @@ -116,7 +116,7 @@ class ExpanderTest {

@Test
fun resetDoesResetThings() {
val message = expand("{#Green|{#Bold|Hi {#reset|world}!}}", mapOf())
val message = expand("{#Green|{#Bold|Hi {#reset|world}!}}", mapOf(), false)
assertEquals(
ChatColor.GREEN.toString() + "" + ChatColor.BOLD + "Hi " + ChatColor.RESET
+ "world" + ChatColor.GREEN + ChatColor.BOLD + "!" + ChatColor.GREEN
Expand All @@ -126,8 +126,8 @@ class ExpanderTest {

@Test
fun formatCodesThroughMessages() {
val a = expand("{#Green|{#bold|A}}", mapOf())
val b = expand("{#Italic|{#Blue|{a}}}", mapOf(Pair("a", a)))
val a = expand("{#Green|{#bold|A}}", mapOf(), false)
val b = expand("{#Italic|{#Blue|{a}}}", mapOf(Pair("a", a)), false)
assertEquals(ChatColor.ITALIC.toString() + "" + ChatColor.BLUE + ChatColor.ITALIC
+ ChatColor.GREEN + ChatColor.ITALIC + ChatColor.BOLD + "A" + ChatColor.GREEN
+ ChatColor.ITALIC + ChatColor.BLUE + ChatColor.ITALIC + ChatColor.RESET
Expand All @@ -137,7 +137,7 @@ class ExpanderTest {

@Test
fun backslashEscapes() {
val a = expand("{#Red|\\{#Green\\|Hello\\{\\}}", mapOf())
val a = expand("{#Red|\\{#Green\\|Hello\\{\\}}", mapOf(), false)
assertEquals(
ChatColor.RED.toString() + "{#Green|Hello{}" + ChatColor.RESET,
a.toString()
Expand All @@ -146,7 +146,7 @@ class ExpanderTest {

@Test
fun testExpandingMissingValueGivesRedHighlight() {
val a = expand("Hello {friend|verb} friend", mapOf())
val a = expand("Hello {friend|verb} friend", mapOf(), false)
assertEquals(
"Hello " + ChatColor.RED + "{friend|verb}" + ChatColor.RESET + " friend",
a.toString()
Expand All @@ -159,9 +159,9 @@ class ExpanderTest {
@Test
fun testMessagesLazyExpanded() {
val badExpand = mock(Formattable::class.java)
`when`(badExpand.format(anyList(),)).thenReturn(Message.of("no no"))
`when`(badExpand.format(anyList(), anyBoolean())).thenReturn(Message.of("no no"))

val a = expand("{#switch|0|0|choose me|{bad}}", mapOf(Pair("bad", badExpand)))
val a = expand("{#switch|0|0|choose me|{bad}}", mapOf(Pair("bad", badExpand)), false)

assertEquals("choose me", a.toString())
verifyNoInteractions(badExpand)
Expand Down
Loading

0 comments on commit 5ca9b99

Please sign in to comment.