tests: reduce boilerplate with template

This commit is contained in:
Daylin Morgan 2023-09-13 03:06:57 -05:00
parent 32abc9910a
commit 13ca3538d9
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -9,31 +9,38 @@ import std/unittest
import bbansi import bbansi
template bbCheck(input: string, output: string): untyped =
check $bb(input) == output
suite "basic": suite "basic":
test "simple": test "simple":
check "\e[31mRed Text\e[0m" == $bb"[red]Red Text" bbCheck "[red]red text", "\e[31mred text\e[0m"
check "\e[33mYellow Text\e[0m" == $bb"[yellow]Yellow Text" bbCheck "[red]Red Text", "\e[31mRed Text\e[0m"
check "\e[1m\e[31mBold Red Text\e[0m" == $bb"[bold red]Bold Red Text" bbCheck "[yellow]Yellow Text","\e[33mYellow Text\e[0m"
bbCheck "[bold red]Bold Red Text", "\e[1m\e[31mBold Red Text\e[0m"
test "closing": test "closing":
check "\e[1mBold\e[0m\e[1m\e[31m Bold Red\e[0m\e[1m Bold Only\e[0m" == bbCheck "[bold]Bold[red] Bold Red[/red] Bold Only",
$bb"[bold]Bold[red] Bold Red[/red] Bold Only" "\e[1mBold\e[0m\e[1m\e[31m Bold Red\e[0m\e[1m Bold Only\e[0m"
test "abbreviated": test "abbreviated":
check "\e[1mBold\e[0m Not Bold" == $bb"[b]Bold[/] Not Bold" bbCheck "[b]Bold[/] Not Bold", "\e[1mBold\e[0m Not Bold"
test "noop": test "noop":
check "No Style" == $bb"No Style" bbCheck "No Style", "No Style"
check "Unknown Style" == $bb"[unknown]Unknown Style" bbCheck "[unknown]Unknown Style", "Unknown Style"
test "escaped": test "escaped":
check "[red] ignored pattern" == $"[[red] ignored pattern".bb bbCheck "[[red] ignored pattern","[red] ignored pattern"
test "newlines": test "newlines":
# Proc Strings: raw strings, # Proc Strings: raw strings,
# but the method name that prefixes the string is called # but the method name that prefixes the string is called
# so that foo"12\" -> foo(r"12\") # so that foo"12\" -> foo(r"12\")
check "\e[31mRed Text\e[0m\nNext Line" == $"[red]Red Text[/]\nNext Line".bb bbCheck "[red]Red Text[/]\nNext Line", "\e[31mRed Text\e[0m\nNext Line"
test "on color":
bbCheck "[red on yellow]Red on Yellow", "\e[31m\e[43mRed on Yellow\e[0m"
test "concat-ops": test "concat-ops":
check "[red]RED[/]".bb & " plain string" == "[red]RED[/] plain string".bb check "[red]RED[/]".bb & " plain string" == "[red]RED[/] plain string".bb