github.com/windmilleng/wat@v0.0.2-0.20180626175338-9349b638e250/cli/wat/ignore_test.go (about) 1 package wat 2 3 import ( 4 "testing" 5 ) 6 7 func TestWatIgnoreOrDummy(t *testing.T) { 8 f := newWatFixture(t) 9 defer f.tearDown() 10 11 // Nil path --> dummy 12 ignore := watIgnoreOrDummy("") 13 if _, ok := ignore.(dummyWatIgnore); !ok { 14 f.t.Fatal("watIgnoreOrDummy called with nil path should return dummyWatIgnore") 15 } 16 17 // Path to non-existent file --> dummy 18 ignore = watIgnoreOrDummy("file/does/not/exist") 19 if _, ok := ignore.(dummyWatIgnore); !ok { 20 f.t.Fatal("watIgnoreOrDummy called with nonexistant filepath should return dummyWatIgnore") 21 } 22 23 // Real and parse-able ignore file --> real Ignore object 24 path := "myIgnore" 25 f.write(path, "foo") 26 ignore = watIgnoreOrDummy(path) 27 if _, ok := ignore.(dummyWatIgnore); ok { 28 f.t.Fatal("watIgnoreOrDummy called with valid ignorePath should NOT return dummyWatIgnore") 29 } 30 if !ignore.Match("foo", false) { 31 f.t.Fatal("this ignore should match 'foo'") 32 } 33 } 34 35 func TestMakeWatIgnoreContentsWithDefaults(t *testing.T) { 36 f := newWatFixture(t) 37 defer f.tearDown() 38 39 defaults := []string{"foo", "bar", "baz"} 40 actual, err := makeWatIgnoreContents(f.root.Path(), defaults) 41 if err != nil { 42 f.t.Fatal("makeWatIgnoreContents", err) 43 } 44 45 expected := "foo\nbar\nbaz" 46 if actual != expected { 47 f.t.Fatalf("expected watIgnore actual:\n%s\nGot:\n%s", expected, actual) 48 } 49 } 50 51 func TestMakeWatIgnoreContentsFromGitIgnore(t *testing.T) { 52 f := newWatFixture(t) 53 defer f.tearDown() 54 55 gitIgnore := "hello\nworld" 56 f.write(fnameGitIgnore, gitIgnore) 57 58 actual, err := makeWatIgnoreContents(f.root.Path(), nil) 59 if err != nil { 60 f.t.Fatal("makeWatIgnoreContents", err) 61 } 62 63 if actual != gitIgnore { 64 f.t.Fatalf("expected watIgnore actual:\n%s\nGot:\n%s", gitIgnore, actual) 65 } 66 } 67 68 func TestMakeWatIgnoreContentsDedupe(t *testing.T) { 69 f := newWatFixture(t) 70 defer f.tearDown() 71 72 defaults := []string{"foo", "bar", "baz"} 73 gitIgnore := `foo 74 hello 75 world 76 bar` 77 f.write(fnameGitIgnore, gitIgnore) 78 79 actual, err := makeWatIgnoreContents(f.root.Path(), defaults) 80 if err != nil { 81 f.t.Fatal("makeWatIgnoreContents", err) 82 } 83 84 expected := `foo 85 hello 86 world 87 bar 88 89 baz` 90 91 if actual != expected { 92 f.t.Fatalf("expected watIgnore actual:\n%s\nGot:\n%s", expected, actual) 93 } 94 95 }