From f540181b30b0cdf452e1d32a0f19db2af6e18c7f Mon Sep 17 00:00:00 2001 From: Viktor Kilin Date: Wed, 12 Apr 2023 22:04:39 +0500 Subject: [PATCH 1/3] Avoided losing brackets in character constants --- src/dspf.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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: From b3318639451dc33f081646354f0ae61f8a8d4d41 Mon Sep 17 00:00:00 2001 From: Viktor Kilin Date: Mon, 17 Apr 2023 23:01:03 +0500 Subject: [PATCH 2/3] Added test for brackets in string. Some new material for other improvments. --- test/file/new_cases.js | 39 +++++++++++++++++++++++++++++++++++++++ test/tests.js | 19 ++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/file/new_cases.js diff --git a/test/file/new_cases.js b/test/file/new_cases.js new file mode 100644 index 0000000..d02fb58 --- /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 5A O +2TEXT('Short')`, + ` A*`, + ` A 4 2'Option . . . . .'`, + ` A FIELD2 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)`); +} From b33d5d81ccf84b8405eabe81e92dbc9c11324cf6 Mon Sep 17 00:00:00 2001 From: Viktor Kilin Date: Mon, 17 Apr 2023 23:18:49 +0500 Subject: [PATCH 3/3] fixed typo in dspf sample --- test/file/new_cases.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/file/new_cases.js b/test/file/new_cases.js index d02fb58..584dfb8 100644 --- a/test/file/new_cases.js +++ b/test/file/new_cases.js @@ -14,10 +14,10 @@ exports.lines = [ ` A 01 72 DSPATTR(RI)`, ` A 01 72 DSPATTR(RED)`, ` A OVRDTA`, - ` A 5A O +2TEXT('Short')`, + ` A FIELD2 5A O +2TEXT('Short')`, ` A*`, ` A 4 2'Option . . . . .'`, - ` A FIELD2 R B 4 19REFFLD(COL1 TABPF)`, + ` A FIELD3 R B 4 19REFFLD(COL1 TABPF)`, ` A 02N72N73 DSPATTR(HI)`, ` A 72 DSPATTR(PR)`, ` A N72 DSPATTR(UL)`,