on master help sign in
simplify the mock terminal tests a bit
commit08c42ea651d3302dffe8927eb2f60bb0ae38bd40 authorCorey O'Connor <corey@ooyala.com> dateFri 16 Aug 2013, 23:13 (13 years ago) parent2a7fce5
5 files changed+34−25
src/Graphics/Vty/PictureToSpans.hs+3−1 src/Graphics/Vty/Terminal/Mock.hs+1−1 test/Verify/Graphics/Vty/Terminal.hs+21 test/VerifyUsingMockTerminal.hs+8−23 vty.cabal+1
src/Graphics/Vty/PictureToSpans.hs+3−1
@@ -66,7 +66,9 @@ type BlitM s a = ReaderT (BlitEnv s) (StateT BlitState (ST s)) a
6666display_ops_for_pic :: Picture -> DisplayRegion -> DisplayOps
6767display_ops_for_pic pic r = Vector.create (combined_ops_for_layers pic r)
6868
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.
7072display_ops_for_image :: Image -> DisplayOps
7173display_ops_for_image i = display_ops_for_pic (pic_for_image i)
7274 (DisplayRegion (image_width i) (image_height i))
src/Graphics/Vty/Terminal/Mock.hs+1−1
@@ -1,7 +1,7 @@
11-- Copyright Corey O'Connor
22{-# LANGUAGE FlexibleInstances #-}
33{-# LANGUAGE TypeFamilies #-}
4−module Graphics.Vty.Terminal.Mock ( mock_terminal )
4+module Graphics.Vty.Terminal.Mock ( MockData, mock_terminal )
55 where
66
77import Graphics.Vty.DisplayRegion
test/Verify/Graphics/Vty/Terminal.hs+21
@@ -1,5 +1,14 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
12module Verify.Graphics.Vty.Terminal where
23
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+
312-- A list of terminals that should be supported.
413-- This started with a list of terminals ubuntu supported. Then those terminals that really could
514-- not be supported were removed.
@@ -36,3 +45,15 @@ terminals_of_interest =
3645 , "rxvt-basic"
3746 , "cygwin"
3847 ]
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
55import Verify.Graphics.Vty.Picture
66import Verify.Graphics.Vty.Image
77import Verify.Graphics.Vty.Span
8+import Verify.Graphics.Vty.Terminal
89import Graphics.Vty.Terminal
910import Graphics.Vty.Terminal.Mock
1011
@@ -18,14 +19,6 @@ import qualified Data.String.UTF8 as UTF8
1819
1920import System.IO
2021
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−
2922unit_image_unit_bounds :: UnitImage -> Property
3023unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
3124 (_,t) <- mock_terminal (DisplayRegion 1 1)
@@ -50,14 +43,12 @@ single_T_row (MockWindow w h) = liftIOResult $ do
5043 let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
5144 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
5245 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
5549 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
5850 ++ 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
51+ compare_mock_output mock_data expected
6152
6253many_T_rows :: MockWindow -> Property
6354many_T_rows (MockWindow w h) = liftIOResult $ do
@@ -67,12 +58,10 @@ many_T_rows (MockWindow w h) = liftIOResult $ do
6758 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
6859 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
6960 output_picture dc pic
70− out_bytes <- readIORef mock_data >>= return . UTF8.toRep
7161 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
7262 -- attribute change. 'A', followed by w 'T's
7363 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
64+ compare_mock_output mock_data expected
7665
7766many_T_rows_cropped_width :: MockWindow -> Property
7867many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
@@ -82,12 +71,10 @@ many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
8271 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
8372 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
8473 output_picture dc pic
85− out_bytes <- readIORef mock_data >>= return . UTF8.toRep
8674 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
8775 -- attribute change. 'A', followed by w 'T's
8876 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
77+ compare_mock_output mock_data expected
9178
9279many_T_rows_cropped_height :: MockWindow -> Property
9380many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
@@ -97,12 +84,10 @@ many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
9784 let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
9885 pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
9986 output_picture dc pic
100− out_bytes <- readIORef mock_data >>= return . UTF8.toRep
10187 -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
10288 -- attribute change. 'A', followed by w count 'T's
10389 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
90+ compare_mock_output mock_data expected
10691
10792tests :: IO [Test]
10893tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
vty.cabal+1
@@ -135,6 +135,7 @@ test-suite verify-using-mock-terminal
135135 Verify.Graphics.Vty.Picture
136136 Verify.Graphics.Vty.Image
137137 Verify.Graphics.Vty.Span
138+ Verify.Graphics.Vty.Terminal
138139
139140 build-depends: vty,
140141 Cabal == 1.17.*,