Fixed colorize function.
This commit is contained in:
parent
04e88264cd
commit
00caee4bc1
4 changed files with 17 additions and 11 deletions
|
@ -31,10 +31,10 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot
|
||||
|
||||
import net.thauvin.erik.mobibot.msg.Message.Companion.DEFAULT_COLOR
|
||||
import org.jibble.pircbot.Colors
|
||||
import org.jsoup.Jsoup
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.net.URL
|
||||
|
@ -59,7 +59,7 @@ object Utils {
|
|||
* Appends a suffix to the end of the String if not present.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun String.appendIfMissing(suffix: Char) : String {
|
||||
fun String.appendIfMissing(suffix: Char): String {
|
||||
return if (this.last() != suffix) {
|
||||
"$this${suffix}"
|
||||
} else {
|
||||
|
@ -106,8 +106,10 @@ object Utils {
|
|||
*/
|
||||
@JvmStatic
|
||||
fun colorize(s: String?, color: String): String {
|
||||
return if (s.isNullOrBlank()) {
|
||||
Colors.NORMAL
|
||||
return if (s.isNullOrEmpty()) {
|
||||
""
|
||||
} else if (color == DEFAULT_COLOR) {
|
||||
s
|
||||
} else if (Colors.BOLD == color || Colors.REVERSE == color) {
|
||||
color + s + color
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot.msg
|
||||
|
||||
import net.thauvin.erik.semver.Constants
|
||||
import org.jibble.pircbot.Colors
|
||||
|
||||
/**
|
||||
|
@ -38,7 +39,7 @@ import org.jibble.pircbot.Colors
|
|||
*/
|
||||
open class Message {
|
||||
companion object {
|
||||
var DEFAULT_COLOR = Colors.NORMAL
|
||||
var DEFAULT_COLOR = Constants.EMPTY
|
||||
}
|
||||
|
||||
/** Message color. */
|
||||
|
|
|
@ -53,6 +53,7 @@ import net.thauvin.erik.mobibot.Utils.today
|
|||
import net.thauvin.erik.mobibot.Utils.unescapeXml
|
||||
import net.thauvin.erik.mobibot.Utils.uptime
|
||||
import net.thauvin.erik.mobibot.Utils.urlReader
|
||||
import net.thauvin.erik.mobibot.msg.Message.Companion.DEFAULT_COLOR
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jibble.pircbot.Colors
|
||||
import org.testng.annotations.BeforeClass
|
||||
|
@ -125,9 +126,11 @@ class UtilsTest {
|
|||
.isEqualTo(Colors.RED + ascii + Colors.NORMAL)
|
||||
assertThat(colorize(ascii, Colors.BOLD)).describedAs("colorized(bold)")
|
||||
.isEqualTo(Colors.BOLD + ascii + Colors.BOLD)
|
||||
assertThat(colorize(null, Colors.RED)).describedAs("colorize(null)").isEqualTo(Colors.NORMAL)
|
||||
assertThat(colorize("", Colors.RED)).describedAs("colorize()").isEqualTo(Colors.NORMAL)
|
||||
|
||||
assertThat(colorize(null, Colors.RED)).describedAs("colorize(null)").isEqualTo("")
|
||||
assertThat(colorize("", Colors.RED)).describedAs("colorize()").isEqualTo("")
|
||||
assertThat(colorize(ascii, DEFAULT_COLOR)).describedAs("colorize(none)").isEqualTo(ascii)
|
||||
assertThat(colorize(" ", Colors.NORMAL)).describedAs("colorize(blank)")
|
||||
.isEqualTo(Colors.NORMAL + " " + Colors.NORMAL)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#Generated by the Semver Plugin for Gradle
|
||||
#Fri Jul 30 02:43:43 PDT 2021
|
||||
version.buildmeta=1111
|
||||
#Fri Jul 30 03:23:18 PDT 2021
|
||||
version.buildmeta=1115
|
||||
version.major=0
|
||||
version.minor=8
|
||||
version.patch=0
|
||||
version.prerelease=beta
|
||||
version.project=mobibot
|
||||
version.semver=0.8.0-beta+1111
|
||||
version.semver=0.8.0-beta+1115
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue