git.iko.soy/typeable/pandoc
on master help sign in
Added tests for collapseFilePath
commit5b5e53024dd9dcaae11f871404baceedc63a4f29 authorMatthew Pickering <matthewtpickering@gmail.com> dateFri 8 Aug 2014, 21:03 (12 years ago) parent2d95667
1 file changed+23−1
tests/Tests/Shared.hs+23−1
tests/Tests/Shared.hs+23−1
@@ -6,7 +6,7 @@ import Test.Framework
66import Tests.Helpers
77import Tests.Arbitrary()
88import Test.Framework.Providers.HUnit
9−import Test.HUnit ( assertBool )
9+import Test.HUnit ( assertBool, (@?=) )
1010import Text.Pandoc.Builder
1111import Data.Monoid
1212
@@ -23,6 +23,7 @@ tests = [ testGroup "normalize"
2323 (let x = [(str "word", [para (str "def"), mempty])]
2424 in compactify'DL x == x)
2525 ]
26+ , testGroup "collapseFilePath" testCollapse
2627 ]
2728
2829p_normalize_blocks_rt :: [Block] -> Bool
@@ -36,3 +37,24 @@ p_normalize_inlines_rt ils =
3637p_normalize_no_trailing_spaces :: [Inline] -> Bool
3738p_normalize_no_trailing_spaces ils = null ils' || last ils' /= Space
3839 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")]