git.iko.soy/typeable/pandoc
on master help sign in
Added tests for collapseFilePath
5b5e530Matthew Pickering
tests/Tests/Shared.hs+23−1
@@ -6,7 +6,7 @@ import Test.Framework
6import Tests.Helpers
6import Tests.Helpers
7import Tests.Arbitrary()
7import Tests.Arbitrary()
8import Test.Framework.Providers.HUnit
8import Test.Framework.Providers.HUnit
9−import Test.HUnit ( assertBool )
9+import Test.HUnit ( assertBool, (@?=) )
10import Text.Pandoc.Builder
10import Text.Pandoc.Builder
11import Data.Monoid
11import Data.Monoid
12
12
@@ -23,6 +23,7 @@ tests = [ testGroup "normalize"
23 (let x = [(str "word", [para (str "def"), mempty])]
23 (let x = [(str "word", [para (str "def"), mempty])]
24 in compactify'DL x == x)
24 in compactify'DL x == x)
25 ]
25 ]
26+ , testGroup "collapseFilePath" testCollapse
26 ]
27 ]
27
28
28p_normalize_blocks_rt :: [Block] -> Bool
29p_normalize_blocks_rt :: [Block] -> Bool
@@ -36,3 +37,24 @@ p_normalize_inlines_rt ils =
36p_normalize_no_trailing_spaces :: [Inline] -> Bool
37p_normalize_no_trailing_spaces :: [Inline] -> Bool
37p_normalize_no_trailing_spaces ils = null ils' || last ils' /= Space
38p_normalize_no_trailing_spaces ils = null ils' || last ils' /= Space
38 where ils' = normalizeInlines $ ils ++ [Space]
39 where ils' = normalizeInlines $ ils ++ [Space]
40+
41+testCollapse :: [Test]
42+testCollapse = map (testCase "collapse")
43+ [ (collapseFilePath "" @?= "")
44+ , (collapseFilePath "./foo" @?= "foo")
45+ , (collapseFilePath "././../foo" @?= "../foo")
46+ , (collapseFilePath "../foo" @?= "../foo")
47+ , (collapseFilePath "/bar/../baz" @?= "/baz")
48+ , (collapseFilePath "/../baz" @?= "/../baz")
49+ , (collapseFilePath "./foo/.././bar/../././baz" @?= "baz")
50+ , (collapseFilePath "./" @?= "")
51+ , (collapseFilePath "././" @?= "")
52+ , (collapseFilePath "../" @?= "..")
53+ , (collapseFilePath ".././" @?= "..")
54+ , (collapseFilePath "./../" @?= "..")
55+ , (collapseFilePath "../../" @?= "../..")
56+ , (collapseFilePath "parent/foo/baz/../bar" @?= "parent/foo/bar")
57+ , (collapseFilePath "parent/foo/baz/../../bar" @?= "parent/bar")
58+ , (collapseFilePath "parent/foo/.." @?= "parent")
59+ , (collapseFilePath "/parent/foo/../../bar" @?= "/bar")
60+ , (collapseFilePath "/./parent/foo" @?= "/parent/foo")]