2024-05-02 20:33:35 +00:00
|
|
|
module TestParser(tests) where
|
|
|
|
|
|
|
|
import Test.HUnit
|
|
|
|
import Parser.Lexer
|
|
|
|
import Parser.JavaParser
|
2024-05-03 13:47:41 +00:00
|
|
|
import Ast
|
2024-05-02 20:33:35 +00:00
|
|
|
|
|
|
|
|
2024-05-03 13:47:41 +00:00
|
|
|
testSingleEmptyClass = TestCase $
|
|
|
|
assertEqual "expect single empty class hello" [Class "Hello" [] []] $
|
|
|
|
parse [CLASS, IDENTIFIER "Hello", LBRACKET, RBRACKET]
|
|
|
|
testTwoEmptyClasses = TestCase $
|
|
|
|
assertEqual "expect two empty classes" [Class "Class1" [] [], Class "Class2" [] []] $
|
|
|
|
parse [CLASS,IDENTIFIER "Class1",LBRACKET,RBRACKET,CLASS,IDENTIFIER "Class2",LBRACKET,RBRACKET]
|
2024-05-03 15:47:59 +00:00
|
|
|
testBooleanField = TestCase $
|
|
|
|
assertEqual "expect class with boolean field" [Class "WithBool" [] [VariableDeclaration "boolean" "value" Nothing]] $
|
|
|
|
parse [CLASS,IDENTIFIER "WithBool",LBRACKET,BOOLEAN,IDENTIFIER "value",SEMICOLON,RBRACKET]
|
|
|
|
testIntField = TestCase $
|
|
|
|
assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $
|
|
|
|
parse [CLASS,IDENTIFIER "WithInt",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,RBRACKET]
|
2024-05-06 08:16:57 +00:00
|
|
|
testCustomTypeField = TestCase $
|
|
|
|
assertEqual "expect class with foo field" [Class "WithFoo" [] [VariableDeclaration "Foo" "value" Nothing]] $
|
|
|
|
parse [CLASS,IDENTIFIER "WithFoo",LBRACKET,IDENTIFIER "Foo",IDENTIFIER "value",SEMICOLON,RBRACKET]
|
2024-05-06 08:33:37 +00:00
|
|
|
testMultipleDeclarationSameLine = TestCase $
|
|
|
|
assertEqual "expect class with two int fields" [Class "TwoInts" [] [VariableDeclaration "int" "num1" Nothing, VariableDeclaration "int" "num2" Nothing]] $
|
|
|
|
parse [CLASS,IDENTIFIER "TwoInts",LBRACKET,INT,IDENTIFIER "num1",COMMA,IDENTIFIER "num2",SEMICOLON,RBRACKET]
|
|
|
|
testMultipleDeclarations = TestCase $
|
|
|
|
assertEqual "expect class with int and char field" [Class "Multiple" [] [VariableDeclaration "int" "value" Nothing, VariableDeclaration "char" "letter" Nothing]] $
|
|
|
|
parse [CLASS,IDENTIFIER "Multiple",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,CHAR,IDENTIFIER "letter",SEMICOLON,RBRACKET]
|
2024-05-06 08:09:50 +00:00
|
|
|
testWithModifier = TestCase $
|
|
|
|
assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $
|
|
|
|
parse [ABSTRACT,CLASS,IDENTIFIER "WithInt",LBRACKET,PUBLIC,INT,IDENTIFIER "value",SEMICOLON,RBRACKET]
|
2024-05-02 20:33:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
tests = TestList [
|
2024-05-03 13:47:41 +00:00
|
|
|
testSingleEmptyClass,
|
2024-05-03 15:47:59 +00:00
|
|
|
testTwoEmptyClasses,
|
|
|
|
testBooleanField,
|
2024-05-06 08:16:57 +00:00
|
|
|
testIntField,
|
2024-05-06 08:33:37 +00:00
|
|
|
testCustomTypeField,
|
2024-05-06 08:09:50 +00:00
|
|
|
testMultipleDeclarations,
|
|
|
|
testWithModifier
|
2024-05-02 20:33:35 +00:00
|
|
|
]
|