1-- File created: 2009-01-24 13:02:48
2
3module Tests.Simplifier (tests) where
4
5import Test.Framework
6import Test.Framework.Providers.QuickCheck2
7import Test.QuickCheck (Property, (==>))
8
9import System.FilePath.Glob.Base (tryCompileWith)
10import System.FilePath.Glob.Match
11import System.FilePath.Glob.Simplify
12
13import Tests.Base
14
15tests :: Test
16tests = testGroup "Simplifier"
17   [ testProperty "simplify-1" prop_simplify1
18   , testProperty "simplify-2" prop_simplify2
19   ]
20
21-- Simplifying twice should give the same result as simplifying once
22prop_simplify1 :: COpts -> PString -> Property
23prop_simplify1 o s =
24   let pat = tryCompileWith (unCOpts o) (unPS s)
25       xs = iterate simplify (fromRight pat)
26    in isRight pat ==> xs !! 1 == xs !! 2
27
28-- Simplifying shouldn't affect whether a match succeeds
29prop_simplify2 :: COpts -> PString -> Path -> Property
30prop_simplify2 o p s =
31   let x   = tryCompileWith (unCOpts o) (unPS p)
32       pat = fromRight x
33       pth = unP s
34    in isRight x ==> match pat pth == match (simplify pat) pth
35