-
Notifications
You must be signed in to change notification settings - Fork 316
/
AbstractXbaseEvaluationTest.java
5017 lines (4261 loc) · 149 KB
/
AbstractXbaseEvaluationTest.java
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 (c) 2010, 2019 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtend.core.tests.compiler;
import static com.google.common.collect.Lists.*;
import static com.google.common.collect.Maps.*;
import static com.google.common.collect.Sets.*;
import static java.util.Collections.*;
import java.io.IOException;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import org.eclipse.xtend.core.tests.util.TemporaryFolder;
import org.eclipse.xtext.xbase.lib.Pair;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import testdata.ExceptionSubclass;
import testdata.OuterClass;
/**
* @author Sebastian Zarnekow - Initial contribution and API
* @author Sven Efftinge
*/
public abstract class AbstractXbaseEvaluationTest extends Assert {
@Rule
@Inject public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test public void testReservedWordEnum() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "typeof(java.lang.annotation.RetentionPolicy).enum");
}
@Test public void testReservedWordEnum_02() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "java.lang.annotation.RetentionPolicy.enum");
}
@Test public void testReservedWordEnum_03() throws Exception {
assertEvaluatesTo(RetentionPolicy.SOURCE, "java.lang.annotation.RetentionPolicy.SOURCE");
}
@Test public void testReservedWordInterface() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "typeof(Iterable).interface");
}
@Test public void testReservedWordInterface_02() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "Iterable.interface");
}
@Test public void testReservedWordAnnotation() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "typeof(Override).annotation");
}
@Test public void testReservedWordClass() throws Exception {
assertEvaluatesTo(Class.class, "typeof(Override).class");
}
@Test public void testDoubleSwitch() throws Exception {
assertEvaluatesTo("foo","{ val x = 'foo' switch x.length { case 2 : 'bla'.toString } switch x.length { case 3 : 'foo'.toString } }");
}
@Test public void testIntLiteral_0() throws Exception {
assertEvaluatesTo(1, "1");
}
@Test public void testIntLiteral_2() throws Exception {
assertEvaluatesTo(0x17, "0x17");
}
@Test public void testIntLiteral_2a() throws Exception {
assertEvaluatesTo(0x17, "0X17");
}
@Test public void testIntLiteral_4() throws Exception {
assertEvaluatesTo(123456789, "123_456_789");
}
@Test public void testIntLiteral_5() throws Exception {
assertEvaluatesTo(0xffffeeee, "0xffff_eeee");
}
@Test public void testLongLiteral_0() throws Exception {
assertEvaluatesTo(1l, "1l");
}
@Test public void testLongLiteral_2() throws Exception {
assertEvaluatesTo(0x17l, "0x17#L");
}
@Test public void testLongLiteral_4() throws Exception {
assertEvaluatesTo(123456789123456789L, "123_456_789_123_456_789L");
}
@Test public void testLongLiteral_5() throws Exception {
assertEvaluatesTo(0xffffeeeeddddccccl, "0xffff_eeee_dddd_cccc#L");
}
@Test public void testFloatLiteral_0() throws Exception {
assertEvaluatesTo(1f, "1f");
}
@Test public void testFloatLiteral_1() throws Exception {
assertEvaluatesTo(17f, "017f");
}
@Test public void testFloatLiteral_2() throws Exception {
assertEvaluatesTo(1.0f, "1.0f");
}
@Test public void testFloatLiteral_3() throws Exception {
assertEvaluatesTo(1.0e-10f, "1.0e-10f");
}
@Test public void testFloatLiteral_4() throws Exception {
assertEvaluatesTo(1.0e+10f, "1.0e+10f");
}
@Test public void testFloatLiteral_5() throws Exception {
assertEvaluatesTo(1.0E10f, "1.0E10f");
}
@Test public void testFloatLiteral_6() throws Exception {
assertEvaluatesTo(1E10f, "1E10f");
}
@Test public void testDoubleLiteral_0() throws Exception {
assertEvaluatesTo(1d, "1d");
}
@Test public void testDoubleLiteral_2() throws Exception {
assertEvaluatesTo(1.0, "1.0");
}
@Test public void testDoubleLiteral_3() throws Exception {
assertEvaluatesTo(1.0e-10, "1.0e-10");
}
@Test public void testDoubleLiteral_4() throws Exception {
assertEvaluatesTo(1.0E+10, "1.0E+10");
}
@Test public void testDoubleLiteral_5() throws Exception {
assertEvaluatesTo(1.0E10, "1.0E10");
}
@Test public void testDoubleLiteral_6() throws Exception {
assertEvaluatesTo(1e10, "1e10");
}
@Test public void testDoubleLiteral_7() throws Exception {
assertEvaluatesTo(1.0d, "1.0d");
}
@Test public void testDoubleLiteral_8() throws Exception {
assertEvaluatesTo(1.0e-10d, "1.0e-10d");
}
@Test public void testDoubleLiteral_9() throws Exception {
assertEvaluatesTo(1.0E+10d, "1.0E+10d");
}
@Test public void testDoubleLiteral_10() throws Exception {
assertEvaluatesTo(1.0E10d, "1.0E10d");
}
@Test public void testDoubleLiteral_11() throws Exception {
assertEvaluatesTo(1e10d, "1e10d");
}
@Test public void testDoubleLiteral_12() throws Exception {
assertEvaluatesTo(1.123456789e10d, "1.123_456_789e1_0d");
}
@Test public void testDoubleLiteral_13() throws Exception {
assertEvaluatesTo(123456789d, "123_456_789d");
}
@Test public void testBigInteger_0() throws Exception {
assertEvaluatesTo(new BigInteger("1"), "1bi");
}
@Test public void testBigInteger_1() throws Exception {
assertEvaluatesTo(new BigInteger("12345678901234567890123456789012345678901234567890"),
"1234567890_12345678901234567890_1234567890_1234567890_Bi");
}
@Test public void testBigInteger_3() throws Exception {
assertEvaluatesTo(new BigInteger("77", 16), "0x77#bI");
}
@Test public void testBigInteger_4() throws Exception {
assertEvaluatesTo(new BigInteger("1000000"), "10e+5bI");
}
@Test public void testBigInteger_5() throws Exception {
assertEvaluatesTo(new BigDecimal("10e+12345").toBigInteger(), "10e+12345bI");
}
@Test public void testBigInteger_6() throws Exception {
assertEvaluatesTo(new BigInteger("beefbeefbeefbeefbeef", 16), "0xbeef_beef_beef_beef_beef#BI");
}
@Test public void testBigDecimal_0() throws Exception {
assertEvaluatesTo(new BigDecimal("1.0"), "1.0bd");
}
@Test public void testBigDecimal_1() throws Exception {
assertEvaluatesTo(new BigDecimal("1.0e500"), "1.0e500Bd");
}
@Test public void testBigDecimal_2() throws Exception {
assertEvaluatesTo(new BigDecimal("123456789012345678901234567890.123456789012345678901234567890"),
"1234567890_1234567890_1234567890.1234567890_1234567890_1234567890bD");
}
@Test public void testBigDecimal_3() throws Exception {
assertEvaluatesTo(new BigDecimal("1e500"), "1e500BD");
}
@Test public void testBug372408() throws Exception {
assertEvaluatesTo(new BigInteger("0"), "0BI");
assertEvaluatesTo(0l, "0l");
}
@Test public void testImplicitOneArgClosure() throws Exception {
assertEvaluatesTo("foo","[it].apply('foo')");
}
@Ignore("To be implemented later")
@Test public void testImplicitOneArgClosure_01() throws Exception {
assertEvaluatesTo(3,"[length].apply('foo')");
}
@Test public void testImplicitOneArgClosure_02() throws Exception {
assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('bb','a','ccc').sortBy([length])");
}
@Test public void testBug362725() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "{ val =>int closure = null closure == null }");
}
@Test public void testBuilderSyntax_01() throws Exception {
assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('a','bb','ccc').sortBy [length]");
}
@Test public void testBuilderSyntax_02() throws Exception {
assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('a','bb','ccc').sortBy [it.length]");
}
@Test public void testBuilderSyntax_03() throws Exception {
assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('a','bb','ccc').sortBy [x | x.length]");
}
@Test public void testBuilderSyntax_04() throws Exception {
assertEvaluatesTo(newArrayList(), "<String>newArrayList.sortBy [length]");
}
@Test public void testNestedClosures_01() throws Exception {
String expr =
"{ " +
" val x = 'foo' " +
" [String s | x + [ String s1 | s1 + s + x].apply(s) ].apply(x)" +
"}";
assertEvaluatesTo("foofoofoofoo", expr);
}
@Test public void testNestedClosures_02() throws Exception {
String expr =
"{ " +
" val x = 'foo' " +
" [ s | x + [ s1 | s1 + s + x].apply(s) ].apply(x)" +
"}";
assertEvaluatesTo("foofoofoofoo", expr);
}
@Test public void testEscapeCharacter() throws Exception {
String expr = "'foo'.^class";
assertEvaluatesTo(String.class, expr);
}
@Test public void testShortCircuitBooleanExpression_00() throws Exception {
String expr = "true || {if (true) throw new NullPointerException() else false}";
assertEvaluatesTo(true, expr);
}
@Test public void testShortCircuitBooleanExpression_01() throws Exception {
String expr = "false && {if (true) throw new NullPointerException() else false}";
assertEvaluatesTo(false, expr);
}
@Test public void testShortCircuitBooleanExpression_02() throws Exception {
String expr = "true || {if (true) throw new NullPointerException else false}";
assertEvaluatesTo(true, expr);
}
@Test public void testShortCircuitBooleanExpression_03() throws Exception {
String expr =
"{ val i = newArrayList(false,true).iterator" +
" if (i.next && i.next)" +
" throw new NullPointerException()" +
" else" +
" i.next" +
"}";
assertEvaluatesTo(true, expr);
}
@Test public void testShortCircuitBooleanExpression_04() throws Exception {
String expr =
"{ val i = newArrayList(true,false).iterator" +
" if (i.next || i.next)" +
" i.next" +
"}";
assertEvaluatesTo(false, expr);
}
@Test public void testShortCircuitBooleanExpression_05() throws Exception {
String expr =
"{ " +
" val i = newArrayList(true, true, true).iterator" +
" if (i.next && i.next && i.next)" +
" i.hasNext" +
"}";
assertEvaluatesTo(false, expr);
}
@Test public void testShortCircuitBooleanExpression_06() throws Exception {
String expr =
"{ " +
" val i = newArrayList(false, true).iterator" +
" if (i.next && i.next || i.next)" +
" i.hasNext" +
"}";
assertEvaluatesTo(false, expr);
}
@Test public void testReferenceInnerClasses_01() throws Exception {
assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata::OuterClass$InnerClass::SINGLETON");
}
@Test public void testReferenceInnerClasses_02() throws Exception {
assertEvaluatesTo("FOO", "[testdata.OuterClass$InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass$InnerClass())");
}
@Test public void testReferenceInnerClasses_03() throws Exception {
assertEvaluatesTo(null, "{for (x : newArrayList(new testdata.OuterClass$InnerClass())) { x.toString } null}");
}
@Test public void testReferenceInnerClasses_04() throws Exception {
assertEvaluatesTo("FOO", "[testdata.OuterClass$InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass$InnerClass)");
}
@Test public void testReferenceInnerClasses_05() throws Exception {
assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata::OuterClass::InnerClass::SINGLETON");
}
@Test public void testReferenceInnerClasses_06() throws Exception {
assertEvaluatesTo("FOO", "[testdata.OuterClass.InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass.InnerClass())");
}
@Test public void testReferenceInnerClasses_07() throws Exception {
assertEvaluatesTo(null, "{for (x : newArrayList(new testdata.OuterClass.InnerClass())) { x.toString } null}");
}
@Test public void testReferenceInnerClasses_08() throws Exception {
assertEvaluatesTo("FOO", "[testdata.OuterClass.InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass.InnerClass)");
}
@Test public void testReferenceInnerClasses_09() throws Exception {
assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata.OuterClass$InnerClass::SINGLETON");
}
@Test public void testReferenceInnerClasses_10() throws Exception {
assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata.OuterClass.InnerClass::SINGLETON");
}
/*
* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=341642
*/
@Test public void testBug341642() throws Exception {
assertEvaluatesTo("a", "newArrayList('a', 'b', 'c').filter(a|a == 'a' || a == 'b').iterator.next");
}
@Test public void testBug341775() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "'a'.charAt(0) == 'a'");
assertEvaluatesTo(Boolean.TRUE, "'a'.charAt(0) == 'a'.charAt(0)");
assertEvaluatesTo(Boolean.TRUE, "'a' == 'a'");
}
@Test public void testCurrying_01() throws Exception {
assertEvaluatesTo("123456", "[String p1, String p2, String p3, String p4, String p5, String p6| p1+p2+p3+p4+p5+p6].curry('1').curry('2').curry('3').curry('4').curry('5').curry('6').apply()");
}
@Test public void testCurrying_02() throws Exception {
assertEvaluatesTo("1", "[String p1| p1].curry('1').apply()");
}
@Test public void testCurrying_03() throws Exception {
assertEvaluatesTo("12", "[String p1, String p2| p1 + p2].curry('1').curry('2').apply()");
}
@Test public void testCurrying_04() throws Exception {
assertEvaluatesTo(newArrayList("1","2","3","4","5","6"),
"{\n" +
" val result = <String>newArrayList\n" +
" var (String,String,String,String,String,String)=>void proc = [ p1, p2, p3, p4, p5, p6 |\n" +
" result.add(p1)\n" +
" result.add(p2)\n" +
" result.add(p3)\n" +
" result.add(p4)\n" +
" result.add(p5)\n" +
" result.add(p6)\n" +
" ]" +
" proc.curry('1').curry('2').curry('3').curry('4').curry('5').curry('6').apply()\n" +
" result\n" +
"}");
}
@Test public void testCurrying_05() throws Exception {
assertEvaluatesTo(newArrayList("1","2"),
"{\n" +
" val result = <String>newArrayList\n" +
" var (String,String)=>void proc = [ p1, p2 |\n" +
" result.add(p1)\n" +
" result.add(p2)\n" +
" ]" +
" proc.curry('1').curry('2').apply()\n" +
" result\n" +
"}");
}
@Test public void testCurrying_06() throws Exception {
assertEvaluatesTo(newArrayList("1","2","3","4","5","6"),
"{\n" +
" val result = <String>newArrayList\n" +
" val (String,String,String,String,String,String)=>void proc6 = [ p1, p2, p3, p4, p5, p6 |\n" +
" result.add(p1)\n" +
" result.add(p2)\n" +
" result.add(p3)\n" +
" result.add(p4)\n" +
" result.add(p5)\n" +
" result.add(p6)\n" +
" ]\n" +
" val (String,String,String,String,String)=>void proc5 = proc6.curry('1')\n" +
" val (String,String,String,String)=>void proc4 = proc5.curry('2')\n" +
" val (String,String,String)=>void proc3 = proc4.curry('3')\n" +
" val (String,String)=>void proc2 = proc3.curry('4')\n" +
" val (String)=>void proc1 = proc2.curry('5')\n" +
" val =>void proc0 = proc1.curry('6')\n" +
" proc0.apply()\n" +
" result\n" +
"}");
}
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=341550
*/
@Test public void testBug341550() throws Exception {
assertEvaluatesTo(emptyList(),"switch emptyList() { case emptyList() : emptyList() }");
}
@Test public void testGenerics_00() throws Exception {
assertEvaluatesTo("", "try {typeof(String).newInstance} catch(Exception e) {}");
}
@Test public void testGenerics_00_b() throws Exception {
assertEvaluatesTo("", "try {String.newInstance} catch(Exception e) {}");
}
@Test public void testGenerics_01() throws Exception {
assertEvaluatesTo("y",
"{" +
" val x = newArrayList('y',23,true)" +
" return x.head" +
"}");
}
@Test public void testGenerics_02() throws Exception {
assertEvaluatesTo(Boolean.TRUE,
"new java.util.ArrayList<Object>().addAll(typeof(String).declaredFields)");
}
@Test public void testGenerics_02_b() throws Exception {
assertEvaluatesTo(Boolean.TRUE,
"new java.util.ArrayList<Object>().addAll(String.declaredFields)");
}
@Test public void testGenerics_03() throws Exception {
assertEvaluatesTo("y",
"{" +
" val x = <Object>newArrayList('y',23,true)" +
" return x.head" +
"}");
}
@Test public void testGenerics_04() throws Exception {
assertEvaluatesTo(Boolean.TRUE,
"new java.util.ArrayList<Object>.addAll(typeof(String).declaredFields)");
}
@Test public void testGenerics_04_b() throws Exception {
assertEvaluatesTo(Boolean.TRUE,
"new java.util.ArrayList<Object>.addAll(String.declaredFields)");
}
@Test public void testGenerics_05() throws Exception {
assertEvaluatesTo("y",
"{" +
" val x = newArrayList('y',23,true)" +
" x.head" +
"}");
}
@Test public void testGenerics_06() throws Exception {
assertEvaluatesTo("y",
"{" +
" val x = <Object>newArrayList('y',23,true)" +
" x.head" +
"}");
}
@Test public void testGenerics_07() throws Exception {
assertEvaluatesTo(Integer.valueOf(23),
"{" +
" val x = newArrayList(23, 23d)" +
" x.head" +
"}");
}
/**
* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=341246
*/
@Test public void testUnreferencedConstructorInBlock_01() throws Exception {
assertEvaluatesTo(false, "{ new String() false}");
}
@Test public void testUnreferencedConstructorInBlock_02() throws Exception {
assertEvaluatesTo(false, "{ new String false}");
}
@Test public void testStaticFeatureCall_01() throws Exception {
assertEvaluatesTo("false", "String::valueOf(false)");
}
@Test public void testStaticFeatureCall_02() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "Boolean::FALSE");
}
@Test public void testStaticFeatureCall_03() throws Exception {
assertEvaluatesTo("false", "String.valueOf(false)");
}
@Test public void testStaticFeatureCall_04() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "Boolean.FALSE");
}
@Test public void testStaticFeatureCall_05() throws Exception {
assertEvaluatesTo("false", "java.lang.String.valueOf(false)");
}
@Test public void testPrimitiveConversion_01() throws Exception {
assertEvaluatesTo("2","'ab'.length.toString");
}
@Test public void testPrimitiveConversion_02() throws Exception {
assertEvaluatesTo("123","123.toString");
}
@Test public void testPrimitiveConversion_03() throws Exception {
assertEvaluatesTo("123","return 123.toString");
}
@Test public void testPrimitiveConversion_04() throws Exception {
assertEvaluatesTo("123","123L.intValue.toString");
}
@Test public void testReturnExpression_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "return true");
}
@Test public void testReturnExpression_02() throws Exception {
assertEvaluatesTo("xx", "return if ('x'=='x') 'xx'");
}
@Test public void testReturnExpression_03() throws Exception {
assertEvaluatesTo(null, "return if ('x'!='x') 'xx'");
}
@Test public void testReturnExpression_04() throws Exception {
assertEvaluatesTo(null, "return null");
}
@Test public void testReturnExpression_05() throws Exception {
assertEvaluatesTo("yy", "if ('x'!='x') return 'xx' else return 'yy'");
assertEvaluatesTo("xx", "if ('x'=='x') return 'xx' else return 'yy'");
}
@Test public void testReturnExpression_06() throws Exception {
assertEvaluatesTo(null,
"{" +
" val closure = [Integer i| return i]" +
" for (x : 1..100) " +
" closure.apply(x)" +
" return null" +
"}");
}
@Ignore("Wrong type")
@Test public void testReturnExpression_07() throws Exception {
assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else null");
assertEvaluatesTo(null, "return if (false) while(false) ('foo'+'bar').length else null");
}
@Ignore("Wrong type")
@Test public void testReturnExpression_08() throws Exception {
assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else 'zonk'");
assertEvaluatesTo("zonk", "return if (false) while(false) ('foo'+'bar').length else 'zonk'");
}
@Test public void testReturnExpression_09() throws Exception {
assertEvaluatesTo(null, "{ return null }");
}
@Test public void testReturnExpression_10() throws Exception {
assertEvaluatesTo(null, "{ { println }; null }");
}
@Test public void testUnaryOperator_00() throws Exception {
assertEvaluatesTo(Integer.valueOf(-19),"-19");
}
@Test public void testUnaryOperator_01() throws Exception {
assertEvaluatesTo(false,"!true");
}
@Test public void testUnaryOperator_02() throws Exception {
assertEvaluatesTo("-1","(-1).toString()");
}
@Test public void testUnaryOperator_03() throws Exception {
assertEvaluatesTo(1,"- -1");
}
@Test public void testUnaryOperator_04() throws Exception {
assertEvaluatesTo(true,"!!true");
}
@Test public void testUpToOperator() throws Exception {
assertEvaluatesTo(Integer.valueOf(9),"(9..13).iterator().next()");
}
@Test public void testExclusiveRangeOperator_0() throws Exception {
assertEvaluatesTo("0,1,2,3", "(0..<4).join(',')");
}
@Test public void testExclusiveRangeOperator_1() throws Exception {
assertEvaluatesTo("3,2,1,0", "(4>..0).join(',')");
}
@Test public void testExclusiveRangeOperator_2() throws Exception {
assertEvaluatesTo("", "(0..<0).join(',')");
}
@Test public void testExclusiveRangeOperator_3() throws Exception {
assertEvaluatesTo("", "(0>..0).join(',')");
}
@Test public void testExclusiveRangeOperator_4() throws Exception {
assertEvaluatesTo("", "(0..<-1).join(',')");
}
@Test public void testExclusiveRangeOperator_5() throws Exception {
assertEvaluatesTo("", "(-1>..0).join(',')");
}
@Test public void testElvisOperator() throws Exception {
assertEvaluatesTo("foo","null as String?:'foo'");
}
@Test public void testElvisOperator_01() throws Exception {
assertEvaluatesTo("bar","'bar' ?: 'foo'");
}
@Test public void testElvisOperator_02() throws Exception {
assertEvaluatesTo(null,"null ?: null");
}
@Test public void testElvisOperator_03() throws Exception {
assertEvaluatesTo(null,"null as String ?: null as String");
}
@Test public void testElvisOperator_04() throws Exception {
assertEvaluatesTo("foo","{var foo='foo' val x=foo?:{foo='bar' foo} foo}");
}
@Test public void testElvisOperator_05() throws Exception {
assertEvaluatesTo("bar","{var String foo=null val x=foo?:{foo='bar' foo} foo}");
}
@Test public void testStringConcatenation_00() throws Exception {
assertEvaluatesTo("foobar", "'foo'+ ('bar' as Object)");
}
@Test public void testStringConcatenation_01() throws Exception {
assertEvaluatesTo("foo3", "'foo'+3");
}
@Test public void testStringConcatenation_2() throws Exception {
assertEvaluatesTo("footrue", "'foo'+true");
}
@Test public void testStringConcatenation_3() throws Exception {
assertEvaluatesTo("42footrue", "42 +'foo'+true");
}
@Test public void testStringConcatenation_4() throws Exception {
assertEvaluatesTo("truefootrue", "true + 'foo'+true");
}
@Test public void testAddOnIntegers() throws Exception {
assertEvaluatesTo(Integer.valueOf(3), "1+2");
}
@Test public void testSubtractionOnIntegers() throws Exception {
assertEvaluatesTo(Integer.valueOf(1), "2-1");
}
@Test public void testMultiplicationOnIntegers() throws Exception {
assertEvaluatesTo(Integer.valueOf(42), "6*7");
}
@Test public void testDivisionOnIntegers_01() throws Exception {
assertEvaluatesTo(Integer.valueOf(2), "6/3");
}
@Test public void testDivisionOnIntegers_02() throws Exception {
assertEvaluatesTo(Integer.valueOf(2), "7/3");
}
@Test public void testModuloOnIntegers() throws Exception {
assertEvaluatesTo(Integer.valueOf(1), "7%3");
}
@Test public void testPowerOnIntegers() throws Exception {
assertEvaluatesTo(Double.valueOf(8), "2**3");
}
@Test public void testLessThanOnIntegers_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "3<4");
}
@Test public void testLessThanOnIntegers_02() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "4<3");
}
@Test public void testGreaterThanOnIntegers_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "4>3");
}
@Test public void testGreaterThanOnIntegers_02() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "3>4");
}
@Test public void testLessEqualsThanOnIntegers_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "3<=3");
}
@Test public void testLessEqualsThanOnIntegers_02() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "3<=4");
}
@Test public void testLessEqualsThanOnIntegers_03() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "4<=3");
}
@Test public void testGreaterEqualsThanOnIntegers_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "3>=3");
}
@Test public void testGreaterEqualsThanOnIntegers_02() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "4>=3");
}
@Test public void testGreaterEqualsThanOnIntegers_03() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "3>=4");
}
@Test public void testOrOnBooleans_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "true||false");
}
@Test public void testOrOnBooleans_02() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "false||true");
}
@Test public void testOrOnBooleans_03() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "true||true");
}
@Test public void testOrOnBooleans_04() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "false||false");
}
@Test public void testAndOnBooleans_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "true&&true");
}
@Test public void testAndOnBooleans_02() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "false&&true");
}
@Test public void testAndOnBooleans_03() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "true&&false");
}
@Test public void testAndOnBooleans_04() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "false&&false");
}
@Test public void testNull() throws Exception {
assertEvaluatesTo(null, "null");
}
@Test public void testNullBlockResult_01() throws Exception {
assertEvaluatesTo(null, "{ null; }");
}
@Test public void testNullBlockResult_02() throws Exception {
assertEvaluatesTo(null, "{ 'literal'.length; null; }");
}
@Test public void testBlock_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE,
"{\n" +
" val (Integer, Double, Boolean) => void fun1 = null\n" +
" val (byte[], Object) => double[] fun2 = null\n" +
" val test = newArrayList.map[1 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" +
" val test2 = newArrayList.map[2 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" +
" val test3 = com::google::common::collect::Iterables::concat(test, test2).toMap[key].entrySet.map[value].toList\n" +
" test3 != null" +
"}");
}
@Test public void testBlock_02() throws Exception {
assertEvaluatesTo("Length: 3",
"{\n" +
" val map = newHashMap\n" +
" map.put(1, 'abc')\n" +
" val x = map.get(1)\n" +
" 'Length: ' + x.length" +
"}");
}
@Test public void testSynchronizedBlock_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE,
"synchronized(new Object) {\n" +
" val (Integer, Double, Boolean) => void fun1 = null\n" +
" val (byte[], Object) => double[] fun2 = null\n" +
" val test = newArrayList.map[1 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" +
" val test2 = newArrayList.map[2 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" +
" val test3 = com::google::common::collect::Iterables::concat(test, test2).toMap[key].entrySet.map[value].toList\n" +
" test3 != null" +
"}");
}
@Test public void testSynchronizedBlock_02() throws Exception {
assertEvaluatesTo("Length: 3",
"synchronized(new Object) {\n" +
" val map = newHashMap\n" +
" map.put(1, 'abc')\n" +
" val x = map.get(1)\n" +
" 'Length: ' + x.length" +
"}");
}
@Test public void testSynchronizedBlock_03() throws Exception {
assertEvaluatesTo("foo",
"{\n" +
" val list = <String>newArrayList\n" +
" val ()=>int x = [|{ list += 'foo'; 1 }]\n" +
" synchronized(x.apply) {\n" +
" list.head\n" +
" }\n" +
"}\n");
}
@Test public void testStringLiteral_01() throws Exception {
assertEvaluatesTo("", "''");
}
@Test public void testStringLiteral_02() throws Exception {
assertEvaluatesTo("literal", "'literal'");
}
@Test public void testStringLiteral_03() throws Exception {
assertEvaluatesTo("lite\nr\\al", "'lite\r\nr\\\\al'");
}
@Test public void testStringLiteral_03_Issue_2293_01() throws Exception {
assertEvaluatesTo("lite\nr\\al", "'lite\\nr\\\\al'");
}
@Test public void testStringLiteral_03_Issue_2293_02() throws Exception {
assertEvaluatesTo("lite\r\nr\\al", "'lite\\r\\nr\\\\al'");
}
@Test public void testStringLiteral_04() throws Exception {
assertEvaluatesTo('\n', "{ val char x = '\n' x}");
}
@Test public void testStringLiteral_05() throws Exception {
assertEvaluatesTo(' ', "{ val char x = ' ' x}");
}
@Test public void testStringLiteral_06() throws Exception {
assertEvaluatesTo('«', "{ val char x = '«' x}");
}
@Test public void testStringLiteral_07() throws Exception {
assertEvaluatesTo('«', "{ val Character x = '«' x}");
}
@Test public void testBooleanLiteral_01() throws Exception {
assertEvaluatesTo(Boolean.TRUE, "true");
}
@Test public void testBooleanLiteral_02() throws Exception {
assertEvaluatesTo(Boolean.FALSE, "false");
}
@Test public void testIntLiteral_01() throws Exception {
assertEvaluatesTo(53, "53");
}
@Test public void testIntLiteral_02() throws Exception {
assertEvaluatesTo(0, "0");
}
@Test public void testTypeLiteral_01() throws Exception {
assertEvaluatesTo(Void.class, "typeof(Void)");
}
@Test public void testTypeLiteral_02() throws Exception {
assertEvaluatesTo(void.class, "typeof(void)");
}
@Test public void testTypeLiteral_03() throws Exception {
assertEvaluatesTo(String[].class, "typeof(String[])");
}
@Test public void testTypeLiteral_04() throws Exception {
assertEvaluatesTo(int[][].class, "typeof(int[][])");
}
@Test public void testTypeLiteral_05() throws Exception {
assertEvaluatesTo(Void.class, "Void");
}
@Test public void testTypeLiteral_06() throws Exception {
assertEvaluatesTo(void.class, "void");
}
@Test public void testTypeLiteral_07() throws Exception {
assertEvaluatesTo(void.class, "void");
}
@Test public void testTypeLiteral_08() throws Exception {
assertEvaluatesTo(Map.Entry.class, "typeof(java.util.Map$Entry)");
}
@Test public void testTypeLiteral_09() throws Exception {
assertEvaluatesTo(Map.Entry.class, "typeof(java.util.Map.Entry)");
}
@Test public void testTypeLiteral_10() throws Exception {
assertEvaluatesTo(Map.Entry.class, "java.util.Map$Entry");
}
@Test public void testTypeLiteral_11() throws Exception {
assertEvaluatesTo(Map.Entry.class, "java.util.Map.Entry");
}
@Test public void testIdentityEquals_0() throws Exception {
assertEvaluatesTo(true, "1===1");
}