Skip to content

A peer-to-peer stack for code collaboration

Doctests

Julian K. Arni32d0b8598424
diff --git a/package.yaml b/package.yaml
index 9e5396a..a6d8fd0 100644
--- a/package.yaml
+++ b/package.yaml
@@ -25,10 +25,9 @@ tests:
spec:
main: Main.hs
source-dirs:
- - test
- ghc-options: -Wall
+ - test/spec
+ ghc-options: -Wall -threaded
dependencies:
- - base
- radicle
- QuickCheck
- quickcheck-instances
@@ -37,6 +36,18 @@ tests:
- tasty-discover
- tasty-hunit
- tasty-quickcheck
+ doctest:
+ main: Main.hs
+ source-dirs:
+ - test/docs
+ ghc-options: -Wall -threaded
+ other-modules:
+ - Paths_radicle
+ dependencies:
+ - radicle
+ - doctest
+ - Glob
+ - hpack
default-extensions:
- AutoDeriveTypeable
diff --git a/radicle.cabal b/radicle.cabal
index 706bc6f..c4bf5eb 100644
--- a/radicle.cabal
+++ b/radicle.cabal
@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
--- hash: fd7a7108d97bdcf99bc499773b87517e72a468ea57d246e1cf78558c72d6922f
+-- hash: 650d134dbbffbd2db37d84261d172a107bc0865d8252df4b363e7bdca4bedeb5
name: radicle
version: 0.0.0
@@ -45,16 +45,39 @@ library
Paths_radicle
default-language: Haskell2010
+test-suite doctest
+ type: exitcode-stdio-1.0
+ main-is: Main.hs
+ hs-source-dirs:
+ test/docs
+ default-extensions: AutoDeriveTypeable DeriveDataTypeable DeriveFunctor DeriveGeneric GeneralizedNewtypeDeriving FlexibleContexts OverloadedStrings TupleSections TypeFamilies TypeOperators RankNTypes RecordWildCards
+ ghc-options: -Wall -threaded
+ build-depends:
+ Glob
+ , base >=4 && <5
+ , containers
+ , doctest
+ , hpack
+ , megaparsec
+ , mmorph
+ , mtl
+ , prettyprinter
+ , radicle
+ , text
+ other-modules:
+ Paths_radicle
+ default-language: Haskell2010
+
test-suite spec
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs:
- test
+ test/spec
default-extensions: AutoDeriveTypeable DeriveDataTypeable DeriveFunctor DeriveGeneric GeneralizedNewtypeDeriving FlexibleContexts OverloadedStrings TupleSections TypeFamilies TypeOperators RankNTypes RecordWildCards
- ghc-options: -Wall
+ ghc-options: -Wall -threaded
build-depends:
QuickCheck
- , base
+ , base >=4 && <5
, containers
, megaparsec
, mmorph
diff --git a/src/Radicle/Internal/Parse.hs b/src/Radicle/Internal/Parse.hs
index 2e738a1..7d7d936 100644
--- a/src/Radicle/Internal/Parse.hs
+++ b/src/Radicle/Internal/Parse.hs
@@ -105,6 +105,11 @@ valueP = do
-- * Utilities
-- | Parse and evaluate a Text.
+--
+-- Examples:
+--
+-- >>> interpret "test" "((lambda (x) x) #t)"
+-- Right (Boolean True)
interpret :: String -> Text -> Either LangError Value
interpret sourceName expr = do
parsed <- first ParseError $ parse valueP sourceName expr
diff --git a/src/Radicle/Internal/Pretty.hs b/src/Radicle/Internal/Pretty.hs
index 458f26c..17fc57a 100644
--- a/src/Radicle/Internal/Pretty.hs
+++ b/src/Radicle/Internal/Pretty.hs
@@ -31,13 +31,31 @@ instance Pretty Value where
escapeStr = T.replace "\"" "\\\"" . T.replace "\\" "\\\\"
-- | A fast and compact layout. Primarily intended for testing.
+--
+-- Examples:
+--
+-- >>> renderCompactPretty (List [String "hi", String "there"])
+-- "'(\"hi\"\n\"there\")"
renderCompactPretty :: Value -> Text
renderCompactPretty = renderStrict . layoutCompact . pretty
-- | Render prettily into text, with specified width.
+--
+-- Examples:
+--
+-- >>> renderPretty Unbounded (List [String "hi", String "there"])
+-- "'(\"hi\" \"there\")"
+--
+-- >>> renderPretty (AvailablePerLine 6 0.5) (List [String "hi", String "there"])
+-- "'(\"hi\"\n\"there\")"
renderPretty :: PageWidth -> Value -> Text
renderPretty pg = renderStrict . layoutSmart (LayoutOptions pg) . pretty
-- | 'renderPretty', but with default layout options (80 chars, 1.0 ribbon)
+--
+-- Examples:
+--
+-- >>> renderPrettyDef (List [String "hi", String "there"])
+-- "'(\"hi\" \"there\")"
renderPrettyDef :: Value -> Text
renderPrettyDef = renderStrict . layoutSmart defaultLayoutOptions . pretty
diff --git a/test/docs/Main.hs b/test/docs/Main.hs
new file mode 100644
index 0000000..e69131c
--- /dev/null
+++ b/test/docs/Main.hs
@@ -0,0 +1,12 @@
+module Main (main) where
+
+import System.FilePath.Glob (glob)
+import Test.DocTest
+import Hpack.Config
+
+main :: IO ()
+main = do
+ Right pkg <- fmap decodeResultPackage <$> readPackageConfig defaultDecodeOptions
+ let Just exts = fmap sectionDefaultExtensions $ packageLibrary pkg
+ srcs <- glob "src/**/*.hs"
+ doctest $ srcs ++ fmap ("-X" ++) exts
diff --git a/test/Main.hs b/test/spec/Main.hs
similarity index 100%
rename from test/Main.hs
rename to test/spec/Main.hs
diff --git a/test/Radicle/Internal/Arbitrary.hs b/test/spec/Radicle/Internal/Arbitrary.hs
similarity index 100%
rename from test/Radicle/Internal/Arbitrary.hs
rename to test/spec/Radicle/Internal/Arbitrary.hs
diff --git a/test/Radicle/Tests.hs b/test/spec/Radicle/Tests.hs
similarity index 100%
rename from test/Radicle/Tests.hs
rename to test/spec/Radicle/Tests.hs