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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
-- File created: 2008-10-15 20:21:41
module Tests.Regression (tests) where
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit.Base hiding (Test)
import System.FilePath.Glob.Base
import System.FilePath.Glob.Match
tests :: Test
tests = testGroup "Regression"
[ testGroup "Matching/compiling" .
flip map matchCases $ \t@(b,p,s) ->
tc (nameMatchTest t) $
match (compile p) s == b
, testGroup "Specific options" .
flip map matchWithCases $ \(b,co,mo,p,s) ->
tc (nameMatchTest (b,p,s)) $
matchWith mo (compileWith co p) s == b
, testGroup "Decompilation" .
flip map decompileCases $ \(n,orig,s) ->
tc n $ decompile (compile orig) == s
]
where
tc n = testCase n . assert
nameMatchTest :: (Bool, String, FilePath) -> String
nameMatchTest (True ,p,s) = show p ++ " matches " ++ show s
nameMatchTest (False,p,s) = show p ++ " doesn't match " ++ show s
decompileCases :: [(String, String, String)]
decompileCases =
[ ("range-compression-1", "[*]", "[*]")
, ("range-compression-2", "[.]", "[.]")
, ("range-compression-3", "**[/]", "[.]")
, ("range-compression-4", "x[.]", "x.")
, ("range-compression-5", "[^~-]", "[^~-]")
, ("range-compression-6", "[^!-]", "[^!-]")
, ("range-compression-7", "/[a.]", "/a")
, ("range-compression-8", "/[.!^]", "/[/^!]")
, ("range-compression-9", "[/!^]", "[/^!]")
, ("num-compression-1", "<->[0-9]<->", "[0-9][0-9]<->")
]
matchCases :: [(Bool, String, String)]
matchCases =
[ (True , "*" , "")
, (True , "**" , "")
, (True , "asdf" , "asdf")
, (True , "a*f" , "asdf")
, (True , "a??f" , "asdf")
, (True , "*" , "asdf")
, (True , "a*bc" , "aXbaXbc")
, (True , "a**bc" , "aXbaXbc")
, (False, "a*b" , "aXc")
, (True , "foo/bar.*" , "foo/bar.baz")
, (True , "foo/*.baz" , "foo/bar.baz")
, (False, "*bar.*" , "foo/bar.baz")
, (False, "*.baz" , "foo/bar.baz")
, (False, "foo*" , "foo/bar.baz")
, (False, "foo?bar.baz", "foo/bar.baz")
, (True , "**/*.baz" , "foo/bar.baz")
, (True , "**/*" , "foo/bar.baz")
, (True , "**/*" , "foo/bar/baz")
, (True , "*/*.baz" , "foo/bar.baz")
, (True , "*/*" , "foo/bar.baz")
, (False, "*/*" , "foo/bar/baz")
, (False, "*.foo" , ".bar.foo")
, (False, "*.bar.foo" , ".bar.foo")
, (False, "?bar.foo" , ".bar.foo")
, (True , ".*.foo" , ".bar.foo")
, (True , ".*bar.foo" , ".bar.foo")
, (False, "foo.[ch]" , "foo.a")
, (True , "foo.[ch]" , "foo.c")
, (True , "foo.[ch]" , "foo.h")
, (False, "foo.[ch]" , "foo.d")
, (False, "foo.[c-h]" , "foo.b")
, (True , "foo.[c-h]" , "foo.c")
, (True , "foo.[c-h]" , "foo.e")
, (True , "foo.[c-h]" , "foo.f")
, (True , "foo.[c-h]" , "foo.h")
, (False, "foo.[c-h]" , "foo.i")
, (True , "<->3foo" , "123foo")
, (True , "<10-15>3foo", "123foo")
, (True , "<0-5>23foo" , "123foo")
, (True , "<94-200>foo", "123foo")
, (False, "[.]x" , ".x")
, (False, "foo[/]bar" , "foo/bar")
, (False, "foo[,-0]bar", "foo/bar")
, (True , "foo[,-0]bar", "foo.bar")
, (True , "[]x]" , "]")
, (True , "[]x]" , "x")
, (False, "[b-a]" , "a")
, (False, "<4-3>" , "3")
, (True, "<0-1>" , "00")
, (True, "<0-1>" , "01")
, (True, "<1-1>" , "01")
, (True , "[]-b]" , "]")
, (False, "[]-b]" , "-")
, (True , "[]-b]" , "b")
, (True , "[]-b]" , "a")
, (True , "[]-]" , "]")
, (True , "[]-]" , "-")
, (True , "[#-[]" , "&")
, (False, "[^x]" , "/")
, (False, "[/]" , "/")
, (True , "a[^x]" , "a.")
, (True , "a[.]" , "a.")
, (False, ".//a" , "/a")
, (True, ".//a" , "a")
, (True, ".//a" , "./a")
, (True , ".*/a" , "./a")
, (True , ".*/a" , "../a")
, (True , ".*/a" , ".foo/a")
, (True , ".**/a" , ".foo/a")
, (False, ".**/a" , "../a")
, (False, ".**/a" , "./a")
, (False, ".**/a" , "a")
, (True , ".**/a" , ".foo/a")
, (True , "f**/a" , "foo/a")
, (True , "f**/" , "f/")
, (True , "f**/" , "f///")
, (True , "f**/x" , "f///x")
, (True , "f/" , "f///")
, (True , "f/x" , "f///x")
, (True , "[]" , "[]")
, (True , "[!]" , "[!]")
, (True , "[^]" , "[^]")
, (True , "[abc" , "[abc")
, (True , "<abc" , "<abc")
, (True , "<1-" , "<1-")
, (True , "[^-~]" , "x")
, (False, "[^-~]" , "X")
, (False, "[^^-~]" , "x")
, (False, "[^-]" , "-")
, (True, "//" , "//")
, (True, ".//" , ".//")
, (True, "?" , ".//a")
, (False, "<-><->" , "1")
, (True, "<0-0><1-1>" , "01")
, (True, "<0-1><0-1>" , "00")
, (False, "a/**/d" , "a/.b/c/d")
, (False, "a/**/d" , "a/b/.c/d")
, (True, "a/**/.d" , "a/b/c/.d")
, (True, "a/**/.c/d" , "a/b/.c/d")
, (True, "a/**/.c/.d" , "a/b/.c/.d")
, (True, "a/**/.d/.e" , "a/b/c/.d/.e")
]
matchWithCases :: [(Bool, CompOptions, MatchOptions, String, String)]
matchWithCases =
[ (True , compDefault, matchDefault { ignoreCase = True }, "[@-[]", "a")
, (True , compPosix , matchDefault , "a[/]b", "a[/]b")
]
|