Commits

Stefan Saasen committed 6701d69

Add a few more tests for skipEvents and hidden path detection

Comments (0)

Files changed (1)

   "Skip path if hidden directory and showing hidden files is not enabled"
   (skipEvent (mockWatch {hidden = False}) "/a/b/.git/refs")
 
+test_dontSkipEventOnMatchingGlob = H.assertBool
+  "Don't skip path if the glob matches"
+  (not $ skipEvent (mockWatch {glob = Just "*.hs"}) "/a/b/Main.hs")
+
+test_skipEventOnMatchingGlob = H.assertBool
+  "Skip path if the glob pattern doesn't match the file path"
+  (skipEvent (mockWatch {glob = Just "*.hs"}) "/a/b/Main.sh")
+
 test_containsHiddenPathElement = H.assertBool
   "Should identify hidden directory"
   (containsHiddenPathElement "/a/b/.git/info/exclude")
 
+test_containsHiddenPathElementFirst = H.assertBool
+  "Should identify hidden directory"
+  (containsHiddenPathElement ".git/info/exclude")
+
+test_containsNoHiddenPathElement = H.assertBool
+  "Should not identify hidden directory"
+  (not $ containsHiddenPathElement "info/exclude")
+
 -- ===========================================================
 mockWatch :: Spy
-mockWatch = Watch { dir = ".", glob = Nothing, format = Nothing, hidden = False }
+mockWatch = Watch { dir = "foo/bar", glob = Nothing, format = Nothing, hidden = False }
 
 -- ===========================================================
 -- Test harness
       testGroup "Watcher opts"
       [
         testCase "watcher/optHidden" test_skipEventHidden,
-        testCase "watcher/containsHiddenPathElement" test_containsHiddenPathElement
+        testCase "watcher/dontSkipEventOnMatchingGlob" test_dontSkipEventOnMatchingGlob,
+        testCase "watcher/skipEventOnMatchingGlob" test_skipEventOnMatchingGlob,
+        testCase "watcher/containsHiddenPathElement" test_containsHiddenPathElement,
+        testCase "watcher/containsHiddenPathElementFirst" test_containsHiddenPathElementFirst,
+        testCase "watcher/containsNoHiddenPathElement" test_containsNoHiddenPathElement
       ]
     ]