File: TestExamples.hs

package info (click to toggle)
haskell-src-meta 0.8.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: haskell: 1,877; makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{-# LANGUAGE QuasiQuotes     #-}
{-# LANGUAGE TemplateHaskell #-}

import qualified BF
import qualified Hs
import qualified HsHere
import qualified SKI

import SKI (SKI (I, K, S, (:$)))

-- Very dumb test framework
shouldBe :: (Show a, Eq a) => a -> a -> IO ()
actual `shouldBe` expected = case actual == expected of
  True -> return ()
  False -> do
    putStr "Expected: "
    print expected
    putStr "Actual: "
    print actual
    fail "Expectation failure"


a :: Int -> String
a x = [HsHere.here| random "text" $(x + 1)
  something else|]

hereTest :: IO ()
hereTest = do
 a 3 `shouldBe` (" random \"text\" "++ show (3 + 1 :: Int) ++"\n  something else")

-- TODO: better test exercising the bf quasiquoter

bfTest :: IO ()
bfTest = do
  BF.eval_ (BF.parse BF.bfHelloWorld) "" `shouldBe` "Hello World!\n"

hsTest :: IO ()
hsTest = do
  (\ [Hs.hs|b@(x,_)|] -> [Hs.hs|(b,x)|]) (42 :: Int,88 :: Int) `shouldBe` ((42,88),42)

-- TODO: better test exercising the ski quasiquoter

skiTest :: IO ()
skiTest = do
  SKI.parse "S(SS)IK(SK)" `shouldBe` ([(((S :$ (S :$ S)) :$ I) :$ K) :$ (S :$ K)],"")

main :: IO ()
main = do
  putStrLn ""
  hereTest
  bfTest
  hsTest
  skiTest