Skip to content

Commit

Permalink
uplift function test grammar (#2537)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Jan 12, 2024
1 parent f0bdb87 commit aec5a5f
Show file tree
Hide file tree
Showing 16 changed files with 477 additions and 699 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ private static Root_meta_legend_function_metamodel_StoreTestData buildFunctionTe
private static Root_meta_legend_function_metamodel_ParameterValue processFunctionTestParameterValue(ParameterValue parameterValue, CompileContext context)
{
Root_meta_legend_function_metamodel_ParameterValue pureParameterValue = new Root_meta_legend_function_metamodel_ParameterValue_Impl("", null, context.pureModel.getClass("meta::legend::function::metamodel::ParameterValue"));
if (parameterValue.name == null || parameterValue.name.isEmpty())
{
throw new EngineException("No associated parameter found for value.", parameterValue.sourceInformation, EngineErrorType.COMPILATION);
}
pureParameterValue._name(parameterValue.name);
pureParameterValue._value(Lists.immutable.with(parameterValue.value.accept(new ValueSpecificationBuilder(context, Lists.mutable.empty(), new ProcessingContext("")))));
return pureParameterValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,314 +29,81 @@ public void testFunctionTest()
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" testSuite_1:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testFail:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" },\n" +
" testPass:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n");

test("function model::MyFunc(): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" testSuite_1:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" },\n" +
" testDuplicate:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n", "COMPILATION error at [6:3-43:3]: Multiple tests found with ids : 'testDuplicate'");
" testSuite1\n" +
" (\n" +
" testFail | MyFunc() => (JSON) '[]';\n" +
" testPass | MyFunc() => (JSON) '[]';\n" +
" )\n" +
" testFail | MyFunc() => (JSON) '[]';\n" +
" testPass | MyFunc() => (JSON) '[]';\n" +
"}\n");

test("function model::MyFunc(): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" duplicateSuite:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" },\n" +
" duplicateSuite:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n", "COMPILATION error at [1:1-50:1]: Multiple testSuites found with ids : 'duplicateSuite'");


test("function model::MyFunc(firstName: String[1]): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" duplicateSuite:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" parameters:\n" +
" [\n" +
" firstName = 'Nicole'\n" +
" ]\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n");
" testSuite1\n" +
" (\n" +
" testDuplicate | MyFunc() => (JSON) '[]';\n" +
" testDuplicate | MyFunc() => (JSON) '[]';\n" +
" )\n" +
"}\n", "COMPILATION error at [6:3-10:3]: Multiple tests found with ids : 'testDuplicate'");
test("function model::MyFunc(): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"{\n" +
" duplicateSuite\n" +
" (\n" +
" testDuplicate | MyFunc() => (JSON) '[]';\n" +
" )\n" +
" duplicateSuite\n" +
" (\n" +
" testDuplicate | MyFunc() => (JSON) '[]';\n" +
" )\n" +
"}\n", "COMPILATION error at [1:1-14:1]: Multiple testSuites found with ids : 'duplicateSuite'");

test("function model::MyFunc(firstName: String[1]): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" duplicateSuite:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n", "COMPILATION error at [10:7-25:7]: Parameter value required for parameter: 'firstName'");
"{\n" +
" testDuplicate | MyFunc('Nicole') => (JSON) '[]';\n" +
"}\n");

test("function model::MyFunc(firstName: String[1]): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" duplicateSuite:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n", "COMPILATION error at [10:7-25:7]: Parameter value required for parameter: 'firstName'");
"{\n" +
" testDuplicate | MyFunc() => (JSON) '[]';\n" +
"}\n", "COMPILATION error at [6:3-42]: Parameter value required for parameter: 'firstName'");

test("function model::MyFunc(): String[1]\n" +
test("function model::MyFunc(firstName: String[1], test: Integer[1], whoops: String[1]): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" duplicateSuite:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" parameters: [" +
" notFound = 'xx' " +
" ]" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualToJson\n" +
" #{\n" +
" expected:\n" +
" ExternalFormat\n" +
" #{\n" +
" contentType: 'application/json';\n" +
" data: '[]';\n" +
" }#;\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n", "COMPILATION error at [10:7-25:7]: Parameter values not found in function parameter: notFound");
"{\n" +
" testDuplicate | MyFunc('John', 1) => (JSON) '[]';\n" +
"}\n", "COMPILATION error at [6:3-51]: Parameter value required for parameter: 'whoops'");

test("function model::MyFunc(): String[1]\n" +
"{\n" +
" ''\n" +
"}\n" +
"[\n" +
" duplicateSuite:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testDuplicate:\n" +
" {\n" +
" asserts:\n" +
" [\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n", "COMPILATION error at [10:7-15:7]: Tests should have at least 1 assert");

"{\n" +
" testDuplicate | MyFunc('John') => (JSON) '[]';\n" +
"}\n", "COMPILATION error at [6:26-31]: No associated parameter found for value.");

