@@ -23,7 +23,6 @@ import Control.Monad
24import System.Console.Terminfo
24import System.Console.Terminfo
25import System.IO
25import System.IO
26−import System.Posix.Env
28import Test.Framework.Providers.SmallCheck
27import Test.Framework.Providers.SmallCheck
29import Test.Framework
28import Test.Framework
@@ -36,6 +35,7 @@ max_bytes_size = 16
36data InputEvent
35data InputEvent
37 = Bytes String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
36 = Bytes String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
38 | Delay Int -- | millisecond delay
37 | Delay Int -- | millisecond delay
40type InputSpec = [InputEvent]
40type InputSpec = [InputEvent]
@@ -49,46 +49,38 @@ exec_input_spec input out_handle = forM_ input f
50assert_events_from_input_block :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO Bool
50assert_events_from_input_block :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO Bool
51assert_events_from_input_block table input_spec expected_events = do
51assert_events_from_input_block table input_spec expected_events = do
52 let classifier = classify table
53 let classifier = classify table
53 input <- newChan
54 input <- newChan
54 output <- newChan
55 output <- newChan
56+ read_complete <- newEmptyMVar
57+ write_complete <- newEmptyMVar
55− forkIO $ write_input_spec_to_chan input input_spec
58+ _ <- forkIO $ write_input_spec_to_chan input input_spec
59+ `finally` putMVar write_complete ()
56− inputToEventThread classifier input output
60+ _ <- forkIO $ inputToEventThread classifier input output
57− -- H: all events are available in output channel
61+ `finally` putMVar read_complete ()
58− -- TODO: switch to using explicit control events. Currently the channel is passing around a
62+ () <- takeMVar write_complete
59− -- magic FFFX characters
63+ () <- takeMVar read_complete
60 -- TODO: use STM channel
64 -- TODO: use STM channel
61− let collect_events = handle (\(e :: BlockedIndefinitelyOnMVar) -> return [])
65+ -- assures the next line does not block.
62− ((:) <$> readChan output <*> collect_events)
66+ writeList2Chan output $ replicate (length expected_events) undefined
63− out_events <- collect_events
67+ out_events <- take (length expected_events) <$> getChanContents output
64 return $ out_events == expected_events
68 return $ out_events == expected_events
66write_input_spec_to_chan :: Chan Char -> InputSpec -> IO ()
70write_input_spec_to_chan :: Chan Char -> InputSpec -> IO ()
67−write_input_spec_to_chan chan [] = writeChan chan '\xFFFD'
71+write_input_spec_to_chan chan [] = do
72+ writeChan chan '\xFFFD'
68−write_input_spec_to_chan chan (Bytes str : input_spec')
73+write_input_spec_to_chan chan (Bytes str : input_spec') = do
74+ writeList2Chan chan str
69− = writeList2Chan chan str >> write_input_spec_to_chan chan input_spec'
75+ write_input_spec_to_chan chan input_spec'
70−write_input_spec_to_chan chan (Delay t : input_spec')
76+write_input_spec_to_chan chan (Delay _t : input_spec') = do
77+ writeChan chan '\xFFFE'
71− = writeChan chan '\xFFFE' >> write_input_spec_to_chan chan input_spec'
78+ write_input_spec_to_chan chan input_spec'
78− <$> pure [ verify "basic block generated from single ansi chars to event translation" ]
79− <*> mapM terminals_of_interest
80− verify_simple_input_block_to_event
81− , verify "keys from caps table are parsed to the same key"
82− verify_keys_from_caps_table
86−-- how to make this data dependent?
88newtype EventBlock event = EventBlock ([(String,event)] -> [(String, event)])
80newtype EventBlock event = EventBlock ([(String,event)] -> [(String, event)])
90instance Show (EventBlock event) where
82instance Show (EventBlock event) where
91− show (EventBlock g) = "EventBlock(* -> *)"
83+ show (EventBlock g) = "EventBlock(*->*)"
93instance Monad m => Serial m (EventBlock event) where
85instance Monad m => Serial m (EventBlock event) where
94 series = do
86 series = do
@@ -106,12 +98,12 @@ verify_keys_from_caps_table_block_to_event :: Property IO
106verify_keys_from_caps_table_block_to_event = forAll $ \(EventBlock block_gen) ->
98verify_keys_from_caps_table_block_to_event = forAll $ \(EventBlock block_gen) ->
107 over (generate (\n -> take n terminals_of_interest)) $ \term_name -> monadic $ do
99 over (generate (\n -> take n terminals_of_interest)) $ \term_name -> monadic $ do
108 terminal <- setupTerm term_name
100 terminal <- setupTerm term_name
101+ let table = caps_classify_table terminal keys_from_caps_table
109− let caps_seq :: [(String, Event)] = block_gen keys_from_caps_table
102+ input_seq :: [(String, Event)] = block_gen table
110− let bytes_seq = caps_classify_table terminal caps_seq
103+ input_bytes = [Bytes s | (s,_) <- input_seq]
111− input = [Bytes s | (s,_) <- bytes_seq]
112− escaped_sequence = intersperse (Delay defaultEscDelay) input
104+ input = intersperse (Delay defaultEscDelay) input_bytes
113− return True :: IO Bool
105+ events = [e | (_,e) <- input_seq]
114− -- cap <- elements keys_from_caps_table
106+ assert_events_from_input_block (map_to_legacy_table table) input events
116main = defaultMain
108main = defaultMain
117 [ testProperty "basic block generated from a single ansi chars to event translation"
109 [ testProperty "basic block generated from a single ansi chars to event translation"