on 5.12 help sign in
vty/test/VerifyUsingMockTerminal.hs
100 lines 4.5 kB history raw
1module VerifyUsingMockTerminal where
3import Verify.Graphics.Vty.Prelude
5import Verify.Graphics.Vty.Picture
6import Verify.Graphics.Vty.Image
7import Verify.Graphics.Vty.Span
8import Verify.Graphics.Vty.Output
9import Graphics.Vty.Output
10import Graphics.Vty.Output.Mock
12import Graphics.Vty.Debug
14import Verify
16import qualified Data.ByteString as BS
17import Data.IORef
18import qualified Data.String.UTF8 as UTF8
20import System.IO
22unitImageUnitBounds :: UnitImage -> Property
23unitImageUnitBounds (UnitImage _ i) = liftIOResult $ do
24 (_,t) <- mockTerminal (1,1)
25 dc <- displayBounds t >>= displayContext t
26 let pic = picForImage i
27 outputPicture dc pic
28 return succeeded
30unitImageArbBounds :: UnitImage -> MockWindow -> Property
31unitImageArbBounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
32 (_,t) <- mockTerminal (w,h)
33 dc <- displayBounds t >>= displayContext t
34 let pic = picForImage i
35 outputPicture dc pic
36 return succeeded
38singleTRow :: MockWindow -> Property
39singleTRow (MockWindow w h) = liftIOResult $ do
40 (mockData,t) <- mockTerminal (w,h)
41 dc <- displayBounds t >>= displayContext t
42 -- create an image that contains just the character T repeated for a single row
43 let i = horizCat $ replicate (fromEnum w) (char defAttr 'T')
44 pic = (picForImage i) { picBackground = Background 'B' defAttr }
45 outputPicture dc pic
46 -- The mock output string that represents the output bytes a single line containing the T
47 -- string: Followed by h - 1 lines of a change to the background attribute and then the
48 -- background character
49 let expected = "H" ++ "MDA" ++ replicate (fromEnum w) 'T'
50 ++ concat (replicate (fromEnum h - 1) $ "MDA" ++ replicate (fromEnum w) 'B')
51 compareMockOutput mockData expected
53manyTRows :: MockWindow -> Property
54manyTRows (MockWindow w h) = liftIOResult $ do
55 (mockData, t) <- mockTerminal (w,h)
56 dc <- displayBounds t >>= displayContext t
57 -- create an image that contains the character 'T' repeated for all the rows
58 let i = vertCat $ replicate (fromEnum h) $ horizCat $ replicate (fromEnum w) (char defAttr 'T')
59 pic = (picForImage i) { picBackground = Background 'B' defAttr }
60 outputPicture dc pic
61 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
62 -- attribute change. 'A', followed by w 'T's
63 let expected = "H" ++ concat (replicate (fromEnum h) $ "MDA" ++ replicate (fromEnum w) 'T')
64 compareMockOutput mockData expected
66manyTRowsCroppedWidth :: MockWindow -> Property
67manyTRowsCroppedWidth (MockWindow w h) = liftIOResult $ do
68 (mockData,t) <- mockTerminal (w,h)
69 dc <- displayBounds t >>= displayContext t
70 -- create an image that contains the character 'T' repeated for all the rows
71 let i = vertCat $ replicate (fromEnum h) $ horizCat $ replicate (fromEnum w * 2) (char defAttr 'T')
72 pic = (picForImage i) { picBackground = Background 'B' defAttr }
73 outputPicture dc pic
74 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
75 -- attribute change. 'A', followed by w 'T's
76 let expected = "H" ++ concat (replicate (fromEnum h) $ "MDA" ++ replicate (fromEnum w) 'T')
77 compareMockOutput mockData expected
79manyTRowsCroppedHeight :: MockWindow -> Property
80manyTRowsCroppedHeight (MockWindow w h) = liftIOResult $ do
81 (mockData,t) <- mockTerminal (w,h)
82 dc <- displayBounds t >>= displayContext t
83 -- create an image that contains the character 'T' repeated for all the rows
84 let i = vertCat $ replicate (fromEnum h * 2) $ horizCat $ replicate (fromEnum w) (char defAttr 'T')
85 pic = (picForImage i) { picBackground = Background 'B' defAttr }
86 outputPicture dc pic
87 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
88 -- attribute change. 'A', followed by w count 'T's
89 let expected = "H" ++ concat (replicate (fromEnum h) $ "MDA" ++ replicate (fromEnum w) 'T')
90 compareMockOutput mockData expected
92tests :: IO [Test]
93tests = return [ verify "unitImageUnitBounds" unitImageUnitBounds
94 , verify "unitImageArbBounds" unitImageArbBounds
95 , verify "singleTRow" singleTRow
96 , verify "manyTRows" manyTRows
97 , verify "manyTRowsCroppedWidth" manyTRowsCroppedWidth
98 , verify "manyTRowsCroppedHeight" manyTRowsCroppedHeight
99 ]