11import { expect , describe , it } from "vitest" ;
2- import { DdsLineRange , DisplayFile } from "../ui/dspf" ;
2+ import { DdsLineRange , DisplayFile , FieldInfo } from "../ui/dspf" ;
33
44describe ( '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 ) ;
0 commit comments