Skip to content
Snippets Groups Projects
Commit ba03d4f3 authored by dario's avatar dario
Browse files

tests: add

parent 4da723e3
No related branches found
No related tags found
No related merge requests found
......@@ -58,3 +58,15 @@ executable myOwnPad-client
build-depends:
base >= 4 && <= 5
, myOwnPad
test-suite myOwnPad-tests
type: detailed-0.9
hs-source-dirs: tests
test-module: Pad.Tests
default-language: Haskell2010
build-depends:
base
, Cabal >= 1.9.2
, myOwnPad
, attoparsec
, blaze-builder
{-# LANGUAGE OverloadedStrings #-}
module Pad.Tests where
-- a lot of copy-paste from
-- https://www.haskell.org/cabal/users-guide/developing-packages.html#test-suites
import Distribution.TestSuite
import Blaze.ByteString.Builder
import qualified Data.Attoparsec.ByteString as APS
import Pad.PadMessage
import Pad.ChangeSet
import Pad.NetProtocol
import Pad.NetProtocol.Parse
import Pad.NetProtocol.Instances
tests :: IO [Test]
tests = return $
map (Test . uncurry serialize_parse_id) $ flip zip [1..] $
[ AddText (Pos 25) "hello"
, AddText (Pos 999999999999999) ""
, RemoveText (Pos 42) (Len 5)
, SetAttribute (Pos 5) (Len 10) (AttrAuthorId (AuthorId "a.foo"))
, ClearAttribute (Pos 0) (Len 1) (AttrFontBold)
]
++
[
]
where
serialize_parse_id change n = TestInstance
{ run = do
let nc = toByteString $ netProtoShow change
ch' = APS.parseOnly parseChange nc
print change
print nc
print ch'
return $ case ch' of
Left err -> Finished $ Error err
Right c | change == c -> Finished Pass
Right c | otherwise -> Finished . Fail $ "expected " ++ (show change) ++ ", but was " ++ (show c)
, name = "serialize_parse_id" ++ (show n)
, tags = []
, options = []
, setOption = \_ _ -> Right (serialize_parse_id change n)
}
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