-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParserTest.hs
100 lines (75 loc) · 3.5 KB
/
ParserTest.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{- Test the Parser-Module-}
module ParserTest where
import Test.HUnit
import Parser
a = TestCase (assertEqual "parse char"
[('a',"b")]
(atom 'a' "ab"))
b = TestCase (assertEqual "parse char"
[]
(atom 'b' "ab"))
ab = TestCase (assertEqual "parse ab next"
[("ab", "c")]
(next (atom 'a') (atom 'b') (\ a b -> [a, b]) "abc" ))
aaltb = TestCase (assertEqual "parse alt"
[('b', "xx")]
(alt (atom 'a') (atom 'b') "bxx"))
digit = TestCase (assertEqual "parse digit"
[(3, "aaa")]
(parseDigit "3aaa"))
number = TestCase (assertEqual "parse Number"
[(1, "23"), (12, "3"), (123,"")]
(parseNumber "123"))
calc = TestCase (assertEqual "calculation"
[(4, "")]
(parseCalc "2+2"))
filtertest = TestCase(assertEqual "filter" [(True, "")]
(pFilter id (alts [always True, always False] ) ""))
longsyntax = TestCase (assertEqual "long"
[("yo","")]
(next (next (next (atom 'a') (atom 'b') f)
(atom 'c')
id)
(atom 'd')
id
"abcd"))
where f a b c d = "yo"
testnext4 = TestCase (assertEqual "next4"
[("yo","")]
(next4 (atom 'a')
(atom 'b')
(atom 'c')
(atom 'd')
(\ a b c d -> "yo")
"abcd"))
testatoms = TestCase (assertEqual "testatoms"
[("abcd","")]
(atoms "abcd" "abcd"))
testrrepeat = TestCase (assertEqual "testrepeat"
[("a a a","")]
(norest (prrepeat (\a b c -> a:(' ':c))
(\ a -> [a])
(atom 'a')
(atom ','))
"a,a,a"))
testpsep = TestCase (assertEqual "testsep"
[("aaa","")]
(norest (pSep (atom 'a') (atom ',')) "a,a,a"))
testkommasep = TestCase (assertEqual "testkommasep"
[("aaa","")]
(norest (pKommaSep (atom 'a')) "a , a,a"))
testNextP = TestCase (
assertEqual "testNextP"
[("bbbb","b")]
(nextP (some (atom 'a'))
(\as -> atoms (replicate (2*(length as)) 'b'))
"aabbbbb"))
testLeftRec = TestCase (
assertEqual "testLeftRec"
[(0, "")]
(norest (pLeftRecur parseNumber
(next (atom '-') parseNumber (\ _ s a-> a-s))
(\d f -> f d))
"10-5-5"))
runall = runTestTT ( "AllTests" ~: test testLst )
where testLst = [a,b, ab, aaltb, digit, number, calc, longsyntax, filtertest, testnext4, testatoms, testrrepeat, testpsep, testkommasep, testNextP, testLeftRec]