@@ -8,7 +8,7 @@ module Main where
88
99import Verify.Graphics.Vty.Terminal
1010
11−import Data.List (intersperse, permutations)
11+import Data.List (intersperse)
1212
1313import Graphics.Vty hiding (resize)
1414import Graphics.Vty.Input.Data
@@ -36,6 +36,9 @@ import Test.SmallCheck.Series
3636max_block_size :: Int
3737max_block_size = 16
3838
39+max_table_size :: Int
40+max_table_size = 28
41+
3942forEachOf :: (Show a, Testable m b) => [a] -> (a -> b) -> Property m
4043forEachOf l = over (generate (\n -> take n l))
4144
@@ -81,7 +84,6 @@ assert_events_from_syn_input :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO
8184assert_events_from_syn_input table input_spec expected_events = do
8285 let max_duration = sum [t | Delay t <- input_spec] + min_detectable_delay
8386 event_count = length expected_events
84− -- create pipe
8587 (output_fd, input_fd) <- createPipe
8688 (output, shutdown_input) <- initInputForFd test_esc_sample_delay table output_fd
8789 events_ref <- newIORef []
@@ -93,13 +95,13 @@ assert_events_from_syn_input table input_spec expected_events = do
9395 closeFd input_fd
9496 closeFd output_fd
9597 -- drain output pipe
96− let read_all_events = read_loop event_count
98+ let read_events = read_loop event_count
9799 read_loop 0 = return ()
98100 read_loop n = do
99101 e <- readChan output
100102 modifyIORef events_ref ((:) e)
101103 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
103105 out_events <- reverse <$> readIORef events_ref
104106 print (input_spec, expected_events, out_events)
105107 return $ out_events == expected_events
@@ -139,8 +141,11 @@ instance Show (InputBlocksUsingTable event) where
139141
140142instance Monad m => Serial m (InputBlocksUsingTable event) where
141143 series = do
142− n :: Int <- localDepth (max max_block_size) series -- what elements to select from the table
143− return $ InputBlocksUsingTable $ \table -> concat (take n (permutations table))
144+ n :: Int <- localDepth (const max_table_size) series
145+ return $ InputBlocksUsingTable $ \table -> concat (take n (selections table))
146+ where
147+ selections [] = []
148+ selections (x:xs) = let z = selections xs in [x] : (z ++ map ((:) x) z)
144149
145150verify_simple_input_block_to_event :: Property IO
146151verify_simple_input_block_to_event = forAll $ \(InputBlocksUsingTable gen) -> do
@@ -161,7 +166,16 @@ verify_keys_from_caps_table_block_to_event = forAll $ \(InputBlocksUsingTable ge
161166 assert_events_from_input_block (map_to_legacy_table table) input events
162167
163168verify_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
176+
177+verify_caps_syn_input_to_event :: Property IO
178+verify_caps_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
165179 forEachOf terminals_of_interest $ \term_name -> monadic $ do
166180 term <- setupTerm term_name
167181 let table = caps_classify_table term keys_from_caps_table
@@ -171,9 +185,9 @@ verify_simple_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
171185 input = intersperse (Delay test_key_delay) keydowns
172186 assert_events_from_syn_input (map_to_legacy_table table) input events
173187
174−verify_fkeys_syn_input_to_event :: Property IO
175−verify_fkeys_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
176− let table = function_keys_0
188+verify_special_syn_input_to_event :: Property IO
189+verify_special_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
190+ let table = function_keys_1 ++ function_keys_2
177191 input_seq = gen table
178192 events = [EvKey k ms | (_,(k,ms)) <- input_seq]
179193 keydowns = [Bytes s | (s,_) <- input_seq]
@@ -182,13 +196,15 @@ verify_fkeys_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monad
182196
183197main :: IO ()
184198main = 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"
186200 verify_simple_input_block_to_event
187201 , testProperty "key sequences read from caps table map to expected events"
188202 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"
190204 verify_simple_syn_input_to_event
191− , testProperty "synthesized typing from function keys translates to expected events"
192− verify_fkeys_syn_input_to_event
205+ , testProperty "synthesized typing from keys from capabilities tables translates to expected events"
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
193209 ]
194210