Skip to content

Commit

Permalink
Merge branch 'tests' of https://github.com/k2d222/turbo_katana into t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
OopsOverflow committed Jan 10, 2022
2 parents d768051 + 39931cd commit 2dfac9f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 16 deletions.
10 changes: 5 additions & 5 deletions doc/contextual_checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@

* No Return instruction ✔
* No reserved keyword in params ✔
* Constructor name and class name are equal
* Constructor parameters and class parameters are equal
* Constructor name and class name are equal
* Constructor parameters and class parameters are equal
* Constructor calls the right super constructor if class is derived
* Constructor does not call any super constructor if class is base

## Instructions

* Perform expression checks for Expr, Ite, Return and Assign
* --
* No reserved keyword declared in Block instructions
* No reserved keyword declared in Block instructions
* Can only Assign to idents, attributes or static attributes
* Assign rhs is compatible with lhs
* Expression in an Ite instruction is of type Integer

## Expressions

* Called method exists
* Called method params are compatible with declaration
* Called method exists
* Called method params are compatible with declaration
* Called static method exists in static class
* Called static method params are compatible with declaration
* Call to New exists
Expand Down
101 changes: 90 additions & 11 deletions test/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ let%test "no-class-inherits-reserved" =
|}
in List.for_all reserved ~f:(fun r -> expects_ctx_err (code r))

let%test "underclared_variable" =
let%test "no-undeclared-variable" =
expects_ctx_err {|
{p1 := 51;}
|}
let%test "unmatched-type" =

let%test "no-unmatched-type" =
expects_ctx_err {|
class Point1() is {
def Point1() is {}
Expand All @@ -37,16 +37,35 @@ let%test "unmatched-type" =
}
|}

let%test "compatible-types" =
expects_ast {|
class Base() is {
def Base() is {}
}

class Derived() extends Base is {
def Derived() : Base() is {}
}

{
p1: Base
p2: Derived
is
p1 := p2;
}
|}

let%test "no-reserved-keyword-in-method-params" =
let reserved = [ "this"; "super"; "result" ]
in let code = Printf.sprintf {|
class Test() is {
def Test() is {}
def testMethod(%s : Integer) : Integer is {}
def testMethod(%s : Integer) : Integer is { return 0; }
}
{}
|}
in List.for_all reserved ~f:(fun r -> expects_ctx_err (code r))
&& expects_ast (code "foo")

let%test "no-reserved-keyword-in-attributes" =
let reserved = [ "this"; "super"; "result" ]
Expand All @@ -59,13 +78,15 @@ let%test "no-reserved-keyword-in-attributes" =

|}
in List.for_all reserved ~f:(fun r -> expects_ctx_err (code r))
&& expects_ast (code "foo")

let%test "no-reserved-keyword-in-instructions" =
let reserved = [ "this"; "super"; "result" ]
in let code = Printf.sprintf {|
{%s : Integer is {}}
|}
in List.for_all reserved ~f:(fun r -> expects_ctx_err (code r))
&& expects_ast (code "foo")

let%test "no-duplicate-class-declaration" =
expects_ctx_err {|
Expand All @@ -89,6 +110,7 @@ let%test "no-reserved-class-name" =
{}
|}
in List.for_all reserved ~f:(fun r -> expects_ctx_err (code r r))
&& expects_ast (code "Foo" "Foo")

let%test "no-duplicate-static-attribute-declaration" =
expects_ctx_err {|
Expand All @@ -105,8 +127,8 @@ let%test "no-duplicate-static-method-declaration" =
expects_ctx_err {|
class Point1() is {
def Point1() is {}
def static static1() : Integer is {return 0;}
def static static1() : String is {return "";}
def static static1() : Integer is { return 0; }
def static static1() : String is { return ""; }
}
{}
|}
Expand Down Expand Up @@ -134,18 +156,18 @@ let%test "no-duplicate-instance-method-declaration" =
let%test "herited-class-exists" =
expects_ctx_err {|
class Point1() extends Point2 is {
def Point1() is {}
def Point1() : Point2() is {}
}
{}
|}

let%test "no-cycle-in-inheritance-graph" =
expects_ctx_err {|
class Point1() extends Point2 is {
def Point1() is {}
def Point1() : Point2() is {}
}
class Point2() extends Point1 is {
def Point2() is {}
def Point2() : Point1() is {}
}
{}
|}
Expand All @@ -166,7 +188,7 @@ let%test "override-methods-have-the-override-keyword" =
def test() is {}
}
class Point2() extends Point1 is {
def Point2() is {}
def Point2() : Point1() is {}
def test() is {}
}
{}
Expand All @@ -179,7 +201,7 @@ let%test "override-methods-match-the-overriden-method-signature" =
def test(i : Integer) is {}
}
class Point2() extends Point1 is {
def Point2() is {}
def Point2() : Point1() is {}
def override test(i1, i2 : Integer) is {}
}
{}
Expand All @@ -205,3 +227,60 @@ let%test "no-reserved-keyword-in-constructor-params" =
|}
in List.for_all reserved ~f:(fun r -> expects_ctx_err (code r r))

let%test "constructor-name-and-class-name-are-equal" =
expects_ctx_err {|
class Point1() is {
def Point2() is {}
}
{}
|}

let%test "constructor-parameters-and-class-parameters-are-equal" =
expects_ctx_err {|
class Point1(i : Integer) is {
def Point1(i : String) is {}
}
{}
|}


let%test "no-reserved-keyword-declared-in-Block-instructions" =
let reserved = [ "this"; "super"; "result" ]
in let code = Printf.sprintf {|
{
%s : Integer is {}
}
|}
in List.for_all reserved ~f:(fun r -> expects_ctx_err (code r))


let%test "called-method-exists" =
expects_ctx_err {|
class Point1() is {
def Point1() is {}
}
{p : Point1
is
p.test();}
|}

let%test "called-method-exists" =
expects_ctx_err {|
class Point1() is {
def Point1() is {}
}
{p : Point1
is
p.test();}
|}

let%test "called-method-params-are-compatible-with-declaration" =
expects_ctx_err {|
class Point1() is {
def Point1() is {}
def test(i : Integer) is {}
}
{p : Point1
is
p.test();}
|}

0 comments on commit 2dfac9f

Please sign in to comment.