on 195282a help sign in
vty/test/VerifyUsingMockTerminal.hs
100 lines 4.7 kB history raw
1{-# LANGUAGE ScopedTypeVariables #-}
2module VerifyUsingMockTerminal where
4import Verify.Graphics.Vty.DisplayRegion
5import Verify.Graphics.Vty.Picture
6import Verify.Graphics.Vty.Image
7import Verify.Graphics.Vty.Span
8import Verify.Graphics.Vty.Terminal
9import Graphics.Vty.Terminal
10import Graphics.Vty.Terminal.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
22unit_image_unit_bounds :: UnitImage -> Property
23unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
24 (_,t) <- mock_terminal (DisplayRegion 1 1)
25 dc <- display_bounds t >>= display_context t
26 let pic = pic_for_image i
27 output_picture dc pic
28 return succeeded
30unit_image_arb_bounds :: UnitImage -> MockWindow -> Property
31unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
32 (_,t) <- mock_terminal (DisplayRegion w h)
33 dc <- display_bounds t >>= display_context t
34 let pic = pic_for_image i
35 output_picture dc pic
36 return succeeded
38single_T_row :: MockWindow -> Property
39single_T_row (MockWindow w h) = liftIOResult $ do
40 (mock_data,t) <- mock_terminal (DisplayRegion w h)
41 dc <- display_bounds t >>= display_context t
42 -- create an image that contains just the character T repeated for a single row
43 let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
44 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
45 output_picture 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 = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
50 ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
51 compare_mock_output mock_data expected
53many_T_rows :: MockWindow -> Property
54many_T_rows (MockWindow w h) = liftIOResult $ do
55 (mock_data, t) <- mock_terminal (DisplayRegion w h)
56 dc <- display_bounds t >>= display_context t
57 -- create an image that contains the character 'T' repeated for all the rows
58 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
59 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
60 output_picture 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 = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
64 compare_mock_output mock_data expected
66many_T_rows_cropped_width :: MockWindow -> Property
67many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
68 (mock_data,t) <- mock_terminal (DisplayRegion w h)
69 dc <- display_bounds t >>= display_context t
70 -- create an image that contains the character 'T' repeated for all the rows
71 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
72 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
73 output_picture 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 = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
77 compare_mock_output mock_data expected
79many_T_rows_cropped_height :: MockWindow -> Property
80many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
81 (mock_data,t) <- mock_terminal (DisplayRegion w h)
82 dc <- display_bounds t >>= display_context t
83 -- create an image that contains the character 'T' repeated for all the rows
84 let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
85 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
86 output_picture 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 = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
90 compare_mock_output mock_data expected
92tests :: IO [Test]
93tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
94 , verify "unit_image_arb_bounds" unit_image_arb_bounds
95 , verify "single_T_row" single_T_row
96 , verify "many_T_rows" many_T_rows
97 , verify "many_T_rows_cropped_width" many_T_rows_cropped_width
98 , verify "many_T_rows_cropped_height" many_T_rows_cropped_height
99 ]