-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#197] Some path canonicalization tests
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io> | ||
- | ||
- SPDX-License-Identifier: MPL-2.0 | ||
-} | ||
|
||
module Test.Xrefcheck.CanonicalPathSpec where | ||
|
||
import Universum | ||
|
||
import System.Directory (getCurrentDirectory) | ||
import Test.Tasty (TestTree, testGroup) | ||
import Test.Tasty.HUnit (testCase, (@?=)) | ||
|
||
import Xrefcheck.System | ||
|
||
test_canonicalPath :: TestTree | ||
test_canonicalPath = testGroup "Path canonicalization" | ||
[ testCase "Trailing separator" $ do | ||
path <- canonicalizePath "./example/dir/" | ||
current <- getCurrentDirectory >>= canonicalizePath | ||
getRelativeOrAbsoluteChild current path @?= "example/dir", | ||
testCase "Parent directory indirection" $ do | ||
path <- canonicalizePath "dir1/../dir2" | ||
current <- getCurrentDirectory >>= canonicalizePath | ||
getRelativeOrAbsoluteChild current path @?= "dir2", | ||
testCase "Through parent directory indirection" $ do | ||
path <- canonicalizePath "dir1/../../../dir2" | ||
current <- getCurrentDirectory >>= canonicalizePath | ||
root <- current </ "../.." | ||
getRelativeOrAbsoluteChild root path @?= "dir2", | ||
testCase "Current directory indirection" $ do | ||
path <- canonicalizePath "././dir1/./././dir2/././" | ||
current <- getCurrentDirectory >>= canonicalizePath | ||
getRelativeOrAbsoluteChild current path @?= "dir1/dir2", | ||
testCase "Mixed indirections result in current directory" $ do | ||
path <- canonicalizePath "././dir1/./.././dir2/./../" | ||
current <- getCurrentDirectory >>= canonicalizePath | ||
getRelativeOrAbsoluteChild current path @?= "./", | ||
testCase "Child directory" $ do | ||
path <- canonicalizePath "./dir1/dir2/" | ||
current <- getCurrentDirectory >>= canonicalizePath | ||
getRelativeChild current path @?= Just "dir1/dir2", | ||
testCase "Not a child directory" $ do | ||
root <- canonicalizePath "./dir1/dir2/" | ||
path <- canonicalizePath "./dir1/dir3/" | ||
getRelativeChild root path @?= Nothing | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters