champagne illinois

This commit is contained in:
Mark Bates 2019-09-01 13:21:34 -04:00
parent f05a546d9e
commit 9666017c2c
4 changed files with 61 additions and 14 deletions

View File

@ -2,7 +2,6 @@ package fstest
import ( import (
"path" "path"
"strings"
"github.com/markbates/pkger/fs" "github.com/markbates/pkger/fs"
) )
@ -23,14 +22,13 @@ func Files(fx fs.FileSystem) (TestFiles, error) {
return tf, nil return tf, nil
} }
func Path(fx fs.FileSystem, ps ...string) (fs.Path, error) { func Path(fx fs.FileSystem, p string) (fs.Path, error) {
name := path.Join(ps...) pt, err := fx.Parse(p)
name = path.Join(".fstest", name) if err != nil {
if !strings.HasPrefix(name, "/") { return pt, err
name = "/" + name
} }
pt.Name = path.Join("/.fstest", pt.Name)
return fx.Parse(name) return pt, nil
} }
var fileList = []string{ var fileList = []string{

View File

@ -63,7 +63,7 @@ func (s *FileSystem) sub(t *testing.T, m reflect.Method) {
} }
func (s *FileSystem) Clean() error { func (s *FileSystem) Clean() error {
pt, err := Path(s) pt, err := Path(s, "/")
if err != nil { if err != nil {
return err return err
} }
@ -81,7 +81,7 @@ func (s *FileSystem) Clean() error {
func (s *FileSystem) Test_Create(t *testing.T) { func (s *FileSystem) Test_Create(t *testing.T) {
r := require.New(t) r := require.New(t)
pt, err := Path(s, "i", "want", "candy.song") pt, err := Path(s, "i/want/candy.song")
r.NoError(err) r.NoError(err)
f, err := s.Create(pt.Name) f, err := s.Create(pt.Name)
@ -139,6 +139,10 @@ func (s *FileSystem) Test_Parse(t *testing.T) {
{in: ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}}, {in: ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ip + ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}}, {in: ip + ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ip, exp: fs.Path{Pkg: ip, Name: "/"}}, {in: ip, exp: fs.Path{Pkg: ip, Name: "/"}},
{in: ":", exp: fs.Path{Pkg: ip, Name: "/"}},
{in: "github.com/old/97s:/foo.go", exp: fs.Path{Pkg: "github.com/old/97s", Name: "/foo.go"}},
{in: "github.com/old/97s", exp: fs.Path{Pkg: "github.com/old/97s", Name: "/"}},
{in: "github.com/old/97s:", exp: fs.Path{Pkg: "github.com/old/97s", Name: "/"}},
} }
for _, tt := range table { for _, tt := range table {
@ -157,7 +161,50 @@ func (s *FileSystem) Test_ReadFile(t *testing.T) {
} }
func (s *FileSystem) Test_Stat(t *testing.T) { func (s *FileSystem) Test_Stat(t *testing.T) {
panic("not implemented") r := require.New(t)
cur, err := s.Current()
r.NoError(err)
ip := cur.ImportPath
table := []struct {
in string
err bool
}{
{in: "/foo.go", err: false},
{in: ":/foo.go", err: false},
{in: ip + ":/foo.go", err: false},
{in: ip, err: false},
{in: "/no.go", err: true},
}
for _, tt := range table {
t.Run(tt.in, func(st *testing.T) {
r := require.New(st)
if tt.err {
_, err := s.Stat(tt.in)
r.Error(err)
return
}
pt, err := Path(s, tt.in)
fmt.Println(">>>TODO fs/fstest/suite.go:189: tt.in ", tt.in)
fmt.Println(">>>TODO fs/fstest/suite.go:189: pt ", pt)
r.NoError(err)
// r.Fail(pt.String())
// f, err := s.Create(tt.in)
// r.NoError(err)
// _, err = io.Copy(f, strings.NewReader("!"+pt.String()))
// r.NoError(err)
// r.NoError(f.Close())
info, err := s.Stat(tt.in)
r.NoError(err)
r.Equal(pt.Name, info.Name())
})
}
} }
func (s *FileSystem) Test_Walk(t *testing.T) { func (s *FileSystem) Test_Walk(t *testing.T) {

View File

@ -14,5 +14,5 @@ func (fx *FS) Stat(name string) (os.FileInfo, error) {
if ok { if ok {
return f.Stat() return f.Stat()
} }
return nil, fmt.Errorf("could not stat %s", name) return nil, fmt.Errorf("could not stat %s", pt)
} }

View File

@ -130,12 +130,14 @@ func (m *Paths) Keys() []string {
func (m *Paths) Parse(p string) (fs.Path, error) { func (m *Paths) Parse(p string) (fs.Path, error) {
p = strings.Replace(p, "\\", "/", -1) p = strings.Replace(p, "\\", "/", -1)
p = strings.TrimSpace(p)
pt, ok := m.Load(p) pt, ok := m.Load(p)
if ok { if ok {
return pt, nil return pt, nil
} }
if len(p) == 0 { if len(p) == 0 || p == ":" {
return m.build(p, "", "") return m.build("", "", "")
} }
res := pathrx.FindAllStringSubmatch(p, -1) res := pathrx.FindAllStringSubmatch(p, -1)