|
1 | 1 | module Test.Main where
|
2 | 2 |
|
3 | 3 | import Prelude
|
4 |
| -import Control.Monad.Eff.Console (CONSOLE, infoShow) |
5 |
| -import Control.Monad.Eff(Eff) |
| 4 | +import Control.Monad.Eff (Eff) |
| 5 | +import Control.Monad.Eff.Console (CONSOLE, info, infoShow) |
| 6 | +import Control.Monad.Rec.Class (Step(..), tailRecM) |
| 7 | +import Data.Foldable (foldl) |
6 | 8 | import Data.Maybe (Maybe(..), fromJust)
|
7 |
| -import Data.Path.Pathy (Path, dir, rootDir, parseAbsDir, parseRelDir, currentDir, file, parseAbsFile, parseRelFile, parentDir', depth, sandbox, dropExtension, renameFile, canonicalize, unsandbox, unsafePrintPath, (</>), (<..>), (<.>)) |
| 9 | +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, (</>), (<..>), (<.>)) |
| 10 | +import Data.String as Str |
8 | 11 | import Partial.Unsafe (unsafePartial)
|
| 12 | +import Test.QuickCheck as QC |
| 13 | +import Test.QuickCheck.Gen as Gen |
| 14 | +import Test.QuickCheck.Laws.Data as Laws.Data |
| 15 | +import Type.Proxy (Proxy(..)) |
9 | 16 |
|
10 |
| -test :: forall a. (Show a, Eq a) => String -> a -> a -> Eff (console :: CONSOLE) Unit |
| 17 | +test :: forall a eff. (Show a, Eq a) => String -> a -> a -> Eff (console :: CONSOLE | eff) Unit |
11 | 18 | test name actual expected= do
|
12 | 19 | infoShow $ "Test: " <> name
|
13 | 20 | if expected == actual then infoShow $ "Passed: " <> (show expected) else infoShow $ "Failed: Expected " <> (show expected) <> " but found " <> (show actual)
|
14 | 21 |
|
15 |
| -test' :: forall a b s. String -> Path a b s -> String -> Eff (console :: CONSOLE) Unit |
| 22 | +test' :: forall a b s eff. String -> Path a b s -> String -> Eff (console :: CONSOLE | eff) Unit |
16 | 23 | test' n p s = test n (unsafePrintPath p) s
|
17 | 24 |
|
18 |
| -main :: Eff (console :: CONSOLE) Unit |
19 |
| -main = do |
20 |
| - infoShow "NEW TEST" |
| 25 | +newtype ArbPath = ArbPath (Path Abs File Sandboxed) |
| 26 | + |
| 27 | +derive newtype instance eqArbPath :: Eq ArbPath |
| 28 | +derive newtype instance ordArbPath :: Ord ArbPath |
| 29 | + |
| 30 | +runArbPath ∷ ArbPath → (Path Abs File Sandboxed) |
| 31 | +runArbPath (ArbPath p) = p |
| 32 | + |
| 33 | +instance arbitraryArbPath ∷ QC.Arbitrary ArbPath where |
| 34 | + arbitrary = do |
| 35 | + numDirs ← Gen.chooseInt 1 10 |
| 36 | + dirs ← map dir <$> Gen.vectorOf numDirs pathPart |
| 37 | + filename ← file <$> pathPart |
| 38 | + pure $ ArbPath $ rootDir </> foldl (flip (</>)) filename (dirs ∷ Array (Path Rel Dir Sandboxed)) |
21 | 39 |
|
| 40 | +pathPart ∷ Gen.Gen String |
| 41 | +pathPart = Gen.suchThat QC.arbitrary (not <<< Str.null) |
| 42 | + |
| 43 | +main :: QC.QC () Unit |
| 44 | +main = do |
22 | 45 | -- Should not compile:
|
23 | 46 | -- test "(</>) - file in dir" (printPath (file "image.png" </> dir "foo")) "./image.png/foo"
|
24 | 47 |
|
@@ -89,3 +112,7 @@ main = do
|
89 | 112 | test "parseAbsDir - /foo/" (parseAbsDir "/foo/") (Just $ rootDir </> dir "foo")
|
90 | 113 |
|
91 | 114 | test "parseAbsDir - /foo/bar" (parseAbsDir "/foo/bar/") (Just $ rootDir </> dir "foo" </> dir "bar")
|
| 115 | + |
| 116 | + info "Checking typeclass laws..." |
| 117 | + Laws.Data.checkEq (Proxy :: Proxy ArbPath) |
| 118 | + Laws.Data.checkOrd (Proxy :: Proxy ArbPath) |
0 commit comments