gcc/libgo/go/testing/fstest/mapfs_test.go
Ian Lance Taylor 8dc2499aa6 libgo: update to Go1.18beta2
gotools/
	* Makefile.am (go_cmd_cgo_files): Add ast_go118.go
	(check-go-tool): Copy golang.org/x/tools directories.
	* Makefile.in: Regenerate.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384695
2022-02-11 15:01:19 -08:00

47 lines
1 KiB
Go

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fstest
import (
"fmt"
"io/fs"
"strings"
"testing"
)
func TestMapFS(t *testing.T) {
m := MapFS{
"hello": {Data: []byte("hello, world\n")},
"fortune/k/ken.txt": {Data: []byte("If a program is too slow, it must have a loop.\n")},
}
if err := TestFS(m, "hello", "fortune/k/ken.txt"); err != nil {
t.Fatal(err)
}
}
func TestMapFSChmodDot(t *testing.T) {
m := MapFS{
"a/b.txt": &MapFile{Mode: 0666},
".": &MapFile{Mode: 0777 | fs.ModeDir},
}
buf := new(strings.Builder)
fs.WalkDir(m, ".", func(path string, d fs.DirEntry, err error) error {
fi, err := d.Info()
if err != nil {
return err
}
fmt.Fprintf(buf, "%s: %v\n", path, fi.Mode())
return nil
})
want := `
.: drwxrwxrwx
a: d---------
a/b.txt: -rw-rw-rw-
`[1:]
got := buf.String()
if want != got {
t.Errorf("MapFS modes want:\n%s\ngot:\n%s\n", want, got)
}
}