fix tests + generative tests

This commit is contained in:
Yann Esposito (Yogsototh) 2017-02-27 23:09:27 +01:00
parent f0301d3c4e
commit e6207fd301
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
3 changed files with 23 additions and 7 deletions

View file

@ -56,13 +56,14 @@ test-suite lish-test
default-language: Haskell2010
ghc-options: -Wall -Werror -O2 -threaded -rtsopts -with-rtsopts=-N
hs-source-dirs: src-test
exposed-modules: Lish.Test.Parser
main-is: Main.hs
other-modules: Lish.Test.Parser
build-depends: base >= 4.8 && < 5
, tasty >= 0.11
, tasty-hunit >= 0.9
, tasty-smallcheck >= 0.8
, lish
, protolude
test-suite lish-doctest
type: exitcode-stdio-1.0

View file

@ -8,12 +8,26 @@ import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.SmallCheck
import Lish.Parser
import Lish.Types
parseTests :: [TestTree]
parseTests =
[ testCase "simple commands" simpleCommand ]
[ testCase "simple commands" (simpleCommand "ls")
, testCase "simple commands" (simpleCommand "atom")
, testCase "simple commands" (simpleCommand "_foo")
, testProperty "simple" propAtom
]
simpleCommand :: Assertion
simpleCommand = parseCmd "ls" @?= Right (Atom "ls")
simpleCommand :: Text -> Assertion
simpleCommand t = parseCmd t @?= Right (Atom t)
propAtom :: [Char] -> Bool
propAtom s = s == "" ||
fromMaybe '0' (head s) `elem` ("0123456789([])" :: [Char]) ||
case s of
"true" -> parseCmd t == Right (Bool True)
"false" -> parseCmd t == Right (Bool False)
_ -> parseCmd t == Right (Atom t)
where t = toS s

View file

@ -4,6 +4,7 @@
module Lish.Types
( SExp(..)
, show
, repr
, Env
, CmdStream
, Command
@ -31,10 +32,10 @@ data SExp = Atom Text
}
| Stream CmdStream
| WaitingStream CmdStream
deriving (Eq)
deriving (Eq,Show)
instance Show SExp where
show = toS . repr
-- instance Show SExp where
-- show = toS . repr
repr :: SExp -> Text
repr (Atom s) = s