1 // Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
12 type caseCanonical struct {
17 func testCanonical(t *testing.T, cases []caseCanonical) {
18 for i, cas := range cases {
19 full, err := canonical(cas.path)
21 t.Errorf("want err=nil; got %v (i=%d)", err, i)
25 t.Errorf("want full=%q; got %q (i=%d)", cas.full, full, i)
31 func TestCanonicalNoSymlink(t *testing.T) {
32 td := filepath.Join(wd, "testdata")
33 cases := [...]caseCanonical{
36 {filepath.Join("testdata", ".."), wd},
38 testCanonical(t, cases[:])
41 func TestJoinevents(t *testing.T) {
42 cases := [...]struct {
48 2: {[]Event{Create}, Create},
49 3: {[]Event{Rename}, Rename},
50 4: {[]Event{Create, Write, Remove}, Create | Write | Remove},
52 for i, cas := range cases {
53 if ev := joinevents(cas.evs); ev != cas.ev {
54 t.Errorf("want event=%v; got %v (i=%d)", cas.ev, ev, i)
59 func TestTreeSplit(t *testing.T) {
60 cases := [...]struct {
65 {"/github.com/rjeczalik/fakerpc", "/github.com/rjeczalik", "fakerpc"},
66 {"/home/rjeczalik/src", "/home/rjeczalik", "src"},
67 {"/Users/pknap/porn/gopher.avi", "/Users/pknap/porn", "gopher.avi"},
68 {"C:/Documents and Users", "C:", "Documents and Users"},
69 {"C:/Documents and Users/pblaszczyk/wiertarka.exe", "C:/Documents and Users/pblaszczyk", "wiertarka.exe"},
70 {"/home/(╯°□°)╯︵ ┻━┻", "/home", "(╯°□°)╯︵ ┻━┻"},
72 for i, cas := range cases {
73 dir, base := split(filepath.FromSlash(cas.path))
74 if want := filepath.FromSlash(cas.dir); dir != want {
75 t.Errorf("want dir=%s; got %s (i=%d)", want, dir, i)
77 if want := filepath.FromSlash(cas.base); base != want {
78 t.Errorf("want base=%s; got %s (i=%d)", want, base, i)
83 func TestTreeBase(t *testing.T) {
84 cases := [...]struct {
88 {"/github.com/rjeczalik/fakerpc", "fakerpc"},
89 {"/home/rjeczalik/src", "src"},
90 {"/Users/pknap/porn/gopher.avi", "gopher.avi"},
91 {"C:/Documents and Users", "Documents and Users"},
92 {"C:/Documents and Users/pblaszczyk/wiertarka.exe", "wiertarka.exe"},
93 {"/home/(╯°□°)╯︵ ┻━┻", "(╯°□°)╯︵ ┻━┻"},
95 for i, cas := range cases {
96 if base := base(filepath.FromSlash(cas.path)); base != cas.base {
97 t.Errorf("want base=%s; got %s (i=%d)", cas.base, base, i)
102 func TestTreeIndexSep(t *testing.T) {
103 cases := [...]struct {
107 {"github.com/rjeczalik/fakerpc", 10},
108 {"home/rjeczalik/src", 4},
109 {"Users/pknap/porn/gopher.avi", 5},
110 {"C:/Documents and Users", 2},
111 {"Documents and Users/pblaszczyk/wiertarka.exe", 19},
112 {"(╯°□°)╯︵ ┻━┻/Downloads", 30},
114 for i, cas := range cases {
115 if n := indexSep(filepath.FromSlash(cas.path)); n != cas.n {
116 t.Errorf("want n=%d; got %d (i=%d)", cas.n, n, i)
121 func TestTreeLastIndexSep(t *testing.T) {
122 cases := [...]struct {
126 {"github.com/rjeczalik/fakerpc", 20},
127 {"home/rjeczalik/src", 14},
128 {"Users/pknap/porn/gopher.avi", 16},
129 {"C:/Documents and Users", 2},
130 {"Documents and Users/pblaszczyk/wiertarka.exe", 30},
131 {"/home/(╯°□°)╯︵ ┻━┻", 5},
133 for i, cas := range cases {
134 if n := lastIndexSep(filepath.FromSlash(cas.path)); n != cas.n {
135 t.Errorf("want n=%d; got %d (i=%d)", cas.n, n, i)
140 func TestCleanpath(t *testing.T) {
141 t.Skip("TODO(rjeczalik)")