diff --git a/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts b/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts index f942f10..ba78b7a 100644 --- a/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts +++ b/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts @@ -6,7 +6,9 @@ import { atccSelection, invalidSelection, ltrkSelection, + mhaiSelection, mmxuSelection, + ptocSelection, } from "./insertSelectedLNodeType.testdata.js"; import { @@ -189,4 +191,28 @@ describe("insertLNodeTypeSelection", () => { const lNodeType = edits[0].node as Element; expect(lNodeType.tagName).to.equal("DataTypeTemplates"); }); + + it("add count attribute to data attribute in case is an array", () => { + const data = nsdToJson("PTOC") as LNodeDescription; + const edits = insertSelectedLNodeType( + missingDataTypes, + ptocSelection, + { class: "PTOC", data }, + ); + + const doTypeEdit = edits[5].node as Element; + expect(doTypeEdit.querySelector('DA[name="crvPts"]')?.getAttribute('count')).to.equal("maxPts"); + }); + + it("add count attribute to sub data object in case is an array", () => { + const data = nsdToJson("MHAI") as LNodeDescription; + const edits = insertSelectedLNodeType( + missingDataTypes, + mhaiSelection, + { class: "MHAI", data }, + ); + + const doTypeEdit = edits[4].node as Element; + expect(doTypeEdit.querySelector('SDO[name="phsAHar"]')?.getAttribute('count')).to.equal("maxPts"); + }); }); diff --git a/tDataTypeTemplates/insertSelectedLNodeType.testdata.ts b/tDataTypeTemplates/insertSelectedLNodeType.testdata.ts index 10fd90f..6e56b3f 100644 --- a/tDataTypeTemplates/insertSelectedLNodeType.testdata.ts +++ b/tDataTypeTemplates/insertSelectedLNodeType.testdata.ts @@ -428,3 +428,88 @@ export const invalidSelection = { "ldNs": {} } }; + +export const ptocSelection = { + "Beh": { + "q": {}, + "stVal": { + "blocked": {}, + "off": {}, + "on": {}, + "test": {}, + "test/blocked": {} + }, + "t": {} + }, + "Op": { + "general": {}, + "q": {}, + "t": {} + }, + "Str": { + "dirGeneral": { + "backward": {}, + "both": {}, + "forward": {}, + "unknown": {} + }, + "general": {}, + "q": {}, + "t": {} + }, + "TmAChr": { + "crvPts": { + "xVal": {}, + "yVal": {} + }, + "maxPts": {}, + "numPts": {}, + "xD": {}, + "yD": {}, + "yUnits": { + "SIUnit": { + "°C": {}, + "1/s": {} + } + }, + "xUnits": { + "SIUnit": { + "°C": {}, + "1/s": {} + } + } + } +} + +export const mhaiSelection = { + "Beh": { + "q": {}, + "stVal": { + "blocked": {}, + "off": {}, + "on": {}, + "test": {}, + "test/blocked": {} + }, + "t": {} + }, + "HA": { + "evalTm": {}, + "frequency": {}, + "maxPts": {}, + "numCyc": {}, + "numHar": {}, + "phsAHar": { + "cVal": { + "mag": { + "f": {} + }, + "ang": { + "f": {} + } + }, + "q": {}, + "t": {} + } + } +} diff --git a/tDataTypeTemplates/insertSelectedLNodeType.ts b/tDataTypeTemplates/insertSelectedLNodeType.ts index de2b39a..0d47fe4 100644 --- a/tDataTypeTemplates/insertSelectedLNodeType.ts +++ b/tDataTypeTemplates/insertSelectedLNodeType.ts @@ -152,6 +152,7 @@ function hashElement(element: Element): string { return cyrb64(JSON.stringify(describeElement(element))); } +// eslint-disable-next-line @typescript-eslint/no-explicit-any function data(lnData: any, path: string[]): any { let d = lnData; for (const slug of path.slice(0, -1)) d = d[slug].children; @@ -329,6 +330,8 @@ export function insertSelectedLNodeType( qchg?: string; typeKind?: "BASIC" | "ENUMERATED" | "CONSTRUCTED" | "undefined"; type?: string; + isArray?: string; + sizeAttribute?: string; }, ][] = Object.entries(dO.children); @@ -340,11 +343,21 @@ export function insertSelectedLNodeType( const type = createDOType(path.concat([name]), selection[name]); const sdo = createElement(doc, "SDO", { name, transient, type }); doType.prepend(sdo); + + // For arrays set count attribute + if (dep.isArray === "true" && dep.sizeAttribute) { + sdo.setAttribute("count", dep.sizeAttribute); + } } else { const { fc, dchg, dupd, qchg } = dep; const da = createElement(doc, "DA", { name, fc, dchg, dupd, qchg }); + // For arrays set count attribute + if (dep.isArray === "true" && dep.sizeAttribute) { + da.setAttribute("count", dep.sizeAttribute); + } + if (dep.typeKind === "BASIC" || !dep.typeKind) { da.setAttribute("bType", dep.type!); } diff --git a/tDataTypeTemplates/nsdToJson.spec.ts b/tDataTypeTemplates/nsdToJson.spec.ts index b35b6b5..4ad093b 100644 --- a/tDataTypeTemplates/nsdToJson.spec.ts +++ b/tDataTypeTemplates/nsdToJson.spec.ts @@ -29,8 +29,6 @@ describe("NSD to Json parsing function", () => { const data = nsdToJson(lnClass)!; const sClass = lnClassData[lnClass]; - console.log(lnClass); - Object.keys(sClass).forEach((key) => { expect(data[key]).to.deep.equal(sClass[key]); });