diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-03-23 15:44:35 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-03-23 15:44:35 +1100 |
commit | 8dbe6cd9102211f7b5a265c7209685c4aa026fb6 (patch) | |
tree | 5317f9a8944c107b99bf2532af8ca7333555e24c /Unlambda | |
parent | ba22791c6f61582b498fc853189fa52129110587 (diff) |
Tests for unlambda interpreter
Diffstat (limited to 'Unlambda')
-rw-r--r-- | Unlambda/Test.hs | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/Unlambda/Test.hs b/Unlambda/Test.hs index 9c0024c..504ae07 100644 --- a/Unlambda/Test.hs +++ b/Unlambda/Test.hs @@ -1,11 +1,15 @@ module Unlambda.Test ( parserTests, - tests + interpreterTests, + tests, + ioTests ) where import Test.HUnit import Text.Parsec.Error +import Control.Monad +import System.IO.Silently import Unlambda.Types import Unlambda.Parser import Unlambda.Interpreter @@ -44,12 +48,47 @@ parser12 = (Right Reed) ~=? (parseUnlambda "@") +interpretString :: String -> IO (Maybe (String,UnlambdaTerm)) +interpretString input = + let t = parseUnlambda input + in case t of + Left _ -> return Nothing + Right term -> do + c <- capture (unlambda term) + return (Just c) + + + +interpreter0 = (liftM2 (~=?)) + (return (Just ("\n",R)) ) + (interpretString "``cir") + +interpreter1 = (liftM2 (~=?)) + (return (Just ("",I)) ) + (interpretString "`c``s`kr``si`ki") + + + + parserTests :: Test parserTests = TestList [parser0, parser1, parser2, parser3, parser4, parser5, parser6, parser7, parser8 ,parser9, parser10, parser11, parser12] +interpreterTests :: IO Test +interpreterTests = do + t0 <- interpreter0 + t1 <- interpreter1 + return (TestList [t0,t1]) + + + tests :: Test tests = parserTests + + +ioTests :: IO Test +ioTests = interpreterTests + |