added methodcall and assigment test
This commit is contained in:
parent
b040130569
commit
acab0add95
@ -72,6 +72,24 @@ exampleBlockResolutionFail = Block [
|
|||||||
StatementExpressionStatement (MethodCall (Reference "bob") "setAge" [IntegerLiteral 30])
|
StatementExpressionStatement (MethodCall (Reference "bob") "setAge" [IntegerLiteral 30])
|
||||||
]
|
]
|
||||||
|
|
||||||
|
exampleMethodCallAndAssignment :: Statement
|
||||||
|
exampleMethodCallAndAssignment = Block [
|
||||||
|
LocalVariableDeclaration (VariableDeclaration "Person" "bob" (Just (StatementExpressionExpression (ConstructorCall "Person" [IntegerLiteral 30])))),
|
||||||
|
LocalVariableDeclaration (VariableDeclaration "int" "age" (Just (StatementExpressionExpression (MethodCall (Reference "bob") "getAge" [])))),
|
||||||
|
StatementExpressionStatement (MethodCall (Reference "bob") "setAge" [IntegerLiteral 30]),
|
||||||
|
LocalVariableDeclaration (VariableDeclaration "int" "a" Nothing),
|
||||||
|
StatementExpressionStatement (Assignment "a" (Reference "age"))
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
exampleMethodCallAndAssignmentFail :: Statement
|
||||||
|
exampleMethodCallAndAssignmentFail = Block [
|
||||||
|
LocalVariableDeclaration (VariableDeclaration "Person" "bob" (Just (StatementExpressionExpression (ConstructorCall "Person" [IntegerLiteral 30])))),
|
||||||
|
LocalVariableDeclaration (VariableDeclaration "int" "age" (Just (StatementExpressionExpression (MethodCall (Reference "bob") "getAge" [])))),
|
||||||
|
StatementExpressionStatement (MethodCall (Reference "bob") "setAge" [IntegerLiteral 30]),
|
||||||
|
StatementExpressionStatement (Assignment "a" (Reference "age"))
|
||||||
|
]
|
||||||
|
|
||||||
runTypeCheck :: IO ()
|
runTypeCheck :: IO ()
|
||||||
runTypeCheck = do
|
runTypeCheck = do
|
||||||
catch (do
|
catch (do
|
||||||
@ -123,3 +141,17 @@ runTypeCheck = do
|
|||||||
printResult "Result Block Resolution:" evaluatedBlockResolutionFail
|
printResult "Result Block Resolution:" evaluatedBlockResolutionFail
|
||||||
) handleError
|
) handleError
|
||||||
|
|
||||||
|
catch (do
|
||||||
|
print "====================================================================================="
|
||||||
|
evaluatedMethodCallAndAssignment <- evaluate (typeCheckStatement exampleMethodCallAndAssignment [] sampleClasses)
|
||||||
|
printSuccess "Type checking of method call and assignment completed successfully"
|
||||||
|
printResult "Result Method Call and Assignment:" evaluatedMethodCallAndAssignment
|
||||||
|
) handleError
|
||||||
|
|
||||||
|
catch (do
|
||||||
|
print "====================================================================================="
|
||||||
|
evaluatedMethodCallAndAssignmentFail <- evaluate (typeCheckStatement exampleMethodCallAndAssignmentFail [] sampleClasses)
|
||||||
|
printSuccess "Type checking of method call and assignment failed"
|
||||||
|
printResult "Result Method Call and Assignment:" evaluatedMethodCallAndAssignmentFail
|
||||||
|
) handleError
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user