>> add tests for new sortPaths function
> add slices formatter
This commit is contained in:
parent
13e6010d04
commit
f517f61c55
1 changed files with 47 additions and 1 deletions
48
owl_test.go
48
owl_test.go
|
|
@ -21,8 +21,21 @@ package main
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func sliceToString(slice []string) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("[\n")
|
||||
for _, s := range slice {
|
||||
b.WriteString(" ")
|
||||
b.WriteString(s)
|
||||
b.WriteRune('\n')
|
||||
}
|
||||
b.WriteRune(']')
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func TestRestrictRuneset(t *testing.T) {
|
||||
removeTCases := map[string]string{
|
||||
"::?\\": "_EMPTY_",
|
||||
|
|
@ -38,7 +51,8 @@ func TestRestrictRuneset(t *testing.T) {
|
|||
"This*-causes-~problems~": "This_U2A_-causes-~problems~",
|
||||
}
|
||||
for input, want := range removeTCases {
|
||||
if have:=restrictRuneset(input, "remove"); have != want {
|
||||
have := restrictRuneset(input, "remove")
|
||||
if ; have != want {
|
||||
t.Errorf(
|
||||
"With strategy \"remove\":\n\twant <<%s>>\n\thave <<%s>>\n",
|
||||
want,
|
||||
|
|
@ -56,3 +70,35 @@ func TestRestrictRuneset(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortPaths(t *testing.T) {
|
||||
paths := []string{
|
||||
"./testdata/Tawnee: The Game",
|
||||
"./testdata/birds:/pengiuns?",
|
||||
"./testdata/birds:/pengiuns?/emperor",
|
||||
"./testdata/birds:/pengiuns?/pingu?",
|
||||
"./testdata/birds:",
|
||||
}
|
||||
want := []string{
|
||||
"./testdata/birds:/pengiuns?/emperor",
|
||||
"./testdata/birds:/pengiuns?/pingu?",
|
||||
"./testdata/birds:/pengiuns?",
|
||||
"./testdata/birds:",
|
||||
"./testdata/Tawnee: The Game",
|
||||
}
|
||||
have := sortPaths(paths)
|
||||
if len(have) > len(want) {
|
||||
t.Fatal("Sorted list is bigger than original")
|
||||
} else if len(have) < len(want) {
|
||||
t.Fatal("Sorted list is smaller than original")
|
||||
}
|
||||
for index, path := range have {
|
||||
if index >= len(want) || path != want[index] {
|
||||
t.Fatalf(
|
||||
"Want: %s\nHave: %s\n",
|
||||
sliceToString(want),
|
||||
sliceToString(have),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue