2023-09-10 18:14:36 -05:00
|
|
|
# This is just an example to get you started. You may wish to put all of your
|
|
|
|
# tests into a single file, or separate them into multiple `test1`, `test2`
|
|
|
|
# etc. files (better names are recommended, just make sure the name starts with
|
|
|
|
# the letter 't').
|
|
|
|
#
|
|
|
|
# To run these tests, simply execute `nimble test`.
|
|
|
|
|
2023-09-20 15:40:19 -05:00
|
|
|
import std/[strutils,unittest]
|
2023-09-10 18:14:36 -05:00
|
|
|
|
|
|
|
import bbansi
|
2023-09-12 00:14:37 -05:00
|
|
|
|
2023-09-13 03:06:57 -05:00
|
|
|
template bbCheck(input: string, output: string): untyped =
|
2023-09-20 15:40:19 -05:00
|
|
|
check escape($bb(input)) == escape(output)
|
2023-09-13 03:06:57 -05:00
|
|
|
|
2023-09-12 00:14:37 -05:00
|
|
|
suite "basic":
|
|
|
|
test "simple":
|
2023-09-13 03:06:57 -05:00
|
|
|
bbCheck "[red]red text", "\e[31mred text\e[0m"
|
|
|
|
bbCheck "[red]Red Text", "\e[31mRed Text\e[0m"
|
2023-09-15 00:17:45 -05:00
|
|
|
bbCheck "[yellow]Yellow Text", "\e[33mYellow Text\e[0m"
|
2023-09-14 22:35:19 -05:00
|
|
|
bbCheck "[bold red]Bold Red Text", "\e[1;31mBold Red Text\e[0m"
|
2023-09-20 15:40:19 -05:00
|
|
|
bbCheck "[red]5[/]", "\e[31m5\e[0m"
|
|
|
|
bbCheck "[bold][red]5","\e[1;31m5\e[0m"
|
2023-09-12 00:14:37 -05:00
|
|
|
|
|
|
|
test "closing":
|
2023-09-13 03:06:57 -05:00
|
|
|
bbCheck "[bold]Bold[red] Bold Red[/red] Bold Only",
|
2023-09-15 00:17:45 -05:00
|
|
|
"\e[1mBold\e[0m\e[1;31m Bold Red\e[0m\e[1m Bold Only\e[0m"
|
2023-09-12 00:14:37 -05:00
|
|
|
|
|
|
|
test "abbreviated":
|
2023-09-13 03:06:57 -05:00
|
|
|
bbCheck "[b]Bold[/] Not Bold", "\e[1mBold\e[0m Not Bold"
|
2023-09-12 00:14:37 -05:00
|
|
|
|
|
|
|
test "noop":
|
2023-09-13 03:06:57 -05:00
|
|
|
bbCheck "No Style", "No Style"
|
|
|
|
bbCheck "[unknown]Unknown Style", "Unknown Style"
|
2023-09-12 00:14:37 -05:00
|
|
|
|
|
|
|
test "escaped":
|
2023-09-15 00:17:45 -05:00
|
|
|
bbCheck "[[red] ignored pattern", "[red] ignored pattern"
|
2023-09-12 00:14:37 -05:00
|
|
|
|
|
|
|
test "newlines":
|
2023-09-13 03:06:57 -05:00
|
|
|
bbCheck "[red]Red Text[/]\nNext Line", "\e[31mRed Text\e[0m\nNext Line"
|
|
|
|
|
|
|
|
test "on color":
|
2023-09-14 22:35:19 -05:00
|
|
|
bbCheck "[red on yellow]Red on Yellow", "\e[31;43mRed on Yellow\e[0m"
|
2023-09-12 00:14:37 -05:00
|
|
|
|
|
|
|
test "concat-ops":
|
|
|
|
check "[red]RED[/]".bb & " plain string" == "[red]RED[/] plain string".bb
|
|
|
|
check "[red]RED[/]".bb.len == 3
|
2023-09-13 02:33:19 -05:00
|
|
|
check bb("[blue]Blue[/]") & " " & bb("[red]Red[/]") ==
|
|
|
|
"[blue]Blue[/] [red]Red[/]".bb
|
|
|
|
check "a plain string" & "[blue] a blue string".bb ==
|
|
|
|
"a plain string[blue] a blue string".bb
|
2023-09-12 10:14:03 -05:00
|
|
|
|
2023-09-15 17:10:25 -05:00
|
|
|
test "case":
|
|
|
|
bbCheck "[red]no case sensitivity[/RED]", "\e[31mno case sensitivity\e[0m"
|
|
|
|
|
2023-09-12 10:14:03 -05:00
|
|
|
test "style full":
|
2023-09-13 02:33:19 -05:00
|
|
|
check "[red]Red[/red]".bb == bb("Red", "red")
|
|
|
|
check "[b][yellow]not yellow[/][/b]".bb == bb("[yellow]not yellow[/]", "b")
|
2023-09-12 10:14:03 -05:00
|
|
|
|