|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { DisplayFile } from "../ui/dspf"; |
| 3 | + |
| 4 | +describe('DisplayFile.parse', () => { |
| 5 | + const dspf: string[] = [ |
| 6 | + ` A DSPSIZ(24 80 *DS3) `, |
| 7 | + ` A R HEAD `, |
| 8 | + ` A 1 32'vscode-displayfile' `, |
| 9 | + ` A R FMT1 `, |
| 10 | + ` A SLNO(03) `, |
| 11 | + ` A 1 3'Opt' `, |
| 12 | + ` A COLOR(BLU) `, |
| 13 | + ` A 1 8'Name' `, |
| 14 | + ` A COLOR(BLU) `, |
| 15 | + ` A R GLOBAL `, |
| 16 | + ` A SLNO(04) `, |
| 17 | + ` A 1 3'---' `, |
| 18 | + ` A R FORM1 `, |
| 19 | + ` A SLNO(06) `, |
| 20 | + ` A FLD0101 10A B 3 5 `, |
| 21 | + ` A 20 DSPATR(PR) `, |
| 22 | + ` A COLOR(YLW) `, |
| 23 | + ` A FLD0102 10 B 3 5 `, |
| 24 | + ]; |
| 25 | + |
| 26 | + it('parses record and field information', () => { |
| 27 | + const dds = new DisplayFile(); |
| 28 | + dds.parse(dspf); |
| 29 | + |
| 30 | + expect(dds.formats[0].name).toBe('_GLOBAL'); |
| 31 | + expect(dds.formats[0].keywords).toContainEqual({name: 'DSPSIZ', value: '24 80 *DS3', conditions: []}); |
| 32 | + |
| 33 | + const head = dds.formats.find(f => f.name === 'HEAD'); |
| 34 | + expect(head).toBeDefined(); |
| 35 | + expect(head!.fields).toHaveLength(1); |
| 36 | + const headField = head!.fields[0]; |
| 37 | + expect(headField.name).toBe('TEXT1'); |
| 38 | + expect(headField.value).toBe('vscode-displayfile'); |
| 39 | + expect(headField.displayType).toBe('const'); |
| 40 | + expect(headField.position).toEqual({x: 32, y: 1}); |
| 41 | + |
| 42 | + const fmt1 = dds.formats.find(f => f.name === 'FMT1'); |
| 43 | + expect(fmt1).toBeDefined(); |
| 44 | + const optField = fmt1!.fields[0]; |
| 45 | + expect(optField.value).toBe('Opt'); |
| 46 | + expect(optField.keywords).toContainEqual({name: 'COLOR', value: 'BLU', conditions: []}); |
| 47 | + |
| 48 | + const form1 = dds.formats.find(f => f.name === 'FORM1'); |
| 49 | + expect(form1).toBeDefined(); |
| 50 | + const fld0101 = form1!.fields.find(f => f.name === 'FLD0101'); |
| 51 | + expect(fld0101).toBeDefined(); |
| 52 | + expect(fld0101!.displayType).toBe('both'); |
| 53 | + expect(fld0101!.type).toBe('A'); |
| 54 | + expect(fld0101!.length).toBe(10); |
| 55 | + expect(fld0101!.position).toEqual({x: 5, y: 3}); |
| 56 | + expect(fld0101!.keywords).toContainEqual({name: 'COLOR', value: 'YLW', conditions: []}); |
| 57 | + expect(fld0101!.keywords).toContainEqual({name: 'DSPATR', value: 'PR', conditions: [{indicator: 20, negate: false}]}); |
| 58 | + }); |
| 59 | +}); |
0 commit comments