Skip to content

Commit

Permalink
Add test to check type narrowing query
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Jan 17, 2024
1 parent b17b9a4 commit abd842f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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);
}

0 comments on commit abd842f

Please sign in to comment.