Merge pull request #19 from nspaseski/master
[deliverable/titan.core.git] / regression_test / templateCharstr / TtemplateCharstr.ttcn
CommitLineData
970ed795 1/******************************************************************************
3abe9331 2 * Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8module TtemplateCharstr {
9type component templateCharstr_mycomp {};
10type record templateCharstr_rec {
11 charstring x1,
12 charstring x2,
13 charstring x3 optional };
14template templateCharstr_rec templateCharstr_tSpec :={ //specific values
15 x1:="00AA",
16 x2:="01AA",
17 x3:="10AA" };
18template templateCharstr_rec templateCharstr_tList :={ //specific value and value list
19 x1:="00AA",
20 x2:=("01AA","01AB","11AC"),
21 x3:="10AA" };
22template templateCharstr_rec templateCharstr_tComp :={ //specific value and compl. list
23 x1:="00AA",
24 x2:=complement ("11","0A","1BC0"),
25 x3:="10AA" };
26template templateCharstr_rec templateCharstr_tOmit :={ //omitting values
27 x1:="00AA",
28 x2:="01AA",
29 x3:=omit } ;
30template templateCharstr_rec templateCharstr_tAny :={ //specific and any value
31 x1:="00AA",
32 x2:="01AA",
33 x3:=? } ;
34template templateCharstr_rec templateCharstr_tAnyorNone :={ //specific and AnyorNone value
35 x1:="00AA",
36 x2:="01AA",
37 x3:=* };
38template templateCharstr_rec templateCharstr_tLength1 :={ //specific value and fix length
39 x1:="00AA",
40 x2:="01AA",
41 x3:=* length(3) };
42template templateCharstr_rec templateCharstr_tLength2 :={ //specific value and length (range)
43 x1:="00AA",
44 x2:="01AA",
45 x3:=? length(2..4) };
46template templateCharstr_rec templateCharstr_tLength3 :={ //specific value and length (range, infinity)
47 x1:="00AA",
48 x2:="01AA",
49 x3:=? length(2..infinity) };
50template templateCharstr_rec templateCharstr_tIfpresent :={ //specific value and ifpresent
51 x1:="00AA",
52 x2:="01AA",
53 x3:="10AA" ifpresent };
54 template templateCharstr_rec templateCharstr_tLengthIfp :={ //specific value and fix length and ifpresent
55 x1:="00AA",
56 x2:="01AA",
57 x3:=? length(3) ifpresent};
58template templateCharstr_rec templateCharstr_tAnyEl :={ //specific value and any element inside value
59 x1:="00AA",
60 x2:="01AA",
61 x3:= pattern "10?" } ;
62template templateCharstr_rec templateCharstr_tAnyorNoneEl :={ //specific value and Any number of elements or none inside value
63 x1:="00AA",
64 x2:="01AA",
65 x3:= pattern "10*" };
66template templateCharstr_rec templateCharstr_tRange1 :={ //specific value and Range
67 x1:="1",
68 x2:=("2" .."4"),
69 x3:="3" };
70template templateCharstr_rec templateCharstr_tRange2 :={ //specific value and Range
71 x1:="1",
72 x2:=("2" .. "4"),
73 x3:="3" };
74template templateCharstr_rec templateCharstr_tRange3 :={ //specific value and Range
75 x1:="1",
76 x2:=("3" .. int2char(127)),
77 x3:="3" };
78template templateCharstr_rec templateCharstr_tRange4 :={ //specific value and Range
79 x1:="1",
80 x2:=(int2char(0) .. "4"),
81 x3:="3" };
82template templateCharstr_rec templateCharstr_tRepeat := {
83 x1:= pattern "6#3", // precisely 3
84 x2:= pattern "6#(,)", // any number
85 x3:= pattern "6#(3)" }; // precisely 3
86template templateCharstr_rec templateCharstr_tRepeatFull := {
87 x1:= pattern "6#(3,)", // at least 3
88 x2:= pattern "6#(,3)", // at most 3
89 x3:= pattern "6#(3,3)" }; // precisely 3
feade998 90template templateCharstr_rec templateCharstr_tPattern := {
91 x1 := pattern "abc?xyz",
92 x2 := pattern @nocase "abc?xyz",
93 x3 := pattern @nocase "abc*xyz" };
970ed795
EL
94
95testcase templateCharstrSpec() runs on templateCharstr_mycomp {
96var templateCharstr_rec x1,x2; //specific value
97x1:={ x1:="00AA", x2:="01AA", x3:="10AA" };
98x2:={ x1:="00BC", x2:="01AA", x3:="10AA" };
99//match
100if (match(x1,templateCharstr_tSpec)) {setverdict(pass);}
101 else {setverdict(fail);}
102//no match
103if (not(match(x2,templateCharstr_tSpec))) {setverdict(pass);}
104 else {setverdict(fail);}
105}
106
107testcase templateCharstrList() runs on templateCharstr_mycomp {
108var templateCharstr_rec x1,x2,x3; //value list
109x1:={ x1:="00AA", x2:="01AA", x3:="10AA" };
110x2:={ x1:="00AA", x2:="00", x3:="10AA" };
111x3:={ x1:="1D", x2:="01AA", x3:="10AA" };
112//match
113if (match(x1,templateCharstr_tList)) {setverdict(pass);}
114 else {setverdict(fail);}
115//no match: out of list
116if (not(match(x2,templateCharstr_tList))) {setverdict(pass);}
117 else {setverdict(fail);}
118//no match: other field
119if (not(match(x3,templateCharstr_tList))) {setverdict(pass);}
120 else {setverdict(fail);}
121}
122
123testcase templateCharstrComp() runs on templateCharstr_mycomp {
124var templateCharstr_rec x1,x2,x3; //complemented list
125x1:={ x1:="00AA", x2:="01AA", x3:="10AA" };
126x2:={ x1:="00AA", x2:="0A", x3:="10AA" };
127x3:={ x1:="11AA", x2:="01AA", x3:="10AA" };
128//match
129if (match(x1,templateCharstr_tComp)) {setverdict(pass);}
130 else {setverdict(fail);}
131//no match: in the list
132if (not(match(x2,templateCharstr_tComp))) {setverdict(pass);}
133 else {setverdict(fail);}
134//no match: other field
135if (not(match(x3,templateCharstr_tComp))) {setverdict(pass);}
136 else {setverdict(fail);}
137}
138
139testcase templateCharstrOmit() runs on templateCharstr_mycomp {
140var templateCharstr_rec x1,x2,x3; //omitting value
141x1:={ x1:="00AA", x2:="01AA", x3:=omit };
142x2:={ x1:="00AA", x2:="01AA", x3:="AB" };
143x3:={ x1:="00DE", x2:="01AA", x3:=omit };
144//match
145if (match(x1,templateCharstr_tOmit)) {setverdict(pass);}
146 else {setverdict(fail);}
147//no match: not omitted
148if (not(match(x2,templateCharstr_tOmit))) {setverdict(pass);}
149 else {setverdict(fail);}
150//no match: other field
151if (not(match(x3,templateCharstr_tOmit))) {setverdict(pass);}
152 else {setverdict(fail);}
153}
154
155testcase templateCharstrAny() runs on templateCharstr_mycomp {
156var templateCharstr_rec x1,x2,x3; //any value
157x1:={ x1:="00AA", x2:="01AA", x3:="ABCD" };
158x2:={ x1:="00AA", x2:="01AA", x3:=omit };
159x3:={ x1:="0A", x2:="01AA", x3:="ABCD" };
160//match
161if (match(x1,templateCharstr_tAny)) {setverdict(pass);}
162 else {setverdict(fail);}
163//no match: field omitted
164if (not(match(x2,templateCharstr_tAny))) {setverdict(pass);}
165 else {setverdict(fail);}
166//no match: other field
167if (not(match(x3,templateCharstr_tAny))) {setverdict(pass);}
168 else {setverdict(fail);}
169}
170
171testcase templateCharstrAnyorNone() runs on templateCharstr_mycomp {
172var templateCharstr_rec x1,x2,x3; //AnyorNone value
173x1:={ x1:="00AA", x2:="01AA", x3:=omit };
174x2:={ x1:="00AA", x2:="01AA", x3:="10AB" };
175x3:={ x1:="1C", x2:="01AA", x3:=omit };
176//match: omitted
177if (match(x1,templateCharstr_tAnyorNone)) {setverdict(pass);}
178 else {setverdict(fail);}
179//match: value
180if (match(x2,templateCharstr_tAnyorNone)) {setverdict(pass);}
181 else {setverdict(fail);}
182//no match: other field
183if (not(match(x3,templateCharstr_tAnyorNone))) {setverdict(pass);}
184 else {setverdict(fail);}
185}
186
187testcase templateCharstrLength1() runs on templateCharstr_mycomp {
188var templateCharstr_rec x1,x2,x3,x4; //length (fix)
189x1:={ x1:="00AA", x2:="01AA", x3:="abc" };
190x2:={ x1:="00AA", x2:="01AA", x3:="abc" };
191x3:={ x1:="00AA", x2:="01AA", x3:="1D" };
192x4:={ x1:="001A", x2:="01AA", x3:="abc" };
193//match: proper length
194if (match(x1,templateCharstr_tLength1)) {setverdict(pass);}
195 else {setverdict(fail);}
196//match: omitted
197if (match(x2,templateCharstr_tLength1)) {setverdict(pass);}
198 else {setverdict(fail);}
199// no match: not proper length
200if (not(match(x3,templateCharstr_tLength1))) {setverdict(pass);}
201 else {setverdict(fail);}
202//no match: other field
203if (not(match(x4,templateCharstr_tLength1))) {setverdict(pass);}
204 else {setverdict(fail);}
205}
206
207testcase templateCharstrLength2() runs on templateCharstr_mycomp {
208var templateCharstr_rec x1,x2,x3; //length (range)
209x1:={ x1:="00AA", x2:="01AA", x3:="abcd" };
210x2:={ x1:="00AA", x2:="01AA", x3:="a" };
211x3:={ x1:="001A", x2:="01AA", x3:="abc" };
212//match
213if (match(x1,templateCharstr_tLength2)) {setverdict(pass);}
214 else {setverdict(fail);}
215// no match: not proper length
216if (not(match(x2,templateCharstr_tLength2))) {setverdict(pass);}
217 else {setverdict(fail);}
218//no match: other field
219if (not(match(x3,templateCharstr_tLength2))) {setverdict(pass);}
220 else {setverdict(fail);}
221}
222
223testcase templateCharstrLength3() runs on templateCharstr_mycomp {
224var templateCharstr_rec x1,x2,x3; //length (range, infinity)
225x1:={ x1:="00AA", x2:="01AA", x3:="abcd" };
226x2:={ x1:="00AA", x2:="01AA", x3:="a" };
227x3:={ x1:="001A", x2:="01AA", x3:="abc" };
228//match
229if (match(x1,templateCharstr_tLength3)) {setverdict(pass);}
230 else {setverdict(fail);}
231// no match: not proper length
232if (not(match(x2,templateCharstr_tLength3))) {setverdict(pass);}
233 else {setverdict(fail);}
234//no match: other field
235if (not(match(x3,templateCharstr_tLength3))) {setverdict(pass);}
236 else {setverdict(fail);}
237}
238testcase templateCharstrIfpresent() runs on templateCharstr_mycomp {
239var templateCharstr_rec x1,x2,x3,x4; //ifpresent
240x1:={ x1:="00AA", x2:="01AA", x3:="10AA" };
241x2:={ x1:="00AA", x2:="01AA", x3:=omit };
242x3:={ x1:="00AA", x2:="01AA", x3:="00AA" };
243x4:={ x1:="00", x2:="01AA", x3:=omit };
244//match: present and match
245if (match(x1,templateCharstr_tIfpresent)) {setverdict(pass);}
246 else {setverdict(fail);}
247//match: not present
248if (match(x2,templateCharstr_tIfpresent)) {setverdict(pass);}
249 else {setverdict(fail);}
250//no match: present and not match
251if (not(match(x3,templateCharstr_tIfpresent))) {setverdict(pass);}
252 else {setverdict(fail);}
253//no match: other field
254if (not(match(x4,templateCharstr_tIfpresent))) {setverdict(pass);}
255 else {setverdict(fail);}
256}
257
258testcase templateCharstrLengthIfp() runs on templateCharstr_mycomp {
259var templateCharstr_rec x1,x2,x3,x4; //length (fix), ifpresent
260x1:={ x1:="00AA", x2:="01AA", x3:="abc" };
261x2:={ x1:="00AA", x2:="01AA", x3:="abc" };
262x3:={ x1:="00AA", x2:="01AA", x3:="1D" };
263x4:={ x1:="001A", x2:="01AA", x3:="abc" };
264//match: proper length
265if (match(x1,templateCharstr_tLengthIfp)) {setverdict(pass);}
266 else {setverdict(fail);}
267//match: omitted
268if (match(x2,templateCharstr_tLengthIfp)) {setverdict(pass);}
269 else {setverdict(fail);}
270// no match: not proper length
271if (not(match(x3,templateCharstr_tLengthIfp))) {setverdict(pass);}
272 else {setverdict(fail);}
273//no match: other field
274if (not(match(x4,templateCharstr_tLengthIfp))) {setverdict(pass);}
275 else {setverdict(fail);}
276}
277
278testcase templateCharstrAnyEl() runs on templateCharstr_mycomp {
279var templateCharstr_rec x1,x2,x3,x4,x5; //any element
280x1:={ x1:="00AA", x2:="01AA", x3:="10a" };
281x2:={ x1:="00AA", x2:="01AA", x3:="10" };
282x3:={ x1:="00AA", x2:="01AA", x3:="10Aa" };
283x4:={ x1:="00AA", x2:="01AA", x3:="12A" };
284x5:={ x1:="0A", x2:="01AA", x3:="10a" };
285//match
286if (match(x1,templateCharstr_tAnyEl)) {setverdict(pass);}
287 else {setverdict(fail);}
288//no match: no element
289if (not(match(x2,templateCharstr_tAnyEl))) {setverdict(pass);}
290 else {setverdict(fail);}
291//no match: two element
292if (not(match(x3,templateCharstr_tAnyEl))) {setverdict(pass);}
293 else {setverdict(fail);}
294//no match: wrong element
295if (not(match(x4,templateCharstr_tAnyEl))) {setverdict(pass);}
296 else {setverdict(fail);}
297//no match: other field
298if (not(match(x5,templateCharstr_tAnyEl))) {setverdict(pass);}
299 else {setverdict(fail);}
300}
301
302testcase templateCharstrAnyorNoneEl() runs on templateCharstr_mycomp {
303var templateCharstr_rec x1,x2,x3,x4,x5; //Any number of elements or none
304x1:={ x1:="00AA", x2:="01AA", x3:="10" };
305x2:={ x1:="00AA", x2:="01AA", x3:="10k" };
306x3:={ x1:="00AA", x2:="01AA", x3:="10Aa" };
307x4:={ x1:="00AA", x2:="01AA", x3:="11a" };
308x5:={ x1:="1A", x2:="01AA", x3:="10a" };
309//match: no element
310if (match(x1,templateCharstr_tAnyorNoneEl)) {setverdict(pass);}
311 else {setverdict(fail);}
312//match: one element
313if (match(x2,templateCharstr_tAnyorNoneEl)) {setverdict(pass);}
314 else {setverdict(fail);}
315//match: two element
316if (match(x3,templateCharstr_tAnyorNoneEl)) {setverdict(pass);}
317 else {setverdict(fail);}
318//no match: wrong element
319if (not(match(x4,templateCharstr_tAnyorNoneEl))) {setverdict(pass);}
320 else {setverdict(fail);}
321//no match: other field
322if (not(match(x5,templateCharstr_tAnyorNoneEl))) {setverdict(pass);}
323 else {setverdict(fail);}
324}
325
326
327testcase templateCharstrRange1() runs on templateCharstr_mycomp {
328var templateCharstr_rec x1,x2,x3; //Range ( .. )
329x1:={ x1:="1", x2:="2", x3:="3" };
330x2:={ x1:="1", x2:="5", x3:="3" };
331x3:={ x1:="2", x2:="2", x3:="3" };
332//match
333if (match(x1,templateCharstr_tRange1)) {setverdict(pass);}
334 else {setverdict(fail);}
335//no match: out of range
336if (not(match(x2,templateCharstr_tRange1))) {setverdict(pass);}
337 else {setverdict(fail);}
338//no match: other field
339if (not(match(x3,templateCharstr_tRange1))) {setverdict(pass);}
340 else {setverdict(fail);}
341}
342
343testcase templateCharstrRange2() runs on templateCharstr_mycomp {
344var templateCharstr_rec x1,x2,x3; //Range ( to )
345x1:={ x1:="1", x2:="2", x3:="3" };
346x2:={ x1:="1", x2:="5", x3:="3"};
347x3:={ x1:="2", x2:="2", x3:="3" };
348//match
349if (match(x1,templateCharstr_tRange2)) {setverdict(pass);}
350 else {setverdict(fail);}
351//no match: out of range
352if (not(match(x2,templateCharstr_tRange2))) {setverdict(pass);}
353 else {setverdict(fail);}
354//no match: other field
355if (not(match(x3,templateCharstr_tRange2))) {setverdict(pass);}
356 else {setverdict(fail);}
357}
358
359testcase templateCharstrRange3() runs on templateCharstr_mycomp {
360var templateCharstr_rec x1,x2,x3; //Range, with infinity
361x1:={ x1:="1", x2:="8", x3:="3" };
362x2:={ x1:="1", x2:="2", x3:="3" };
363x3:={ x1:="2", x2:="2", x3:="3" };
364//match
365if (match(x1,templateCharstr_tRange3)) {setverdict(pass);}
366 else {setverdict(fail);}
367//no match: out of range
368if (not(match(x2,templateCharstr_tRange3))) {setverdict(pass);}
369 else {setverdict(fail);}
370//no match: other field
371if (not(match(x3,templateCharstr_tRange3))) {setverdict(pass);}
372 else {setverdict(fail);}
373}
374
375testcase templateCharstrRange4() runs on templateCharstr_mycomp {
376var templateCharstr_rec x1,x2,x3; //Range with - infinity
377x1:={ x1:="1", x2:="2", x3:="3" };
378x2:={ x1:="1", x2:="5", x3:="3" };
379x3:={ x1:="2", x2:="2", x3:="3" };
380//match
381if (match(x1,templateCharstr_tRange4)) {setverdict(pass);}
382 else {setverdict(fail);}
383//no match: out of range
384if (not(match(x2,templateCharstr_tRange4))) {setverdict(pass);}
385 else {setverdict(fail);}
386//no match: other field
387if (not(match(x3,templateCharstr_tRange4))) {setverdict(pass);}
388 else {setverdict(fail);}
389}
390
391
392type record templateCharstr_myrec {
393 charstring f1 optional,
394 charstring f2 optional
395}
396
397const templateCharstr_myrec mr := {
398 f1 := "b",
399 f2 := "a"
400}
401
402type component templateCharstr_mycomp2 {
403 const charstring x1 := "";
404 var charstring x2 := "";
405 const charstring x3 := "x";
406 var charstring x4 := "x";
407}
408
409function tryPatternReferenceWithOptionalField(in templateCharstr_myrec p) runs on templateCharstr_mycomp2
410{ // regression test for TR 909
411 template charstring piecemeal := pattern "{p.f1}{p.f2}r";
412 if (match("bar", piecemeal)) { setverdict(pass); }
413 else { setverdict(fail); }
414 if (match("r", piecemeal)) { setverdict(fail); }
415 else { setverdict(pass); }
416
417 var template charstring piecemealv := pattern "{p.f1}{p.f2}r";
418 if (match("bar", piecemealv)) { setverdict(pass); }
419 else { setverdict(fail); }
420 if (match("r", piecemealv)) { setverdict(fail); }
421 else { setverdict(pass); }
422}
423
424testcase templateCharstrEmptyPattern() runs on templateCharstr_mycomp2
425{
426 if (match("", pattern "")) { setverdict(pass); }
427 else { setverdict(fail); }
428 if (not match("x", pattern "{x1}{x2}")) { setverdict(pass); }
429 else { setverdict(fail); }
430 if (match("xxx", pattern "{x3}x{x4}")) { setverdict(pass); }
431 else { setverdict(fail); }
432
433 tryPatternReferenceWithOptionalField(mr);
434}
435
436testcase templateCharstrRepeat() runs on templateCharstr_mycomp {
437var templateCharstr_rec x1,x2,x3,x4; //repeat
438x1:={ x1:="666", x2:="", x3:="666" };
439x2:={ x1:="6" , x2:="", x3:="666" };
440x3:={ x1:="666", x2:="", x3:="6666" };
441x4:={ x1:="666", x2:="6 6 6", x3:="666" };
442//match
443if (match(x1,templateCharstr_tRepeat)) {setverdict(pass);}
444 else {setverdict(fail);}
445//no match
446if (not(match(x2,templateCharstr_tRepeat))) {setverdict(pass);}
447 else {setverdict(fail);}
448if (not(match(x3,templateCharstr_tRepeat))) {setverdict(pass);}
449 else {setverdict(fail);}
450if (not(match(x4,templateCharstr_tRepeat))) {setverdict(pass);}
451 else {setverdict(fail);}
452}
453
454testcase templateCharstrRepeatFull() runs on templateCharstr_mycomp {
455var templateCharstr_rec x0,x1,x2,x3,x4; //repeat
456x0:={ x1:="666", x2:="", x3:="666" }; // shortest possible
457x1:={ x1:="6666", x2:="666", x3:="666" }; // just over
458x2:={ x1:="6" , x2:="", x3:="666" }; // fail first
459x3:={ x1:="666", x2:="6666", x3:="6666" }; // fail second
460x4:={ x1:="666", x2:="", x3:="6" }; // fail third
461//match
462if (match(x0,templateCharstr_tRepeatFull)) {setverdict(pass);}
463 else {setverdict(fail);}
464if (match(x1,templateCharstr_tRepeatFull)) {setverdict(pass);}
465 else {setverdict(fail);}
466//no match
467if (not(match(x2,templateCharstr_tRepeatFull))) {setverdict(pass);}
468 else {setverdict(fail);}
469if (not(match(x3,templateCharstr_tRepeatFull))) {setverdict(pass);}
470 else {setverdict(fail);}
471if (not(match(x4,templateCharstr_tRepeatFull))) {setverdict(pass);}
472 else {setverdict(fail);}
473}
474
feade998 475testcase templateCharstrPattern() runs on templateCharstr_mycomp {
476 var templateCharstr_rec x0, x1, x2, x3, x4; // pattern
477 x0 := { x1 := "abc,xyz", x2 := "abc1xyz", x3 := "abcxyz" };
478 x1 := { x1 := "abcpxyz", x2 := "abcPxyz", x3 := "abc123abcJKL.? \txyz" };
479 x2 := { x1 := "abcxyz", x2 := "abcPxyz", x3 := "abc123xyz" }; // fail first
480 x3 := { x1 := "abcpxyz", x2 := "abc123xyz", x3 := "abc123xyz" }; // fail second
481 x4 := { x1 := "abcpxyz", x2 := "abcPxyz", x3 := "abc123xy z" }; // fail third
482
483 // match
484 if (match(x0, templateCharstr_tPattern)) { setverdict(pass); }
485 else { setverdict(fail); }
486 if (match(x1, templateCharstr_tPattern)) { setverdict(pass); }
487 else { setverdict(fail); }
488
489 // not match
490 if (not match(x2, templateCharstr_tPattern)) { setverdict(pass); }
491 else { setverdict(fail); }
492 if (not match(x3, templateCharstr_tPattern)) { setverdict(pass); }
493 else { setverdict(fail); }
494 if (not match(x4, templateCharstr_tPattern)) { setverdict(pass); }
495 else { setverdict(fail); }
496}
497
970ed795
EL
498testcase TR920() runs on templateCharstr_mycomp {
499 var template charstring temp := pattern "[0-9]|[0-9][0-9]";
500 const charstring x := "10a";
501
502 if(match(x, temp)){
503 setverdict(fail);
504 }else{
505 setverdict(pass);
506 }
507}
508
509// http://t-ort.etsi.org/view.php?id=3761
510testcase templateCharstrPatternCat() runs on templateCharstr_mycomp
511{
512 if (match("aazz", pattern "a" & "*z")) { setverdict(pass); }
513 else { setverdict(fail); }
514 if (match("AAZZ", pattern "a*" & "z|" & "A*Z")) { setverdict(pass); }
515 else { setverdict(fail); }
516 if (match("AAZZ0123456789", pattern "(a*" & "z|" & "A*Z)" & "[0-9]+")) { setverdict(pass); }
517 else { setverdict(fail); }
518}
519
520testcase CatBasic() runs on templateCharstr_mycomp {
521 var charstring cs1 := "xyz"
522 var charstring cs2 := "(xyz)*[abc]+"
523 var charstring cs3 := "{xyz}" // No run-time references.
524 var template charstring t1, t2, t3, t4, t5, t6, t7
525 t1 := pattern cs1
526 t2 := pattern cs2
527 t3 := pattern cs1 & "utoljara"
528 t4 := pattern cs1 & "utoljar(a)+" & cs1
529 t5 := pattern "utoljara" & cs1
530 t6 := pattern "valami" & cs1 & "megegyszer" & "utoljara"
531 t7 := pattern "valami" & cs3 & "megegyszer" & "utoljara"
532 if (match("xyz", t1)) { setverdict(pass) } else { setverdict(fail) }
533 if (match("xyzxyzxyza", t2)) { setverdict(pass) } else { setverdict(fail) }
534 if (match("xyzabcaabbccac", t2)) { setverdict(pass) } else { setverdict(fail) }
535 if (match("xyzutoljara", t3)) { setverdict(pass) } else { setverdict(fail) }
536 if (match("xyzutoljaraaaaaaaaaaaxyz", t4)) { setverdict(pass) } else { setverdict(fail) }
537 if (match("utoljaraxyz", t5)) { setverdict(pass) } else { setverdict(fail) }
538 if (match("valamixyzmegegyszerutoljara", t6)) { setverdict(pass) } else { setverdict(fail) }
539 if (match("valami{xyz}megegyszerutoljara", t7)) { setverdict(pass) } else { setverdict(fail) }
540}
541
542template srec pt1(in charstring sp) := { s := pattern sp }
543template srec pt2(in charstring sp) := { s := pattern sp & "megvalami" }
544template srec pt3(in charstring sp) := { s := pattern "valami" & sp }
545template srec pt4(in charstring sp) := { s := pattern "valami" & sp & "megvalami" }
546template srec pt5(in charstring sp) := { s := pattern sp & "valami" & sp }
547
548testcase CatParametrized() runs on templateCharstr_mycomp
549{
550 var srec r1, r2, r3, r4, r5
551 r1 := { "xyz" }
552 r2 := { "xyzmegvalami" }
553 r3 := { "valamixyz" }
554 r4 := { "valamixyzmegvalami" }
555 r5 := { "xyzvalamixyz" }
556 if (match(r1, pt1("xyz"))) { setverdict(pass) } else { setverdict(fail) }
557 if (match(r2, pt2("xyz"))) { setverdict(pass) } else { setverdict(fail) }
558 if (match(r3, pt3("xyz"))) { setverdict(pass) } else { setverdict(fail) }
559 if (match(r4, pt4("xyz"))) { setverdict(pass) } else { setverdict(fail) }
560 if (match(r5, pt5("xyz"))) { setverdict(pass) } else { setverdict(fail) }
561}
562
563function f1(in charstring s) return integer {
564 var template charstring t := pattern s; if (match(s, t)) { return 0 } else { return 1 }
565}
566
567function f2(in charstring s) return integer {
568 var template charstring t := pattern s & "megvalami"; if (match(s & "megvalami", t)) { return 0 } else { return 1 }
569}
570
571function f3(in charstring s) return integer {
572 var template charstring t := pattern "valami" & s; if (match("valami" & s, t)) { return 0 } else { return 1 }
573}
574
575function f4(in charstring s) return integer {
576 var template charstring t := pattern "valami" & s & "megvalami"; if (match("valami" & s & "megvalami", t)) { return 0 } else { return 1 }
577}
578
579function f5(in charstring s) return integer {
580 var template charstring t := pattern s & "valami" & s; if (match(s & "valami" & s, t)) { return 0 } else { return 1 }
581}
582
583type record srec { charstring s }
584
585testcase CatFunctions() runs on templateCharstr_mycomp
586{
587 if (f1("xyz") == 0) { setverdict(pass) } else { setverdict(fail) }
588 if (f2("xyz") == 0) { setverdict(pass) } else { setverdict(fail) }
589 if (f3("xyz") == 0) { setverdict(pass) } else { setverdict(fail) }
590 if (f4("xyz") == 0) { setverdict(pass) } else { setverdict(fail) }
591 if (f5("xyz") == 0) { setverdict(pass) } else { setverdict(fail) }
592}
593
594testcase CatStructured() runs on templateCharstr_mycomp
595{
596 var srec r1 := { "xyz" }
597 var template charstring t1, t2, t3, t4, t5
598 t1 := pattern r1.s
599 t2 := pattern r1.s & "megvalami"
600 t3 := pattern "valami" & r1.s
601 t4 := pattern "valami" & r1.s & "megvalami"
602 t5 := pattern r1.s & "valami" & r1.s
603 if (match("xyz", t1)) { setverdict(pass) } else { setverdict(fail) }
604 if (match("xyzmegvalami", t2)) { setverdict(pass) } else { setverdict(fail) }
605 if (match("valamixyz", t3)) { setverdict(pass) } else { setverdict(fail) }
606 if (match("valamixyzmegvalami", t4)) { setverdict(pass) } else { setverdict(fail) }
607 if (match("xyzvalamixyz", t5)) { setverdict(pass) } else { setverdict(fail) }
608}
609
610
611const charstring base_1:= "ab?";
612const charstring base_2 := "ab*";
613
614template charstring p1:= pattern "{base_1}";
615template charstring p2:= pattern base_1;
616
617template charstring p3 := pattern "{base_2}";
618template charstring p4 := pattern base_2;
619
620template charstring p5 := pattern "{p3}{p3}";
621template charstring p6 := pattern "{p3}" & "{p3}";
622template charstring p7 := pattern p3 & p3;
623template charstring p8 := pattern "c{p4}d";
624
625
626testcase pattern_reference() runs on templateCharstr_mycomp {
627
628 var charstring string_1 := "abc";
629 var charstring string_2 := "ab"
630
631 if (match(string_1, p1)) {setverdict(pass);} else {setverdict(fail);}
632 if (match(base_1, p1)) {setverdict(pass);} else {setverdict(fail);}
633 if (match(base_1, p2)) {setverdict(pass);} else {setverdict(fail);}
634
635 if (match(string_2, p3)) {setverdict(pass);} else {setverdict(fail);}
636 if (match(base_2, p3)) {setverdict(pass);} else {setverdict(fail);}
637 if (match(base_2, p4)) {setverdict(pass);} else {setverdict(fail);}
638
639 if (match("abnabn", p5)) {setverdict(pass);} else {setverdict(fail);}
640 if (match("abnabn", p6)) {setverdict(pass);} else {setverdict(fail);}
641 if (match("abnabn", p7)) {setverdict(pass);} else {setverdict(fail);}
642 if (match("cabxd", p8)) {setverdict(pass);} else {setverdict(fail);}
643
644}
645
646type record of charstring Ss;
647
648type record ss_x
649{
650 //integer a;
651 charstring a,
652 integer b
653};
654
655
656type record ss_x2
657{
658 //integer a;
659 ss_x a,
660 integer b
661};
662
663
664testcase HO30913_reference() runs on templateCharstr_mycomp {
665 //test to check [1] reference
666
667 var Ss ss;
668 var charstring s;
669
670 s := "s";
671 ss[0] := "0";
672 ss[1] := "1";
673 log(match(ss[0], pattern s)); // this compiles
674 log(match(ss[0], pattern ss[1])); // this does not compile
675
676 var ss_x xx;
677 var ss_x2 xx2;
678
679 xx.a := "a";
680
681 //log(match(ss[0], pattern x.a)); // this does not compile segmentation fault
682 log(match(ss[0], pattern xx.a )); // this does not compile
683 setverdict(pass);
684}
685
686testcase CR_TR00018474() runs on templateCharstr_mycomp {
687 // Indexing of string template variables.
688 var template charstring vtc1 := "fisherman"
689 var template charstring vtc2 := "?*?****" // It's still a plain charstring.
690 vtc1[0] := "F" // Normal usage.
691 if (match("Fisherman", vtc1)) { setverdict(pass) } else { setverdict(fail) }
692 vtc1[0] := "*" // Just an ASCII character.
693 if (match("*isherman", vtc1)) { setverdict(pass) } else { setverdict(fail) }
694 vtc1[1] := "?" // Just an ASCII character.
695 if (match("*?sherman", vtc1)) { setverdict(pass) } else { setverdict(fail) }
696 vtc1[0] := "F" // Indexed assignment notation cannot be used here.
697 vtc1[1] := "i" // Still works, nothing special.
698 if (match("Fisherman", vtc1)) { setverdict(pass) } else { setverdict(fail) }
699 vtc2[0] := "*"
700 if (match("**?****", vtc2)) { setverdict(pass) } else { setverdict(fail) }
701}
702
703control {
704 execute(templateCharstrSpec());
705 execute(templateCharstrList());
706 execute(templateCharstrComp());
707 execute(templateCharstrOmit());
708 execute(templateCharstrAny());
709 execute(templateCharstrAnyorNone());
710 execute(templateCharstrLength1());
711 execute(templateCharstrLength2());
712 execute(templateCharstrLength3());
713 execute(templateCharstrIfpresent());
714 execute(templateCharstrLengthIfp());
715 execute(templateCharstrAnyEl());
716 execute(templateCharstrAnyorNoneEl());
717 execute(templateCharstrRange1());
718 execute(templateCharstrRange2());
719 execute(templateCharstrRange3());
720 execute(templateCharstrRange4());
721 execute(templateCharstrEmptyPattern());
722 execute(templateCharstrRepeat());
723 execute(templateCharstrRepeatFull());
feade998 724 execute(templateCharstrPattern());
970ed795
EL
725 execute(TR920());
726 execute(templateCharstrPatternCat());
727 execute(CatBasic())
728 execute(CatParametrized())
729 execute(CatFunctions())
730 execute(CatStructured())
731 execute(pattern_reference());
732 execute(HO30913_reference());
733 execute(CR_TR00018474());
734}
735}
This page took 0.051652 seconds and 5 git commands to generate.