From 58261b1fc487f4c1e37bd2f37f01b800ed3d4fb8 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Tue, 17 May 2022 12:22:02 +0200 Subject: [PATCH] Add assertions to IntegrationTest --- src/test/scala/IntegrationTest.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/scala/IntegrationTest.scala b/src/test/scala/IntegrationTest.scala index 2674000..75925e1 100644 --- a/src/test/scala/IntegrationTest.scala +++ b/src/test/scala/IntegrationTest.scala @@ -7,73 +7,86 @@ class IntegrationTest extends FunSuite { val ast = (fastparse.parse(("e.m(a)"), hb.dhbw.Parser.classDefinition(_))) //hb.dhbw.TYPE.TYPEClass(ast.get) val result = FJTypeinference.typeinference("class Test extends Object {\n\n}") + assert(result.isRight) println(result) } test("IdMethod"){ val result = FJTypeinference.typeinference("class Test extends Object {\nObject f;\nm(a){return a;}\n}") + assert(result.isRight) println(result) } test("IdMethodRecursive"){ val result = FJTypeinference.typeinference("class Test extends Object {\n Object f;\n m(a, b){return this.m(b, a); }\n}") + assert(result.isRight) println(result) } test("ListAddDefinition"){ val result = FJTypeinference.typeinference("class List extends Object{\n add(a){\n return this;\n}\n}") + assert(result.isRight) println(result.map(Main.prettyPrintAST(_))) } test("constructor.FieldInitialization") { val input = "class List extends Object{\nA f;\n add(a){\n return new List(a);\n}\n}" val result = FJTypeinference.typeinference(input ) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("list.add") { val input = "class List extends Object{\nA f;\n add( a){\n return new List(a);\n}\n}\nclass Test extends Object{\n\nm(a){return a.add(this);}\n}" val result = FJTypeinference.typeinference(input ) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("list.add.2") { val input = "class List extends Object{\n A head;\n List tail;\n add( a){\n return new List(a, this);\n}\nget(){\nreturn this.head;\n}\n}\n\nclass Test extends Object{\nm(a){\nreturn a.add(this).get();\n}\n}" val result = FJTypeinference.typeinference(input ) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("functionClass") { val input = "class SameType extends Object{\nA a;\nA b;\nB c;\nget(){return this.c;}\n}\nclass Function extends Object{\nA ret;\nB param;\napply(a){\nreturn new SameType(this.param, a, this).get().ret;\n}\n\n}" val result = FJTypeinference.typeinference(input ) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("TwoRecursiveMethods") { val input = "class RecursiveMethods extends Object{\n\na1(x){ return this.a2(x);}\na2(y){ return this.a1(y);}}" val result = FJTypeinference.typeinference(input) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("Function.typeAnnotaded") { val input = "\nclass Function extends Object{\nB b;\nB apply(A a){\nreturn this.b;\n}\n\n}" val result = FJTypeinference.typeinference(input) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("Box.Map") { val input = "class Function extends Object{\nB b;\nB apply(A a){\nreturn this.b;\n}\n}\n\n\nclass Box extends Object {\nS val ;\nmap( f ) {\nreturn new Box(f.apply(this.val)) ;\n}\n}" val result = FJTypeinference.typeinference(input) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("PrincipalType") { val input = "\nclass List extends Object{\n A head;\n List tail;\n add( a){\n return new List(a, this);\n }\n get(){\n return this.head;\n }\n}\n\nclass PrincipleType extends Object {\n function(a){\n return a.add(this).get();\n }\n}" val result = FJTypeinference.typeinference(input) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } test("ListExample") { val input = "\n\nclass List extends Object{\n A element;\n List succ; \n add(a){\n return new List(a, this);\n }\n\n}\n\nclass Example extends Object{\n\n test(a){\n return a.add(this);\n }\n}" val result = FJTypeinference.typeinference(input) + assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } }