1
1
import { expect , describe , it } from "vitest" ;
2
- import { Conditional , DdsLineRange , DisplayFile } from "../ui/dspf" ;
2
+ import { Conditional , DdsLineRange , DisplayFile , FieldInfo } from "../ui/dspf" ;
3
3
4
4
describe ( 'DisplayFile tests' , ( ) => {
5
5
@@ -16,6 +16,12 @@ describe('DisplayFile tests', () => {
16
16
` A R GLOBAL ` ,
17
17
` A SLNO(04) ` ,
18
18
` 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 ` ,
19
25
] ;
20
26
21
27
it ( 'getRangeForFormat' , ( ) => {
@@ -35,6 +41,60 @@ describe('DisplayFile tests', () => {
35
41
expect ( range ?. end ) . toBe ( 3 ) ;
36
42
} ) ;
37
43
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
+
38
98
it ( 'No duplicate RecordInfo' , ( ) => {
39
99
let dds = new DisplayFile ( ) ;
40
100
dds . parse ( dspf1 ) ;
0 commit comments