@@ -8,7 +8,7 @@ module Main where
9import Verify.Graphics.Vty.Terminal
9import Verify.Graphics.Vty.Terminal
11−import Data.List (intersperse, permutations)
11+import Data.List (intersperse)
13import Graphics.Vty hiding (resize)
13import Graphics.Vty hiding (resize)
14import Graphics.Vty.Input.Data
14import Graphics.Vty.Input.Data
@@ -36,6 +36,9 @@ import Test.SmallCheck.Series
36max_block_size :: Int
36max_block_size :: Int
37max_block_size = 16
37max_block_size = 16
39forEachOf :: (Show a, Testable m b) => [a] -> (a -> b) -> Property m
42forEachOf :: (Show a, Testable m b) => [a] -> (a -> b) -> Property m
40forEachOf l = over (generate (\n -> take n l))
43forEachOf l = over (generate (\n -> take n l))
@@ -81,7 +84,6 @@ assert_events_from_syn_input :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO
81assert_events_from_syn_input table input_spec expected_events = do
84assert_events_from_syn_input table input_spec expected_events = do
82 let max_duration = sum [t | Delay t <- input_spec] + min_detectable_delay
85 let max_duration = sum [t | Delay t <- input_spec] + min_detectable_delay
83 event_count = length expected_events
86 event_count = length expected_events
85 (output_fd, input_fd) <- createPipe
87 (output_fd, input_fd) <- createPipe
86 (output, shutdown_input) <- initInputForFd test_esc_sample_delay table output_fd
88 (output, shutdown_input) <- initInputForFd test_esc_sample_delay table output_fd
87 events_ref <- newIORef []
89 events_ref <- newIORef []
@@ -93,13 +95,13 @@ assert_events_from_syn_input table input_spec expected_events = do
93 closeFd input_fd
95 closeFd input_fd
94 closeFd output_fd
96 closeFd output_fd
95 -- drain output pipe
97 -- drain output pipe
96− let read_all_events = read_loop event_count
98+ let read_events = read_loop event_count
97 read_loop 0 = return ()
99 read_loop 0 = return ()
98 read_loop n = do
100 read_loop n = do
99 e <- readChan output
101 e <- readChan output
100 modifyIORef events_ref ((:) e)
102 modifyIORef events_ref ((:) e)
101 read_loop (n - 1)
103 read_loop (n - 1)
102− gen_events_using_io_actions max_duration write_wait_close read_all_events
104+ gen_events_using_io_actions max_duration write_wait_close read_events
103 out_events <- reverse <$> readIORef events_ref
105 out_events <- reverse <$> readIORef events_ref
104 print (input_spec, expected_events, out_events)
106 print (input_spec, expected_events, out_events)
105 return $ out_events == expected_events
107 return $ out_events == expected_events
@@ -139,8 +141,11 @@ instance Show (InputBlocksUsingTable event) where
140instance Monad m => Serial m (InputBlocksUsingTable event) where
142instance Monad m => Serial m (InputBlocksUsingTable event) where
141 series = do
143 series = do
142− n :: Int <- localDepth (max max_block_size) series -- what elements to select from the table
144+ n :: Int <- localDepth (const max_table_size) series
143− return $ InputBlocksUsingTable $ \table -> concat (take n (permutations table))
145+ return $ InputBlocksUsingTable $ \table -> concat (take n (selections table))
148+ selections (x:xs) = let z = selections xs in [x] : (z ++ map ((:) x) z)
145verify_simple_input_block_to_event :: Property IO
150verify_simple_input_block_to_event :: Property IO
146verify_simple_input_block_to_event = forAll $ \(InputBlocksUsingTable gen) -> do
151verify_simple_input_block_to_event = forAll $ \(InputBlocksUsingTable gen) -> do
@@ -161,7 +166,16 @@ verify_keys_from_caps_table_block_to_event = forAll $ \(InputBlocksUsingTable ge
161 assert_events_from_input_block (map_to_legacy_table table) input events
166 assert_events_from_input_block (map_to_legacy_table table) input events
163verify_simple_syn_input_to_event :: Property IO
168verify_simple_syn_input_to_event :: Property IO
164−verify_simple_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
169+verify_simple_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
170+ let table = simple_chars
171+ input_seq = gen table
172+ events = [EvKey k ms | (_,(k,ms)) <- input_seq]
173+ keydowns = [Bytes s | (s,_) <- input_seq]
174+ input = intersperse (Delay test_key_delay) keydowns
175+ assert_events_from_syn_input (concat ansi_classify_table) input events
177+verify_caps_syn_input_to_event :: Property IO
178+verify_caps_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
165 forEachOf terminals_of_interest $ \term_name -> monadic $ do
179 forEachOf terminals_of_interest $ \term_name -> monadic $ do
166 term <- setupTerm term_name
180 term <- setupTerm term_name
167 let table = caps_classify_table term keys_from_caps_table
181 let table = caps_classify_table term keys_from_caps_table
@@ -171,9 +185,9 @@ verify_simple_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
171 input = intersperse (Delay test_key_delay) keydowns
185 input = intersperse (Delay test_key_delay) keydowns
172 assert_events_from_syn_input (map_to_legacy_table table) input events
186 assert_events_from_syn_input (map_to_legacy_table table) input events
174−verify_fkeys_syn_input_to_event :: Property IO
188+verify_special_syn_input_to_event :: Property IO
175−verify_fkeys_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
189+verify_special_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
176− let table = function_keys_0
190+ let table = function_keys_1 ++ function_keys_2
177 input_seq = gen table
191 input_seq = gen table
178 events = [EvKey k ms | (_,(k,ms)) <- input_seq]
192 events = [EvKey k ms | (_,(k,ms)) <- input_seq]
179 keydowns = [Bytes s | (s,_) <- input_seq]
193 keydowns = [Bytes s | (s,_) <- input_seq]
@@ -182,13 +196,15 @@ verify_fkeys_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monad
183main :: IO ()
197main :: IO ()
184main = defaultMain
198main = defaultMain
185− [ testProperty "basic block generated from a single ansi chars to event translation"
199+ [ testProperty "basic block generated from a single visible chars to event translation"
186 verify_simple_input_block_to_event
200 verify_simple_input_block_to_event
187 , testProperty "key sequences read from caps table map to expected events"
201 , testProperty "key sequences read from caps table map to expected events"
188 verify_keys_from_caps_table_block_to_event
202 verify_keys_from_caps_table_block_to_event
189− , testProperty "synthesized typing from basic blocks translates to expected events"
203+ , testProperty "synthesized typing from single visible chars translates to expected events"
190 verify_simple_syn_input_to_event
204 verify_simple_syn_input_to_event
191− , testProperty "synthesized typing from function keys translates to expected events"
205+ , testProperty "synthesized typing from keys from capabilities tables translates to expected events"
192− verify_fkeys_syn_input_to_event
206+ verify_caps_syn_input_to_event
207+ , testProperty "synthesized typing from hard coded special keys translates to expected events"
208+ verify_special_syn_input_to_event