Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / godoc / vfs / mapfs / mapfs_test.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/godoc/vfs/mapfs/mapfs_test.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/godoc/vfs/mapfs/mapfs_test.go
new file mode 100644 (file)
index 0000000..6b7db29
--- /dev/null
@@ -0,0 +1,111 @@
+// Copyright 2013 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 mapfs
+
+import (
+       "io/ioutil"
+       "os"
+       "reflect"
+       "testing"
+)
+
+func TestOpenRoot(t *testing.T) {
+       fs := New(map[string]string{
+               "foo/bar/three.txt": "a",
+               "foo/bar.txt":       "b",
+               "top.txt":           "c",
+               "other-top.txt":     "d",
+       })
+       tests := []struct {
+               path string
+               want string
+       }{
+               {"/foo/bar/three.txt", "a"},
+               {"foo/bar/three.txt", "a"},
+               {"foo/bar.txt", "b"},
+               {"top.txt", "c"},
+               {"/top.txt", "c"},
+               {"other-top.txt", "d"},
+               {"/other-top.txt", "d"},
+       }
+       for _, tt := range tests {
+               rsc, err := fs.Open(tt.path)
+               if err != nil {
+                       t.Errorf("Open(%q) = %v", tt.path, err)
+                       continue
+               }
+               slurp, err := ioutil.ReadAll(rsc)
+               if err != nil {
+                       t.Error(err)
+               }
+               if string(slurp) != tt.want {
+                       t.Errorf("Read(%q) = %q; want %q", tt.path, tt.want, slurp)
+               }
+               rsc.Close()
+       }
+
+       _, err := fs.Open("/xxxx")
+       if !os.IsNotExist(err) {
+               t.Errorf("ReadDir /xxxx = %v; want os.IsNotExist error", err)
+       }
+}
+
+func TestReaddir(t *testing.T) {
+       fs := New(map[string]string{
+               "foo/bar/three.txt": "333",
+               "foo/bar.txt":       "22",
+               "top.txt":           "top.txt file",
+               "other-top.txt":     "other-top.txt file",
+       })
+       tests := []struct {
+               dir  string
+               want []os.FileInfo
+       }{
+               {
+                       dir: "/",
+                       want: []os.FileInfo{
+                               mapFI{name: "foo", dir: true},
+                               mapFI{name: "other-top.txt", size: len("other-top.txt file")},
+                               mapFI{name: "top.txt", size: len("top.txt file")},
+                       },
+               },
+               {
+                       dir: "/foo",
+                       want: []os.FileInfo{
+                               mapFI{name: "bar", dir: true},
+                               mapFI{name: "bar.txt", size: 2},
+                       },
+               },
+               {
+                       dir: "/foo/",
+                       want: []os.FileInfo{
+                               mapFI{name: "bar", dir: true},
+                               mapFI{name: "bar.txt", size: 2},
+                       },
+               },
+               {
+                       dir: "/foo/bar",
+                       want: []os.FileInfo{
+                               mapFI{name: "three.txt", size: 3},
+                       },
+               },
+       }
+       for _, tt := range tests {
+               fis, err := fs.ReadDir(tt.dir)
+               if err != nil {
+                       t.Errorf("ReadDir(%q) = %v", tt.dir, err)
+                       continue
+               }
+               if !reflect.DeepEqual(fis, tt.want) {
+                       t.Errorf("ReadDir(%q) = %#v; want %#v", tt.dir, fis, tt.want)
+                       continue
+               }
+       }
+
+       _, err := fs.ReadDir("/xxxx")
+       if !os.IsNotExist(err) {
+               t.Errorf("ReadDir /xxxx = %v; want os.IsNotExist error", err)
+       }
+}