49 lines
2.5 KiB
Haskell
49 lines
2.5 KiB
Haskell
module TestLexer(tests) where
|
|
|
|
import Test.HUnit
|
|
import Parser.Lexer
|
|
|
|
|
|
emptyTokenList :: [Token]
|
|
emptyTokenList = []
|
|
testCommentSomething = TestCase $ assertEqual "scan '/*Something*/'" emptyTokenList $ alexScanTokens "/*Something*/"
|
|
testEmptyComment = TestCase $ assertEqual "scan '/*x*/'" emptyTokenList $ alexScanTokens "/**/"
|
|
testLineComment = TestCase $ assertEqual "scan '// comment'" emptyTokenList $ alexScanTokens "// comment"
|
|
testLineCommentEnds = TestCase $ assertEqual "scan '// com\\n'" emptyTokenList $ alexScanTokens "// com\n"
|
|
|
|
testIdentifier = TestCase $ assertEqual "scan 'identifier'" [IDENTIFIER "identifier"] $ alexScanTokens "identifier"
|
|
testShortIdentifier = TestCase $ assertEqual "scan 'i'" [IDENTIFIER "i"] $ alexScanTokens "i"
|
|
testIdentifierWithNumber = TestCase $ assertEqual "scan 'i2'" [IDENTIFIER "i2"] $ alexScanTokens "i2"
|
|
|
|
testKeywordBreak = TestCase $ assertEqual "scan 'break'" [BREAK] $ alexScanTokens "break"
|
|
testKeywordInt = TestCase $ assertEqual "scan 'int'" [INT] $ alexScanTokens "int"
|
|
|
|
testIntLiteral = TestCase $ assertEqual "scan '234'" [INTEGERLITERAL 234] $ alexScanTokens "234"
|
|
testIntLiteral2 = TestCase $ assertEqual "scan '54_2'" [INTEGERLITERAL 542] $ alexScanTokens "54_2"
|
|
|
|
testCharLiteral = TestCase $ assertEqual "scan ''f''" [CHARLITERAL 'f'] $ alexScanTokens "'f'"
|
|
|
|
testBoolLiteralTrue = TestCase $ assertEqual "scan 'true'" [BOOLLITERAL True] $ alexScanTokens "true"
|
|
testBoolLiteralFalse = TestCase $ assertEqual "scan 'false'" [BOOLLITERAL False] $ alexScanTokens "false"
|
|
|
|
testLBrace = TestCase $ assertEqual "scan '('" [LBRACE] $ alexScanTokens "("
|
|
testAnd = TestCase $ assertEqual "scan '&&'" [AND] $ alexScanTokens "&&"
|
|
|
|
tests = TestList [
|
|
TestLabel "TestCommentSomething" testCommentSomething,
|
|
TestLabel "TestEmptyComment" testEmptyComment,
|
|
TestLabel "TestLineComment" testLineComment,
|
|
TestLabel "TestLineCommentEnds" testLineCommentEnds,
|
|
TestLabel "TestIdentifier" testIdentifier,
|
|
TestLabel "TestShortIdentifier" testShortIdentifier,
|
|
TestLabel "TestIdentifierWithNumber" testIdentifierWithNumber,
|
|
TestLabel "TestKeywordBreak" testKeywordBreak,
|
|
TestLabel "TestKeywordInt" testKeywordInt,
|
|
TestLabel "TestIntLiteral" testIntLiteral,
|
|
TestLabel "TestIntLiteral2" testIntLiteral2,
|
|
TestLabel "TestCharLiteral" testCharLiteral,
|
|
TestLabel "TestBoolLiteralTrue" testBoolLiteralTrue,
|
|
TestLabel "TestBoolLiteralFalse" testBoolLiteralFalse,
|
|
TestLabel "TestLBrace" testLBrace,
|
|
TestLabel "TestAnd" testAnd
|
|
] |