-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParserTests.hs
43 lines (32 loc) · 1.06 KB
/
ParserTests.hs
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
{-# LANGUAGE OverloadedStrings #-}
module ParserTests (allTests, main) where
import qualified Prelude as P
import Common
import Tests
import AST
import Parser (parse, toExpr, Expr(..))
-- I write this way too many times
e = toExpr
type ETest = Test String Expr
foo, bar, baz, qux, one, two, three :: Expr
[foo, bar, baz, qux] = e . Variable <$> ["foo", "bar", "baz", "qux"]
[one, two, three] = e . Number <$> [1, 2, 3]
test desc input res = Test desc input (e res)
termTests :: ETest
termTests = TestGroup "Terms" [
]
forInTests :: ETest
forInTests = TestGroup "For statements" tests where
tests =
[
test "basic" "for foo in bar\n baz" (ForIn ["foo"] bar baz)
, test "basic one-line" "for foo in bar then baz" (ForIn ["foo"] bar baz)
, test "nested via one-line" "for foo in bar do for baz in qux do 1"
(ForIn ["foo"] bar $ e (ForIn ["baz"] qux one))
]
doTests :: IO TesterState
doTests = runTests parse [ forInTests ]
allTests :: [TesterState -> IO TesterState]
allTests = [run parse [forInTests]]
main :: IO ()
main = doTests >> return ()