@@ -6,11 +6,15 @@ import Control.Monad.Eff (Eff)
6
6
import Control.Monad.Eff.Console (CONSOLE , info )
7
7
import Control.Monad.Eff.Exception (EXCEPTION , throw )
8
8
import Data.Maybe (Maybe (..))
9
+ import Data.Newtype (un )
10
+ import Data.NonEmpty ((:|))
9
11
import Data.String as Str
10
12
import Data.String.NonEmpty (NonEmptyString )
13
+ import Data.String.NonEmpty as NES
11
14
import Data.Symbol (SProxy (..))
12
- import Pathy (class IsDirOrFile , class IsRelOrAbs , Abs , Dir , Path , Rel , alterExtension , canonicalize , currentDir , dir , file , parentOf , parseAbsDir , parseAbsFile , parseRelDir , parseRelFile , posixParser , posixPrinter , printPath , relativeTo , rename , rootDir , sandbox , debugPrintPath , unsandbox , (<..>), (<.>), (</>))
15
+ import Pathy (class IsDirOrFile , class IsRelOrAbs , Abs , Dir , Name (..), Path , Rel , alterExtension , canonicalize , currentDir , debugPrintPath , dir , extension , file , parentOf , parseAbsDir , parseAbsFile , parseRelDir , parseRelFile , posixParser , posixPrinter , printPath , relativeTo , rename , rootDir , sandbox , unsandbox , (<..>), (<.>), (</>), joinName , reflectName , splitName )
13
16
import Pathy.Gen as PG
17
+ import Test.QuickCheck ((===))
14
18
import Test.QuickCheck as QC
15
19
import Test.QuickCheck.Gen as Gen
16
20
import Unsafe.Coerce (unsafeCoerce )
@@ -65,6 +69,31 @@ parsePrintRelFilePath :: Gen.Gen QC.Result
65
69
parsePrintRelFilePath = PG .genRelFilePath <#> \path ->
66
70
parsePrintCheck path (parseRelFile posixParser $ printTestPath path)
67
71
72
+ genAmbigiousName :: forall a . Gen.Gen (Name a )
73
+ genAmbigiousName =
74
+ let
75
+ genNES = PG .genName <#> un Name
76
+ in
77
+ map Name $ Gen .oneOf $ genNES :|
78
+ [ genNES <#> \a -> a <> (NES .singleton ' .' )
79
+ , genNES <#> \a -> (NES .singleton ' .' ) <> a
80
+ , pure (NES .singleton ' .' )
81
+ , do
82
+ a <- genNES
83
+ b <- genNES
84
+ pure $ a <> (NES .singleton ' .' ) <> b
85
+ ]
86
+
87
+ checkAlterExtensionId :: Gen.Gen QC.Result
88
+ checkAlterExtensionId = do
89
+ n <- genAmbigiousName
90
+ pure $ alterExtension id n === id n
91
+
92
+ checkJoinSplitNameId :: Gen.Gen QC.Result
93
+ checkJoinSplitNameId = do
94
+ n <- genAmbigiousName
95
+ pure $ joinName (splitName n) === id n
96
+
68
97
checkRelative :: forall b . IsDirOrFile b => Gen.Gen (Path Abs b ) -> Gen.Gen QC.Result
69
98
checkRelative gen = do
70
99
p1 <- gen
@@ -92,6 +121,8 @@ main = do
92
121
info " checking `parse <<< print` for `RelFile`" *> QC .quickCheck parsePrintRelFilePath
93
122
info " checking `relativeTo` for `AbsDir`" *> QC .quickCheck (checkRelative PG .genAbsDirPath)
94
123
info " checking `relativeTo` for `AbsFile`" *> QC .quickCheck (checkRelative PG .genAbsFilePath)
124
+ info " checking `joinName <<< splitName === id`" *> QC .quickCheck 100 checkJoinSplitNameId
125
+ info " checking `alterExtension id === id`" *> QC .quickCheck 100 checkAlterExtensionId
95
126
96
127
-- Should not compile:
97
128
-- test
@@ -231,6 +262,22 @@ main = do
231
262
(rename (alterExtension (const Nothing )) (file (SProxy :: SProxy " image.png" )))
232
263
(file $ SProxy :: SProxy " image" )
233
264
265
+ test """ extension (Name ".foo") == Nothing"""
266
+ (extension (reflectName $ SProxy :: SProxy " .foo" ))
267
+ (Nothing )
268
+ test """ extension (Name "foo.") == Nothing"""
269
+ (extension (reflectName $ SProxy :: SProxy " foo." ))
270
+ (Nothing )
271
+ test """ extension (Name "foo") == Nothing"""
272
+ (extension (reflectName $ SProxy :: SProxy " foo" ))
273
+ (Nothing )
274
+ test """ extension (Name ".") == Nothing"""
275
+ (extension (reflectName $ SProxy :: SProxy " ." ))
276
+ (Nothing )
277
+ test """ extension (Name "foo.baz") == (Just "baz")"""
278
+ (extension (reflectName $ SProxy :: SProxy " foo.baz" ))
279
+ (NES .fromString " baz" )
280
+
234
281
test " sandbox - fail when relative path lies outside sandbox (above)"
235
282
(sandbox (rootDir </> dirBar) (parentOf currentDir))
236
283
Nothing
0 commit comments