vty/test/VerifyUsingMockTerminal.hs
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 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
21compare_bytes out_bytes expected_bytes =
22 if out_bytes /= expected_bytes
23 then return $ failed { reason = "bytes\n" ++ show out_bytes
24 ++ "\nare not the expected bytes\n"
25 ++ show expected_bytes
29unit_image_unit_bounds :: UnitImage -> Property
30unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
31 (_,t) <- mock_terminal (DisplayRegion 1 1)
32 dc <- display_bounds t >>= display_context t
33 let pic = pic_for_image i
37unit_image_arb_bounds :: UnitImage -> MockWindow -> Property
38unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
39 (_,t) <- mock_terminal (DisplayRegion w h)
40 dc <- display_bounds t >>= display_context t
41 let pic = pic_for_image i
45single_T_row :: MockWindow -> Property
46single_T_row (MockWindow w h) = liftIOResult $ do
47 (mock_data,t) <- mock_terminal (DisplayRegion w h)
48 dc <- display_bounds t >>= display_context t
49 -- create an image that contains just the character T repeated for a single row
50 let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
51 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
53 out_bytes <- readIORef mock_data >>= return . UTF8.toRep
54 -- The UTF8 string that represents the output bytes a single line containing the T string:
55 let expected = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
56 -- Followed by h - 1 lines of a change to the background attribute and then the background
58 ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
59 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
60 compare_bytes out_bytes expected_bytes
62many_T_rows :: MockWindow -> Property
63many_T_rows (MockWindow w h) = liftIOResult $ do
64 (mock_data, t) <- mock_terminal (DisplayRegion w h)
65 dc <- display_bounds t >>= display_context t
66 -- create an image that contains the character 'T' repeated for all the rows
67 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
68 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
70 out_bytes <- readIORef mock_data >>= return . UTF8.toRep
71 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
72 -- attribute change. 'A', followed by w 'T's
73 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
74 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
75 compare_bytes out_bytes expected_bytes
77many_T_rows_cropped_width :: MockWindow -> Property
78many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
79 (mock_data,t) <- mock_terminal (DisplayRegion w h)
80 dc <- display_bounds t >>= display_context t
81 -- create an image that contains the character 'T' repeated for all the rows
82 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
83 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
85 out_bytes <- readIORef mock_data >>= return . UTF8.toRep
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 'T's
88 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
89 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
90 compare_bytes out_bytes expected_bytes
92many_T_rows_cropped_height :: MockWindow -> Property
93many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
94 (mock_data,t) <- mock_terminal (DisplayRegion w h)
95 dc <- display_bounds t >>= display_context t
96 -- create an image that contains the character 'T' repeated for all the rows
97 let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
98 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
100 out_bytes <- readIORef mock_data >>= return . UTF8.toRep
101 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
102 -- attribute change. 'A', followed by w count 'T's
103 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
104 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
105 compare_bytes out_bytes expected_bytes
108tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
109 , verify "unit_image_arb_bounds" unit_image_arb_bounds
110 , verify "single_T_row" single_T_row
111 , verify "many_T_rows" many_T_rows
112 , verify "many_T_rows_cropped_width" many_T_rows_cropped_width
113 , 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