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.Span
8import Verify.Graphics.Vty.Output
9import Graphics.Vty.Output
10import Graphics.Vty.Output.Mock
12import Graphics.Vty.Debug
16import qualified Data.ByteString as BS
18import qualified Data.String.UTF8 as UTF8
22unit_image_unit_bounds :: UnitImage -> Property
23unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
24 (_,t) <- mock_terminal (1,1)
25 dc <- display_bounds t >>= display_context t
26 let pic = pic_for_image i
30unit_image_arb_bounds :: UnitImage -> MockWindow -> Property
31unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
32 (_,t) <- mock_terminal (w,h)
33 dc <- display_bounds t >>= display_context t
34 let pic = pic_for_image i
38single_T_row :: MockWindow -> Property
39single_T_row (MockWindow w h) = liftIOResult $ do
40 (mock_data,t) <- mock_terminal (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 }
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 (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 }
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 (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 }
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 (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 }
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
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
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