bbansi/tests/tbasic.nim

57 lines
1.9 KiB
Nim
Raw Normal View History

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-13 01:37:24 -05:00
import std/unittest
2023-09-10 18:14:36 -05:00
import bbansi
2023-09-12 00:14:37 -05:00
template bbCheck(input: string, output: string): untyped =
check $bb(input) == output
2023-09-12 00:14:37 -05:00
suite "basic":
test "simple":
bbCheck "[red]red text", "\e[31mred text\e[0m"
bbCheck "[red]Red Text", "\e[31mRed Text\e[0m"
bbCheck "[yellow]Yellow Text", "\e[33mYellow Text\e[0m"
bbCheck "[bold red]Bold Red Text", "\e[1;31mBold Red Text\e[0m"
2023-09-12 00:14:37 -05:00
test "closing":
bbCheck "[bold]Bold[red] Bold Red[/red] Bold Only",
"\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":
bbCheck "[b]Bold[/] Not Bold", "\e[1mBold\e[0m Not Bold"
2023-09-12 00:14:37 -05:00
test "noop":
bbCheck "No Style", "No Style"
bbCheck "[unknown]Unknown Style", "Unknown Style"
2023-09-12 00:14:37 -05:00
test "escaped":
bbCheck "[[red] ignored pattern", "[red] ignored pattern"
2023-09-12 00:14:37 -05:00
test "newlines":
# Proc Strings: raw strings,
# but the method name that prefixes the string is called
# so that foo"12\" -> foo(r"12\")
bbCheck "[red]Red Text[/]\nNext Line", "\e[31mRed Text\e[0m\nNext Line"
test "on color":
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
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