diff --git a/src/tests/dspf.test.ts b/src/tests/dspf.test.ts index 19514db..cc5469a 100644 --- a/src/tests/dspf.test.ts +++ b/src/tests/dspf.test.ts @@ -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', () => { @@ -16,6 +16,12 @@ describe('DisplayFile tests', () => { ` 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', () => { @@ -35,6 +41,60 @@ describe('DisplayFile tests', () => { 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", + value: "BLU", + conditions: [] + }, + { + name: "DSPATR", + value: "PR", + conditions: [] + } + ); + + 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 DSPATR(PR)`); + + }); + it('No duplicate RecordInfo', () => { let dds = new DisplayFile(); dds.parse(dspf1); diff --git a/src/ui/dspf.ts b/src/ui/dspf.ts index 955c0ab..7440563 100644 --- a/src/ui/dspf.ts +++ b/src/ui/dspf.ts @@ -351,7 +351,6 @@ export class DisplayFile { return result; } - // TODO: test cases public static getLinesForField(field: FieldInfo): string[] { const newLines: string[] = []; @@ -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);