Skip to content

Commit 06b0132

Browse files
authored
Merge pull request #4 from codefori/fix/chars_in_string
Fix string parsing issues and add additional test case
2 parents ab709fb + d4fe0ac commit 06b0132

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

src/dspf.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class DisplayFile {
264264
if (value.length > 0) {
265265
value += ` `;
266266

267-
let inBrakcets = 0;
267+
let inBrackets = 0;
268268
let word = ``;
269269
let innerValue = ``;
270270
let inString = false;
@@ -273,13 +273,13 @@ class DisplayFile {
273273
switch (value[i]) {
274274
case `+`:
275275
case `-`:
276-
if (!inString && value[i+1] !== newLineMark) {
276+
if (value[i+1] !== newLineMark) {
277277
innerValue += value[i];
278278
}
279279
break;
280280

281281
case `'`:
282-
if (inBrakcets > 0) {
282+
if (inBrackets > 0) {
283283
innerValue += value[i];
284284
} else {
285285
if (inString) {
@@ -294,15 +294,23 @@ class DisplayFile {
294294
break;
295295

296296
case `(`:
297-
inBrakcets++;
297+
if (inString) {
298+
innerValue += value[i];
299+
} else {
300+
inBrackets++;
301+
}
298302
break;
299303
case `)`:
300-
inBrakcets--;
304+
if (inString) {
305+
innerValue += value[i];
306+
} else {
307+
inBrackets--;
308+
}
301309
break;
302310

303311
case newLineMark:
304312
case ` `:
305-
if (inBrakcets > 0 || inString) {
313+
if (inBrackets > 0 || inString) {
306314
if (value[i] !== newLineMark) {
307315
innerValue += value[i];
308316
}
@@ -324,7 +332,7 @@ class DisplayFile {
324332
if (value[i] === newLineMark) conditionalLine += 1;
325333
break;
326334
default:
327-
if (inBrakcets > 0 || inString)
335+
if (inBrackets > 0 || inString)
328336
innerValue += value[i];
329337
else
330338
word += value[i];

test/file/issue1382.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exports.lines = [
2+
` A DSPSIZ(27 132 *DS4)`,
3+
` A R SCRN2`,
4+
` A 2 2'This text containt parentheses (Y/N)'`,
5+
` A 3 2'This text containt dashes -Y/N-'`,
6+
];

test/tests.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { DisplayFile } = require("../src/dspf");
44
const depts = require("./file/depts");
55
const replloadfm = require("./file/replloadfm");
66
const issue1149 = require(`./file/issue1149`);
7+
const issue1382 = require(`./file/issue1382`);
78

89
exports.simple = () => {
910
const file = new DisplayFile();
@@ -151,4 +152,25 @@ exports.issue1149 = () => {
151152

152153
const windowTitle = windowFormat.keywords.find(keyword => keyword.name === `WDWTITLE`);
153154
assert.strictEqual(windowTitle.value, `*TEXT 'Print accounts by store number for status type - Help' *COLOR WHT`);
155+
156+
const text4 = windowFormat.fields.find(field => field.name === `TEXT4`);
157+
assert.ok(text4);
158+
assert.strictEqual(text4.value, `taken a check from that account. You can only select one status type`);
159+
assert.deepStrictEqual(text4.position, {x: 2, y: 5});
160+
}
161+
162+
exports.issue1382 = () => {
163+
const file = new DisplayFile();
164+
file.parse(issue1382.lines);
165+
166+
const screenFormat = file.formats[1];
167+
assert.strictEqual(screenFormat.name, `SCRN2`);
168+
169+
const textField1 = screenFormat.fields[0];
170+
assert.strictEqual(textField1.name, `TEXT1`);
171+
assert.strictEqual(textField1.value, `This text containt parentheses (Y/N)`);
172+
173+
const textField2 = screenFormat.fields[1];
174+
assert.strictEqual(textField2.name, `TEXT2`);
175+
assert.strictEqual(textField2.value, `This text containt dashes -Y/N-`);
154176
}

0 commit comments

Comments
 (0)