diff --git a/src/dspf.js b/src/dspf.js index 704c0b9..256cefd 100644 --- a/src/dspf.js +++ b/src/dspf.js @@ -294,10 +294,16 @@ class DisplayFile { break; case `(`: - inBrakcets++; + if (inString) + innerValue += value[i]; + else + inBrakcets++; break; case `)`: - inBrakcets--; + if (inString) + innerValue += value[i]; + else + inBrakcets--; break; case newLineMark: diff --git a/test/file/new_cases.js b/test/file/new_cases.js new file mode 100644 index 0000000..584dfb8 --- /dev/null +++ b/test/file/new_cases.js @@ -0,0 +1,39 @@ +exports.lines = [ + ` A R TEST_REC`, + ` A N71 INVITE`, + ` A N71 PUTOVR`, + ` A 71 OVERLAY`, + ` A 71 FRCDTA`, + ` A*`, + ` A 3 2'some text (detail)'`, + ` A FIELD1 12A B 3 21TEXT('MY FIELD')`, + ` A 01N72N73 DSPATTR(HI)`, + ` A 72 DSPATTR(PR)`, + ` A N72 DSPATTR(UL)`, + ` A 01 DSPATTR(PC)`, + ` A 01 72 DSPATTR(RI)`, + ` A 01 72 DSPATTR(RED)`, + ` A OVRDTA`, + ` A FIELD2 5A O +2TEXT('Short')`, + ` A*`, + ` A 4 2'Option . . . . .'`, + ` A FIELD3 R B 4 19REFFLD(COL1 TABPF)`, + ` A 02N72N73 DSPATTR(HI)`, + ` A 72 DSPATTR(PR)`, + ` A N72 DSPATTR(UL)`, + ` A 02 DSPATTR(PC)`, + ` A 02 72 DSPATTR(RI)`, + ` A 02 72 DSPATTR(RED)`, + ` A OVRDTA`, + ` A*`, + ` A 6 2'Address . . . . .'`, + ` A ADDRESS 140A B 6 19TEXT('MY FIELD')`, + ` A 03N72N73 DSPATTR(HI)`, + ` A 72 DSPATTR(PR)`, + ` A N72 DSPATTR(UL)`, + ` A 03 DSPATTR(PC)`, + ` A 03 72 DSPATTR(RI)`, + ` A 03 72 DSPATTR(RED)`, + ` A OVRDTA`, + ` A CNTFLD(50)`, + ]; \ No newline at end of file diff --git a/test/tests.js b/test/tests.js index 96cc251..6c15c5b 100644 --- a/test/tests.js +++ b/test/tests.js @@ -4,6 +4,7 @@ const { DisplayFile } = require("../src/dspf"); const depts = require("./file/depts"); const replloadfm = require("./file/replloadfm"); const issue1149 = require(`./file/issue1149`); +const newcases = require(`./file/new_cases`); exports.simple = () => { const file = new DisplayFile(); @@ -151,4 +152,20 @@ exports.issue1149 = () => { const windowTitle = windowFormat.keywords.find(keyword => keyword.name === `WDWTITLE`); assert.strictEqual(windowTitle.value, `*TEXT 'Print accounts by store number for status type - Help' *COLOR WHT`); -} \ No newline at end of file +} + +exports.additional_cases = () => { + const file = new DisplayFile(); + file.parse(newcases.lines); + + assert.strictEqual(file.formats.length, 2); + + const record = file.formats[1]; + assert.strictEqual(record.fields.length, 7); + assert.strictEqual(record.name, `TEST_REC`); + + // Verify parsing character constants with brackets + const fieldWithBrackets = record.fields[0]; + assert.strictEqual(fieldWithBrackets.displayType, `const`); + assert.strictEqual(fieldWithBrackets.value, `some text (detail)`); +}