-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEfxExpressionTranslatorV2Test.java
More file actions
4654 lines (3923 loc) · 179 KB
/
EfxExpressionTranslatorV2Test.java
File metadata and controls
4654 lines (3923 loc) · 179 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2023 European Union
*
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
* compliance with the Licence. You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the Licence for the specific language governing permissions and limitations under
* the Licence.
*/
package eu.europa.ted.efx.sdk2;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.junit.jupiter.api.Test;
import eu.europa.ted.efx.EfxTestsBase;
import eu.europa.ted.efx.exceptions.InvalidIdentifierException;
import eu.europa.ted.efx.exceptions.InvalidUsageException;
import eu.europa.ted.efx.exceptions.TypeMismatchException;
class EfxExpressionTranslatorV2Test extends EfxTestsBase {
@Override
protected String getSdkVersion() {
return "eforms-sdk-2.0";
}
// #region: Boolean expressions ---------------------------------------------
@Test
void testParenthesizedBooleanExpression() {
testExpressionTranslationWithContext("(true() or true()) and false()", "BT-00-Text",
"(ALWAYS or TRUE) and NEVER");
}
@Test
void testLogicalOrCondition() {
testExpressionTranslationWithContext("true() or false()", "BT-00-Text", "ALWAYS or NEVER");
}
@Test
void testLogicalAndCondition() {
testExpressionTranslationWithContext("true() and 1 + 1 = 2", "BT-00-Text",
"ALWAYS and 1 + 1 == 2");
}
@Test
void testInListCondition() {
testExpressionTranslationWithContext("not('x' = ('a','b','c'))", "BT-00-Text",
"'x' not in ['a', 'b', 'c']");
}
@Test
void testPresenceCondition() {
testExpressionTranslationWithContext("PathNode/TextField", "ND-Root", "BT-00-Text is present");
}
@Test
void testPresenceCondition_WithNot() {
testExpressionTranslationWithContext("not(PathNode/TextField)", "ND-Root",
"BT-00-Text is not present");
}
@Test
void testUniqueValueCondition() {
testExpressionTranslationWithContext(
"count(for $n in PathNode/TextField/normalize-space(text()), $x in /*/PathNode/TextField/normalize-space(text())[. = $n] return $x) = 1",
"ND-Root", "BT-00-Text is unique in /BT-00-Text");
}
@Test
void testUniqueValueCondition_WithNot() {
testExpressionTranslationWithContext(
"not(count(for $n in PathNode/TextField/normalize-space(text()), $x in /*/PathNode/TextField/normalize-space(text())[. = $n] return $x) = 1)",
"ND-Root", "BT-00-Text is not unique in /BT-00-Text");
}
@Test
void testStringUniqueValueCondition_WithLiteralSequence() {
testExpressionTranslationWithContext(
"count(for $n in 'b', $x in ('a','b','c','b')[. = $n] return $x) = 1",
"BT-00-Text", "'b' is unique in ['a', 'b', 'c', 'b']");
}
@Test
void testNumericUniqueValueCondition_WithLiteralSequence() {
testExpressionTranslationWithContext(
"count(for $n in 2, $x in (1,2,3,2)[. = $n] return $x) = 1",
"BT-00-Number", "2 is unique in [1, 2, 3, 2]");
}
@Test
void testStringUniqueValueCondition_WithRepeatableField() {
testExpressionTranslationWithContext(
"count(for $n in PathNode/TextField/normalize-space(text()), $x in /*/PathNode/RepeatableTextField/normalize-space(text())[. = $n] return $x) = 1",
"ND-Root", "BT-00-Text is unique in /BT-00-Repeatable-Text");
}
@Test
void testStringUniqueValueCondition_WithNot() {
testExpressionTranslationWithContext(
"not(count(for $n in 'x', $x in ('a','b','c')[. = $n] return $x) = 1)",
"BT-00-Text", "'x' is not unique in ['a', 'b', 'c']");
}
@Test
void testStringUniqueValueCondition_WithRelativeFieldReference() {
testExpressionTranslationWithContext(
"count(for $n in PathNode/TextField/normalize-space(text()), $x in PathNode/RepeatableTextField/normalize-space(text())[. = $n] return $x) = 1",
"ND-Root", "BT-00-Text is unique in BT-00-Repeatable-Text");
}
@Test
void testStringUniqueValueCondition_WithFieldReferencePredicate() {
testExpressionTranslationWithContext(
"count(for $n in PathNode/TextField/normalize-space(text()), $x in /*/PathNode/RepeatableTextField[./normalize-space(text()) != '']/normalize-space(text())[. = $n] return $x) = 1",
"ND-Root", "BT-00-Text is unique in /BT-00-Repeatable-Text[BT-00-Repeatable-Text != '']");
}
@Test
void testStringUniqueValueCondition_WithFieldInRepeatableNodePredicate() {
testExpressionTranslationWithContext(
"count(for $n in PathNode/TextField/normalize-space(text()), $x in /*/RepeatableNode/TextField[./normalize-space(text()) != '']/normalize-space(text())[. = $n] return $x) = 1",
"ND-Root", "BT-00-Text is unique in /BT-00-Text-In-Repeatable-Node[BT-00-Text-In-Repeatable-Node != '']");
}
@Test
void testLikePatternCondition() {
testExpressionTranslationWithContext("fn:matches(normalize-space('123'), '[0-9]*')",
"BT-00-Text", "'123' like '[0-9]*'");
}
@Test
void testLikePatternCondition_WithEscapedDot() {
testExpressionTranslationWithContext(
"fn:matches(normalize-space('12.3'), '[0-9]+\\.[0-9]+')",
"BT-00-Text", "'12.3' like '[0-9]+\\.[0-9]+'");
}
@Test
void testLikePatternCondition_WithEscapedSingleQuote() {
testExpressionTranslationWithContext("fn:matches(normalize-space('test'), 'a''b')",
"BT-00-Text", "'test' like 'a\\'b'");
}
@Test
void testLikePatternCondition_WithEscapedDoubleQuote() {
testExpressionTranslationWithContext("fn:matches(normalize-space('test'), 'a\"b')",
"BT-00-Text", "'test' like 'a\\\"b'");
}
@Test
void testLikePatternCondition_WithNot() {
testExpressionTranslationWithContext("not(fn:matches(normalize-space('123'), '[0-9]*'))",
"BT-00-Text", "'123' not like '[0-9]*'");
}
@Test
void testLikePatternCondition_WithTextField() {
testExpressionTranslation("fn:matches(normalize-space(PathNode/TextField/normalize-space(text())), '[0-9]*')",
"{ND-Root} ${BT-00-Text like '[0-9]*'}");
}
@Test
void testPreferredLanguage_ThrowsInExpressionContext() {
InvalidUsageException exception = assertThrows(InvalidUsageException.class,
() -> translateExpressionWithContext("ND-Root", "preferred-language(BT-00-Text-Multilingual)"));
assertEquals(InvalidUsageException.ErrorCode.TEMPLATE_ONLY_FUNCTION, exception.getErrorCode());
assertTrue(exception.getMessage().startsWith("line "), "Error message should include source position");
}
@Test
void testPreferredLanguageText_ThrowsInExpressionContext() {
InvalidUsageException exception = assertThrows(InvalidUsageException.class,
() -> translateExpressionWithContext("ND-Root", "preferred-language-text(BT-00-Text-Multilingual)"));
assertEquals(InvalidUsageException.ErrorCode.TEMPLATE_ONLY_FUNCTION, exception.getErrorCode());
}
@Test
void testPreferredLanguageProperty_ThrowsInExpressionContext() {
InvalidUsageException exception = assertThrows(InvalidUsageException.class,
() -> translateExpressionWithContext("ND-Root", "BT-00-Text-Multilingual:preferredLanguage"));
assertEquals(InvalidUsageException.ErrorCode.TEMPLATE_ONLY_FUNCTION, exception.getErrorCode());
}
@Test
void testPreferredLanguageTextProperty_ThrowsInExpressionContext() {
InvalidUsageException exception = assertThrows(InvalidUsageException.class,
() -> translateExpressionWithContext("ND-Root", "BT-00-Text-Multilingual:preferredLanguageText"));
assertEquals(InvalidUsageException.ErrorCode.TEMPLATE_ONLY_FUNCTION, exception.getErrorCode());
}
@Test
void testFieldValueComparison_UsingTextFields_ThrowsBecauseMultilingual() {
TypeMismatchException exception = assertThrows(TypeMismatchException.class,
() -> translateExpressionWithContext("Root", "textField == textMultilingualField"));
assertEquals(TypeMismatchException.ErrorCode.FIELD_IS_MULTILINGUAL, exception.getErrorCode());
}
@Test
void testFieldValueComparison_UsingNumericFields() {
testExpressionTranslationWithContext(
"PathNode/NumberField/number() <= PathNode/IntegerField/number()", "ND-Root",
"BT-00-Number <= integerField");
}
@Test
void testFieldValueComparison_UsingIndicatorFields() {
testExpressionTranslationWithContext("PathNode/IndicatorField != PathNode/IndicatorField",
"ND-Root", "BT-00-Indicator != BT-00-Indicator");
}
@Test
void testFieldValueComparison_UsingDateFields() {
testExpressionTranslationWithContext(
"PathNode/StartDateField/xs:date(text()) <= PathNode/EndDateField/xs:date(text())",
"ND-Root", "BT-00-StartDate <= BT-00-EndDate");
}
@Test
void testFieldValueComparison_UsingTimeFields() {
testExpressionTranslationWithContext(
"PathNode/StartTimeField/xs:time(text()) <= PathNode/EndTimeField/xs:time(text())",
"ND-Root", "BT-00-StartTime <= BT-00-EndTime");
}
@Test
void testFieldValueComparison_UsingDurationFields() {
assertEquals(
"boolean(for $T in (current-date()) return ($T + (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ())) <= $T + (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ()))))",
translateExpressionWithContext("ND-Root", "BT-00-Duration <= BT-00-Duration"));
}
@Test
void testFieldValueComparison_WithStringLiteral() {
testExpressionTranslationWithContext("PathNode/TextField/normalize-space(text()) = 'abc'",
"ND-Root", "BT-00-Text == 'abc'");
}
@Test
void testFieldValueComparison_WithNumericLiteral() {
testExpressionTranslationWithContext(
"PathNode/IntegerField/number() - PathNode/NumberField/number() > 0", "ND-Root",
"integerField - BT-00-Number > 0");
}
@Test
void testFieldValueComparison_WithDateLiteral() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') > PathNode/StartDateField/xs:date(text())", "ND-Root",
"2022-01-01Z > BT-00-StartDate");
}
@Test
void testFieldValueComparison_WithTimeLiteral() {
testExpressionTranslationWithContext(
"xs:time('00:01:00Z') > PathNode/EndTimeField/xs:time(text())", "ND-Root",
"00:01:00Z > BT-00-EndTime");
}
@Test
void testFieldValueComparison_TypeMismatch() {
assertThrows(ParseCancellationException.class,
() -> translateExpressionWithContext("ND-Root", "00:01:00 > BT-00-StartDate"));
}
@Test
void testBooleanComparison_UsingLiterals() {
testExpressionTranslationWithContext("false() != true()", "BT-00-Text", "NEVER != ALWAYS");
}
@Test
void testBooleanComparison_UsingFieldReference() {
testExpressionTranslationWithContext("../IndicatorField != true()", "BT-00-Text",
"BT-00-Indicator != ALWAYS");
}
@Test
void testNumericComparison() {
testExpressionTranslationWithContext(
"2 > 1 and 3 >= 1 and 1 = 1 and 4 < 5 and 5 <= 5 and ../NumberField/number() > ../IntegerField/number()",
"BT-00-Text", "2 > 1 and 3>=1 and 1==1 and 4<5 and 5<=5 and BT-00-Number > BT-00-Integer");
}
@Test
void testStringComparison() {
testExpressionTranslationWithContext("'aaa' < 'bbb'", "BT-00-Text", "'aaa' < 'bbb'");
}
@Test
void testStringComparison_WithEscapedSingleQuote() {
testExpressionTranslationWithContext("'a''b' = 'c''d'", "BT-00-Text", "'a\\'b' == 'c\\'d'");
}
@Test
void testDateComparison_OfTwoDateLiterals() {
testExpressionTranslationWithContext("xs:date('2018-01-01Z') > xs:date('2018-01-01Z')",
"BT-00-Text", "2018-01-01Z > 2018-01-01Z");
}
@Test
void testDateComparison_OfTwoDateReferences() {
testExpressionTranslationWithContext(
"PathNode/StartDateField/xs:date(text()) = PathNode/EndDateField/xs:date(text())",
"ND-Root", "BT-00-StartDate == BT-00-EndDate");
}
@Test
void testDateComparison_OfDateReferenceAndDateFunction() {
testExpressionTranslationWithContext(
"PathNode/StartDateField/xs:date(text()) = xs:date(PathNode/TextField/normalize-space(text()))",
"ND-Root", "BT-00-StartDate == date(BT-00-Text)");
}
@Test
void testTimeComparison_OfTwoTimeLiterals() {
testExpressionTranslationWithContext("xs:time('13:00:10Z') > xs:time('21:20:30Z')",
"BT-00-Text", "13:00:10Z > 21:20:30Z");
}
@Test
void testZonedTimeComparison_OfTwoTimeLiterals() {
testExpressionTranslationWithContext("xs:time('13:00:10+01:00') > xs:time('21:20:30+02:00')",
"BT-00-Text", "13:00:10+01:00 > 21:20:30+02:00");
}
@Test
void testTimeComparison_OfTwoTimeReferences() {
testExpressionTranslationWithContext(
"PathNode/StartTimeField/xs:time(text()) = PathNode/EndTimeField/xs:time(text())",
"ND-Root", "BT-00-StartTime == BT-00-EndTime");
}
@Test
void testTimeComparison_OfTimeReferenceAndTimeFunction() {
testExpressionTranslationWithContext(
"PathNode/StartTimeField/xs:time(text()) = xs:time(PathNode/TextField/normalize-space(text()))",
"ND-Root", "BT-00-StartTime == time(BT-00-Text)");
}
@Test
void testDurationComparison_UsingYearMonthDurationLiterals() {
testExpressionTranslationWithContext(
"boolean(for $T in (current-date()) return ($T + xs:yearMonthDuration('P1Y') = $T + xs:yearMonthDuration('P12M')))",
"BT-00-Text", "P1Y == P12M");
}
@Test
void testDurationComparison_UsingDayTimeDurationLiterals() {
testExpressionTranslationWithContext(
"boolean(for $T in (current-date()) return ($T + xs:dayTimeDuration('P21D') > $T + xs:dayTimeDuration('P7D')))",
"BT-00-Text", "P3W > P7D");
}
@Test
void testCalculatedDurationComparison() {
testExpressionTranslationWithContext(
"boolean(for $T in (current-date()) return ($T + xs:yearMonthDuration('P3M') > $T + (xs:dayTimeDuration(PathNode/EndDateField/xs:date(text()) - PathNode/StartDateField/xs:date(text())))))",
"ND-Root", "P3M > (BT-00-EndDate - BT-00-StartDate)");
}
@Test
void testNegativeDuration_Literal() {
testExpressionTranslationWithContext("xs:yearMonthDuration('-P3M')", "ND-Root", "-P3M");
}
@Test
void testNegativeDuration_ViaMultiplication() {
testExpressionTranslationWithContext("(-3 * (2 * xs:yearMonthDuration('-P3M')))", "ND-Root",
"2 * -P3M * -3");
}
@Test
void testNegativeDuration_ViaMultiplicationWithField() {
assertEquals(
"(-3 * (2 * (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ()))))",
translateExpressionWithContext("ND-Root", "2 * (duration)BT-00-Duration * -3"));
}
@Test
void testDurationMultiplication_DurationTimesLateBoundNumeric() {
testExpressionTranslationWithContext(
"(PathNode/NumberField/number() * xs:dayTimeDuration('P1D'))",
"ND-Root", "P1D * BT-00-Number");
}
@Test
void testDurationAddition() {
testExpressionTranslationWithContext(
"(xs:dayTimeDuration('P3D') + (xs:dayTimeDuration(PathNode/StartDateField/xs:date(text()) - PathNode/EndDateField/xs:date(text()))))",
"ND-Root", "P3D + (BT-00-StartDate - BT-00-EndDate)");
}
@Test
void testDurationSubtraction() {
testExpressionTranslationWithContext(
"(xs:dayTimeDuration('P3D') - (xs:dayTimeDuration(PathNode/StartDateField/xs:date(text()) - PathNode/EndDateField/xs:date(text()))))",
"ND-Root", "P3D - (BT-00-StartDate - BT-00-EndDate)");
}
@Test
void testBooleanLiteralExpression_Always() {
testExpressionTranslationWithContext("true()", "BT-00-Text", "ALWAYS");
}
@Test
void testBooleanLiteralExpression_Never() {
testExpressionTranslationWithContext("false()", "BT-00-Text", "NEVER");
}
// #endregion: Boolean expressions
// #region: Quantified expressions ------------------------------------------
@Test
void testStringQuantifiedExpression_UsingLiterals() {
testExpressionTranslationWithContext("every $x in ('a','b','c') satisfies $x <= 'a'", "ND-Root",
"every text:$x in ['a', 'b', 'c'] satisfies $x <= 'a'");
}
@Test
void testStringQuantifiedExpression_UsingFieldReference() {
testExpressionTranslationWithContext("every $x in PathNode/TextField/normalize-space(text()) satisfies $x <= 'a'",
"ND-Root", "every text:$x in BT-00-Text satisfies $x <= 'a'");
}
@Test
void testBooleanQuantifiedExpression_UsingLiterals() {
testExpressionTranslationWithContext("every $x in (true(),false(),true()) satisfies $x",
"ND-Root", "every indicator:$x in [TRUE, FALSE, ALWAYS] satisfies $x");
}
@Test
void testBooleanQuantifiedExpression_UsingFieldReference() {
testExpressionTranslationWithContext("every $x in PathNode/IndicatorField satisfies $x",
"ND-Root", "every indicator:$x in BT-00-Indicator satisfies $x");
}
@Test
void testNumericQuantifiedExpression_UsingLiterals() {
testExpressionTranslationWithContext("every $x in (1,2,3) satisfies $x <= 1", "ND-Root",
"every number:$x in [1, 2, 3] satisfies $x <= 1");
}
@Test
void testNumericQuantifiedExpression_UsingFieldReference() {
testExpressionTranslationWithContext("every $x in PathNode/NumberField/number() satisfies $x <= 1",
"ND-Root", "every number:$x in BT-00-Number satisfies $x <= 1");
}
@Test
void testDateQuantifiedExpression_UsingLiterals() {
testExpressionTranslationWithContext(
"every $x in (xs:date('2012-01-01Z'),xs:date('2012-01-02Z'),xs:date('2012-01-03Z')) satisfies $x <= xs:date('2012-01-01Z')",
"ND-Root",
"every date:$x in [2012-01-01Z, 2012-01-02Z, 2012-01-03Z] satisfies $x <= 2012-01-01Z");
}
@Test
void testDateQuantifiedExpression_UsingFieldReference() {
testExpressionTranslationWithContext(
"every $x in PathNode/StartDateField/xs:date(text()) satisfies $x <= xs:date('2012-01-01Z')", "ND-Root",
"every date:$x in BT-00-StartDate satisfies $x <= 2012-01-01Z");
}
@Test
void testDateQuantifiedExpression_UsingMultipleIterators() {
testExpressionTranslationWithContext(
"every $x in PathNode/StartDateField/xs:date(text()), $y in ($x,xs:date('2022-02-02Z')), $i in (true(),true()) satisfies $x <= xs:date('2012-01-01Z')",
"ND-Root",
"every date:$x in BT-00-StartDate, date:$y in [$x, 2022-02-02Z], indicator:$i in [ALWAYS, TRUE] satisfies $x <= 2012-01-01Z");
}
@Test
void testTimeQuantifiedExpression_UsingLiterals() {
testExpressionTranslationWithContext(
"every $x in (xs:time('00:00:00Z'),xs:time('00:00:01Z'),xs:time('00:00:02Z')) satisfies $x <= xs:time('00:00:00Z')",
"ND-Root", "every time:$x in [00:00:00Z, 00:00:01Z, 00:00:02Z] satisfies $x <= 00:00:00Z");
}
@Test
void testTimeQuantifiedExpression_UsingFieldReference() {
testExpressionTranslationWithContext(
"every $x in PathNode/StartTimeField/xs:time(text()) satisfies $x <= xs:time('00:00:00Z')", "ND-Root",
"every time:$x in BT-00-StartTime satisfies $x <= 00:00:00Z");
}
@Test
void testDurationQuantifiedExpression_UsingLiterals() {
testExpressionTranslationWithContext(
"every $x in (xs:dayTimeDuration('P1D'),xs:dayTimeDuration('P2D'),xs:dayTimeDuration('P3D')) satisfies boolean(for $T in (current-date()) return ($T + $x <= $T + xs:dayTimeDuration('P1D')))",
"ND-Root", "every duration:$x in [P1D, P2D, P3D] satisfies $x <= P1D");
}
@Test
void testDurationQuantifiedExpression_UsingFieldReference() {
testExpressionTranslationWithContext(
"every $x in (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ())) satisfies boolean(for $T in (current-date()) return ($T + $x <= $T + xs:dayTimeDuration('P1D')))",
"ND-Root", "every duration:$x in BT-00-Duration satisfies $x <= P1D");
}
// #endregion: Quantified expressions
// #region: Conditional expressions -----------------------------------------
@Test
void testConditionalExpression() {
testExpressionTranslationWithContext("(if (1 > 2) then 'a' else 'b')", "ND-Root",
"if 1 > 2 then 'a' else 'b'");
}
@Test
void testConditionalStringExpression_UsingLiterals() {
testExpressionTranslationWithContext("(if ('a' > 'b') then 'a' else 'b')", "ND-Root",
"if 'a' > 'b' then 'a' else 'b'");
}
@Test
void testConditionalStringExpression_UsingFieldReferenceInCondition() {
testExpressionTranslationWithContext(
"(if ('a' > PathNode/TextField/normalize-space(text())) then 'a' else 'b')", "ND-Root",
"if 'a' > BT-00-Text then 'a' else 'b'");
testExpressionTranslationWithContext(
"(if (PathNode/TextField/normalize-space(text()) >= 'a') then 'a' else 'b')", "ND-Root",
"if BT-00-Text >= 'a' then 'a' else 'b'");
testExpressionTranslationWithContext(
"(if (PathNode/TextField/normalize-space(text()) >= PathNode/TextField/normalize-space(text())) then 'a' else 'b')",
"ND-Root", "if BT-00-Text >= BT-00-Text then 'a' else 'b'");
testExpressionTranslationWithContext(
"(if (PathNode/StartDateField/xs:date(text()) >= PathNode/EndDateField/xs:date(text())) then 'a' else 'b')",
"ND-Root", "if BT-00-StartDate >= BT-00-EndDate then 'a' else 'b'");
}
@Test
void testConditionalStringExpression_UsingFieldReference() {
testExpressionTranslationWithContext(
"(if ('a' > 'b') then PathNode/TextField/normalize-space(text()) else 'b')", "ND-Root",
"if 'a' > 'b' then BT-00-Text else 'b'");
testExpressionTranslationWithContext(
"(if ('a' > 'b') then 'a' else PathNode/TextField/normalize-space(text()))", "ND-Root",
"if 'a' > 'b' then 'a' else BT-00-Text");
testExpressionTranslationWithContext(
"(if ('a' > 'b') then PathNode/TextField/normalize-space(text()) else PathNode/TextField/normalize-space(text()))",
"ND-Root", "if 'a' > 'b' then BT-00-Text else BT-00-Text");
}
@Test
void testConditionalStringExpression_UsingFieldReferences_TypeMismatch() {
assertThrows(ParseCancellationException.class, () -> translateExpressionWithContext("ND-Root",
"if 'a' > 'b' then BT-00-StartDate else BT-00-Text"));
}
@Test
void testConditionalBooleanExpression() {
testExpressionTranslationWithContext("(if (PathNode/IndicatorField) then true() else false())",
"ND-Root", "if BT-00-Indicator then TRUE else FALSE");
}
@Test
void testConditionalNumericExpression() {
testExpressionTranslationWithContext("(if (1 > 2) then 1 else PathNode/NumberField/number())",
"ND-Root", "if 1 > 2 then 1 else BT-00-Number");
}
@Test
void testConditionalDateExpression() {
testExpressionTranslationWithContext(
"(if (xs:date('2012-01-01Z') > PathNode/EndDateField/xs:date(text())) then PathNode/StartDateField/xs:date(text()) else xs:date('2012-01-02Z'))",
"ND-Root", "if 2012-01-01Z > BT-00-EndDate then BT-00-StartDate else 2012-01-02Z");
}
@Test
void testConditionalTimeExpression() {
testExpressionTranslationWithContext(
"(if (PathNode/EndTimeField/xs:time(text()) > xs:time('00:00:01Z')) then PathNode/StartTimeField/xs:time(text()) else xs:time('00:00:01Z'))",
"ND-Root", "if BT-00-EndTime > 00:00:01Z then BT-00-StartTime else 00:00:01Z");
}
@Test
void testConditionalDurationExpression() {
assertEquals(
"(if (boolean(for $T in (current-date()) return ($T + xs:dayTimeDuration('P1D') > $T + (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ()))))) then xs:dayTimeDuration('P1D') else xs:dayTimeDuration('P2D'))",
translateExpressionWithContext("ND-Root", "if P1D > BT-00-Duration then P1D else P2D"));
}
// #endregion: Conditional expressions
// #region: Iteration expressions -------------------------------------------
// Strings from iteration ---------------------------------------------------
@Test
void testStringsFromStringIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"'a' = (for $x in ('a','b','c') return concat($x, 'text'))", "ND-Root",
"'a' in (for text:$x in ['a', 'b', 'c'] return concat($x, 'text'))");
}
@Test
void testStringsSequenceFromIteration_UsingMultipleIterators() {
testExpressionTranslationWithContext(
"'a' = (for $x in ('a','b','c'), $y in (1,2), $z in PathNode/IndicatorField return concat($x, string($y), 'text'))",
"ND-Root",
"'a' in (for text:$x in ['a', 'b', 'c'], number:$y in [1, 2], indicator:$z in BT-00-Indicator return concat($x, string($y), 'text'))");
}
@Test
void testStringsSequenceFromIteration_UsingObjectVariable() {
testExpressionTranslationWithContext(
"for $n in PathNode/TextField[../NumberField], $d in $n/../StartDateField/xs:date(text()) return 'text'",
"ND-Root",
"for context:$n in BT-00-Text[BT-00-Number is present], date:$d in $n::BT-00-StartDate return 'text'");
}
@Test
void testStringsSequenceFromIteration_UsingNodeContextVariable() {
testExpressionTranslationWithContext(
"for $n in .[PathNode/TextField/normalize-space(text()) = 'a'] return 'text'", "ND-Root",
"for context:$n in ND-Root[BT-00-Text == 'a'] return 'text'");
}
@Test
void testStringsFromStringIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"'a' = (for $x in PathNode/TextField/normalize-space(text()) return concat($x, 'text'))", "ND-Root",
"'a' in (for text:$x in BT-00-Text return concat($x, 'text'))");
}
@Test
void testStringsFromStringIteration_UsingMultilingualFieldReference() {
// This test verifies that iterating over a multilingual text field with a text iterator works correctly
// The iterator variable should inherit the actual type (multilingual string) from the sequence
testExpressionTranslationWithContext(
"'a' = (for $x in PathNode/TextMultilingualField/normalize-space(text()) return concat($x, 'text'))", "ND-Root",
"'a' in (for text:$x in BT-00-Text-Multilingual return concat($x, 'text'))");
}
@Test
void testStringsFromBooleanIteration_UsingLiterals() {
testExpressionTranslationWithContext("'a' = (for $x in (true(),false()) return 'y')", "ND-Root",
"'a' in (for indicator:$x in [TRUE, FALSE] return 'y')");
}
@Test
void testStringsFromBooleanIteration_UsingFieldReference() {
testExpressionTranslationWithContext("'a' = (for $x in PathNode/IndicatorField return 'y')",
"ND-Root", "'a' in (for indicator:$x in BT-00-Indicator return 'y')");
}
@Test
void testStringsFromNumericIteration_UsingLiterals() {
testExpressionTranslationWithContext("'a' = (for $x in (1,2,3) return 'y')", "ND-Root",
"'a' in (for number:$x in [1, 2, 3] return 'y')");
}
@Test
void testStringsFromNumericIteration_UsingFieldReference() {
testExpressionTranslationWithContext("'a' = (for $x in PathNode/NumberField/number() return 'y')",
"ND-Root", "'a' in (for number:$x in BT-00-Number return 'y')");
}
@Test
void testStringsFromDateIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"'a' = (for $x in (xs:date('2012-01-01Z'),xs:date('2012-01-02Z'),xs:date('2012-01-03Z')) return 'y')",
"ND-Root", "'a' in (for date:$x in [2012-01-01Z, 2012-01-02Z, 2012-01-03Z] return 'y')");
}
@Test
void testStringsFromDateIteration_UsingFieldReference() {
testExpressionTranslationWithContext("'a' = (for $x in PathNode/StartDateField/xs:date(text()) return 'y')",
"ND-Root", "'a' in (for date:$x in BT-00-StartDate return 'y')");
}
@Test
void testStringsFromTimeIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"'a' = (for $x in (xs:time('12:00:00Z'),xs:time('12:00:01Z'),xs:time('12:00:02Z')) return 'y')",
"ND-Root", "'a' in (for time:$x in [12:00:00Z, 12:00:01Z, 12:00:02Z] return 'y')");
}
@Test
void testStringsFromTimeIteration_UsingFieldReference() {
testExpressionTranslationWithContext("'a' = (for $x in PathNode/StartTimeField/xs:time(text()) return 'y')",
"ND-Root", "'a' in (for time:$x in BT-00-StartTime return 'y')");
}
@Test
void testStringsFromDurationIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"'a' = (for $x in (xs:dayTimeDuration('P1D'),xs:yearMonthDuration('P1Y'),xs:yearMonthDuration('P2M')) return 'y')",
"ND-Root", "'a' in (for duration:$x in [P1D, P1Y, P2M] return 'y')");
}
@Test
void testStringsFromDurationIteration_UsingFieldReference() {
testExpressionTranslationWithContext("'a' = (for $x in (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ())) return 'y')",
"ND-Root", "'a' in (for duration:$x in BT-00-Duration return 'y')");
}
// Numbers from iteration ---------------------------------------------------
@Test
void testNumbersFromStringIteration_UsingLiterals() {
testExpressionTranslationWithContext("123 = (for $x in ('a','b','c') return number($x))",
"ND-Root", "123 in (for text:$x in ['a', 'b', 'c'] return number($x))");
}
@Test
void testNumbersFromStringIteration_UsingFieldReference() {
testExpressionTranslationWithContext("123 = (for $x in PathNode/TextField/normalize-space(text()) return number($x))",
"ND-Root", "123 in (for text:$x in BT-00-Text return number($x))");
}
@Test
void testNumbersFromBooleanIteration_UsingLiterals() {
testExpressionTranslationWithContext("123 = (for $x in (true(),false()) return 0)", "ND-Root",
"123 in (for indicator:$x in [TRUE, FALSE] return 0)");
}
@Test
void testNumbersFromBooleanIteration_UsingFieldReference() {
testExpressionTranslationWithContext("123 = (for $x in PathNode/IndicatorField return 0)",
"ND-Root", "123 in (for indicator:$x in BT-00-Indicator return 0)");
}
@Test
void testNumbersFromNumericIteration_UsingLiterals() {
testExpressionTranslationWithContext("123 = (for $x in (1,2,3) return 0)", "ND-Root",
"123 in (for number:$x in [1, 2, 3] return 0)");
}
@Test
void testNumbersFromNumericIteration_UsingFieldReference() {
testExpressionTranslationWithContext("123 = (for $x in PathNode/NumberField/number() return 0)",
"ND-Root", "123 in (for number:$x in BT-00-Number return 0)");
}
@Test
void testNumbersFromDateIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"123 = (for $x in (xs:date('2012-01-01Z'),xs:date('2012-01-02Z'),xs:date('2012-01-03Z')) return 0)",
"ND-Root", "123 in (for date:$x in [2012-01-01Z, 2012-01-02Z, 2012-01-03Z] return 0)");
}
@Test
void testNumbersFromDateIteration_UsingFieldReference() {
testExpressionTranslationWithContext("123 = (for $x in PathNode/StartDateField/xs:date(text()) return 0)",
"ND-Root", "123 in (for date:$x in BT-00-StartDate return 0)");
}
@Test
void testNumbersFromTimeIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"123 = (for $x in (xs:time('12:00:00Z'),xs:time('12:00:01Z'),xs:time('12:00:02Z')) return 0)",
"ND-Root", "123 in (for time:$x in [12:00:00Z, 12:00:01Z, 12:00:02Z] return 0)");
}
@Test
void testNumbersFromTimeIteration_UsingFieldReference() {
testExpressionTranslationWithContext("123 = (for $x in PathNode/StartTimeField/xs:time(text()) return 0)",
"ND-Root", "123 in (for time:$x in BT-00-StartTime return 0)");
}
@Test
void testNumbersFromDurationIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"123 = (for $x in (xs:dayTimeDuration('P1D'),xs:yearMonthDuration('P1Y'),xs:yearMonthDuration('P2M')) return 0)",
"ND-Root", "123 in (for duration:$x in [P1D, P1Y, P2M] return 0)");
}
@Test
void testNumbersFromDurationIteration_UsingFieldReference() {
testExpressionTranslationWithContext("123 = (for $x in (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ())) return 0)",
"ND-Root", "123 in (for duration:$x in BT-00-Duration return 0)");
}
// Dates from iteration ---------------------------------------------------
@Test
void testDatesFromStringIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in ('a','b','c') return xs:date($x))", "ND-Root",
"2022-01-01Z in (for text:$x in ['a', 'b', 'c'] return date($x))");
}
@Test
void testDatesFromStringIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in PathNode/TextField/normalize-space(text()) return xs:date($x))", "ND-Root",
"2022-01-01Z in (for text:$x in BT-00-Text return date($x))");
}
@Test
void testDatesFromBooleanIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in (true(),false()) return xs:date('2022-01-01Z'))",
"ND-Root", "2022-01-01Z in (for indicator:$x in [TRUE, FALSE] return 2022-01-01Z)");
}
@Test
void testDatesFromBooleanIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in PathNode/IndicatorField return xs:date('2022-01-01Z'))",
"ND-Root", "2022-01-01Z in (for indicator:$x in BT-00-Indicator return 2022-01-01Z)");
}
@Test
void testDatesFromNumericIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in (1,2,3) return xs:date('2022-01-01Z'))", "ND-Root",
"2022-01-01Z in (for number:$x in [1, 2, 3] return 2022-01-01Z)");
}
@Test
void testDatesFromNumericIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in PathNode/NumberField/number() return xs:date('2022-01-01Z'))",
"ND-Root", "2022-01-01Z in (for number:$x in BT-00-Number return 2022-01-01Z)");
}
@Test
void testDatesFromDateIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in (xs:date('2012-01-01Z'),xs:date('2012-01-02Z'),xs:date('2012-01-03Z')) return xs:date('2022-01-01Z'))",
"ND-Root",
"2022-01-01Z in (for date:$x in [2012-01-01Z, 2012-01-02Z, 2012-01-03Z] return 2022-01-01Z)");
}
@Test
void testDatesFromDateIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in PathNode/StartDateField/xs:date(text()) return xs:date('2022-01-01Z'))",
"ND-Root", "2022-01-01Z in (for date:$x in BT-00-StartDate return 2022-01-01Z)");
}
@Test
void testDatesFromTimeIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in (xs:time('12:00:00Z'),xs:time('12:00:01Z'),xs:time('12:00:02Z')) return xs:date('2022-01-01Z'))",
"ND-Root",
"2022-01-01Z in (for time:$x in [12:00:00Z, 12:00:01Z, 12:00:02Z] return 2022-01-01Z)");
}
@Test
void testDatesFromTimeIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in PathNode/StartTimeField/xs:time(text()) return xs:date('2022-01-01Z'))",
"ND-Root", "2022-01-01Z in (for time:$x in BT-00-StartTime return 2022-01-01Z)");
}
@Test
void testDatesFromDurationIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in (xs:dayTimeDuration('P1D'),xs:yearMonthDuration('P1Y'),xs:yearMonthDuration('P2M')) return xs:date('2022-01-01Z'))",
"ND-Root", "2022-01-01Z in (for duration:$x in [P1D, P1Y, P2M] return 2022-01-01Z)");
}
@Test
void testDatesFromDurationIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:date('2022-01-01Z') = (for $x in (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ())) return xs:date('2022-01-01Z'))",
"ND-Root", "2022-01-01Z in (for duration:$x in BT-00-Duration return 2022-01-01Z)");
}
// Times from iteration ---------------------------------------------------
@Test
void testTimesFromStringIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in ('a','b','c') return xs:time($x))", "ND-Root",
"12:00:00Z in (for text:$x in ['a', 'b', 'c'] return time($x))");
}
@Test
void testTimesFromStringIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in PathNode/TextField/normalize-space(text()) return xs:time($x))", "ND-Root",
"12:00:00Z in (for text:$x in BT-00-Text return time($x))");
}
@Test
void testTimesFromBooleanIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in (true(),false()) return xs:time('12:00:00Z'))",
"ND-Root", "12:00:00Z in (for indicator:$x in [TRUE, FALSE] return 12:00:00Z)");
}
@Test
void testTimesFromBooleanIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in PathNode/IndicatorField return xs:time('12:00:00Z'))",
"ND-Root", "12:00:00Z in (for indicator:$x in BT-00-Indicator return 12:00:00Z)");
}
@Test
void testTimesFromNumericIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in (1,2,3) return xs:time('12:00:00Z'))", "ND-Root",
"12:00:00Z in (for number:$x in [1, 2, 3] return 12:00:00Z)");
}
@Test
void testTimesFromNumericIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in PathNode/NumberField/number() return xs:time('12:00:00Z'))",
"ND-Root", "12:00:00Z in (for number:$x in BT-00-Number return 12:00:00Z)");
}
@Test
void testTimesFromDateIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in (xs:date('2012-01-01Z'),xs:date('2012-01-02Z'),xs:date('2012-01-03Z')) return xs:time('12:00:00Z'))",
"ND-Root",
"12:00:00Z in (for date:$x in [2012-01-01Z, 2012-01-02Z, 2012-01-03Z] return 12:00:00Z)");
}
@Test
void testTimesFromDateIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in PathNode/StartDateField/xs:date(text()) return xs:time('12:00:00Z'))",
"ND-Root", "12:00:00Z in (for date:$x in BT-00-StartDate return 12:00:00Z)");
}
@Test
void testTimesFromTimeIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in (xs:time('12:00:00Z'),xs:time('12:00:01Z'),xs:time('12:00:02Z')) return xs:time('12:00:00Z'))",
"ND-Root",
"12:00:00Z in (for time:$x in [12:00:00Z, 12:00:01Z, 12:00:02Z] return 12:00:00Z)");
}
@Test
void testTimesFromTimeIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in PathNode/StartTimeField/xs:time(text()) return xs:time('12:00:00Z'))",
"ND-Root", "12:00:00Z in (for time:$x in BT-00-StartTime return 12:00:00Z)");
}
@Test
void testTimesFromDurationIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in (xs:dayTimeDuration('P1D'),xs:yearMonthDuration('P1Y'),xs:yearMonthDuration('P2M')) return xs:time('12:00:00Z'))",
"ND-Root", "12:00:00Z in (for duration:$x in [P1D, P1Y, P2M] return 12:00:00Z)");
}
@Test
void testTimesFromDurationIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:time('12:00:00Z') = (for $x in (for $F in PathNode/DurationField return (if ($F/@unitCode='WEEK') then xs:dayTimeDuration(concat('P', $F/number() * 7, 'D')) else if ($F/@unitCode='DAY') then xs:dayTimeDuration(concat('P', $F/number(), 'D')) else if ($F/@unitCode='YEAR') then xs:yearMonthDuration(concat('P', $F/number(), 'Y')) else if ($F/@unitCode='MONTH') then xs:yearMonthDuration(concat('P', $F/number(), 'M')) else ())) return xs:time('12:00:00Z'))",
"ND-Root", "12:00:00Z in (for duration:$x in BT-00-Duration return 12:00:00Z)");
}
// Durations from iteration ---------------------------------------------------
@Test
void testDurationsFromStringIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:dayTimeDuration('P1D') = (for $x in (xs:dayTimeDuration('P1D'),xs:dayTimeDuration('P2D'),xs:dayTimeDuration('P7D')) return $x)",
"ND-Root", "P1D in (for duration:$x in [P1D, P2D, P1W] return $x)");
}
@Test
void testDurationsFromStringIteration_UsingFieldReference() {
testExpressionTranslationWithContext(
"xs:dayTimeDuration('P1D') = (for $x in PathNode/TextField/normalize-space(text()) return xs:dayTimeDuration($x))",
"ND-Root", "P1D in (for text:$x in BT-00-Text return day-time-duration($x))");
}
@Test
void testDurationsFromBooleanIteration_UsingLiterals() {
testExpressionTranslationWithContext(
"xs:dayTimeDuration('P1D') = (for $x in (true(),false()) return xs:dayTimeDuration('P1D'))",
"ND-Root", "P1D in (for indicator:$x in [TRUE, FALSE] return P1D)");
}
@Test
void testDurationsFromBooleanIteration_UsingFieldReference() {
testExpressionTranslationWithContext(