vty/test/VerifyUsingMockTerminal.hs
1module VerifyUsingMockTerminal where
3import Verify.Graphics.Vty.DisplayRegion
4import Verify.Graphics.Vty.Picture
5import Verify.Graphics.Vty.Image
6import Verify.Graphics.Vty.Span
7import Verify.Graphics.Vty.Terminal
8import Graphics.Vty.Terminal
9import Graphics.Vty.Terminal.Mock
11import Graphics.Vty.Debug
15import qualified Data.ByteString as BS
17import qualified Data.String.UTF8 as UTF8
21unit_image_unit_bounds :: UnitImage -> Property
22unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
23 (_,t) <- mock_terminal (DisplayRegion 1 1)
24 dc <- display_bounds t >>= display_context t
25 let pic = pic_for_image i
29unit_image_arb_bounds :: UnitImage -> MockWindow -> Property
30unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
31 (_,t) <- mock_terminal (DisplayRegion w h)
32 dc <- display_bounds t >>= display_context t
33 let pic = pic_for_image i
37single_T_row :: MockWindow -> Property
38single_T_row (MockWindow w h) = liftIOResult $ do
39 (mock_data,t) <- mock_terminal (DisplayRegion w h)
40 dc <- display_bounds t >>= display_context t
41 -- create an image that contains just the character T repeated for a single row
42 let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
43 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
45 -- The mock output string that represents the output bytes a single line containing the T
46 -- string: Followed by h - 1 lines of a change to the background attribute and then the
47 -- background character
48 let expected = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
49 ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
50 compare_mock_output mock_data expected
52many_T_rows :: MockWindow -> Property
53many_T_rows (MockWindow w h) = liftIOResult $ do
54 (mock_data, t) <- mock_terminal (DisplayRegion w h)
55 dc <- display_bounds t >>= display_context t
56 -- create an image that contains the character 'T' repeated for all the rows
57 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
58 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
60 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
61 -- attribute change. 'A', followed by w 'T's
62 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
63 compare_mock_output mock_data expected
65many_T_rows_cropped_width :: MockWindow -> Property
66many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
67 (mock_data,t) <- mock_terminal (DisplayRegion w h)
68 dc <- display_bounds t >>= display_context t
69 -- create an image that contains the character 'T' repeated for all the rows
70 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
71 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
73 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
74 -- attribute change. 'A', followed by w 'T's
75 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
76 compare_mock_output mock_data expected
78many_T_rows_cropped_height :: MockWindow -> Property
79many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
80 (mock_data,t) <- mock_terminal (DisplayRegion w h)
81 dc <- display_bounds t >>= display_context t
82 -- create an image that contains the character 'T' repeated for all the rows
83 let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
84 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
86 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
87 -- attribute change. 'A', followed by w count 'T's
88 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
89 compare_mock_output mock_data expected
92tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
93 , verify "unit_image_arb_bounds" unit_image_arb_bounds
94 , verify "single_T_row" single_T_row
95 , verify "many_T_rows" many_T_rows
96 , verify "many_T_rows_cropped_width" many_T_rows_cropped_width
97 , verify "many_T_rows_cropped_height" many_T_rows_cropped_height
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