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