From abd842faa2b24e9f2dbee7bec85e09ca4e5a3d9d Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Tue, 5 Dec 2023 14:31:38 +0530 Subject: [PATCH] Add test to check type narrowing query --- .../tests/retry_transaction_stmt.bal | 23 +++++++++++++++++++ .../tests/transaction_stmt.bal | 20 ++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/transaction-ballerina/tests/retry_transaction_stmt.bal b/transaction-ballerina/tests/retry_transaction_stmt.bal index 37bad085..96518b74 100644 --- a/transaction-ballerina/tests/retry_transaction_stmt.bal +++ b/transaction-ballerina/tests/retry_transaction_stmt.bal @@ -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); +} diff --git a/transaction-ballerina/tests/transaction_stmt.bal b/transaction-ballerina/tests/transaction_stmt.bal index 050e1149..926c70e1 100644 --- a/transaction-ballerina/tests/transaction_stmt.bal +++ b/transaction-ballerina/tests/transaction_stmt.bal @@ -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); +}