1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
-- File created: 2008-10-11 11:18:31
module Tests.Optimizer (tests) where
import Test.Framework
import Test.Framework.Providers.QuickCheck
import System.FilePath.Glob.Base (tokenize, optimize)
import System.FilePath.Glob.Match
import Tests.Base
tests = testGroup "Optimizer"
[ testProperty "optimize-1" prop_optimize1
, testProperty "optimize-2" prop_optimize2
]
-- Optimizing twice should give the same result as optimizing once
prop_optimize1 o s =
let pat = tokenize (unCOpts o) (unPS s)
xs = iterate optimize (fromRight pat)
in isRight pat && xs !! 1 == xs !! 2
-- Optimizing shouldn't affect whether a match succeeds
prop_optimize2 o p s =
let x = tokenize (unCOpts o) (unPS p)
pat = fromRight x
pth = unP s
in isRight x && match pat pth == match (optimize pat) pth
|