From 49d997a61cee30ffa11f76ba4d7d82ef3d4cdf0f Mon Sep 17 00:00:00 2001 From: Sahil Shah Date: Wed, 22 Nov 2023 10:24:56 +0000 Subject: [PATCH] fix mastery composer - extra comma being added (#2469) --- .../to/HelperMasteryGrammarComposer.java | 2 +- .../TestMasteryCompilationFromGrammar.java | 67 +++++++++++++++++++ .../test/TestMasteryGrammarRoundtrip.java | 6 ++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/main/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/to/HelperMasteryGrammarComposer.java b/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/main/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/to/HelperMasteryGrammarComposer.java index 39f33ca4252..bc007bc9631 100644 --- a/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/main/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/to/HelperMasteryGrammarComposer.java +++ b/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/main/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/to/HelperMasteryGrammarComposer.java @@ -252,7 +252,7 @@ private static String renderPrecedenceRules(List precedenceRules { String precedenceRuleString = precedenceRule.accept(new PrecedenceRuleComposer(indentLevel + 1, context, uniqueSourcePrecedenceRules)); nonSourcePrecedenceRulesBuilder.append(precedenceRuleString); - nonSourcePrecedenceRulesBuilder.append(i < precedenceRules.size() && !precedenceRuleString.equals("") ? "," : ""); + nonSourcePrecedenceRulesBuilder.append(i < precedenceRules.size() - 1 && !precedenceRuleString.equals("") ? "," : ""); }); return combinePrecedenceRules(uniqueSourcePrecedenceRules, nonSourcePrecedenceRulesBuilder.toString(), indentLevel); } diff --git a/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/compiler/test/TestMasteryCompilationFromGrammar.java b/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/compiler/test/TestMasteryCompilationFromGrammar.java index f93c109d262..850329abd7c 100644 --- a/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/compiler/test/TestMasteryCompilationFromGrammar.java +++ b/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/compiler/test/TestMasteryCompilationFromGrammar.java @@ -373,6 +373,60 @@ public class TestMasteryCompilationFromGrammar extends TestCompilationFromGramma " }#;\n" + "}\n"; + public static String MASTERY_MODEL_WITH_ONE_RULE = "###Pure\n" + + "Class org::dataeng::Widget\n" + + "{\n" + + " widgetId: String[0..1];\n" + + " identifiers: org::dataeng::MilestonedIdentifier[*];\n" + + "}\n\n" + + "Class org::dataeng::MilestonedIdentifier\n" + + "{\n" + + " identifierType: String[1];\n" + + " identifier: String[1];\n" + + " FROM_Z: StrictDate[0..1];\n" + + " THRU_Z: StrictDate[0..1];\n" + + "}\n\n\n" + + MAPPING_AND_CONNECTION + + "###Service\n" + + "Service org::dataeng::ParseWidget\n" + WIDGET_SERVICE_BODY + "\n" + + "Service org::dataeng::TransformWidget\n" + WIDGET_SERVICE_BODY + "\n" + + "\n" + + "###Mastery\n" + "MasterRecordDefinition alloy::mastery::WidgetMasterRecord" + + "\n" + + "{\n" + + " modelClass: org::dataeng::Widget;\n" + + " identityResolution: \n" + + " {\n" + + " resolutionQueries:\n" + + " [\n" + + " {\n" + + " queries: [ {input: org::dataeng::Widget[1]|org::dataeng::Widget.all()->filter(widget|$widget.widgetId == $input.widgetId)}\n" + + " ];\n" + + " precedence: 1;\n" + + " }\n" + + " ]\n" + + " }\n" + + " precedenceRules: [\n" + + " DeleteRule: {\n" + + " path: org::dataeng::Widget.identifiers.identifier;\n" + + " ruleScope: [\n" + + " RecordSourceScope {widget-producer}\n" + + " ];\n" + + " }\n" + + " ]\n" + + " recordSources:\n" + + " [\n" + + " widget-producer: {\n" + + " description: 'REST Acquisition source.';\n" + + " status: Development;\n" + + " recordService: {\n" + + " acquisitionProtocol: REST;\n" + + " };\n" + + " trigger: Manual;\n" + + " }\n" + + " ]\n" + + "}\n"; + public static String MINIMUM_CORRECT_MASTERY_MODEL = "###Pure\n" + "Class org::dataeng::Widget\n" + "{\n" + @@ -926,6 +980,19 @@ public void testMasteryMinimumCorrectModel() assertEquals("Widget", masterRecordDefinition._modelClass()._name()); } + @Test + public void testMasteryModelWithOneRule() + { + Pair result = test(MASTERY_MODEL_WITH_ONE_RULE); + PureModel model = result.getTwo(); + + PackageableElement packageableElement = model.getPackageableElement("alloy::mastery::WidgetMasterRecord"); + assertNotNull(packageableElement); + assertTrue(packageableElement instanceof Root_meta_pure_mastery_metamodel_MasterRecordDefinition); + Root_meta_pure_mastery_metamodel_MasterRecordDefinition masterRecordDefinition = (Root_meta_pure_mastery_metamodel_MasterRecordDefinition) packageableElement; + assertEquals(1, masterRecordDefinition._precedenceRules().size()); + } + @Test public void testMasteryDeprecatedModelCanStillCompile() { diff --git a/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/test/TestMasteryGrammarRoundtrip.java b/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/test/TestMasteryGrammarRoundtrip.java index 36a6e0a74f6..94ead970261 100644 --- a/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/test/TestMasteryGrammarRoundtrip.java +++ b/legend-engine-xts-mastery/legend-engine-xt-mastery-grammar/src/test/java/org/finos/legend/engine/language/pure/dsl/mastery/grammar/test/TestMasteryGrammarRoundtrip.java @@ -27,6 +27,12 @@ public void masteryRoundTripFull() testWithSectionInfoPreserved(TestMasteryCompilationFromGrammar.COMPLETE_CORRECT_MASTERY_MODEL); } + @Test + public void masteryRoundTripWithOneRule() + { + testWithSectionInfoPreserved(TestMasteryCompilationFromGrammar.MASTERY_MODEL_WITH_ONE_RULE); + } + @Test public void masteryRoundTripMinimum() {