on master help sign in
simplify the mock terminal tests a bit
08c42eaCorey O'Connor
src/Graphics/Vty/PictureToSpans.hs+3−1
@@ -66,7 +66,9 @@ type BlitM s a = ReaderT (BlitEnv s) (StateT BlitState (ST s)) a
66display_ops_for_pic :: Picture -> DisplayRegion -> DisplayOps
66display_ops_for_pic :: Picture -> DisplayRegion -> DisplayOps
67display_ops_for_pic pic r = Vector.create (combined_ops_for_layers pic r)
67display_ops_for_pic pic r = Vector.create (combined_ops_for_layers pic r)
68
68
69−-- | Returns the DisplayOps for an image rendered to a window the size of the image. Used only for debugging.
69+-- | Returns the DisplayOps for an image rendered to a window the size of the image.
70+--
71+-- largerly used only for debugging.
70display_ops_for_image :: Image -> DisplayOps
72display_ops_for_image :: Image -> DisplayOps
71display_ops_for_image i = display_ops_for_pic (pic_for_image i)
73display_ops_for_image i = display_ops_for_pic (pic_for_image i)
72 (DisplayRegion (image_width i) (image_height i))
74 (DisplayRegion (image_width i) (image_height i))
src/Graphics/Vty/Terminal/Mock.hs+1−1
@@ -1,7 +1,7 @@
1-- Copyright Corey O'Connor
1-- Copyright Corey O'Connor
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeFamilies #-}
4−module Graphics.Vty.Terminal.Mock ( mock_terminal )
4+module Graphics.Vty.Terminal.Mock ( MockData, mock_terminal )
5 where
5 where
6
6
7import Graphics.Vty.DisplayRegion
7import Graphics.Vty.DisplayRegion
test/Verify/Graphics/Vty/Terminal.hs+21
@@ -1,5 +1,14 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
1module Verify.Graphics.Vty.Terminal where
2module Verify.Graphics.Vty.Terminal where
2
3
4+import Graphics.Vty.Terminal.Mock
5+
6+import qualified Data.ByteString as BS
7+import Data.IORef
8+import qualified Data.String.UTF8 as UTF8
9+
10+import Test.QuickCheck.Property
11+
3-- A list of terminals that should be supported.
12-- A list of terminals that should be supported.
4-- This started with a list of terminals ubuntu supported. Then those terminals that really could
13-- This started with a list of terminals ubuntu supported. Then those terminals that really could
5-- not be supported were removed.
14-- not be supported were removed.
@@ -36,3 +45,15 @@ terminals_of_interest =
36 , "rxvt-basic"
45 , "rxvt-basic"
37 , "cygwin"
46 , "cygwin"
38 ]
47 ]
48+
49+compare_mock_output :: MockData -> String -> IO Result
50+compare_mock_output mock_data expected_str = do
51+ out_bytes <- readIORef mock_data >>= return . UTF8.toRep
52+ let expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected_str
53+ if out_bytes /= expected_bytes
54+ then return $ failed { reason = "bytes\n" ++ show out_bytes
55+ ++ "\nare not the expected bytes\n"
56+ ++ show expected_bytes
57+ }
58+ else return succeeded
59+
test/VerifyUsingMockTerminal.hs+8−23
@@ -5,6 +5,7 @@ import Verify.Graphics.Vty.DisplayRegion
5import Verify.Graphics.Vty.Picture
5import Verify.Graphics.Vty.Picture
6import Verify.Graphics.Vty.Image
6import Verify.Graphics.Vty.Image
7import Verify.Graphics.Vty.Span
7import Verify.Graphics.Vty.Span
8+import Verify.Graphics.Vty.Terminal
8import Graphics.Vty.Terminal
9import Graphics.Vty.Terminal
9import Graphics.Vty.Terminal.Mock
10import Graphics.Vty.Terminal.Mock
10
11
@@ -18,14 +19,6 @@ import qualified Data.String.UTF8 as UTF8
18
19
19import System.IO
20import System.IO
20
21
21−compare_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
26− }
27− else return succeeded
28−
29unit_image_unit_bounds :: UnitImage -> Property
22unit_image_unit_bounds :: UnitImage -> Property
30unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
23unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
31 (_,t) <- mock_terminal (DisplayRegion 1 1)
24 (_,t) <- mock_terminal (DisplayRegion 1 1)
@@ -50,14 +43,12 @@ single_T_row (MockWindow w h) = liftIOResult $ do
50 let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
43 let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
51 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
44 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
52 output_picture dc pic
45 output_picture dc pic
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:
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
55 let expected = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
49 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
57− -- character
58 ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
50 ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
59− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
51+ compare_mock_output mock_data expected
60− compare_bytes out_bytes expected_bytes
61
52
62many_T_rows :: MockWindow -> Property
53many_T_rows :: MockWindow -> Property
63many_T_rows (MockWindow w h) = liftIOResult $ do
54many_T_rows (MockWindow w h) = liftIOResult $ do
@@ -67,12 +58,10 @@ many_T_rows (MockWindow w h) = liftIOResult $ do
67 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
58 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 }
59 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
69 output_picture dc pic
60 output_picture dc pic
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
61 -- 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
62 -- attribute change. 'A', followed by w 'T's
73 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
63 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
74− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
64+ compare_mock_output mock_data expected
75− compare_bytes out_bytes expected_bytes
76
65
77many_T_rows_cropped_width :: MockWindow -> Property
66many_T_rows_cropped_width :: MockWindow -> Property
78many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
67many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
@@ -82,12 +71,10 @@ many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
82 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
71 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 }
72 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
84 output_picture dc pic
73 output_picture dc pic
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
74 -- 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
75 -- attribute change. 'A', followed by w 'T's
88 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
76 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
89− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
77+ compare_mock_output mock_data expected
90− compare_bytes out_bytes expected_bytes
91
78
92many_T_rows_cropped_height :: MockWindow -> Property
79many_T_rows_cropped_height :: MockWindow -> Property
93many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
80many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
@@ -97,12 +84,10 @@ many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
97 let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
84 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 }
85 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
99 output_picture dc pic
86 output_picture dc pic
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
87 -- 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
88 -- attribute change. 'A', followed by w count 'T's
103 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
89 let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
104− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
90+ compare_mock_output mock_data expected
105− compare_bytes out_bytes expected_bytes
106
91
107tests :: IO [Test]
92tests :: IO [Test]
108tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
93tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
vty.cabal+1
@@ -135,6 +135,7 @@ test-suite verify-using-mock-terminal
135 Verify.Graphics.Vty.Picture
135 Verify.Graphics.Vty.Picture
136 Verify.Graphics.Vty.Image
136 Verify.Graphics.Vty.Image
137 Verify.Graphics.Vty.Span
137 Verify.Graphics.Vty.Span
138+ Verify.Graphics.Vty.Terminal
138
139
139 build-depends: vty,
140 build-depends: vty,
140 Cabal == 1.17.*,
141 Cabal == 1.17.*,