File: Simplifier.hs

package info (click to toggle)
haskell-glob 0.10.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: haskell: 1,583; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
-- File created: 2009-01-24 13:02:48

module Tests.Simplifier (tests) where

import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.QuickCheck (Property, (==>))

import System.FilePath.Glob.Base (tryCompileWith)
import System.FilePath.Glob.Match
import System.FilePath.Glob.Simplify

import Tests.Base

tests :: Test
tests = testGroup "Simplifier"
   [ testProperty "simplify-1" prop_simplify1
   , testProperty "simplify-2" prop_simplify2
   ]

-- Simplifying twice should give the same result as simplifying once
prop_simplify1 :: COpts -> PString -> Property
prop_simplify1 o s =
   let pat = tryCompileWith (unCOpts o) (unPS s)
       xs = iterate simplify (fromRight pat)
    in isRight pat ==> xs !! 1 == xs !! 2

-- Simplifying shouldn't affect whether a match succeeds
prop_simplify2 :: COpts -> PString -> Path -> Property
prop_simplify2 o p s =
   let x   = tryCompileWith (unCOpts o) (unPS p)
       pat = fromRight x
       pth = unP s
    in isRight x ==> match pat pth == match (simplify pat) pth