From 7e4b27223d299ad325f685c63fa0f267fe2d8a00 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 13 Jan 2024 15:46:59 +0530 Subject: [PATCH] Add tests for R.hs --- emanote/emanote.cabal | 1 + emanote/test/Emanote/Route/RSpec.hs | 60 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 emanote/test/Emanote/Route/RSpec.hs diff --git a/emanote/emanote.cabal b/emanote/emanote.cabal index f0af334bb..f164d6657 100644 --- a/emanote/emanote.cabal +++ b/emanote/emanote.cabal @@ -243,3 +243,4 @@ test-suite test Emanote.Model.QuerySpec Emanote.Pandoc.ExternalLinkSpec Emanote.Pandoc.Renderer.CalloutSpec + Emanote.Route.RSpec diff --git a/emanote/test/Emanote/Route/RSpec.hs b/emanote/test/Emanote/Route/RSpec.hs new file mode 100644 index 000000000..c7b643aa8 --- /dev/null +++ b/emanote/test/Emanote/Route/RSpec.hs @@ -0,0 +1,60 @@ +module Emanote.Route.RSpec where + +import Emanote.Route.Ext +import Emanote.Route.R +import Hedgehog +import Relude +import Test.Hspec +import Test.Hspec.Hedgehog + +type SomeExt = ('LMLType 'Md) + +spec :: Spec +spec = do + mkRouteFromFilePathSpec + routeInitsSpec + +mkRouteFromFilePathSpec :: Spec +mkRouteFromFilePathSpec = describe "mkRouteFromFilePath" $ do + describe "basic" $ do + it "index route" . hedgehog $ do + mkRouteFromFilePath @_ @SomeExt "index.md" === Just indexRoute + it "single slug" . hedgehog $ do + mkRouteFromFilePath "foo.md" === Just r1 + it "two slugs" . hedgehog $ do + mkRouteFromFilePath "foo/bar.md" === Just r2 + it "three slugs" . hedgehog $ do + mkRouteFromFilePath "foo/bar/qux.md" === Just r3 + +routeInitsSpec :: Spec +routeInitsSpec = describe "routeInits" $ do + describe "basic" $ do + it "index route returns itself" . hedgehog $ do + routeInits rIndex === one rIndex + it "single slug returns index and itself" . hedgehog $ do + routeInits r1 === rIndex :| [r1] + it "two slugs returns index, first slug, and itself" . hedgehog $ do + routeInits r2 === rIndex :| [r1, r2] + it "three slugs returns index, first slug, second slug, and itself" . hedgehog $ do + routeInits r3 === rIndex :| [r1, r2, r3] + +r1 :: R ('LMLType 'Md) +r1 = R $ "foo" :| [] + +r1Index :: R ('LMLType 'Md) +r1Index = R $ "foo" :| ["index"] + +r2 :: R ('LMLType 'Md) +r2 = R $ "foo" :| ["bar"] + +r2Index :: R ('LMLType 'Md) +r2Index = R $ "foo" :| ["bar", "index"] + +r3 :: R ('LMLType 'Md) +r3 = R $ "foo" :| ["bar", "qux"] + +r3Index :: R ('LMLType 'Md) +r3Index = R $ "foo" :| ["bar", "qux", "index"] + +rIndex :: R ('LMLType 'Md) +rIndex = R $ "index" :| []