Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
46 changes: 46 additions & 0 deletions src/tests/dspf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,50 @@ describe('DisplayFile tests', () => {
expect(new Set(names).size).toBe(names.length);
});

it("should parse field with type and attach keywords", () => {
const lines = [
" A FIELD1 10A",
" A TEXT('Customer Name')",
" A COLHDG('Cust' 'Name')"
];

const file = new DisplayFile();
file.parse(lines);

const record = file.formats[0];
const field = record.fields[0];

expect(record.fields.length).toBe(1);
expect(field.name).toBe("FIELD1");
expect(field.type).toBe("A");
expect(field.length).toBe(10);
expect(field.keywords.length).toBe(2);
expect(field.keywords[0].name).toBe("TEXT");
expect(field.keywords[0].value).toBe("'Customer Name'");
expect(field.keywords[1].name).toBe("COLHDG");
expect(field.keywords[1].value).toBe("'Cust' 'Name'");
});

it("should parse field without type (REFFLD) and attach keywords", () => {
const lines = [
" A FIELD2",
" A REFFLD(ADRNO)",
" A TEXT('Address Number')"
];

const file = new DisplayFile();
file.parse(lines);

const record = file.formats[0];
const field = record.fields[0];

expect(record.fields.length).toBe(1);
expect(field.name).toBe("FIELD2");
expect(field.type).toBe("");
expect(field.keywords.length).toBe(2);
expect(field.keywords[0].name).toBe("REFFLD");
expect(field.keywords[0].value).toBe("ADRNO");
expect(field.keywords[1].name).toBe("TEXT");
expect(field.keywords[1].value).toBe("'Address Number'");
});
});
2 changes: 1 addition & 1 deletion src/ui/dspf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class DisplayFile {
x: totalX,
y: 0
};
} else if (name !== undefined && type !== "") {
} else if (name!=="" && name !== undefined) { // start a new field if a field name exists
// Some fields have no positions
if (this.currentField) {
this.currentField.handleKeywords();
Expand Down