test("function model::Hello(name: String[1]): String[1]\n" +
"{\n" +
" 'Hello!. My name is ' + $name + '.';\n" +
"}\n" +
"[\n" +
" testSuite_1:\n" +
" {\n" +
" tests:\n" +
" [\n" +
" testFail:\n" +
" {\n" +
" parameters: \n" +
" [\n" +
" name = 'John'\n" +
" ]\n" +
" asserts:\n" +
" [\n" +
" assertion_1:\n" +
" EqualTo\n" +
" #{\n" +
" expected: 'Hello!. My name is John.';\n" +
" }#\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]\n");
"{\n" +
" myTest | Hello('John') => 'Hello! My name is John.';\n" +
"}\n");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testLambdaParsingError()
@Test
public void testMixedParsingErrors()
{
test("{\"code\": \"Class A {},\", \"isolatedLambdas\": {\"good\": \"|'good'\", \"bad\": \"|,\"}}", "{\"codeError\":{\"message\":\"Unexpected token\",\"sourceInformation\":{\"endColumn\":11,\"endLine\":1,\"sourceId\":\"\",\"startColumn\":11,\"startLine\":1}},\"isolatedLambdas\":{\"lambdaErrors\":{\"bad\":{\"message\":\"Unexpected token ','. Valid alternatives: ['import', 'Class', 'Association', 'Profile', 'Enum', 'Measure', 'function', 'extends', 'stereotypes', 'tags', 'Error', 'Warn', 'native', 'projects', 'as', 'composite', 'shared', 'none', 'data', 'tests', 'parameters', 'asserts', 'store', 'all', 'let', 'allVersions', 'allVersionsInRange', 'toBytes', '!', '[', '(', '$', '^', '|', '@', '+', '-']\",\"sourceInformation\":{\"endColumn\":2,\"endLine\":1,\"sourceId\":\"bad\",\"startColumn\":2,\"startLine\":1}}},\"lambdas\":{\"good\":{\"_type\":\"lambda\",\"body\":[{\"_type\":\"string\",\"sourceInformation\":{\"endColumn\":7,\"endLine\":1,\"sourceId\":\"good\",\"startColumn\":2,\"startLine\":1},\"value\":\"good\"}],\"parameters\":[],\"sourceInformation\":{\"endColumn\":7,\"endLine\":1,\"sourceId\":\"good\",\"startColumn\":1,\"startLine\":1}}}},\"renderStyle\":\"STANDARD\"}");
test("{\"code\": \"Class A {},\", \"isolatedLambdas\": {\"good\": \"|'good'\", \"bad\": \"|,\"}}", "{\"codeError\":{\"message\":\"Unexpected token\",\"sourceInformation\":{\"endColumn\":11,\"endLine\":1,\"sourceId\":\"\",\"startColumn\":11,\"startLine\":1}},\"isolatedLambdas\":{\"lambdaErrors\":{\"bad\":{\"message\":\"Unexpected token ','. Valid alternatives: ['import', 'Class', 'Association', 'Profile', 'Enum', 'Measure', 'function', 'extends', 'stereotypes', 'tags', 'Error', 'Warn', 'native', 'projects', 'as', 'composite', 'shared', 'none', 'all', 'let', 'allVersions', 'allVersionsInRange', 'toBytes', '!', '[', '(', '$', '^', '|', '@', '+', '-']\",\"sourceInformation\":{\"endColumn\":2,\"endLine\":1,\"sourceId\":\"bad\",\"startColumn\":2,\"startLine\":1}}},\"lambdas\":{\"good\":{\"_type\":\"lambda\",\"body\":[{\"_type\":\"string\",\"sourceInformation\":{\"endColumn\":7,\"endLine\":1,\"sourceId\":\"good\",\"startColumn\":2,\"startLine\":1},\"value\":\"good\"}],\"parameters\":[],\"sourceInformation\":{\"endColumn\":7,\"endLine\":1,\"sourceId\":\"good\",\"startColumn\":1,\"startLine\":1}}}},\"renderStyle\":\"STANDARD\"}");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ AS: 'as';

AGGREGATION_TYPE_COMPOSITE: 'composite';
AGGREGATION_TYPE_SHARED: 'shared';
AGGREGATION_TYPE_NONE: 'none';

FUNCTION_TEST_DATA: 'data';
FUNCTION_SUITE_TESTS: 'tests';
FUNCTION_TEST_PARAMETERS: 'parameters';
FUNCTION_TEST_ASSERTS: 'asserts';
FUNCTION_TEST_DATA_STORE: 'store';
AGGREGATION_TYPE_NONE: 'none';
Loading

0 comments on commit aec5a5f

Please sign in to comment.