Search in sources :

Example 1 with Root_meta_data_PureCollectionData

use of org.finos.legend.pure.generated.Root_meta_data_PureCollectionData in project legend-engine by finos.

the class TestDataCompilationFromGrammar method testPureCollectionDataCompilation.

@Test
public void testPureCollectionDataCompilation() {
    Pair<PureModelContextData, PureModel> result = test("###Pure\n" + "Enum enums::Gender\n" + "{\n" + "  MALE, FEMALE, OTHER\n" + "}\n" + "Class my::Address\n" + "{\n" + "  street : String[1];\n" + "}\n" + "Class my::Person\n" + "{\n" + "  givenNames  : String[*];\n" + "  lastName    : String[1];\n" + "  dateOfBirth : StrictDate[1];\n" + "  timeOfBirth : StrictTime[1];\n" + "  timeOfDeath : DateTime[0..1];\n" + "  isAlive     : Boolean[1];\n" + "  height      : Float[1];\n" + "  girth       : Decimal[1];\n" + "  shoeSize    : Integer[1];\n" + "  score1      : Integer[1];\n" + "  score2      : Float[1];\n" + "  score3      : Decimal[1];\n" + "  gender      : enums::Gender[1];\n" + "  address     : my::Address[1];\n" + "}\n" + "\n" + "###Data\n" + "Data <<meta::pure::profiles::typemodifiers.abstract>> {doc.doc = 'something'} meta::data::MyData\n" + "PureCollection #{\n" + "  data: [\n" + "    ^my::Person(\n" + "      givenNames  = ['Fred', 'William'],\n" + "      lastName    = 'Bloggs',\n" + "      dateOfBirth = %2001-03-12,\n" + "      timeOfBirth = %12:23,\n" + "      timeOfDeath = %2020-09-11T12:56:24.487,\n" + "      isAlive     = false,\n" + "      height      = 1.76,\n" + "      girth       = 0.98D,\n" + "      shoeSize    = 10,\n" + "      score1      = -1,\n" + "      score2      = -1.3,\n" + "      score3      = -1.8D,\n" + "      gender      = enums::Gender.MALE,\n" + "      address     = ^my::Address(street = 'A Road')\n" + "    ),\n" + "    ^my::Person(\n" + "      givenNames  = 'Jane',\n" + "      lastName    = 'Doe',\n" + "      dateOfBirth = %1984-04-22,\n" + "      timeOfBirth = %19:41:21,\n" + "      isAlive     = true,\n" + "      height      = 1.61,\n" + "      girth       = 0.81D,\n" + "      shoeSize    = 4,\n" + "      score1      = -1,\n" + "      score2      = -1.3,\n" + "      score3      = -1.8D,\n" + "      gender      = enums::Gender.FEMALE,\n" + "      address     = ^my::Address(street = 'B Road')\n" + "    )\n" + "  ];\n" + "}#\n");
    PackageableElement element = result.getTwo().getPackageableElement("meta::data::MyData");
    Assert.assertTrue(element instanceof Root_meta_data_DataElement);
    Root_meta_data_DataElement dataElement = (Root_meta_data_DataElement) element;
    Assert.assertTrue(dataElement._data() instanceof Root_meta_data_PureCollectionData);
    Root_meta_data_PureCollectionData pureCollectionData = (Root_meta_data_PureCollectionData) dataElement._data();
    InstanceValue collection = pureCollectionData._collection();
    Assert.assertEquals(2, collection._values().size());
    Assert.assertTrue(collection._values().allSatisfy(SimpleFunctionExpression.class::isInstance));
}
Also used : PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) Root_meta_data_PureCollectionData(org.finos.legend.pure.generated.Root_meta_data_PureCollectionData) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Root_meta_data_DataElement(org.finos.legend.pure.generated.Root_meta_data_DataElement) Test(org.junit.Test)

Aggregations

PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)1 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)1 Root_meta_data_DataElement (org.finos.legend.pure.generated.Root_meta_data_DataElement)1 Root_meta_data_PureCollectionData (org.finos.legend.pure.generated.Root_meta_data_PureCollectionData)1 PackageableElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement)1 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)1 Test (org.junit.Test)1