{-# OPTIONS -fglasgow-exts -fth -fno-monomorphism-restriction #-} -- |Tests for the Term module module QuicQuid.TermTest(t) where -- import Data.List import Data.Maybe import qualified Data.Map as M import Test.SmallCheck hiding(test) import Data.DeriveTH import Data.Derive.Arbitrary import Data.Derive.Serial import QuicQuid.Test import QuicQuid.Term $( derive makeSerial ''Term ) t = do putStrLn "Test that any possible term can be rendered and parsed back to itself." smallCheck 2 prop_parse testShowJSON1 -- |Any possible term can be rendered in the canonical format and parsed back to itself. prop_parse :: Term -> Bool prop_parse tr = let r = parse (showCanonical tr); Just v = r in isJust r && v == tr --prop_parse2 s = isJust (parse s) => (sh1 tr) in tr2 == tr -- TODO: complete testShowJSON1 = run $ tests "testShowJSON1" chk [ t2 "null" "null" ,t2 "[12,abc]" "[12,\"abc\"]" ,t2 "true" "true" ,t2 "false" "false" ,t2 "abc" "\"abc\"" ,t2 "\"abc\"" "\"abc\"" ,t2 "34.5" "34.5" ,t2 "(random new) (integer ?r)" "{\"t\":\"a\",\"v\":[{\"t\":\"a\",\"v\":[\"random\",\"new\"]},{\"t\":\"a\",\"v\":[\"integer\",{\"t\":\"v\",\"v\":\"r\"}]}]}" ,t2 "?xyz" "{\"t\":\"v\",\"v\":\"xyz\"}" ,t2 "f 11" "{\"t\":\"a\",\"v\":[\"f\",11]}" ,t2 "{ab:2,cd:s(2)}" "{\"t\":\"o\",\"v\":{\"ab\":2,\"cd\":{\"t\":\"a\",\"v\":[\"s\",2]}}}" ] where chk (canonical,js) = assertEqual "showJSON1" js (showJSON1.fromJust.parse $ canonical)