GoPLS Viewer

Home|gopls/godoc/vfs/mapfs/mapfs_test.go
1// Copyright 2013 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package mapfs
6
7import (
8    "io/ioutil"
9    "os"
10    "reflect"
11    "testing"
12)
13
14func TestOpenRoot(t *testing.T) {
15    fs := New(map[string]string{
16        "foo/bar/three.txt""a",
17        "foo/bar.txt":       "b",
18        "top.txt":           "c",
19        "other-top.txt":     "d",
20    })
21    tests := []struct {
22        path string
23        want string
24    }{
25        {"/foo/bar/three.txt""a"},
26        {"foo/bar/three.txt""a"},
27        {"foo/bar.txt""b"},
28        {"top.txt""c"},
29        {"/top.txt""c"},
30        {"other-top.txt""d"},
31        {"/other-top.txt""d"},
32    }
33    for _tt := range tests {
34        rscerr := fs.Open(tt.path)
35        if err != nil {
36            t.Errorf("Open(%q) = %v"tt.patherr)
37            continue
38        }
39        slurperr := ioutil.ReadAll(rsc)
40        if err != nil {
41            t.Error(err)
42        }
43        if string(slurp) != tt.want {
44            t.Errorf("Read(%q) = %q; want %q"tt.pathtt.wantslurp)
45        }
46        rsc.Close()
47    }
48
49    _err := fs.Open("/xxxx")
50    if !os.IsNotExist(err) {
51        t.Errorf("ReadDir /xxxx = %v; want os.IsNotExist error"err)
52    }
53}
54
55func TestReaddir(t *testing.T) {
56    fs := New(map[string]string{
57        "foo/bar/three.txt""333",
58        "foo/bar.txt":       "22",
59        "top.txt":           "top.txt file",
60        "other-top.txt":     "other-top.txt file",
61    })
62    tests := []struct {
63        dir  string
64        want []os.FileInfo
65    }{
66        {
67            dir"/",
68            want: []os.FileInfo{
69                mapFI{name"foo"dirtrue},
70                mapFI{name"other-top.txt"sizelen("other-top.txt file")},
71                mapFI{name"top.txt"sizelen("top.txt file")},
72            },
73        },
74        {
75            dir"/foo",
76            want: []os.FileInfo{
77                mapFI{name"bar"dirtrue},
78                mapFI{name"bar.txt"size2},
79            },
80        },
81        {
82            dir"/foo/",
83            want: []os.FileInfo{
84                mapFI{name"bar"dirtrue},
85                mapFI{name"bar.txt"size2},
86            },
87        },
88        {
89            dir"/foo/bar",
90            want: []os.FileInfo{
91                mapFI{name"three.txt"size3},
92            },
93        },
94    }
95    for _tt := range tests {
96        fiserr := fs.ReadDir(tt.dir)
97        if err != nil {
98            t.Errorf("ReadDir(%q) = %v"tt.direrr)
99            continue
100        }
101        if !reflect.DeepEqual(fistt.want) {
102            t.Errorf("ReadDir(%q) = %#v; want %#v"tt.dirfistt.want)
103            continue
104        }
105    }
106
107    _err := fs.ReadDir("/xxxx")
108    if !os.IsNotExist(err) {
109        t.Errorf("ReadDir /xxxx = %v; want os.IsNotExist error"err)
110    }
111}
112
MembersX
TestOpenRoot.RangeStmt_645.BlockStmt.rsc
TestOpenRoot.err
TestReaddir
TestReaddir.fs
TestReaddir.RangeStmt_1931.BlockStmt.fis
ioutil
TestOpenRoot
TestOpenRoot.fs
TestReaddir._
TestReaddir.RangeStmt_1931.tt
TestOpenRoot.t
TestOpenRoot.RangeStmt_645.BlockStmt.slurp
TestReaddir.t
TestOpenRoot.RangeStmt_645.BlockStmt.err
TestReaddir.tests
TestReaddir.err
reflect
TestOpenRoot.tests
TestOpenRoot.RangeStmt_645.tt
testing
TestOpenRoot._
TestReaddir.RangeStmt_1931.BlockStmt.err
Members
X