-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
650 additions
and
556 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...a-integration-tests/src/test/java/com/regnosys/rosetta/types/RosettaTypeProviderTest.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,65 @@ | ||
package com.regnosys.rosetta.types; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
import org.eclipse.xtext.testing.InjectWith; | ||
import org.eclipse.xtext.testing.extensions.InjectionExtension; | ||
import org.eclipse.xtext.testing.validation.ValidationTestHelper; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import com.regnosys.rosetta.rosetta.expression.RosettaExpression; | ||
import com.regnosys.rosetta.tests.RosettaTestInjectorProvider; | ||
import com.regnosys.rosetta.tests.testmodel.RosettaTestModel; | ||
import com.regnosys.rosetta.tests.testmodel.RosettaTestModelService; | ||
import com.regnosys.rosetta.types.builtin.RBuiltinTypeService; | ||
|
||
@ExtendWith(InjectionExtension.class) | ||
@InjectWith(RosettaTestInjectorProvider.class) | ||
public class RosettaTypeProviderTest { | ||
@Inject | ||
private RosettaTestModelService modelService; | ||
@Inject | ||
private ValidationTestHelper validationTestHelper; | ||
@Inject | ||
private RosettaTypeProvider typeProvider; | ||
@Inject | ||
private CardinalityProvider cardinalityProvider; | ||
@Inject | ||
private RBuiltinTypeService builtins; | ||
|
||
private void assertIsValidWithType(RosettaExpression expr, RMetaAnnotatedType expectedType, boolean expectedIsMulti) { | ||
assertIsValidWithType(expr, NodeModelUtils.findActualNodeFor(expr).getText(), expectedType, expectedIsMulti); | ||
} | ||
private void assertIsValidWithType(RosettaExpression expr, CharSequence originalExpression, RMetaAnnotatedType expectedType, boolean expectedIsMulti) { | ||
validationTestHelper.assertNoIssues(expr); | ||
RMetaAnnotatedType actualType = typeProvider.getRMetaAnnotatedType(expr); | ||
boolean actualIsMulti = cardinalityProvider.isMulti(expr); | ||
|
||
Assertions.assertAll( | ||
() -> Assertions.assertEquals(expectedType, actualType, "Expression: " + originalExpression), | ||
() -> { | ||
if (expectedIsMulti) { | ||
Assertions.assertTrue(actualIsMulti, "Expected multi cardinality. Expression: " + originalExpression); | ||
} else { | ||
Assertions.assertFalse(actualIsMulti, "Expected single cardinality. Expression: " + originalExpression); | ||
} | ||
} | ||
); | ||
} | ||
|
||
@Test | ||
void testRecursiveRuleTypeInference() { | ||
RosettaTestModel model = modelService.toTestModel(""" | ||
namespace test | ||
reporting rule InfiniteRecursion from int: | ||
InfiniteRecursion | ||
"""); | ||
RosettaExpression expr = model.parseExpression("InfiniteRecursion(42)"); | ||
|
||
assertIsValidWithType(expr, builtins.NOTHING_WITH_NO_META, false); | ||
} | ||
} |
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
Oops, something went wrong.