vty/test/VerifyUsingMockTerminal.hs
1module VerifyUsingMockTerminal where
3import Verify.Graphics.Vty.Prelude
5import Verify.Graphics.Vty.Picture
6import Verify.Graphics.Vty.Image
7import Verify.Graphics.Vty.Attributes
8import Verify.Graphics.Vty.Span
9import Verify.Graphics.Vty.Output
10import Graphics.Vty.Output
11import Graphics.Vty.Output.Interface
12import Graphics.Vty.Output.Mock
14import Graphics.Vty.Debug
18import qualified Data.ByteString as BS
20import qualified Data.String.UTF8 as UTF8
24unitImageUnitBounds :: UnitImage -> Property
25unitImageUnitBounds (UnitImage _ i) = liftIOResult $ do
26 (_,t) <- mockTerminal (1,1)
27 dc <- displayBounds t >>= displayContext t
28 let pic = picForImage i
32unitImageArbBounds :: UnitImage -> MockWindow -> Property
33unitImageArbBounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
34 (_,t) <- mockTerminal (w,h)
35 dc <- displayBounds t >>= displayContext t
36 let pic = picForImage i
40singleTRow :: MockWindow -> Property
41singleTRow (MockWindow w h) = liftIOResult $ do
42 (mockData,t) <- mockTerminal (w,h)
43 dc <- displayBounds t >>= displayContext t
44 -- create an image that contains just the character T repeated for a
46 let i = horizCat $ replicate (fromEnum w) (char defAttr 'T')
47 pic = (picForImage i) { picBackground = Background 'B' defAttr }
49 -- The mock output string that represents the output bytes a single
50 -- line containing the T string: Followed by h - 1 lines of a change
51 -- to the background attribute and then the background character
52 let expected = "H" ++ "MDA" ++ replicate (fromEnum w) 'T'
53 ++ concat (replicate (fromEnum h - 1) $ "MDA" ++ replicate (fromEnum w) 'B')
54 compareMockOutput mockData expected
56manyTRows :: MockWindow -> Property
57manyTRows (MockWindow w h) = liftIOResult $ do
58 (mockData, t) <- mockTerminal (w,h)
59 dc <- displayBounds t >>= displayContext t
60 -- create an image that contains the character 'T' repeated for all
62 let i = vertCat $ replicate (fromEnum h) $ horizCat $ replicate (fromEnum w) (char defAttr 'T')
63 pic = (picForImage i) { picBackground = Background 'B' defAttr }
65 -- The UTF8 string that represents the output bytes is h repeats of
66 -- a move, 'M', followed by an attribute change. 'A', followed by w
68 let expected = "H" ++ concat (replicate (fromEnum h) $ "MDA" ++ replicate (fromEnum w) 'T')
69 compareMockOutput mockData expected
71manyTRowsCroppedWidth :: MockWindow -> Property
72manyTRowsCroppedWidth (MockWindow w h) = liftIOResult $ do
73 (mockData,t) <- mockTerminal (w,h)
74 dc <- displayBounds t >>= displayContext t
75 -- create an image that contains the character 'T' repeated for all
77 let i = vertCat $ replicate (fromEnum h) $ horizCat $ replicate (fromEnum w * 2) (char defAttr 'T')
78 pic = (picForImage i) { picBackground = Background 'B' defAttr }
80 -- The UTF8 string that represents the output bytes is h repeats of
81 -- a move, 'M', followed by an attribute change. 'A', followed by w
83 let expected = "H" ++ concat (replicate (fromEnum h) $ "MDA" ++ replicate (fromEnum w) 'T')
84 compareMockOutput mockData expected
86manyTRowsCroppedHeight :: MockWindow -> Property
87manyTRowsCroppedHeight (MockWindow w h) = liftIOResult $ do
88 (mockData,t) <- mockTerminal (w,h)
89 dc <- displayBounds t >>= displayContext t
90 -- create an image that contains the character 'T' repeated for all
92 let i = vertCat $ replicate (fromEnum h * 2) $ horizCat $ replicate (fromEnum w) (char defAttr 'T')
93 pic = (picForImage i) { picBackground = Background 'B' defAttr }
95 -- The UTF8 string that represents the output bytes is h repeats of
96 -- a move, 'M', followed by an attribute change. 'A', followed by w
98 let expected = "H" ++ concat (replicate (fromEnum h) $ "MDA" ++ replicate (fromEnum w) 'T')
99 compareMockOutput mockData expected
102tests = return [ verify "unitImageUnitBounds" unitImageUnitBounds
103 , verify "unitImageArbBounds" unitImageArbBounds
104 , verify "singleTRow" singleTRow
105 , verify "manyTRows" manyTRows
106 , verify "manyTRowsCroppedWidth" manyTRowsCroppedWidth
107 , verify "manyTRowsCroppedHeight" manyTRowsCroppedHeight
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list