diff options
-rw-r--r-- | src/gobang.go | 4 | ||||
-rw-r--r-- | tests/gobang.go | 33 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/gobang.go b/src/gobang.go index 8777247..3c705b7 100644 --- a/src/gobang.go +++ b/src/gobang.go @@ -76,6 +76,10 @@ var ( +func Heredoc(s string) string { + return strings.Trim(strings.ReplaceAll(s, "\t", ""), "\n") + "\n" +} + func SetOf[T comparable](values ...T) SetT[T] { s := SetT[T]{ data: map[T]struct{}{ diff --git a/tests/gobang.go b/tests/gobang.go index fe47086..7391475 100644 --- a/tests/gobang.go +++ b/tests/gobang.go @@ -15,6 +15,38 @@ import ( +func test_Heredoc() { + TestStart("Heredoc()") + + Testing("only add newline on empty string", func() { + TAssertEqual(Heredoc(""), "\n") + }) + + Testing("remove leading newline", func() { + given := Heredoc(` + Start + and + end +`) + expected := ` Start + and + end +` + + TAssertEqual(given, expected) + }) + + Testing("removes ALL tabs", func() { + given := Heredoc(` + Tab here> <within the line + `) + + expected := "Tab here><within the line\n" + + TAssertEqual(given, expected) + }) +} + func test_SetOf() { TestStart("SetOf()") @@ -1556,6 +1588,7 @@ func test_setHostname() { func MainTest() { Init() + test_Heredoc() test_SetOf() test_Contains() test_MapIndexed() |