diff options
Diffstat (limited to 'lec02/Log.hs')
-rw-r--r-- | lec02/Log.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lec02/Log.hs b/lec02/Log.hs new file mode 100644 index 0000000..dce9367 --- /dev/null +++ b/lec02/Log.hs @@ -0,0 +1,38 @@ +-- CIS 194 Homework 2 + +module Log where + +import Control.Applicative + +data MessageType = Info + | Warning + | Error Int + deriving (Show, Eq) + +type TimeStamp = Int + +data LogMessage = LogMessage MessageType TimeStamp String + | Unknown String + deriving (Show, Eq) + +data MessageTree = Leaf + | Node MessageTree LogMessage MessageTree + deriving (Show, Eq) + +-- | @testParse p n f@ tests the log file parser @p@ by running it +-- on the first @n@ lines of file @f@. +testParse :: (String -> [LogMessage]) + -> Int + -> FilePath + -> IO [LogMessage] +testParse parse n file = take n . parse <$> readFile file + +-- | @testWhatWentWrong p w f@ tests the log file parser @p@ and +-- warning message extractor @w@ by running them on the log file +-- @f@. +testWhatWentWrong :: (String -> [LogMessage]) + -> ([LogMessage] -> [String]) + -> FilePath + -> IO [String] +testWhatWentWrong parse whatWentWrong file + = whatWentWrong . parse <$> readFile file |