-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c9cc32
commit 531fbf2
Showing
3 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ina-unit-test/src/test/java/org/ballerinalang/test/record/RecordDefaultFunctionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.ballerinalang.test.record; | ||
|
||
import org.ballerinalang.test.BCompileUtil; | ||
import org.ballerinalang.test.BRunUtil; | ||
import org.ballerinalang.test.CompileResult; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Test cases for record default functions in Ballerina. | ||
*/ | ||
public class RecordDefaultFunctionsTest { | ||
|
||
private CompileResult compileResult; | ||
|
||
@BeforeClass | ||
public void setup() { | ||
compileResult = BCompileUtil.compile("test-src/record/record_default_functions.bal"); | ||
} | ||
|
||
@Test(description = "Test record type with function invocations for default values") | ||
public void testRecordWithDefaultFunction() { | ||
Object returns = BRunUtil.invoke(compileResult, "recordDefaultFunctionWithArgument"); | ||
Object returns2 = BRunUtil.invoke(compileResult, "recordDefaultFunction"); | ||
Assert.assertNotNull(returns); | ||
Assert.assertNotNull(returns2); | ||
} | ||
|
||
@AfterClass | ||
public void tearDown() { | ||
compileResult = null; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/jballerina-unit-test/src/test/resources/test-src/record/record_default_functions.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
isolated function getAsInt(string s) returns int { | ||
return 777; | ||
} | ||
|
||
type Bar record { | ||
int a = getAsInt("777"); | ||
}; | ||
|
||
function recordDefaultFunctionWithArgument() returns Bar { | ||
return {}; | ||
} | ||
|
||
isolated function returnString() returns string { | ||
return "hello"; | ||
} | ||
|
||
type Foo record { | ||
string b = returnString(); | ||
}; | ||
|
||
function recordDefaultFunction () returns Foo { | ||
return {}; | ||
} |