From f517f61c55312700b125c12c0b269eef48cb03b7 Mon Sep 17 00:00:00 2001 From: Thomas Lindop Date: Sat, 17 May 2025 15:44:39 +0100 Subject: [PATCH] >> add tests for new sortPaths function > add slices formatter --- owl_test.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/owl_test.go b/owl_test.go index f67795d..0c1e20d 100644 --- a/owl_test.go +++ b/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), + ) + } + } +}