Skip to content

Commit

Permalink
fix: Handle entries in Execution Groups better
Browse files Browse the repository at this point in the history
  • Loading branch information
ianshade committed May 11, 2020
1 parent bd581da commit 074be52
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/__tests__/xml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ let entryListXML = `<entry name="program">
</entry>
</entry>`

let executionGroupsXML = `<entry name="execution_groups">
<entry allocate="false" name="OVL">
<entry>
<entry name="viz">background_d</entry>
</entry>
<entry>
<entry name="viz">background_e</entry>
</entry>
</entry>
<entry allocate="false" name="FULL">
<entry>
<entry name="viz">background_d</entry>
</entry>
</entry>
<entry allocate="false" name="WALL">
<entry name="entry#2">
<entry name="viz">background_f</entry>
</entry>
</entry>
</entry>`

describe('Roundtrip XML', () => {

test('Roundtrip a VizEngine entry', async () => {
Expand All @@ -39,6 +60,13 @@ describe('Roundtrip XML', () => {
let fat = entry2XML(flat)
expect(buildXML(fat)).toBe(entryListXML)
})

test('Roundtrip Execution Groups', async () => {
let fromXML = await Xml2JS.parseStringPromise(executionGroupsXML)
let flat = await flattenEntry(fromXML.entry)
let fat = entry2XML(flat)
expect(buildXML(fat)).toBe(executionGroupsXML)
})
})

let nonEntry = `<entry name="elements">
Expand Down
12 changes: 9 additions & 3 deletions src/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ export async function flattenEntry (x: AtomEntry): Promise<FlatEntry> {
}
// MSE uses entries with nested sub-entries. Not Atom-compliant, but fairly consistent
if (x.entry && Array.isArray(x.entry)) {
let unnamedCount = 0
for (let e of x.entry) {
if (typeof e === 'object') {
if (e.$) {
if (e.$ && e.$.name) {
if (e.$.name === 'model_xml') {
try {
y[e.$.name] = e._ ? await Xml2JS.parseStringPromise(e._) : ''
Expand All @@ -66,7 +67,7 @@ export async function flattenEntry (x: AtomEntry): Promise<FlatEntry> {
}
delete y[e.$.name].name
} else {
y.entry = await flattenEntry(e)
y[`_entry#${unnamedCount++}`] = await flattenEntry(e)
}
} else {
if (!y.value) { y = { value: [] } }
Expand Down Expand Up @@ -127,7 +128,12 @@ export function entry2XML (x: FlatEntry): AtomEntry {
if (typeof x[a] === 'object') {
let e = entry2XML(x[a] as FlatEntry)
// console.log('EEE >>>', a, x[a], e)
e.$.name = a
if (!a.startsWith('_')) {
e.$.name = a
}
if (e.$.value && e.$.key) {
delete e.$.key
}
if (e.entry && e.$.value && Array.isArray(e.entry) && e.entry.length === 0) {
e._ = e.$.value
delete e.$.value
Expand Down

0 comments on commit 074be52

Please sign in to comment.