1
1
module Main (main ) where
2
2
3
+ import Control.Exception
4
+ import Control.Exception (evaluate )
3
5
import Control.Monad
6
+ import Data.ByteString qualified as B
7
+ import Data.Either qualified as E
4
8
import Data.Map
5
- import MyLib qualified
6
- import System.Directory.Tree qualified as DT
7
- import System.FilePath
8
- import Test.HUnit
9
- import qualified System.Directory.Tree as DT
10
- import qualified Data.ByteString as B
11
9
import Data.Text qualified as T
12
- import Data.Text.IO qualified as TIO
13
10
import Data.Text.Encoding qualified as Encoding
14
- import Control.Exception
15
- import Data.Either qualified as E
11
+ import Data.Text.IO qualified as TIO
12
+ import MyLib qualified
13
+ import System.Directory.Tree qualified as DT
14
+ import System.FilePath qualified as F
15
+ import Test.Hspec
16
+ import Test.QuickCheck
17
+ import Control.Lens
18
+
19
+ main :: IO ()
20
+ main = hspec $ do
21
+ describe " Prelude.head" $ do
22
+ it " returns the first element of a list" $ do
23
+ testCase
24
+
16
25
src :: FilePath
17
- src = " test" </> " answers-db"
26
+ src = " test" F. </> " answers-db"
18
27
19
28
dst :: FilePath
20
- dst = " test" </> " dst"
29
+ dst = " test" F. </> " dst"
21
30
22
31
expect :: FilePath
23
- expect = " test" </> " expect"
32
+ expect = " test" F. </> " expect"
24
33
25
34
prefix :: String
26
35
prefix = " prefix"
27
36
28
- main :: IO ()
29
- main = do
30
- count <- runTestTT testCase
31
- print $ showCounts count
32
37
testCase =
33
- TestCase
34
- ( do
35
- _ <- MyLib. someFunc prefix src dst
36
- let reader x = do
37
- b <- B. readFile x
38
- return $ E. fromRight (T. pack $ x ++ " : " ++ show (B. length b)) $ Encoding. decodeUtf8' b
39
- a <- DT. readDirectoryWith reader dst
40
- b <- DT. readDirectoryWith reader expect
41
- assertEqual " for the first result of partA," a b
42
- )
38
+ do
39
+ _ <- MyLib. someFunc prefix src dst
40
+ let reader x = do
41
+ b <- B. readFile x
42
+ return $ E. fromRight (T. pack $ F. takeBaseName x ++ " : " ++ show (B. length b)) $ Encoding. decodeUtf8' b
43
+ a <- DT. readDirectoryWith reader dst
44
+ let a' = a ^. DT. _dirTree
45
+ let a'' = DT. flattenDir (set DT. _name " " a')
46
+ b <- DT. readDirectoryWith reader expect
47
+ let b' = b ^. DT. _dirTree
48
+ let b'' = DT. flattenDir (set DT. _name " " b')
49
+ zipWithM_ shouldBe a'' b''
0 commit comments