mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
43 lines
681 B
Go
43 lines
681 B
Go
package util
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
var claimFileTests = []struct {
|
|
pattern string
|
|
wantFileName string
|
|
}{
|
|
{"a*.log", "a9.log"},
|
|
{"*.txt", "1.txt"},
|
|
}
|
|
|
|
func TestClaimFile(t *testing.T) {
|
|
_, cleanup := InTestDir()
|
|
defer cleanup()
|
|
|
|
touch("a0.log")
|
|
touch("a1.log")
|
|
touch("a8.log")
|
|
|
|
for _, test := range claimFileTests {
|
|
f, err := ClaimFile(".", test.pattern)
|
|
defer f.Close()
|
|
if err != nil {
|
|
t.Errorf("ClaimFile errors: %v", err)
|
|
}
|
|
if f.Name() != test.wantFileName {
|
|
t.Errorf("ClaimFile claims %s, want %s", f.Name(), test.wantFileName)
|
|
}
|
|
}
|
|
}
|
|
|
|
func touch(fname string) {
|
|
f, err := os.Create(fname)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
f.Close()
|
|
}
|