Skip to content
Snippets Groups Projects
Commit b282bde7 authored by Alice Brenon's avatar Alice Brenon
Browse files

Draft tests

parent 6967dbd4
No related branches found
No related tags found
No related merge requests found
{-# LANGUAGE OverloadedStrings #-}
module ExtractMetadata (
tests
) where
import Data.Attoparsec.Text (Parser, parseOnly)
import Data.Text as Text (Text, pack)
import Distribution.TestSuite (Test, testGroup)
import Text.Encyclopedia.Article (body_)
import Toolbox (simpleTest)
import Text.Printf (printf)
checkAttoparsec :: (Show a, Eq a) => (String, Parser a, Text, Either String a) -> Test
checkAttoparsec (what, parser, input, expected) =
simpleTest (what, parseOnly parser input, expected)
testBodyGrammar :: Test
testBodyGrammar = testGroup "body" $ checkAttoparsec <$> [
("Positive", body_, positive, Right positive)
, ("Negative", body_, Text.pack negative, errorMessage)
]
where
positive = "Une phrase commence par une majuscule."
negative = "pas par une minuscule"
errorMessage =
Left . printf "Failed reading: body (got «%s…»)" $ take 20 negative
tests :: IO [Test]
tests = pure [
testBodyGrammar
]
{-# LANGUAGE NamedFieldPuns #-}
module Toolbox (
SimpleTest
, simpleTest
) where
import Distribution.TestSuite (
Progress(..), Result(..), Test(..), TestInstance(..)
)
import Text.Printf (printf)
type SimpleTest a = (String, a, a)
simpleTest :: (Show a, Eq a) => SimpleTest a -> Test
simpleTest (name, actual, expected) = Test $ TestInstance {
run = check name actual expected
, name
, tags = []
, options = []
, setOption = \_ _ -> Left "No option available in this simple test"
}
check :: (Show a, Eq a) => String -> a -> a -> IO Progress
check name actual expected
| actual == expected = pure . Finished $ Pass
| otherwise = do
printf "Expected %s but got %s\n" (show expected) (show actual)
pure . Finished $ Fail name
...@@ -44,3 +44,16 @@ executable parseTrevoux ...@@ -44,3 +44,16 @@ executable parseTrevoux
, text , text
hs-source-dirs: app hs-source-dirs: app
default-language: Haskell2010 default-language: Haskell2010
test-suite extractMetadata
type: detailed-0.9
test-module: ExtractMetadata
other-modules: Toolbox
build-depends: attoparsec
, base >=4.11 && <4.13
, Cabal
, text
, trevouxGrammar
hs-source-dirs: test
ghc-options: -Wall
default-language: Haskell2010
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment