summaryrefslogtreecommitdiff
path: root/src/Thue/Test.hs
blob: be4e38b581f10a147a48ec48454a12886bfd8a0f (plain)
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
module Thue.Test (
	parserTests,
	extractInfixTests,
	tests
    ) where


import Test.HUnit
import Text.Parsec.Error
import Thue.Parser
import Thue.Interpreter


instance Eq Text.Parsec.Error.ParseError




parser0 = (Right (ThueProgram [ThueRule (tStr "a") (tStr "b")] (tStr "a") Ver1) ) ~=? (parseThue "a::=b\n::=\na")

parser1 = (Right (ThueProgram [] (tStr "b") Ver1) ) ~=? (parseThue "::=\nb")



extractInfix0 = Nothing ~=? (extractInfix [1,2] [3,4,5])

extractInfix1 = (Just ([1,2],[5,6])) ~=? (extractInfix [3,4] [1,2,3,4,5,6])

extractInfix2 = (Just ([],[3,4])) ~=? (extractInfix [0,1,2] [0,1,2,3,4])

extractInfix3 = (Just ([1],[])) ~=? (extractInfix [2,3] [1,2,3])

extractInfix4 = (Just ([],[1])) ~=? (extractInfix [] [1])

extractInfix5 = (Just ("before","after")) ~=? (extractInfix "middle" "beforemiddleafter")



parserTests :: Test
parserTests = TestList [parser0, parser1]



extractInfixTests :: Test
extractInfixTests = TestList [extractInfix0, extractInfix1, extractInfix2, extractInfix3, extractInfix4, extractInfix5]



tests :: Test
tests = case (parserTests, extractInfixTests) of
	(TestList a, TestList b) -> TestList (a ++ b)