Skip to content

Commit 32213ce

Browse files
committed
Window tests
Signed-off-by: Liam Allan <[email protected]>
1 parent 8605ea2 commit 32213ce

File tree

3 files changed

+137
-13
lines changed

3 files changed

+137
-13
lines changed

src/dspf.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DisplayFile {
3535
inout = line[37].toUpperCase();
3636
y = line.substring(38, 41).trim();
3737
x = line.substring(41, 44).trim();
38-
keywords = line.substring(44).trim();
38+
keywords = line.substring(44).trimEnd();
3939

4040
switch (line[16]) {
4141
case 'R':
@@ -256,7 +256,9 @@ class DisplayFile {
256256
conditions: []
257257
};
258258

259-
let value = keywordStrings.join(`!`) + `!`;
259+
const newLineMark = `~`;
260+
261+
let value = keywordStrings.join(newLineMark) + newLineMark;
260262
let conditionalLine = 1;
261263

262264
if (value.length > 0) {
@@ -277,14 +279,17 @@ class DisplayFile {
277279
break;
278280

279281
case `'`:
280-
if (inString) {
281-
inBrakcets = 0;
282-
inString = false;
283-
284-
result.value = innerValue;
285-
innerValue = ``;
282+
if (inBrakcets > 0) {
283+
innerValue += value[i];
286284
} else {
287-
inString = true;
285+
if (inString) {
286+
inString = false;
287+
288+
result.value = innerValue;
289+
innerValue = ``;
290+
} else {
291+
inString = true;
292+
}
288293
}
289294
break;
290295

@@ -295,10 +300,12 @@ class DisplayFile {
295300
inBrakcets--;
296301
break;
297302

298-
case `!`:
303+
case newLineMark:
299304
case ` `:
300305
if (inBrakcets > 0 || inString) {
301-
innerValue += value[i];
306+
if (value[i] !== newLineMark) {
307+
innerValue += value[i];
308+
}
302309
} else {
303310
if (word.length > 0) {
304311
let conditionals = conditionalStrings ? conditionalStrings[conditionalLine] : undefined;
@@ -314,7 +321,7 @@ class DisplayFile {
314321
}
315322
}
316323

317-
if (value[i] === `!`) conditionalLine += 1;
324+
if (value[i] === newLineMark) conditionalLine += 1;
318325
break;
319326
default:
320327
if (inBrakcets > 0 || inString)

test/file/replloadfm.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// https://github.com/tom-writes-code/rpgle-repl
2+
3+
exports.lines = [
4+
` DSPSIZ(27 132 *DS4)`,
5+
` INDARA`,
6+
``,
7+
` R HEADER`,
8+
` 1 2'repl:load snippets'`,
9+
` COLOR(BLU)`,
10+
``,
11+
` 2 2'1=Load 4=Delete'`,
12+
` COLOR(WHT)`,
13+
``,
14+
` H_MODE 16A O 2 84`,
15+
` 50 COLOR(WHT)`,
16+
` N50 COLOR(RED)`,
17+
` 2102'filter by profile:'`,
18+
` COLOR(WHT)`,
19+
` H_FILTER 10A B 2122`,
20+
` COLOR(WHT)`,
21+
``,
22+
` R SNIPPET SFL`,
23+
` CHGINPDFT(LC)`,
24+
` S_SELECT 1A B 3 2COLOR(WHT)`,
25+
` DSPATR(UL)`,
26+
` 99 DSPATR(RI)`,
27+
` 99 DSPATR(PC)`,
28+
` S_ORIGIN 30A O 3 4COLOR(BLU)`,
29+
` S_LASTCHG 10A O 3 35COLOR(BLU)`,
30+
` S_PREVIEW 85A O 3 46COLOR(GRN)`,
31+
` S_OWNER 10A H`,
32+
` S_SAVENAME 20A H`,
33+
` S_SESSION 28A H`,
34+
``,
35+
` R SNIPPETS SFLCTL(SNIPPET)`,
36+
` SFLSIZ(23)`,
37+
` SFLPAG(22)`,
38+
` TEXT('Snippets Control Format')`,
39+
` CF03(03 'Exit')`,
40+
` CF11(11 'Saved/Unsaved')`,
41+
` OVERLAY`,
42+
` 40 SFLDSP`,
43+
` 41 SFLDSPCTL`,
44+
` 42 SFLCLR`,
45+
` 43 SFLEND(*MORE)`,
46+
``,
47+
` R NORECORDS`,
48+
` OVERLAY`,
49+
` 4 5'no snippets found for the current -`,
50+
` search criteria'`,
51+
``,
52+
` R FKEYS`,
53+
` FRCDTA`,
54+
` OVERLAY`,
55+
` MSGLIN 129A O 27 2DSPATR(HI)`,
56+
``,
57+
` 26 2'F3=Exit F11=Saved/Unsaved Snippet-`,
58+
` s'`,
59+
` COLOR(BLU)`,
60+
``,
61+
` R CONFIRM`,
62+
` OVERLAY`,
63+
` WINDOW(6 6 6 54)`,
64+
` CF10(10 'Confirm')`,
65+
` CF12(12 'Cancel')`,
66+
``,
67+
``,
68+
` CNFTXT1 50A O 2 3COLOR(WHT)`,
69+
` CNFTXT2 50A O 3 3COLOR(WHT)`,
70+
``,
71+
` 5 3'F10=Confirm -`,
72+
` F12=Cancel'`,
73+
` COLOR(BLU)`,
74+
]

test/tests.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const assert = require("assert");
22
const { DisplayFile } = require("../src/dspf");
33
const depts = require("./file/depts");
4+
const replloadfm = require("./file/replloadfm");
45

5-
exports.testa = () => {
6+
exports.simple = () => {
67
const file = new DisplayFile();
78
file.parse(depts.lines);
89

@@ -92,4 +93,46 @@ exports.testa = () => {
9293
assert.deepStrictEqual(sameLineField.keywords, [
9394
{ name: `COLOR`, value: `BLU`, conditions: [] },
9495
]);
96+
}
97+
98+
exports.strings = () => {
99+
const file = new DisplayFile();
100+
file.parse(replloadfm.lines);
101+
102+
assert.strictEqual(file.formats.length, 7);
103+
104+
// Verify parsing keywords with strings in
105+
const snippetsFormat = file.formats[3];
106+
assert.strictEqual(snippetsFormat.name, `SNIPPETS`);
107+
108+
const CF03 = snippetsFormat.keywords.find(keyword => keyword.name === `CF03`);
109+
assert.notStrictEqual(CF03, undefined);
110+
assert.strictEqual(CF03.value, `03 'Exit'`);
111+
112+
// Verify strings over many lines
113+
114+
const noRecordsFormat = file.formats[4];
115+
assert.strictEqual(noRecordsFormat.name, `NORECORDS`);
116+
const textField = noRecordsFormat.fields[0];
117+
assert.strictEqual(textField.name, `TEXT4`);
118+
assert.deepStrictEqual(textField.position, {x: 5, y: 4});
119+
assert.strictEqual(textField.value, `no snippets found for the current search criteria`);
120+
121+
// Second verification, with space at the start
122+
123+
const confirmWindowFormat = file.formats[6];
124+
assert.strictEqual(confirmWindowFormat.name, `CONFIRM`);
125+
const longTextField = confirmWindowFormat.fields[2];
126+
assert.strictEqual(longTextField.value, `F10=Confirm F12=Cancel`)
127+
}
128+
129+
exports.window = () => {
130+
const file = new DisplayFile();
131+
file.parse(replloadfm.lines);
132+
133+
const confirmWindowFormat = file.formats[6];
134+
assert.strictEqual(confirmWindowFormat.name, `CONFIRM`);
135+
assert.deepStrictEqual(confirmWindowFormat.windowSize, {
136+
height: 6, width: 54, x: 6, y: 6
137+
});
95138
}

0 commit comments

Comments
 (0)