2020-07-27 14:09:22 +03:00
|
|
|
module StrongPathTest where
|
|
|
|
|
|
|
|
import Test.Tasty.Hspec
|
|
|
|
|
|
|
|
import qualified Path as P
|
2020-07-28 17:52:03 +03:00
|
|
|
import StrongPath (Path, Abs, Rel, Dir, File, (</>))
|
|
|
|
import qualified StrongPath as SP
|
2020-07-27 14:09:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
data Bar
|
|
|
|
data Fizz
|
|
|
|
|
|
|
|
spec_StrongPath :: Spec
|
|
|
|
spec_StrongPath = do
|
|
|
|
describe "Example with Foo file and Bar, Fizz and Kokolo dirs" $ do
|
2020-07-28 17:52:03 +03:00
|
|
|
let fooFileInBarDir = (SP.fromPathRelFile [P.relfile|foo.txt|]) :: Path (Rel Bar) File
|
|
|
|
let barDirInFizzDir = (SP.fromPathRelDir [P.reldir|kokolo/bar|]) :: Path (Rel Fizz) (Dir Bar)
|
|
|
|
let fizzDir = (SP.fromPathAbsDir [P.absdir|/fizz|]) :: Path Abs (Dir Fizz)
|
2020-07-27 14:09:22 +03:00
|
|
|
let fooFile = (fizzDir </> barDirInFizzDir </> fooFileInBarDir) :: Path Abs File
|
2020-07-28 17:52:03 +03:00
|
|
|
let fooFileInFizzDir = (barDirInFizzDir </> fooFileInBarDir) :: Path (Rel Fizz) File
|
2020-07-27 14:09:22 +03:00
|
|
|
|
|
|
|
it "Paths are correctly concatenated" $ do
|
2020-07-28 17:52:03 +03:00
|
|
|
(P.toFilePath $ SP.toPathAbsFile fooFile) `shouldBe` "/fizz/kokolo/bar/foo.txt"
|
|
|
|
(P.toFilePath $ SP.toPathRelFile fooFileInFizzDir) `shouldBe` "kokolo/bar/foo.txt"
|
2020-07-27 14:09:22 +03:00
|
|
|
|
|
|
|
it "Paths are unchanged when packed and unpacked" $ do
|
2020-07-28 17:52:03 +03:00
|
|
|
(P.toFilePath $ SP.toPathRelFile $ SP.fromPathRelFile [P.relfile|some/file.txt|]) `shouldBe` "some/file.txt"
|
|
|
|
(P.toFilePath $ SP.toPathRelDir $ SP.fromPathRelDir [P.reldir|some/dir/|]) `shouldBe` "some/dir/"
|
|
|
|
(P.toFilePath $ SP.toPathAbsFile $ SP.fromPathAbsFile [P.absfile|/some/file.txt|]) `shouldBe` "/some/file.txt"
|
|
|
|
(P.toFilePath $ SP.toPathAbsDir $ SP.fromPathAbsDir [P.absdir|/some/dir/|]) `shouldBe` "/some/dir/"
|