1-- File created: 2009-01-30 13:26:51 2 3module Tests.Compiler (tests) where 4 5import Test.Framework 6import Test.Framework.Providers.QuickCheck2 7import Test.QuickCheck (Property, (==>)) 8 9import System.FilePath.Glob.Base 10 (CompOptions(..), compDefault, compile, decompile, isLiteral, tryCompileWith) 11 12import Tests.Base 13 14tests :: Test 15tests = testGroup "Compiler" 16 [ testProperty "compile-decompile-1" prop_compileDecompile1 17 , testProperty "isliteral" prop_isLiteral 18 ] 19 20-- compile . decompile should be the identity function 21prop_compileDecompile1 :: COpts -> PString -> Property 22prop_compileDecompile1 o s = 23 let opt = unCOpts o 24 epat1 = tryCompileWith opt (unPS s) 25 pat1 = fromRight epat1 26 pat2 = compile . decompile $ pat1 27 in isRight epat1 ==> pat1 == pat2 28 29prop_isLiteral :: PString -> Property 30prop_isLiteral p = 31 let epat = tryCompileWith noWildcardOptions (unPS p) 32 pat = fromRight epat 33 in isRight epat ==> (isLiteral . compile . decompile) pat 34 where 35 noWildcardOptions = compDefault 36 { characterClasses = False 37 , characterRanges = False 38 , numberRanges = False 39 , wildcards = False 40 , recursiveWildcards = False 41 } 42