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.
5 // +build darwin,!kqueue
14 func TestSplitflags(t *testing.T) {
15 cases := [...]struct {
20 {0xD, []uint32{0x1, 0x4, 0x8}},
21 {0x0010 | 0x0040 | 0x0080 | 0x01000, []uint32{0x0010, 0x0040, 0x0080, 0x01000}},
22 {0x40000 | 0x00100 | 0x00200, []uint32{0x00100, 0x00200, 0x40000}},
24 for i, cas := range cases {
25 if flags := splitflags(cas.set); !reflect.DeepEqual(flags, cas.flags) {
26 t.Errorf("want flags=%v; got %v (i=%d)", cas.flags, flags, i)
31 func TestWatchStrip(t *testing.T) {
33 create = uint32(FSEventsCreated)
34 remove = uint32(FSEventsRemoved)
35 rename = uint32(FSEventsRenamed)
36 write = uint32(FSEventsModified)
37 inode = uint32(FSEventsInodeMetaMod)
38 owner = uint32(FSEventsChangeOwner)
40 cases := [...][]struct {
47 {"file", create | write, create | write},
48 {"file", create | write | inode, write | inode},
52 {"file", create, create},
53 {"file", create | remove, remove},
54 {"file", create | remove, create},
58 {"file", create | write, create | write},
59 {"file", create | write | owner, write | owner},
63 {"file", create | write, create | write},
64 {"file", write | inode, write | inode},
65 {"file", remove | write | inode, remove},
68 {"file", remove | write | inode, remove},
72 for i, cas := range cases {
77 w := &watch{prev: make(map[string]uint32)}
78 for j, cas := range cas {
79 if diff := w.strip(cas.path, cas.flag); diff != cas.diff {
80 t.Errorf("want diff=%v; got %v (i=%d, j=%d)", Event(cas.diff),
88 // Test for cases 3) and 5) with shadowed write&create events.
90 // See comment for (flagdiff).diff method.
91 func TestWatcherShadowedWriteCreate(t *testing.T) {
92 w := NewWatcherTest(t, "testdata/vfs.txt")
97 create(w, "src/github.com/rjeczalik/fs/.fs.go.swp"),
99 write(w, "src/github.com/rjeczalik/fs/.fs.go.swp", []byte("XD")),
101 write(w, "src/github.com/rjeczalik/fs/.fs.go.swp", []byte("XD")),
103 remove(w, "src/github.com/rjeczalik/fs/.fs.go.swp"),
105 create(w, "src/github.com/rjeczalik/fs/.fs.go.swp"),
107 write(w, "src/github.com/rjeczalik/fs/.fs.go.swp", []byte("XD")),
110 w.ExpectAny(cases[:5]) // BUG(rjeczalik): #62