@@ -3,17 +3,26 @@
3 - interest.
3 - interest.
5module VerifyUsingMockInput where
5module VerifyUsingMockInput where
6−import Verify
6+import Verify hiding (classify)
8−import Graphics.Vty
8+import Graphics.Vty hiding (resize)
9+import Graphics.Vty.Input
9import Graphics.Vty.Input.Data
10import Graphics.Vty.Input.Data
11+import Graphics.Vty.Input.Internal
11import Control.Concurrent
13import Control.Concurrent
14+import Control.Exception
12import Control.Monad
15import Control.Monad
14import System.Posix.Env
17import System.Posix.Env
15import System.IO
18import System.IO
20+import Test.QuickCheck.Assertions
21+import Test.QuickCheck.Property ( morallyDubiousIOProperty )
23+-- processing a block of 16 chars is the largest I can do without taking too long to run the test.
17data InputEvent
26data InputEvent
18 = Bytes String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
27 = Bytes String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
19 | Delay Int -- | millisecond delay
28 | Delay Int -- | millisecond delay
@@ -31,19 +40,37 @@ exec_input_spec input out_handle = forM_ input f
31assert_events_from_IO_reads :: InputSpec -> ExpectedSpec -> IO Result
40assert_events_from_IO_reads :: InputSpec -> ExpectedSpec -> IO Result
32assert_events_from_IO_reads input events = undefined
41assert_events_from_IO_reads input events = undefined
34−assert_events_from_input_block :: InputSpec -> ExpectedSpec -> Result
43+assert_events_from_input_block :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO Result
35−assert_events_from_input_block input events = undefined
44+assert_events_from_input_block table input_spec expected_events = do
45+ let classifier = classify table
48+ forkIO $ write_input_spec_to_chan input input_spec
49+ handle (\(e :: BlockedIndefinitelyOnMVar) ->
50+ return $ failed { reason = show expected_events ++ " -> " ++ show e }
52+ inputToEventThread classifier input output
53+ out_events <- replicateM (length expected_events) (readChan output)
54+ return $ out_events ?== expected_events
56+write_input_spec_to_chan :: Chan Char -> InputSpec -> IO ()
57+write_input_spec_to_chan chan [] = writeChan chan '\xFFFD'
58+write_input_spec_to_chan chan (Bytes str : input_spec')
59+ = writeList2Chan chan str >> write_input_spec_to_chan chan input_spec'
60+write_input_spec_to_chan chan (Delay t : input_spec')
61+ = writeChan chan '\xFFFE' >> write_input_spec_to_chan chan input_spec'
37−verify_ansi_table_input_block_to_event :: Gen Result
63+verify_simple_input_block_to_event :: Property
38−verify_ansi_table_input_block_to_event = do
64+verify_simple_input_block_to_event = do
39− Positive block_length <- arbitrary
65+ Positive block_length <- resize 16 $ arbitrary
40− block_event_pairs <- vectorOf block_length $ elements $ concat ansi_classify_table
66+ block_event_pairs <- vectorOf block_length $ elements $ simple_chars
41 let input = [Bytes $ concatMap fst block_event_pairs]
67 let input = [Bytes $ concatMap fst block_event_pairs]
42 events = map (\(k,ms) -> EvKey k ms) $ map snd block_event_pairs
68 events = map (\(k,ms) -> EvKey k ms) $ map snd block_event_pairs
43− return $ assert_events_from_input_block input events
69+ morallyDubiousIOProperty $ assert_events_from_input_block simple_chars input events
45tests :: IO [Test]
71tests :: IO [Test]
46tests = return
72tests = return
47− [ verify "basic input block to event translation" verify_ansi_table_input_block_to_event
73+ [ verify "basic block generated from ansi table to event translation"
74+ verify_simple_input_block_to_event