2013-08-15 08:32:02 +04:00
|
|
|
module VerifyUsingMockTerminal where
|
|
|
|
|
2013-12-20 10:24:56 +04:00
|
|
|
import Verify.Graphics.Vty.Prelude
|
|
|
|
|
2013-08-15 08:32:02 +04:00
|
|
|
import Verify.Graphics.Vty.Picture
|
|
|
|
import Verify.Graphics.Vty.Image
|
|
|
|
import Verify.Graphics.Vty.Span
|
2013-12-20 10:24:56 +04:00
|
|
|
import Verify.Graphics.Vty.Output
|
|
|
|
import Graphics.Vty.Output
|
|
|
|
import Graphics.Vty.Output.Mock
|
2013-08-15 08:32:02 +04:00
|
|
|
|
|
|
|
import Graphics.Vty.Debug
|
|
|
|
|
|
|
|
import Verify
|
|
|
|
|
|
|
|
import qualified Data.ByteString as BS
|
|
|
|
import Data.IORef
|
|
|
|
import qualified Data.String.UTF8 as UTF8
|
|
|
|
|
|
|
|
import System.IO
|
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
unitImageUnitBounds :: UnitImage -> Property
|
|
|
|
unitImageUnitBounds (UnitImage _ i) = liftIOResult $ do
|
|
|
|
(_,t) <- mockTerminal (1,1)
|
|
|
|
dc <- displayBounds t >>= displayContext t
|
|
|
|
let pic = picForImage i
|
|
|
|
outputPicture dc pic
|
2013-08-15 08:32:02 +04:00
|
|
|
return succeeded
|
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
unitImageArbBounds :: UnitImage -> MockWindow -> Property
|
|
|
|
unitImageArbBounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
|
|
|
|
(_,t) <- mockTerminal (w,h)
|
|
|
|
dc <- displayBounds t >>= displayContext t
|
|
|
|
let pic = picForImage i
|
|
|
|
outputPicture dc pic
|
2013-08-15 08:32:02 +04:00
|
|
|
return succeeded
|
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
singleTRow :: MockWindow -> Property
|
|
|
|
singleTRow (MockWindow w h) = liftIOResult $ do
|
|
|
|
(mockData,t) <- mockTerminal (w,h)
|
|
|
|
dc <- displayBounds t >>= displayContext t
|
2013-08-15 08:32:02 +04:00
|
|
|
-- create an image that contains just the character T repeated for a single row
|
2014-04-12 04:51:13 +04:00
|
|
|
let i = horizCat $ replicate (fromEnum w) (char defAttr 'T')
|
|
|
|
pic = (picForImage i) { picBackground = Background 'B' defAttr }
|
|
|
|
outputPicture dc pic
|
2013-08-17 09:13:05 +04:00
|
|
|
-- The mock output string that represents the output bytes a single line containing the T
|
|
|
|
-- string: Followed by h - 1 lines of a change to the background attribute and then the
|
|
|
|
-- background character
|
2013-08-15 08:32:02 +04:00
|
|
|
let expected = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
|
2014-04-12 04:51:13 +04:00
|
|
|
++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
|
|
|
|
compareMockOutput mockData expected
|
2013-08-15 08:32:02 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
manyTRows :: MockWindow -> Property
|
|
|
|
manyTRows (MockWindow w h) = liftIOResult $ do
|
|
|
|
(mockData, t) <- mockTerminal (w,h)
|
|
|
|
dc <- displayBounds t >>= displayContext t
|
2013-08-15 08:32:02 +04:00
|
|
|
-- create an image that contains the character 'T' repeated for all the rows
|
2014-04-12 04:51:13 +04:00
|
|
|
let i = vertCat $ replicate (fromEnum h) $ horizCat $ replicate (fromEnum w) (char defAttr 'T')
|
|
|
|
pic = (picForImage i) { picBackground = Background 'B' defAttr }
|
|
|
|
outputPicture dc pic
|
2013-08-15 08:32:02 +04:00
|
|
|
-- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
|
|
|
|
-- attribute change. 'A', followed by w 'T's
|
|
|
|
let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
|
2014-04-12 04:51:13 +04:00
|
|
|
compareMockOutput mockData expected
|
2013-08-15 08:32:02 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
manyTRowsCroppedWidth :: MockWindow -> Property
|
|
|
|
manyTRowsCroppedWidth (MockWindow w h) = liftIOResult $ do
|
|
|
|
(mockData,t) <- mockTerminal (w,h)
|
|
|
|
dc <- displayBounds t >>= displayContext t
|
2013-08-15 08:32:02 +04:00
|
|
|
-- create an image that contains the character 'T' repeated for all the rows
|
2014-04-12 04:51:13 +04:00
|
|
|
let i = vertCat $ replicate (fromEnum h) $ horizCat $ replicate (fromEnum w * 2) (char defAttr 'T')
|
|
|
|
pic = (picForImage i) { picBackground = Background 'B' defAttr }
|
|
|
|
outputPicture dc pic
|
2013-08-15 08:32:02 +04:00
|
|
|
-- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
|
|
|
|
-- attribute change. 'A', followed by w 'T's
|
|
|
|
let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
|
2014-04-12 04:51:13 +04:00
|
|
|
compareMockOutput mockData expected
|
2013-08-15 08:32:02 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
manyTRowsCroppedHeight :: MockWindow -> Property
|
|
|
|
manyTRowsCroppedHeight (MockWindow w h) = liftIOResult $ do
|
|
|
|
(mockData,t) <- mockTerminal (w,h)
|
|
|
|
dc <- displayBounds t >>= displayContext t
|
2013-08-15 08:32:02 +04:00
|
|
|
-- create an image that contains the character 'T' repeated for all the rows
|
2014-04-12 04:51:13 +04:00
|
|
|
let i = vertCat $ replicate (fromEnum h * 2) $ horizCat $ replicate (fromEnum w) (char defAttr 'T')
|
|
|
|
pic = (picForImage i) { picBackground = Background 'B' defAttr }
|
|
|
|
outputPicture dc pic
|
2013-08-15 08:32:02 +04:00
|
|
|
-- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
|
|
|
|
-- attribute change. 'A', followed by w count 'T's
|
|
|
|
let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
|
2014-04-12 04:51:13 +04:00
|
|
|
compareMockOutput mockData expected
|
2013-08-15 08:32:02 +04:00
|
|
|
|
|
|
|
tests :: IO [Test]
|
2014-04-12 04:51:13 +04:00
|
|
|
tests = return [ verify "unitImageUnitBounds" unitImageUnitBounds
|
|
|
|
, verify "unitImageArbBounds" unitImageArbBounds
|
|
|
|
, verify "singleTRow" singleTRow
|
|
|
|
, verify "manyTRows" manyTRows
|
|
|
|
, verify "manyTRowsCroppedWidth" manyTRowsCroppedWidth
|
|
|
|
, verify "manyTRowsCroppedHeight" manyTRowsCroppedHeight
|
2013-08-15 08:32:02 +04:00
|
|
|
]
|
|
|
|
|