Skip to content

Commit

Permalink
test: add tests for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Jan 30, 2024
1 parent 44a1928 commit 2f43fb5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
56 changes: 56 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package gore

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestOsAwarePathDir(t *testing.T) {
tests := []struct {
input string
expected string
}{
{input: "path/to/file", expected: "path/to"},
{input: "path/to/dir/", expected: "path/to/dir"},
{input: "<autogenerated>", expected: "<autogenerated>"},
}

for _, test := range tests {
actual := osAwarePathDir(test.input)
assert.Equal(t, test.expected, actual)
}
}

func TestOsAwarePathBase(t *testing.T) {
tests := []struct {
input string
expected string
}{
{input: "path/to/file", expected: "file"},
{input: "path/to/dir/", expected: "dir"},
{input: "<autogenerated>", expected: "<autogenerated>"},
}

for _, test := range tests {
actual := osAwarePathBase(test.input)
assert.Equal(t, test.expected, actual)
}
}

func TestOsAwarePathClean(t *testing.T) {
tests := []struct {
input string
expected string
}{
{input: "path/to/file", expected: "path/to/file"},
{input: "path/to/dir/", expected: "path/to/dir"},
{input: "<autogenerated>", expected: "<autogenerated>"},
{input: "path/./to/../file", expected: "path/file"},
}

for _, test := range tests {
actual := osAwarePathClean(test.input)
assert.Equal(t, test.expected, actual)
}
}
1 change: 0 additions & 1 deletion utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func osAwarePathDir(s string) string {
return strings.ReplaceAll(filepath.Dir(s), "\\", "/")
}
return s

}

func osAwarePathBase(s string) string {
Expand Down

0 comments on commit 2f43fb5

Please sign in to comment.