Add tests

This commit is contained in:
Florian Schroedl
2022-01-20 17:00:00 +01:00
parent d24e596ce3
commit 49ebf7329a
5 changed files with 59 additions and 3 deletions

4
tests/config.nims Normal file
View File

@@ -0,0 +1,4 @@
switch("define", "nimUnittestOutputLevel:PRINT_FAILURES")
switch("warnings", false)
switch("hints", false)
switch("path", "$projectDir/../src")

1
tests/nim.cfg Normal file
View File

@@ -0,0 +1 @@
--path: "../src/"

22
tests/utils/test_str.nim Normal file
View File

@@ -0,0 +1,22 @@
import std/unittest
import utils/str
suite "utils/str":
test "safeDelete":
let t = "abc"
check(t.safeDelete(0..0) == "abc")
check(t.safeDelete(0..1) == "c")
check(t.safeDelete(1..1) == "ac")
check(t.safeDelete(2..2) == "ab")
# Out of bounds slicing
check(t.safeDelete(0..10) == "")
check(t.safeDelete(10..1) == t)
check(t.safeDelete(3..3) == t)
check(t.safeDelete(3..(-1)) == t)
test "findAndDelete":
let t = "foo\nbar"
check(t.deleteAfterNewline() == "foo")
check(t.deleteAfterNewline(start = 4) == t)