-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add conformance tests for checking expression #1069
Add conformance tests for checking expression #1069
Conversation
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
} | ||
|
||
function fn1() returns error? { | ||
string a1 = checkpanic (string`${12 + 212 - 0}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we also write some tests using checking expressions inside the string template?
} | ||
|
||
function listConstructor() returns error? { | ||
int[] a1 = checkpanic [1, 2, 3, -0x12, int:MIN_VALUE]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we add test cases like,
int[] a1 = checkpanic [1, 2, 0/0, -0x12, int:MIN_VALUE];
int[] a1 = [1, 2, checkpanic 0/0, -0x12, int:MIN_VALUE];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, checkpanic
is not necessary because 0/0
causes to panic the code. will add this with trap.
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
|
||
function fn() returns error { | ||
io:println("function"); | ||
return error("error1!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return error("error1!"); | |
return error("error!"); |
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
I think we can add few more cases
|
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
mapping-constructor-expr, nil-type, string, function-defn, function-call-expr, union-type, optional-type | ||
|
||
function errorFunction() { | ||
error? x1 = listConstructor(); // @error expected '(int|error)' but found '[int,int,int,int,int]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above.
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
error? x1 = fn1(); // @output 123 | ||
// @output 9223372036854775807 | ||
// @output -9223372036854775808 | ||
// @output 1223617 | ||
// @output -11256097 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables are not used. Can we inline these outputs with io:println
lines. One solution is to introduce a printResult()
function at the bottom and pass the result x1
to it and print it there @SandaruJayawardana @MaryamZi WDYT?
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
class C1 { | ||
C2 c2 = new(); | ||
|
||
public function method1(int i) returns error? { | ||
check self.c2.method2(i); | ||
io:println("No errors"); | ||
} | ||
} | ||
|
||
class C2 { | ||
public int x = 1; | ||
|
||
public function method2(int i) returns error? { | ||
if i == 0 { | ||
return; | ||
} | ||
return error("mothod2"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simplify this test using one object constructor and removing class defn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will check
if i >= 0 { | ||
return i; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the tests as minimalized as possible and remove these logics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. But I think we need a simple logic to verify the functionality of inner and outer check-expr
in this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just returning the error in fn1
and fn2
is enough right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case we cannot test whether the check expression properly work for non-error scenarios.
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/check_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
conformance/lang/expressions/checking-expression/checkpanic_expr.balt
Outdated
Show resolved
Hide resolved
7f6944d
to
d5d1dd8
Compare
Purpose
Related lang issue #34999