Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
63 changes: 62 additions & 1 deletion src/tests/dspf.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "vitest";
import { DdsLineRange, DisplayFile } from "../ui/dspf";
import { DdsLineRange, DisplayFile, FieldInfo } from "../ui/dspf";

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

Expand All @@ -16,6 +16,12 @@
` A R GLOBAL `,
` A SLNO(04) `,
` A 1 3'---' `,
` A R FORM1 `,
` A SLNO(06) `,
` A FLD0101 10A B 3 5 `,
` A 20 DSPATR(PR) `,
` A COLOR(YLW) `,
` A FLD0102 10 B 3 5 `,
];

it('getRangeForFormat', () => {
Expand All @@ -35,6 +41,61 @@
expect(range?.end).toBe(3);
});

it('getRangeForField', () => {
let dds = new DisplayFile();
dds.parse(dspf1);

let range: DdsLineRange | undefined;

expect(dds.getRangeForField(`FORM1`, `UNKNOWN`)).toBeUndefined();

range = dds.getRangeForField(`FORM1`, `FLD0101`);
expect(range?.start).toBe(14);
expect(range?.end).toBe(16);

range = dds.getRangeForField(`FORM1`, `FLD0102`);
expect(range?.start).toBe(17);
expect(range?.end).toBe(17);

});

it('getLinesForField', () => {

let dds = new DisplayFile();

let field = new FieldInfo(0);
field.displayType = `const`;
field.value = `Some text`;
field.position.x = 10;
field.position.y = 4;

let lines = DisplayFile.getLinesForField(field);

expect(lines.length).toBe(1);
expect(lines[0]).toBe(` A 4 10'Some text'`);

field.keywords.push(
{
name: "COLOR(BLU)",
conditions: []
},
{
name: "DSPATR(PR)",
conditions: [{
indicator: 21,
negate: true
}]
}
);

lines = DisplayFile.getLinesForField(field);
expect(lines.length).toBe(3);
expect(lines[0]).toBe(` A 4 10'Some text'`);
expect(lines[1]).toBe(` A COLOR(BLU)`);
expect(lines[2]).toBe(` A N21 DSPATR(PR)`);

Check failure on line 95 in src/tests/dspf.test.ts

View workflow job for this annotation

GitHub Actions / Test runner

src/tests/dspf.test.ts > DisplayFile tests > getLinesForField

AssertionError: expected ' A …' to be ' A N21 …' // Object.is equality Expected: " A N21 DSPATR(PR)" Received: " A DSPATR(PR)" ❯ src/tests/dspf.test.ts:95:22

});

it('No duplicate RecordInfo', () => {
let dds = new DisplayFile();
dds.parse(dspf1);
Expand Down
2 changes: 0 additions & 2 deletions src/ui/dspf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ export class DisplayFile {
return result;
}

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

Expand Down Expand Up @@ -391,7 +390,6 @@ export class DisplayFile {
return newLines;
}

// TODO: test cases
public getRangeForField(recordFormat: string, fieldName: string): DdsLineRange|undefined {
let range: DdsLineRange|undefined = undefined;
const currentFormatI = this.formats.findIndex(format => format.name === recordFormat);
Expand Down
Loading