-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy path01-Common.purs
47 lines (36 loc) · 1.5 KB
/
01-Common.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Test.ToC.MainLogic.Common (IncludedOrNot, VerifiedOrNot, FileSystemInfo(..), TestRows, TestEnv, separator, getPathName, includePath, isDirectoryInfo, isFileInfo) where
import Prelude
import Data.Tree (Tree, Forest)
import ToC.Core.FileTypes (HeaderInfo)
import ToC.Core.Paths (FilePath)
import ToC.Domain.Types (Env)
type IncludedOrNot = Boolean
type VerifiedOrNot = Boolean
data FileSystemInfo
= DirectoryInfo FilePath IncludedOrNot
| FileInfo FilePath IncludedOrNot (Forest HeaderInfo) VerifiedOrNot
instance showFileSystemInfo :: Show FileSystemInfo where
show (DirectoryInfo path includedOrNot) =
"DirectoryInfo(path=" <> path <> " includedOrNot=" <> show includedOrNot <> ")"
show (FileInfo path includedOrNot headerList verifiedOrNot) =
"FileInfo(path=" <> path <> " includedOrNot=" <> show includedOrNot <>
" headers=<headerList> verifiedOrNot=" <> show verifiedOrNot <> ")"
type TestRows = ( fileSystem :: Tree FileSystemInfo
)
type TestEnv = Env TestRows
-- helper functions
separator :: String
separator = "/"
getPathName :: FileSystemInfo -> String
getPathName = case _ of
DirectoryInfo name _ -> name
FileInfo name _ _ _ -> name
includePath :: FileSystemInfo -> Boolean
includePath (DirectoryInfo _ value) = value
includePath (FileInfo _ value _ _) = value
isDirectoryInfo :: FileSystemInfo -> Boolean
isDirectoryInfo (DirectoryInfo _ _) = true
isDirectoryInfo _ = false
isFileInfo :: FileSystemInfo -> Boolean
isFileInfo (FileInfo _ _ _ _) = true
isFileInfo _ = false