12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package filterfs
- import "testing"
- import "testing/fstest"
- import "reflect"
- import "regexp"
- type Is struct{ *testing.T }
- func (is *Is) Is(test bool) {
- if !test {
- is.Fatalf("Expected true.\n")
- }
- }
- func (is *Is) Equal(expected, actual any) {
- if !reflect.DeepEqual(expected, actual) {
- is.Fatalf("Not equal: %v != %v.\n", expected, actual)
- }
- }
- func (is *Is) Nil(actual any) {
- if actual != nil {
- is.Fatalf("Expected nil: %v.\n", actual)
- }
- }
- func helperMakeFS() fstest.MapFS {
- return fstest.MapFS{
- "foo.go": {Data: []byte("1")},
- "bar/foo.go": {Data: []byte("2")},
- "foo.txt": {Data: []byte("a")},
- "bar/foo.txt": {Data: []byte("b")},
- }
- }
- func TestTest(t *testing.T) {
- is := Is{t}
- under := helperMakeFS()
- is.Nil(fstest.TestFS(under, "foo.go", "bar/foo.go"))
- }
- func TestFilesystem(t *testing.T) {
- is := Is{t}
- under := helperMakeFS()
- filtered := Apply(under, func(name string) bool {
- ok, _ := regexp.Match(".*\\.go", []byte(name))
- return ok
- })
- is.Nil(fstest.TestFS(filtered, "foo.go", "bar/foo.go"))
- }
|