Skip to content
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

Avoided losing brackets in character constants #3

Open
wants to merge 3 commits into
base: main
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
10 changes: 8 additions & 2 deletions src/dspf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions test/file/new_cases.js
Original file line number Diff line number Diff line change
@@ -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)`,
];
19 changes: 18 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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`);
}
}

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)`);
}