Skip to content

Nested SystemTypes: Add 'parent' to SystemType, update SystemType discovery, add tests #457

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

Open
wants to merge 1 commit into
base: issue431_multiLibs
Choose a base branch
from
Open
Show file tree
Hide file tree
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
50 changes: 33 additions & 17 deletions server/src/parser/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function _mapInputToOption(input: parser.TemplateInput): Option {
export interface SystemTypeN {
description: string;
modelicaPath: string; // Modelica fully qualified class name
parent: string;
}

export interface SystemTemplateN {
Expand Down Expand Up @@ -235,26 +236,41 @@ export class Template {
_extractSystemTypes(element: parser.Element) {
const path = element.modelicaPath.split(".");
path.pop();
let curPath: string[] = [];
const systemTypes: SystemTypeN[] = [];

// Fix for https://github.com/lbl-srg/ctrl-flow-dev/issues/422
// Currently the UI does not support nested system types.
// Therefore, we only add the Modelica class name of the containing package.
const type = parser.findElement(path.join("."));
if (type && type.entryPoint) {
if (!type.description) {
console.error(
"Error: missing class description string in entry point " +
type.modelicaPath,
);
process.exit(1);
while (path.length > 0) {
const pathSegment = path.shift();
if (!pathSegment) {
break;
}
curPath.push(pathSegment);
const type = parser.findElement(curPath.join("."));

if (type && type.entryPoint) {
if (!type.description) {
console.error(
"Error: missing class description string in entry point " +
type.modelicaPath,
);
process.exit(1);
}
const parent = systemTypes.at(-1);
const systemType = {
description: type.description,
modelicaPath: type.modelicaPath,
parent: parent?.modelicaPath || "",
};
systemTypes.push(systemType);
}
const systemType = {
description: type.description,
modelicaPath: type.modelicaPath,
};
this.systemTypes.unshift(systemType);
systemTypeStore.set(type.modelicaPath, systemType);
}

// add all found system types to systemType store
systemTypes.forEach((systemType) =>
systemTypeStore.set(systemType.modelicaPath, systemType),
);
// set the systemType reference on the template
this.systemTypes.unshift(systemTypes.at(-1)!);
}

_findRedeclareTypesHelper(
Expand Down
30 changes: 26 additions & 4 deletions server/tests/integration/parser/template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,40 @@ const TEMPLATE_PATH = "TestPackage.Template.TestTemplate";
const NESTED_TEMPLATE_PATH =
"TestPackage.NestedTemplate.Subcategory.SecondTemplate";

describe("SystemType extraction", () => {
beforeAll(() => {
initializeTestModelicaJson();
loadPackage('TestPackage');
});

it("Extracts three SystemTypes including subcategories", () => {
const systemTypes = [...getSystemTypes()];
expect(systemTypes.length).toBe(3);
});

it("Sets the parent value as expected", () => {
const systemTypes = [...getSystemTypes()];
const noParent = "";
const nestedCategoryPath = "TestPackage.NestedTemplate";
const subCategory = systemTypes.find(s => s.modelicaPath === "TestPackage.NestedTemplate.Subcategory");
const nestedCategory = systemTypes.find(s => s.modelicaPath === nestedCategoryPath);
const templateCategory = systemTypes.find(s => s.modelicaPath === "TestPackage.Template");

expect(subCategory?.parent).toEqual(nestedCategoryPath);
expect(nestedCategory?.parent).toEqual(noParent);
expect(templateCategory?.parent).toEqual(noParent);
});
});

describe("Template wrapper class functionality", () => {
beforeAll(() => {
initializeTestModelicaJson();
loadPackage('TestPackage');
});

it("Extracts two templates and three Template types to be in stores", () => {
it("Extracts two templates", () => {
const templates = [...getTemplates()];
expect(templates.length).toBe(2);

const systemTypes = [...getSystemTypes()];
expect(systemTypes.length).toBe(2);
});

it("Templates have expected SystemTypes", () => {
Expand Down