mirror of
https://github.com/frasertweedale/hs-fresnel.git
synced 2024-10-05 14:17:22 +03:00
add doctest test suite
This commit is contained in:
parent
7ef30a4caf
commit
5a22d863b8
@ -43,3 +43,13 @@ library
|
||||
|
||||
if impl(ghc < 7.10)
|
||||
build-depends: nats
|
||||
|
||||
test-suite doctest
|
||||
default-language: Haskell2010
|
||||
type: exitcode-stdio-1.0
|
||||
ghc-options: -threaded
|
||||
hs-source-dirs: test
|
||||
main-is: doctest.hs
|
||||
build-depends:
|
||||
base >= 4 && < 5
|
||||
, doctest
|
||||
|
@ -96,7 +96,7 @@ infixr 4 <<$>>
|
||||
|
||||
-- | Sequence two grammars and combine their results as a tuple
|
||||
--
|
||||
-- >>> let g = integralG <<*>> many (satisfy isAlpha)
|
||||
-- >>> let g = integral <<*>> many (satisfy isAlpha)
|
||||
-- >>> parse g "-10abc"
|
||||
-- Just (-10,"abc")
|
||||
-- >>> print g (42, "xyz") :: String
|
||||
@ -110,7 +110,7 @@ infixr 6 <<*>>
|
||||
|
||||
-- | Choice between two grammars
|
||||
--
|
||||
-- >>> let g = integralG <<+>> satisfy isAlpha
|
||||
-- >>> let g = integral <<+>> satisfy isAlpha
|
||||
-- >>> parse g "-10!"
|
||||
-- Just (Left (-10))
|
||||
-- >>> parse g "abc!"
|
||||
@ -172,7 +172,7 @@ many1 g = isoTupleNEL <<$>> g <<*>> many g where
|
||||
|
||||
-- | Sequence two grammars, ignoring the second value.
|
||||
--
|
||||
-- >>> let g = integralG <<* literal '~'
|
||||
-- >>> let g = integral <<* literal '~'
|
||||
-- >>> parse g "123~"
|
||||
-- Just 123
|
||||
-- >>> parse g "123!"
|
||||
@ -185,7 +185,7 @@ p1 <<* p2 = iso (\(a, ()) -> a) (\a -> (a, ())) <<$>> p1 <<*>> p2
|
||||
|
||||
-- | Sequence two grammars, ignoring the first value.
|
||||
--
|
||||
-- >>> let g = literal '~' *>> integralG
|
||||
-- >>> let g = literal '~' *>> integral
|
||||
-- >>> parse g "~123"
|
||||
-- Just 123
|
||||
-- >>> parse g "123"
|
||||
@ -215,7 +215,7 @@ replicate n g = isoList <<$>> (g <<*>> replicate (n - 1) g) <<+>> failure
|
||||
-- | Sequence a grammar based on functions that return the next
|
||||
-- grammar and yield a determinant.
|
||||
--
|
||||
-- >>> let g = bind integralG (\n -> replicate n (satisfy isAlpha)) (fromIntegral . length)
|
||||
-- >>> let g = bind integral (\n -> replicate n (satisfy isAlpha)) (fromIntegral . length)
|
||||
-- >>> parse g "3abc2de?"
|
||||
-- Just "abc"
|
||||
-- >>> parse g "3ab2de?"
|
||||
@ -233,7 +233,7 @@ bind p f g = prism'
|
||||
-- | Given left and right "surrounding" grammars and an interior
|
||||
-- grammar sequence all three, discarding the surrounds.
|
||||
--
|
||||
-- >>> let g = between (literal '<') (literal '>') integralG
|
||||
-- >>> let g = between (literal '<') (literal '>') integral
|
||||
-- >>> parse g "<-123>"
|
||||
-- Just (-123)
|
||||
-- >>> print g 42 :: String
|
||||
@ -258,7 +258,7 @@ literal a = iso (const ()) (const a) <<$>> symbol a
|
||||
-- A defaulted grammar can always be viewed. If a reviewed value
|
||||
-- is equal to the default nothing is written.
|
||||
--
|
||||
-- >>> let g = def 0 integralG
|
||||
-- >>> let g = def 0 integral
|
||||
-- >>> parse g "1~"
|
||||
-- Just 1
|
||||
-- >>> parse g "~"
|
||||
@ -276,7 +276,7 @@ def a' p = iso f g <<$>> p <<+>> success a' where
|
||||
-- | Make a grammar optional; a failed view yields 'Nothing' and
|
||||
-- a review of 'Nothing' writes nothing.
|
||||
--
|
||||
-- >>> let g = opt integralG
|
||||
-- >>> let g = opt integral
|
||||
-- >>> parse g "1~"
|
||||
-- Just (Just 1)
|
||||
-- >>> parse g "~"
|
||||
|
@ -1,7 +1,7 @@
|
||||
# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md
|
||||
|
||||
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
|
||||
resolver: lts-3.18
|
||||
resolver: lts-5.10
|
||||
|
||||
# Local packages, usually specified by relative directory name
|
||||
packages:
|
||||
|
4
test/doctest.hs
Normal file
4
test/doctest.hs
Normal file
@ -0,0 +1,4 @@
|
||||
import Test.DocTest
|
||||
|
||||
main :: IO ()
|
||||
main = doctest ["-XFlexibleContexts", "src/"]
|
Loading…
Reference in New Issue
Block a user