|
15 | 15 | assert_guess :mimetype => 'text/x-abap' |
16 | 16 | end |
17 | 17 | end |
18 | | - |
19 | | - describe 'lexing' do |
20 | | - include Support::Lexing |
21 | | - |
22 | | - it 'recognizes modern constructor operators' do |
23 | | - # NEW operator |
24 | | - assert_tokens_equal 'DATA(obj) = NEW class( )', |
25 | | - ['Keyword', 'DATA'], |
26 | | - ['Punctuation', '('], |
27 | | - ['Name', 'obj'], |
28 | | - ['Punctuation', ')'], |
29 | | - ['Text', ' '], |
30 | | - ['Operator', '='], |
31 | | - ['Text', ' '], |
32 | | - ['Keyword', 'NEW'], |
33 | | - ['Text', ' '], |
34 | | - ['Name', 'class'], |
35 | | - ['Punctuation', '('], |
36 | | - ['Text', ' '], |
37 | | - ['Punctuation', ')'] |
38 | | - |
39 | | - # VALUE operator |
40 | | - assert_tokens_equal 'itab = VALUE #( )', |
41 | | - ['Name', 'itab'], |
42 | | - ['Text', ' '], |
43 | | - ['Operator', '='], |
44 | | - ['Text', ' '], |
45 | | - ['Keyword', 'VALUE'], |
46 | | - ['Text', ' '], |
47 | | - ['Operator', '#'], |
48 | | - ['Punctuation', '('], |
49 | | - ['Text', ' '], |
50 | | - ['Punctuation', ')'] |
51 | | - |
52 | | - # CORRESPONDING operator |
53 | | - assert_tokens_equal 'struct2 = CORRESPONDING #( struct1 )', |
54 | | - ['Name', 'struct2'], |
55 | | - ['Text', ' '], |
56 | | - ['Operator', '='], |
57 | | - ['Text', ' '], |
58 | | - ['Keyword', 'CORRESPONDING'], |
59 | | - ['Text', ' '], |
60 | | - ['Operator', '#'], |
61 | | - ['Punctuation', '('], |
62 | | - ['Text', ' '], |
63 | | - ['Name', 'struct1'], |
64 | | - ['Text', ' '], |
65 | | - ['Punctuation', ')'] |
66 | | - end |
67 | | - |
68 | | - it 'recognizes CDS keywords' do |
69 | | - # DEFINE VIEW ENTITY |
70 | | - assert_tokens_equal 'DEFINE VIEW ENTITY ZTest', |
71 | | - ['Keyword', 'DEFINE'], |
72 | | - ['Text', ' '], |
73 | | - ['Keyword', 'VIEW'], |
74 | | - ['Text', ' '], |
75 | | - ['Keyword', 'ENTITY'], |
76 | | - ['Text', ' '], |
77 | | - ['Name', 'ZTest'] |
78 | | - |
79 | | - # ASSOCIATION |
80 | | - assert_tokens_equal 'ASSOCIATION TO ZEntity', |
81 | | - ['Keyword', 'ASSOCIATION'], |
82 | | - ['Text', ' '], |
83 | | - ['Keyword', 'TO'], |
84 | | - ['Text', ' '], |
85 | | - ['Name', 'ZEntity'] |
86 | | - |
87 | | - # COMPOSITION |
88 | | - assert_tokens_equal 'COMPOSITION OF ZChild', |
89 | | - ['Keyword', 'COMPOSITION'], |
90 | | - ['Text', ' '], |
91 | | - ['Keyword', 'OF'], |
92 | | - ['Text', ' '], |
93 | | - ['Name', 'ZChild'] |
94 | | - end |
95 | | - |
96 | | - it 'recognizes CDS and modern ABAP functions as builtins' do |
97 | | - # Modern constructor functions |
98 | | - assert_tokens_equal 'lv_result = conv( lv_value )', |
99 | | - ['Name', 'lv_result'], |
100 | | - ['Text', ' '], |
101 | | - ['Operator', '='], |
102 | | - ['Text', ' '], |
103 | | - ['Name.Builtin', 'conv'], |
104 | | - ['Punctuation', '('], |
105 | | - ['Text', ' '], |
106 | | - ['Name', 'lv_value'], |
107 | | - ['Text', ' '], |
108 | | - ['Punctuation', ')'] |
109 | | - |
110 | | - # CDS numeric functions - note 'b' is a type keyword, use different variable name |
111 | | - assert_tokens_equal 'div( arg1 arg2 )', |
112 | | - ['Name.Builtin', 'div'], |
113 | | - ['Punctuation', '('], |
114 | | - ['Text', ' '], |
115 | | - ['Name', 'arg1'], |
116 | | - ['Text', ' '], |
117 | | - ['Name', 'arg2'], |
118 | | - ['Text', ' '], |
119 | | - ['Punctuation', ')'] |
120 | | - |
121 | | - # CDS currency conversion |
122 | | - assert_tokens_equal 'currency_conversion( )', |
123 | | - ['Name.Builtin', 'currency_conversion'], |
124 | | - ['Punctuation', '('], |
125 | | - ['Text', ' '], |
126 | | - ['Punctuation', ')'] |
127 | | - |
128 | | - # REDUCE operator |
129 | | - assert_tokens_equal 'reduce( )', |
130 | | - ['Name.Builtin', 'reduce'], |
131 | | - ['Punctuation', '('], |
132 | | - ['Text', ' '], |
133 | | - ['Punctuation', ')'] |
134 | | - |
135 | | - # FILTER operator |
136 | | - assert_tokens_equal 'filter( )', |
137 | | - ['Name.Builtin', 'filter'], |
138 | | - ['Punctuation', '('], |
139 | | - ['Text', ' '], |
140 | | - ['Punctuation', ')'] |
141 | | - |
142 | | - # CORRESPONDING function |
143 | | - assert_tokens_equal 'corresponding( )', |
144 | | - ['Name.Builtin', 'corresponding'], |
145 | | - ['Punctuation', '('], |
146 | | - ['Text', ' '], |
147 | | - ['Punctuation', ')'] |
148 | | - end |
149 | | - |
150 | | - it 'recognizes COND and SWITCH expressions' do |
151 | | - # COND expression - note 'x' is a type keyword in ABAP |
152 | | - assert_tokens_equal 'lv_result = COND #( WHEN lv_var = 1 THEN a )', |
153 | | - ['Name', 'lv_result'], |
154 | | - ['Text', ' '], |
155 | | - ['Operator', '='], |
156 | | - ['Text', ' '], |
157 | | - ['Keyword', 'COND'], |
158 | | - ['Text', ' '], |
159 | | - ['Operator', '#'], |
160 | | - ['Punctuation', '('], |
161 | | - ['Text', ' '], |
162 | | - ['Keyword', 'WHEN'], |
163 | | - ['Text', ' '], |
164 | | - ['Name', 'lv_var'], |
165 | | - ['Text', ' '], |
166 | | - ['Operator', '='], |
167 | | - ['Text', ' '], |
168 | | - ['Literal.Number.Integer', '1'], |
169 | | - ['Text', ' '], |
170 | | - ['Keyword', 'THEN'], |
171 | | - ['Text', ' '], |
172 | | - ['Name', 'a'], |
173 | | - ['Text', ' '], |
174 | | - ['Punctuation', ')'] |
175 | | - |
176 | | - # SWITCH expression |
177 | | - assert_tokens_equal 'lv_result = SWITCH #( lv_var )', |
178 | | - ['Name', 'lv_result'], |
179 | | - ['Text', ' '], |
180 | | - ['Operator', '='], |
181 | | - ['Text', ' '], |
182 | | - ['Keyword', 'SWITCH'], |
183 | | - ['Text', ' '], |
184 | | - ['Operator', '#'], |
185 | | - ['Punctuation', '('], |
186 | | - ['Text', ' '], |
187 | | - ['Name', 'lv_var'], |
188 | | - ['Text', ' '], |
189 | | - ['Punctuation', ')'] |
190 | | - end |
191 | | - |
192 | | - it 'recognizes LET expressions' do |
193 | | - assert_tokens_equal 'LET lv_var = 1 IN y', |
194 | | - ['Keyword', 'LET'], |
195 | | - ['Text', ' '], |
196 | | - ['Name', 'lv_var'], |
197 | | - ['Text', ' '], |
198 | | - ['Operator', '='], |
199 | | - ['Text', ' '], |
200 | | - ['Literal.Number.Integer', '1'], |
201 | | - ['Text', ' '], |
202 | | - ['Keyword', 'IN'], |
203 | | - ['Text', ' '], |
204 | | - ['Name', 'y'] |
205 | | - end |
206 | | - |
207 | | - it 'handles LOOP with STEP' do |
208 | | - assert_tokens_equal 'LOOP AT itab STEP 2', |
209 | | - ['Keyword', 'LOOP'], |
210 | | - ['Text', ' '], |
211 | | - ['Keyword', 'AT'], |
212 | | - ['Text', ' '], |
213 | | - ['Name', 'itab'], |
214 | | - ['Text', ' '], |
215 | | - ['Keyword', 'STEP'], |
216 | | - ['Text', ' '], |
217 | | - ['Literal.Number.Integer', '2'] |
218 | | - end |
219 | | - |
220 | | - it 'recognizes ANNOTATION keyword' do |
221 | | - assert_tokens_equal '@ANNOTATION.label', |
222 | | - ['Operator', '@'], |
223 | | - ['Keyword', 'ANNOTATION'], |
224 | | - ['Punctuation', '.'], |
225 | | - ['Name', 'label'] |
226 | | - end |
227 | | - |
228 | | - it 'recognizes cardinality keywords' do |
229 | | - assert_tokens_equal 'MANY TO ONE', |
230 | | - ['Keyword', 'MANY'], |
231 | | - ['Text', ' '], |
232 | | - ['Keyword', 'TO'], |
233 | | - ['Text', ' '], |
234 | | - ['Keyword', 'ONE'] |
235 | | - end |
236 | | - |
237 | | - it 'recognizes $ as valid character in variable names' do |
238 | | - assert_tokens_equal '$session.system_language', |
239 | | - ['Name', '$session'], |
240 | | - ['Punctuation', '.'], |
241 | | - ['Name', 'system_language'] |
242 | | - end |
243 | | - |
244 | | - it 'recognizes structure field access without highlighting field as keyword' do |
245 | | - # 'decimals' is a keyword, but in dd04l.decimals it should be a field name |
246 | | - assert_tokens_equal 'dd04l.decimals', |
247 | | - ['Name', 'dd04l'], |
248 | | - ['Punctuation', '.'], |
249 | | - ['Name', 'decimals'] |
250 | | - |
251 | | - # Another example with a keyword as field name |
252 | | - assert_tokens_equal 'table.data', |
253 | | - ['Name', 'table'], |
254 | | - ['Punctuation', '.'], |
255 | | - ['Name', 'data'] |
256 | | - end |
257 | | - |
258 | | - it 'recognizes parameter names in CALL FUNCTION statements' do |
259 | | - # Parameter names after EXPORTING/IMPORTING should be Name, not Keyword |
260 | | - # Testing that 'input' and 'output' are recognized as parameter names (Name tokens) |
261 | | - # not as keywords when they appear in these contexts |
262 | | - assert_tokens_equal "input = 'test'", |
263 | | - ['Name', 'input'], |
264 | | - ['Text', ' '], |
265 | | - ['Operator', '='], |
266 | | - ['Text', ' '], |
267 | | - ['Literal.String.Single', "'test'"] |
268 | | - |
269 | | - assert_tokens_equal "output = 'result'", |
270 | | - ['Name', 'output'], |
271 | | - ['Text', ' '], |
272 | | - ['Operator', '='], |
273 | | - ['Text', ' '], |
274 | | - ['Literal.String.Single', "'result'"] |
275 | | - end |
276 | | - end |
277 | 18 | end |
0 commit comments