1{-# LANGUAGE ScopedTypeVariables #-}
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.Debug
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 <- terminal_instance (DisplayRegion 1 1)
24 d <- display_bounds t >>= display_context t
25 let pic = pic_for_image i
29unit_image_arb_bounds :: UnitImage -> DebugWindow -> Property
30unit_image_arb_bounds (UnitImage _ i) (DebugWindow w h) = liftIOResult $ do
31 t <- terminal_instance (DisplayRegion w h)
32 d <- display_bounds t >>= display_context t
33 let pic = pic_for_image i
37single_T_row :: DebugWindow -> Property
38single_T_row (DebugWindow w h) = liftIOResult $ do
39 t <- terminal_instance (DisplayRegion w h)
40 d <- 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 out_bytes <- readIORef (debug_terminal_last_output $ dehandle t) >>= return . UTF8.toRep
46 -- The UTF8 string that represents the output bytes a single line containing the T string:
47 let expected = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
48 -- Followed by h - 1 lines of a change to the background attribute and then the background
50 ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
51 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
52 if out_bytes /= expected_bytes
53 then return $ failed $ result { reason = "\n" ++ show out_bytes ++ "\n\n" ++ show expected_bytes }
56many_T_rows :: DebugWindow -> Property
57many_T_rows (DebugWindow w h) = liftIOResult $ do
58 t <- terminal_instance (DisplayRegion w h)
59 d <- display_bounds t >>= display_context t
60 -- create an image that contains the character 'T' repeated for all the rows
61 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
62 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
64 out_bytes <- readIORef (debug_terminal_last_output $ dehandle t) >>= return . UTF8.toRep
65 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
66 -- attribute change. 'A', followed by w 'T's
67 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
68 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
69 if out_bytes /= expected_bytes
70 then return $ failed $ result { reason = "\n" ++ show out_bytes ++ "\n\n" ++ show expected_bytes }
73many_T_rows_cropped_width :: DebugWindow -> Property
74many_T_rows_cropped_width (DebugWindow w h) = liftIOResult $ do
75 t <- terminal_instance (DisplayRegion w h)
76 d <- display_bounds t >>= display_context t
77 -- create an image that contains the character 'T' repeated for all the rows
78 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
79 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
81 out_bytes <- readIORef (debug_terminal_last_output $ dehandle t) >>= return . UTF8.toRep
82 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
83 -- attribute change. 'A', followed by w 'T's
84 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
85 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
86 if out_bytes /= expected_bytes
87 then return $ failed $ result { reason = "\n" ++ show out_bytes ++ "\n\n" ++ show expected_bytes }
90many_T_rows_cropped_height :: DebugWindow -> Property
91many_T_rows_cropped_height (DebugWindow w h) = liftIOResult $ do
92 t <- terminal_instance (DisplayRegion w h)
93 d <- display_bounds t >>= display_context t
94 -- create an image that contains the character 'T' repeated for all the rows
95 let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
96 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
98 out_bytes <- readIORef (debug_terminal_last_output $ dehandle t) >>= return . UTF8.toRep
99 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
100 -- attribute change. 'A', followed by w count 'T's
101 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
102 expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
103 if out_bytes /= expected_bytes
104 then return $ failed $ result { reason = "\n" ++ show out_bytes ++ "\n\n" ++ show expected_bytes }
105 else return succeeded
108 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