Skip to content

Commit

Permalink
Close #188 - [extras-scala-io] Add syntax: Seq[String].rainbowed
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lee committed Jul 7, 2022
1 parent 474e67c commit 20778ad
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package extras.scala.io.syntax.truecolor

import extras.scala.io.syntax.truecolor.RainbowSyntax.RainbowSyntaxOps
import extras.scala.io.syntax.truecolor.RainbowSyntax.{RainbowSyntaxOps, RainbowsSyntaxOps}
import extras.scala.io.truecolor.Rainbow

/** @author Kevin Lee
* @since 2022-06-13
*/
trait RainbowSyntax {
implicit def rainbowSyntax(s: String): RainbowSyntaxOps = new RainbowSyntaxOps(s)

implicit def rainbowsSyntax(ss: Seq[String]): RainbowsSyntaxOps = new RainbowsSyntaxOps(ss)
}
object RainbowSyntax {
class RainbowSyntaxOps(private val s: String) extends AnyVal {
def rainbowed: String = Rainbow.rainbow(s)
def rainbowedHtml: String = Rainbow.rainbowHtml(s)
}

class RainbowsSyntaxOps(private val ss: Seq[String]) extends AnyVal {
def rainbowed: Seq[String] = Rainbow.rainbows(ss)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ trait RainbowSyntax {
def rainbowed: String = Rainbow.rainbow(s)
def rainbowedHtml: String = Rainbow.rainbowHtml(s)
}

extension (ss: Seq[String]) {
def rainbowed: Seq[String] = Rainbow.rainbows(ss)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import extras.scala.io.truecolor.Rainbow
import hedgehog._
import hedgehog.runner._

import extras.scala.io.truecolor.Data.{expectedRainbowAsciiArt, rainbowAsciiArt}

/** @author Kevin Lee
* @since 2022-06-19
*/
object RainbowSyntaxSpec extends Properties {
override def tests: List[Prop] = List(
example("test Rainbow.rainbow(Big RAINBOW ASCII art) should return rainbowed String", testRainbowAsciiArt),
example("test List[String].map(_.rainbowed) should return rainbowed List[String]", testRainbowAsciiArt),
example("test Seq[String].rainbowed should return rainbowed Seq[String]", testRainbowAsciiArtWithSeq),
property("test String.rainbowed should return rainbowed String", testRainbow),
property("test String.rainbowed should return rainbowed String2", testRainbow2),
example("""test "".rainbowed should return rainbowed """"", testEmptyStringRainbowed),
Expand All @@ -19,42 +22,19 @@ object RainbowSyntaxSpec extends Properties {

def testRainbowAsciiArt: Result = {
import extras.scala.io.syntax.truecolor.rainbow._
val rainbowAsciiArt =
List(
""" ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ """,
"""▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░▌ ▐░▌▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░▌""",
"""▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀ ▐░▌░▌ ▐░▌▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌""",
"""▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌""",
"""▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌▐░▌ ▄ ▐░▌""",
"""▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░░░░░░░░░░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌""",
"""▐░█▀▀▀▀█░█▀▀ ▐░█▀▀▀▀▀▀▀█░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌▐░▌ ▐░▌░▌ ▐░▌""",
"""▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌""",
"""▐░▌ ▐░▌ ▐░▌ ▐░▌ ▄▄▄▄█░█▄▄▄▄ ▐░▌ ▐░▐░▌▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░▌░▌ ▐░▐░▌""",
"""▐░▌ ▐░▌▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░▌ ▐░░▌▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░▌ ▐░░▌""",
""" ▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀ """
)

val expected = {
import extras.scala.io.truecolor.Rainbow._
import extras.scala.io.Color
// format: off
List(
s"""${Red.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Orange.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Yellow.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Green.toAsciiEsc} ▄▄ ▄ ${Blue.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄ ${Indigo.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Violet.toAsciiEsc} ▄ ▄ ${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░░░░░░░░░░░▌${Orange.toAsciiEsc}▐░░░░░░░░░░░▌${Yellow.toAsciiEsc}▐░░░░░░░░░░░▌${Green.toAsciiEsc}▐░░▌ ▐░▌${Blue.toAsciiEsc}▐░░░░░░░░░░▌ ${Indigo.toAsciiEsc}▐░░░░░░░░░░░▌${Violet.toAsciiEsc}▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Orange.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Yellow.toAsciiEsc} ▀▀▀▀█░█▀▀▀▀ ${Green.toAsciiEsc}▐░▌░▌ ▐░▌${Blue.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Indigo.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Violet.toAsciiEsc}▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌▐░▌ ▐░▌${Blue.toAsciiEsc}▐░▌ ▐░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Orange.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Blue.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▄ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░░░░░░░░░░░▌${Orange.toAsciiEsc}▐░░░░░░░░░░░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Blue.toAsciiEsc}▐░░░░░░░░░░▌ ${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░█▀▀▀▀█░█▀▀ ${Orange.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Blue.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▐░▌░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌ ${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌▐░▌${Blue.toAsciiEsc}▐░▌ ▐░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌▐░▌ ▐░▌▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌ ${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc} ▄▄▄▄█░█▄▄▄▄ ${Green.toAsciiEsc}▐░▌ ▐░▐░▌${Blue.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Indigo.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Violet.toAsciiEsc}▐░▌░▌ ▐░▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc}▐░░░░░░░░░░░▌${Green.toAsciiEsc}▐░▌ ▐░░▌${Blue.toAsciiEsc}▐░░░░░░░░░░▌ ${Indigo.toAsciiEsc}▐░░░░░░░░░░░▌${Violet.toAsciiEsc}▐░░▌ ▐░░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc} ▀ ▀ ${Orange.toAsciiEsc} ▀ ▀ ${Yellow.toAsciiEsc} ▀▀▀▀▀▀▀▀▀▀▀ ${Green.toAsciiEsc} ▀ ▀▀ ${Blue.toAsciiEsc} ▀▀▀▀▀▀▀▀▀▀ ${Indigo.toAsciiEsc} ▀▀▀▀▀▀▀▀▀▀▀ ${Violet.toAsciiEsc} ▀▀ ▀▀ ${Color.reset.toAnsi}"""
).mkString("\n")
// format: on
}

val actual = rainbowAsciiArt.map(_.rainbowed).mkString("\n")

val expected = expectedRainbowAsciiArt
val actual = rainbowAsciiArt.map(_.rainbowed).mkString("\n")
println(actual)

actual ==== expected
}

def testRainbowAsciiArtWithSeq: Result = {
import extras.scala.io.syntax.truecolor.rainbow._

val expected = expectedRainbowAsciiArt
val actual = rainbowAsciiArt.rainbowed.mkString("\n")
println(actual)

actual ==== expected
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package extras.scala.io.truecolor

/**
* @author Kevin Lee
* @since 2022-07-07
*/
object Data {

val rainbowAsciiArt: Seq[String] =
List(
""" ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ """,
"""▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░▌ ▐░▌▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░▌""",
"""▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀ ▐░▌░▌ ▐░▌▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌""",
"""▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌""",
"""▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌▐░▌ ▄ ▐░▌""",
"""▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░░░░░░░░░░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌""",
"""▐░█▀▀▀▀█░█▀▀ ▐░█▀▀▀▀▀▀▀█░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌▐░▌ ▐░▌░▌ ▐░▌""",
"""▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌""",
"""▐░▌ ▐░▌ ▐░▌ ▐░▌ ▄▄▄▄█░█▄▄▄▄ ▐░▌ ▐░▐░▌▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░▌░▌ ▐░▐░▌""",
"""▐░▌ ▐░▌▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░▌ ▐░░▌▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░▌ ▐░░▌""",
""" ▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀ """
)

val expectedRainbowAsciiArt: String = {
import Rainbow._
import extras.scala.io.Color
// format: off
List(
s"""${Red.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Orange.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Yellow.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Green.toAsciiEsc} ▄▄ ▄ ${Blue.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄ ${Indigo.toAsciiEsc} ▄▄▄▄▄▄▄▄▄▄▄ ${Violet.toAsciiEsc} ▄ ▄ ${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░░░░░░░░░░░▌${Orange.toAsciiEsc}▐░░░░░░░░░░░▌${Yellow.toAsciiEsc}▐░░░░░░░░░░░▌${Green.toAsciiEsc}▐░░▌ ▐░▌${Blue.toAsciiEsc}▐░░░░░░░░░░▌ ${Indigo.toAsciiEsc}▐░░░░░░░░░░░▌${Violet.toAsciiEsc}▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Orange.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Yellow.toAsciiEsc} ▀▀▀▀█░█▀▀▀▀ ${Green.toAsciiEsc}▐░▌░▌ ▐░▌${Blue.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Indigo.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Violet.toAsciiEsc}▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌▐░▌ ▐░▌${Blue.toAsciiEsc}▐░▌ ▐░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Orange.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Blue.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▄ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░░░░░░░░░░░▌${Orange.toAsciiEsc}▐░░░░░░░░░░░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Blue.toAsciiEsc}▐░░░░░░░░░░▌ ${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░█▀▀▀▀█░█▀▀ ${Orange.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌ ▐░▌${Blue.toAsciiEsc}▐░█▀▀▀▀▀▀▀█░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌ ▐░▌░▌ ▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌ ${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc} ▐░▌ ${Green.toAsciiEsc}▐░▌ ▐░▌▐░▌${Blue.toAsciiEsc}▐░▌ ▐░▌${Indigo.toAsciiEsc}▐░▌ ▐░▌${Violet.toAsciiEsc}▐░▌▐░▌ ▐░▌▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌ ${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc} ▄▄▄▄█░█▄▄▄▄ ${Green.toAsciiEsc}▐░▌ ▐░▐░▌${Blue.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Indigo.toAsciiEsc}▐░█▄▄▄▄▄▄▄█░▌${Violet.toAsciiEsc}▐░▌░▌ ▐░▐░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc}▐░▌ ▐░▌${Orange.toAsciiEsc}▐░▌ ▐░▌${Yellow.toAsciiEsc}▐░░░░░░░░░░░▌${Green.toAsciiEsc}▐░▌ ▐░░▌${Blue.toAsciiEsc}▐░░░░░░░░░░▌ ${Indigo.toAsciiEsc}▐░░░░░░░░░░░▌${Violet.toAsciiEsc}▐░░▌ ▐░░▌${Color.reset.toAnsi}""",
s"""${Red.toAsciiEsc} ▀ ▀ ${Orange.toAsciiEsc} ▀ ▀ ${Yellow.toAsciiEsc} ▀▀▀▀▀▀▀▀▀▀▀ ${Green.toAsciiEsc} ▀ ▀▀ ${Blue.toAsciiEsc} ▀▀▀▀▀▀▀▀▀▀ ${Indigo.toAsciiEsc} ▀▀▀▀▀▀▀▀▀▀▀ ${Violet.toAsciiEsc} ▀▀ ▀▀ ${Color.reset.toAnsi}"""
).mkString("\n")
// format: on
}

}
Loading

0 comments on commit 20778ad

Please sign in to comment.