@@ -5,7 +5,8 @@ import Control.Monad.Eff (Eff)
5
5
import Control.Monad.Eff.Console (CONSOLE , info , infoShow )
6
6
import Data.Foldable (foldl )
7
7
import Data.Maybe (Maybe (..), fromJust )
8
- import Data.Path.Pathy (Path , Abs , Rel , Dir , File , Sandboxed , dir , rootDir , parseAbsDir , parseRelDir , currentDir , file , parseAbsFile , parseRelFile , parentDir' , depth , sandbox , dropExtension , renameFile , canonicalize , unsandbox , unsafePrintPath , (</>), (<..>), (<.>))
8
+ import Data.Path.Pathy (Path , Abs , Rel , Dir , File , Unsandboxed , Sandboxed , dir , rootDir , parseAbsDir , parseRelDir , currentDir , file , parseAbsFile , parseRelFile , parentDir' , depth , sandbox , dropExtension , renameFile , canonicalize , unsandbox , unsafePrintPath , (</>), (<..>), (<.>))
9
+ import Data.Path.Pathy.Gen as PG
9
10
import Data.String as Str
10
11
import Partial.Unsafe (unsafePartial )
11
12
import Test.QuickCheck as QC
@@ -39,8 +40,37 @@ instance arbitraryArbPath ∷ QC.Arbitrary ArbPath where
39
40
pathPart ∷ Gen.Gen String
40
41
pathPart = Gen .suchThat QC .arbitrary (not <<< Str .null)
41
42
43
+ parsePrintCheck :: forall a b . Path a b Sandboxed -> Maybe (Path a b Unsandboxed ) -> QC.Result
44
+ parsePrintCheck input parsed =
45
+ if parsed == Just (unsandbox input)
46
+ then QC.Success
47
+ else QC.Failed
48
+ $ " `parse (print path) != Just path` for path: `" <> show input <> " ` which was re-parsed into `" <> show parsed <> " `"
49
+ <> " \n\t Printed path: " <> show (unsafePrintPath input)
50
+ <> " \n\t Printed path': `" <> show (map unsafePrintPath parsed) <> " `"
51
+
52
+ parsePrintAbsDirPath :: Gen.Gen QC.Result
53
+ parsePrintAbsDirPath = PG .genAbsDirPath <#> \path ->
54
+ parsePrintCheck path (parseAbsDir $ unsafePrintPath path)
55
+
56
+ parsePrintAbsFilePath :: Gen.Gen QC.Result
57
+ parsePrintAbsFilePath = PG .genAbsFilePath <#> \path ->
58
+ parsePrintCheck path (parseAbsFile $ unsafePrintPath path)
59
+
60
+ parsePrintRelDirPath :: Gen.Gen QC.Result
61
+ parsePrintRelDirPath = PG .genRelDirPath <#> \path ->
62
+ parsePrintCheck path (parseRelDir $ unsafePrintPath path)
63
+
64
+ parsePrintRelFilePath :: Gen.Gen QC.Result
65
+ parsePrintRelFilePath = PG .genRelFilePath <#> \path ->
66
+ parsePrintCheck path (parseRelFile $ unsafePrintPath path)
67
+
42
68
main :: QC.QC () Unit
43
69
main = do
70
+ info " checking `parse <<< print` for `AbsDir``" *> QC .quickCheck parsePrintAbsDirPath
71
+ info " checking `parse <<< print` for `AbsFile``" *> QC .quickCheck parsePrintAbsFilePath
72
+ info " checking `parse <<< print` for `RelDir``" *> QC .quickCheck parsePrintRelDirPath
73
+ info " checking `parse <<< print` for `RelFile``" *> QC .quickCheck parsePrintRelFilePath
44
74
-- Should not compile:
45
75
-- test "(</>) - file in dir" (printPath (file "image.png" </> dir "foo")) "./image.png/foo"
46
76
0 commit comments