Skip to content
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 tests to check the type narrowing of a query in a transaction scenario #530

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions transaction-ballerina/tests/retry_transaction_stmt.bal
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,26 @@ function getPrevInfoInNested() returns string|error {
}
return str;
}

@test:Config
function testTypeNarrowingQueryWithRetry() {
int? i = 3;
int|int[] result;

transaction {
if i is () {
any|error out = commit;
} else {
rollback;
}
}

retry {
result = i is int ?
from var _ in [1, 2]
where i + 2 == 5
select 2 : 2;
}

test:assertEquals([2, 2], result);
}
20 changes: 20 additions & 0 deletions transaction-ballerina/tests/transaction_stmt.bal
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,23 @@ function testBreakWithinTransactionToOuterLoop() {
test:assertEquals(str, "Loop continued with digit: 1 ->Loop continued with digit: 2 " +
"->Loop continued with digit: 3 ->Loop broke with digit: 4");
}

@test:Config
function testTypeNarrowingQueryWithTransaction() {
int? i = 3;
int|int[] result;

transaction {
if i is () {
result = 2;
any|error out = commit;
} else {
result = i is int ?
from var _ in [1, 2]
where i + 2 == 5
select 2 : 2;
}
}

test:assertEquals([2, 2], result);
}
Loading