Skip to content

Commit 3e99ce2

Browse files
committed
Merge branch 'feature/editor' into feature/conditional
# Conflicts: # src/tests/dspf.test.ts
2 parents 0c68153 + 6455de6 commit 3e99ce2

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

src/tests/dspf.test.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, describe, it } from "vitest";
2-
import { Conditional, DdsLineRange, DisplayFile } from "../ui/dspf";
2+
import { Conditional, DdsLineRange, DisplayFile, FieldInfo } from "../ui/dspf";
33

44
describe('DisplayFile tests', () => {
55

@@ -16,6 +16,12 @@ describe('DisplayFile tests', () => {
1616
` A R GLOBAL `,
1717
` A SLNO(04) `,
1818
` A 1 3'---' `,
19+
` A R FORM1 `,
20+
` A SLNO(06) `,
21+
` A FLD0101 10A B 3 5 `,
22+
` A 20 DSPATR(PR) `,
23+
` A COLOR(YLW) `,
24+
` A FLD0102 10 B 3 5 `,
1925
];
2026

2127
it('getRangeForFormat', () => {
@@ -35,6 +41,60 @@ describe('DisplayFile tests', () => {
3541
expect(range?.end).toBe(3);
3642
});
3743

44+
it('getRangeForField', () => {
45+
let dds = new DisplayFile();
46+
dds.parse(dspf1);
47+
48+
let range: DdsLineRange | undefined;
49+
50+
expect(dds.getRangeForField(`FORM1`, `UNKNOWN`)).toBeUndefined();
51+
52+
range = dds.getRangeForField(`FORM1`, `FLD0101`);
53+
expect(range?.start).toBe(14);
54+
expect(range?.end).toBe(16);
55+
56+
range = dds.getRangeForField(`FORM1`, `FLD0102`);
57+
expect(range?.start).toBe(17);
58+
expect(range?.end).toBe(17);
59+
60+
});
61+
62+
it('getLinesForField', () => {
63+
64+
let dds = new DisplayFile();
65+
66+
let field = new FieldInfo(0);
67+
field.displayType = `const`;
68+
field.value = `Some text`;
69+
field.position.x = 10;
70+
field.position.y = 4;
71+
72+
let lines = DisplayFile.getLinesForField(field);
73+
74+
expect(lines.length).toBe(1);
75+
expect(lines[0]).toBe(` A 4 10'Some text'`);
76+
77+
field.keywords.push(
78+
{
79+
name: "COLOR",
80+
value: "BLU",
81+
conditions: []
82+
},
83+
{
84+
name: "DSPATR",
85+
value: "PR",
86+
conditions: []
87+
}
88+
);
89+
90+
lines = DisplayFile.getLinesForField(field);
91+
expect(lines.length).toBe(3);
92+
expect(lines[0]).toBe(` A 4 10'Some text'`);
93+
expect(lines[1]).toBe(` A COLOR(BLU)`);
94+
expect(lines[2]).toBe(` A DSPATR(PR)`);
95+
96+
});
97+
3898
it('No duplicate RecordInfo', () => {
3999
let dds = new DisplayFile();
40100
dds.parse(dspf1);

src/ui/dspf.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ export class DisplayFile {
316316
return result;
317317
}
318318

319-
// TODO: test cases
320319
public static getLinesForField(field: FieldInfo): string[] {
321320
const newLines: string[] = [];
322321

@@ -356,7 +355,6 @@ export class DisplayFile {
356355
return newLines;
357356
}
358357

359-
// TODO: test cases
360358
public getRangeForField(recordFormat: string, fieldName: string): DdsLineRange|undefined {
361359
let range: DdsLineRange|undefined = undefined;
362360
const currentFormatI = this.formats.findIndex(format => format.name === recordFormat);

0 commit comments

Comments
 (0)