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