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 unit test for compilation issue - func add list from alias #842

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5032,6 +5032,81 @@ class FunctionGeneratorTest {
assertThat(foos, hasItems(foo1, foo2, foo3, foo4)); // appends to existing list
}

@Test
def void shouldAddComplexTypeListWithIfStatement() {
val model = '''
type Bar:
foos Foo (0..*)

type Foo:
attr string (1..1)

func FuncFoo:
inputs:
newFoos Foo (0..*)
test boolean (1..1)
output:
bar Bar (1..1)

add bar -> foos:
if test
then newFoos
'''
val code = model.generateCode
val classes = code.compileToClasses
val func = classes.createFunc("FuncFoo");

val foo1 = classes.createFoo("1")
val foo2 = classes.createFoo("2")

val res = func.invokeFunc(RosettaModelObject, newArrayList(foo1, foo2), true)

// reflective Bar.getFoos()
val foos = res.class.getMethod("getFoos").invoke(res) as List<RosettaModelObject>;

assertEquals(2, foos.size);
assertThat(foos, hasItems(foo1, foo2)); // appends to existing list
}

@Test
@Disabled
def void shouldAddComplexTypeListAliasWithIfStatement() {
val model = '''
type Bar:
foos Foo (0..*)

type Foo:
attr string (1..1)

func FuncFoo:
inputs:
newFoos Foo (0..*)
test boolean (1..1)
output:
bar Bar (1..1)

alias filteredFoos: newFoos

add bar -> foos:
if test
then filteredFoos
'''
val code = model.generateCode
val classes = code.compileToClasses
val func = classes.createFunc("FuncFoo");

val foo1 = classes.createFoo("1")
val foo2 = classes.createFoo("2")

val res = func.invokeFunc(RosettaModelObject, newArrayList(foo1, foo2), true)

// reflective Bar.getFoos()
val foos = res.class.getMethod("getFoos").invoke(res) as List<RosettaModelObject>;

assertEquals(2, foos.size);
assertThat(foos, hasItems(foo1, foo2)); // appends to existing list
}

@Test
def void shouldSetComplexTypeList() {
val model = '''
Expand Down