Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BinaryOperatorTests.cs « Resolver « CSharp « ICSharpCode.NRefactory.Tests - github.com/xamarin/NRefactory.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 35d5706902758361465171247fb6d6d47ddd3a64 (plain)
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
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using NUnit.Framework;

namespace ICSharpCode.NRefactory.CSharp.Resolver
{
	// assign short name to the fake reflection type
	using dynamic = ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.Dynamic;
	
	[TestFixture]
	public unsafe class BinaryOperatorTests : ResolverTestBase
	{
		CSharpResolver resolver;
		
		public override void SetUp()
		{
			base.SetUp();
			resolver = new CSharpResolver(compilation);
		}
		
		[Test]
		public void Multiplication()
		{
			TestOperator(MakeResult(typeof(int)), BinaryOperatorType.Multiply, MakeResult(typeof(int)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(int));
			
			TestOperator(MakeResult(typeof(int)), BinaryOperatorType.Multiply, MakeConstant(0.0f),
			             Conversion.ImplicitNumericConversion, Conversion.IdentityConversion, typeof(float));
			
			AssertConstant(3.0f, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Multiply, MakeConstant(1.5f), MakeConstant(2)));
			
			AssertConstant(6, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Multiply, MakeConstant((byte)2), MakeConstant((byte)3)));
			
			TestOperator(MakeResult(typeof(uint?)), BinaryOperatorType.Multiply, MakeResult(typeof(int?)),
			             Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(long?));
			
			AssertError(typeof(decimal), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Multiply, MakeResult(typeof(float)), MakeResult(typeof(decimal))));
		}
		
		[Test]
		public void Addition()
		{
			TestOperator(MakeResult(typeof(short)), BinaryOperatorType.Add, MakeResult(typeof(byte?)),
			             Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(int?));
			
			AssertConstant(3.0, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant(1.0f), MakeConstant(2.0)));
			
			AssertConstant("Text", resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant("Te"), MakeConstant("xt")));
			
			AssertConstant("", resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant(null), resolver.ResolveCast(ResolveType(typeof(string)), MakeConstant(null))));
			
			AssertError(typeof(ReflectionHelper.Null), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant(null), MakeConstant(null)));
			
			TestOperator(MakeResult(typeof(int?)), BinaryOperatorType.Add, MakeResult(typeof(uint?)),
			             Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(long?));
			
			TestOperator(MakeResult(typeof(ushort?)), BinaryOperatorType.Add, MakeResult(typeof(ushort?)),
			             Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(int?));
			
			TestOperator(MakeConstant(1), BinaryOperatorType.Add, MakeConstant(null),
			             Conversion.ImplicitNullableConversion, Conversion.NullLiteralConversion, typeof(int?));
		}
		
		[Test]
		public void StringPlusNull()
		{
			ResolveResult left = MakeResult(typeof(string));
			var rr = (OperatorResolveResult)resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, left, MakeConstant(null));
			AssertType(typeof(string), rr);
			Assert.AreSame(left, rr.Operands[0]);
			Assert.AreEqual("System.String", rr.Operands[1].Type.FullName);
			Assert.IsTrue(rr.Operands[1].IsCompileTimeConstant);
			Assert.IsNull(rr.Operands[1].ConstantValue);
		}
		
		[Test]
		public void DelegateAddition()
		{
			TestOperator(MakeResult(typeof(Action)), BinaryOperatorType.Add, MakeResult(typeof(Action)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(Action));
			
			TestOperator(MakeResult(typeof(Action<object>)), BinaryOperatorType.Add, MakeResult(typeof(Action<string>)),
			             Conversion.ImplicitReferenceConversion, Conversion.IdentityConversion, typeof(Action<string>));
			
			TestOperator(MakeResult(typeof(Action<string>)), BinaryOperatorType.Add, MakeResult(typeof(Action<object>)),
			             Conversion.IdentityConversion, Conversion.ImplicitReferenceConversion, typeof(Action<string>));
			
			Assert.IsTrue(resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeResult(typeof(Action<int>)), MakeResult(typeof(Action<long>))).IsError);
		}
		
		
		[Test]
		public void EnumAddition()
		{
			AssertConstant(StringComparison.Ordinal, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant(StringComparison.InvariantCulture), MakeConstant(2)));
			
			AssertConstant(StringComparison.OrdinalIgnoreCase, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant((short)3), MakeConstant(StringComparison.InvariantCulture)));
			
			TestOperator(MakeResult(typeof(StringComparison?)), BinaryOperatorType.Add, MakeResult(typeof(int)),
			             Conversion.IdentityConversion, Conversion.ImplicitNullableConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(StringComparison)), BinaryOperatorType.Add, MakeResult(typeof(int?)),
			             Conversion.ImplicitNullableConversion, Conversion.IdentityConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(StringComparison?)), BinaryOperatorType.Add, MakeResult(typeof(int?)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(int)), BinaryOperatorType.Add, MakeResult(typeof(StringComparison?)),
			             Conversion.ImplicitNullableConversion, Conversion.IdentityConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(int?)), BinaryOperatorType.Add, MakeResult(typeof(StringComparison?)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(StringComparison?));
		}
		
		[Test]
		public void PointerAddition()
		{
			TestOperator(MakeResult(typeof(int*)), BinaryOperatorType.Add, MakeConstant(1),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(int*));
			
			TestOperator(MakeResult(typeof(long)), BinaryOperatorType.Add, MakeResult(typeof(byte*)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(byte*));
		}
		
		[Test]
		public void AdditionWithOverflow()
		{
			AssertConstant(int.MinValue, resolver.WithCheckForOverflow(false).ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant(int.MaxValue), MakeConstant(1)));
			
			AssertError(typeof(int), resolver.WithCheckForOverflow(true).ResolveBinaryOperator(
				BinaryOperatorType.Add, MakeConstant(int.MaxValue), MakeConstant(1)));
		}
		
		
		[Test]
		public void Subtraction()
		{
			TestOperator(MakeResult(typeof(short)), BinaryOperatorType.Subtract, MakeResult(typeof(byte?)),
			             Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(int?));
			
			TestOperator(MakeResult(typeof(float)), BinaryOperatorType.Subtract, MakeResult(typeof(long)),
			             Conversion.IdentityConversion, Conversion.ImplicitNumericConversion, typeof(float));
			
			AssertConstant(-1.0, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeConstant(1.0f), MakeConstant(2.0)));
			
			Assert.IsTrue(resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeConstant("Te"), MakeConstant("xt")).IsError);
		}
		
		[Test]
		public void EnumSubtraction()
		{
			AssertConstant(StringComparison.InvariantCulture, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeConstant(StringComparison.Ordinal), MakeConstant(2)));
			
			AssertConstant(3, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeConstant(StringComparison.OrdinalIgnoreCase), MakeConstant(StringComparison.InvariantCulture)));
			
			AssertConstant(StringComparison.InvariantCulture, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeConstant(StringComparison.InvariantCulture), MakeConstant(0)));
			
			TestOperator(MakeResult(typeof(StringComparison?)), BinaryOperatorType.Subtract, MakeResult(typeof(int)),
			             Conversion.IdentityConversion, Conversion.ImplicitNullableConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(StringComparison?)), BinaryOperatorType.Subtract, MakeResult(typeof(StringComparison)),
			             Conversion.IdentityConversion, Conversion.ImplicitNullableConversion, typeof(int?));
			
			TestOperator(MakeResult(typeof(int?)), BinaryOperatorType.Subtract, MakeResult(typeof(StringComparison)),
			             Conversion.IdentityConversion, Conversion.ImplicitNullableConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(int)), BinaryOperatorType.Subtract, MakeResult(typeof(StringComparison?)),
			             Conversion.ImplicitNullableConversion, Conversion.IdentityConversion, typeof(StringComparison?));
		}
		
		[Test]
		public void DelegateSubtraction()
		{
			TestOperator(MakeResult(typeof(Action)), BinaryOperatorType.Subtract, MakeResult(typeof(Action)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(Action));
			
			TestOperator(MakeResult(typeof(Action<object>)), BinaryOperatorType.Subtract, MakeResult(typeof(Action<string>)),
			             Conversion.ImplicitReferenceConversion, Conversion.IdentityConversion, typeof(Action<string>));
			
			TestOperator(MakeResult(typeof(Action<string>)), BinaryOperatorType.Subtract, MakeResult(typeof(Action<object>)),
			             Conversion.IdentityConversion, Conversion.ImplicitReferenceConversion, typeof(Action<string>));
			
			Assert.IsTrue(resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeResult(typeof(Action<int>)), MakeResult(typeof(Action<long>))).IsError);
		}
		
		[Test]
		public void PointerSubtraction()
		{
			TestOperator(MakeResult(typeof(int*)), BinaryOperatorType.Subtract, MakeConstant(1),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(int*));
			
			TestOperator(MakeResult(typeof(byte*)), BinaryOperatorType.Subtract, MakeResult(typeof(uint)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(byte*));
			
			TestOperator(MakeResult(typeof(byte*)), BinaryOperatorType.Subtract, MakeResult(typeof(short)),
			             Conversion.IdentityConversion, Conversion.ImplicitNumericConversion, typeof(byte*));
			
			TestOperator(MakeResult(typeof(byte*)), BinaryOperatorType.Subtract, MakeResult(typeof(byte*)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(long));
			
			AssertError(typeof(long), resolver.ResolveBinaryOperator(BinaryOperatorType.Subtract, MakeResult(typeof(byte*)), MakeResult(typeof(int*))));
		}
		
		[Test]
		public void ShiftTest()
		{
			AssertConstant(6, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ShiftLeft, MakeConstant(3), MakeConstant(1)));
			
			AssertConstant(ulong.MaxValue >> 2, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ShiftRight, MakeConstant(ulong.MaxValue), MakeConstant(2)));
			
			TestOperator(MakeResult(typeof(ushort?)), BinaryOperatorType.ShiftLeft, MakeConstant(1),
			             Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(int?));
			
			TestOperator(MakeConstant(null), BinaryOperatorType.ShiftLeft, MakeConstant(1),
			             Conversion.NullLiteralConversion, Conversion.ImplicitNullableConversion, typeof(int?));
			
			TestOperator(MakeResult(typeof(long)), BinaryOperatorType.ShiftLeft, MakeConstant(null),
			             Conversion.ImplicitNullableConversion, Conversion.NullLiteralConversion, typeof(long?));
			
			TestOperator(MakeConstant(null), BinaryOperatorType.ShiftLeft,  MakeConstant(null),
			             Conversion.NullLiteralConversion, Conversion.NullLiteralConversion, typeof(int?));
		}
		
		[Test]
		public void ConstantEquality()
		{
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(3), MakeConstant(3)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(3), MakeConstant(3.0)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(2.9), MakeConstant(3)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(double.NaN), MakeConstant(double.NaN)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(float.NaN), MakeConstant(float.NaN)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant("A"), MakeConstant("B")));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant("A"), MakeConstant("A")));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(""), MakeConstant(null)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(null), MakeConstant(null)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(1), MakeConstant(null)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(null), MakeConstant('a')));
		}
		
		[Test]
		public void Equality()
		{
			TestOperator(MakeResult(typeof(int*)), BinaryOperatorType.Equality, MakeResult(typeof(uint*)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(bool));
			
			TestOperator(MakeResult(typeof(int)), BinaryOperatorType.Equality, MakeResult(typeof(int?)),
			             Conversion.ImplicitNullableConversion, Conversion.IdentityConversion, typeof(bool));
			
			TestOperator(MakeResult(typeof(int)), BinaryOperatorType.Equality, MakeResult(typeof(float)),
			             Conversion.ImplicitNumericConversion, Conversion.IdentityConversion, typeof(bool));
			
			AssertType(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeResult(typeof(int)), MakeConstant(null)));
			
			AssertError(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeResult(typeof(int)), MakeResult(typeof(string))));
			
			AssertError(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeResult(typeof(int)), MakeResult(typeof(object))));
		}
		
		[Test]
		public void Inequality()
		{
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(3), MakeConstant(3)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(3), MakeConstant(3.0)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(2.9), MakeConstant(3)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(double.NaN), MakeConstant(double.NaN)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(float.NaN), MakeConstant(double.NaN)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(float.NaN), MakeConstant(float.NaN)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant("A"), MakeConstant("B")));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant("A"), MakeConstant("A")));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(""), MakeConstant(null)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(null), MakeConstant(null)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(1), MakeConstant(null)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeConstant(null), MakeConstant('a')));
			
			AssertType(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeResult(typeof(int*)), MakeResult(typeof(uint*))));
			
			AssertType(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.InEquality, MakeResult(typeof(bool?)), MakeConstant(null)));
		}
		
		[Test]
		public void EqualityEnum()
		{
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(0), MakeConstant(StringComparison.Ordinal)));
			
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(0), MakeConstant(StringComparison.CurrentCulture)));
			
			Assert.IsFalse(resolver.ResolveBinaryOperator(
				BinaryOperatorType.Equality, MakeConstant(StringComparison.Ordinal), MakeConstant(1)).IsCompileTimeConstant);
		}
		
		[Test]
		public void RelationalOperators()
		{
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.LessThan, MakeConstant(0), MakeConstant(0)));
			
			AssertType(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.LessThan, MakeResult(typeof(int*)), MakeResult(typeof(uint*))));
			
			TestOperator(MakeResult(typeof(int?)), BinaryOperatorType.LessThan, MakeResult(typeof(int)),
			             Conversion.IdentityConversion, Conversion.ImplicitNullableConversion, typeof(bool));
		}
		
		[Test]
		public void RelationalEnum()
		{
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.LessThan, MakeConstant(0), MakeConstant(StringComparison.Ordinal)));
			
			AssertError(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.LessThanOrEqual, MakeConstant(1), MakeConstant(StringComparison.Ordinal)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.GreaterThan, MakeConstant(StringComparison.CurrentCultureIgnoreCase), MakeConstant(StringComparison.Ordinal)));
			
			AssertType(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.GreaterThan, MakeResult(typeof(StringComparison?)), MakeResult(typeof(StringComparison?))));
		}
		
		[Test]
		public void BitAnd()
		{
			AssertConstant(5, resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeConstant(7), MakeConstant(13)));
			
			AssertType(typeof(int?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeConstant(null), MakeConstant((short)13)));
			
			AssertType(typeof(long?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeResult(typeof(uint?)), MakeConstant((short)13)));
			
			AssertType(typeof(uint?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeResult(typeof(uint?)), MakeConstant((int)13)));
			
			AssertType(typeof(ulong?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeResult(typeof(ulong?)), MakeConstant((long)13)));
			
			Assert.IsTrue(resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeResult(typeof(ulong?)), MakeConstant((short)13)).IsError);
		}
		
		[Test]
		public void BitXor()
		{
			AssertConstant(6L ^ 3, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ExclusiveOr, MakeConstant(6L), MakeConstant(3)));
			
			AssertConstant(6UL ^ 3L, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ExclusiveOr, MakeConstant(6UL), MakeConstant(3L)));
			
			AssertError(typeof(ulong), resolver.ResolveBinaryOperator(
				BinaryOperatorType.ExclusiveOr, MakeConstant(6UL), MakeConstant(-3L)));
		}
		
		[Test]
		public void BitwiseEnum()
		{
			AssertConstant(AttributeTargets.Field | AttributeTargets.Property, resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseOr, MakeConstant(AttributeTargets.Field), MakeConstant(AttributeTargets.Property)));
			
			AssertConstant(AttributeTargets.Field & AttributeTargets.All, resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeConstant(AttributeTargets.Field), MakeConstant(AttributeTargets.All)));
			
			AssertConstant(AttributeTargets.Field & 0, resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseAnd, MakeConstant(AttributeTargets.Field), MakeConstant(0)));
			
			AssertConstant(0 | AttributeTargets.Field, resolver.ResolveBinaryOperator(
				BinaryOperatorType.BitwiseOr, MakeConstant(0), MakeConstant(AttributeTargets.Field)));
		}
		
		[Test]
		public void NullableBitwiseEnum()
		{
			TestOperator(MakeResult(typeof(StringComparison?)), BinaryOperatorType.BitwiseAnd, MakeResult(typeof(StringComparison?)),
			             Conversion.IdentityConversion, Conversion.IdentityConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(StringComparison)), BinaryOperatorType.BitwiseAnd, MakeResult(typeof(StringComparison?)),
			             Conversion.ImplicitNullableConversion, Conversion.IdentityConversion, typeof(StringComparison?));
			
			TestOperator(MakeResult(typeof(StringComparison?)), BinaryOperatorType.BitwiseAnd, MakeResult(typeof(StringComparison)),
			             Conversion.IdentityConversion, Conversion.ImplicitNullableConversion, typeof(StringComparison?));
		}
		
		[Test]
		public void LogicalAnd()
		{
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ConditionalAnd, MakeConstant(true), MakeConstant(true)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ConditionalAnd, MakeConstant(false), MakeConstant(true)));
			
			AssertError(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.ConditionalAnd, MakeConstant(false), MakeResult(typeof(bool?))));
		}
		
		[Test]
		public void LogicalOr()
		{
			AssertConstant(true, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ConditionalOr, MakeConstant(false), MakeConstant(true)));
			
			AssertConstant(false, resolver.ResolveBinaryOperator(
				BinaryOperatorType.ConditionalOr, MakeConstant(false), MakeConstant(false)));
			
			AssertError(typeof(bool), resolver.ResolveBinaryOperator(
				BinaryOperatorType.ConditionalOr, MakeConstant(false), MakeResult(typeof(bool?))));
		}
		
		[Test]
		public void NullCoalescing()
		{
			AssertType(typeof(int), resolver.ResolveBinaryOperator(
				BinaryOperatorType.NullCoalescing, MakeResult(typeof(int?)), MakeResult(typeof(short))));
			
			AssertType(typeof(int?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.NullCoalescing, MakeResult(typeof(int?)), MakeResult(typeof(short?))));
			
			AssertType(typeof(object), resolver.ResolveBinaryOperator(
				BinaryOperatorType.NullCoalescing, MakeResult(typeof(string)), MakeResult(typeof(object))));
			
			AssertError(typeof(string), resolver.ResolveBinaryOperator(
				BinaryOperatorType.NullCoalescing, MakeResult(typeof(string)), MakeResult(typeof(int))));
			
			AssertType(typeof(dynamic), resolver.ResolveBinaryOperator(
				BinaryOperatorType.NullCoalescing, MakeResult(typeof(dynamic)), MakeResult(typeof(string))));
			
			AssertType(typeof(dynamic), resolver.ResolveBinaryOperator(
				BinaryOperatorType.NullCoalescing, MakeResult(typeof(string)), MakeResult(typeof(dynamic))));
		}
		
		[Test]
		public void LiftedUserDefined()
		{
			AssertType(typeof(TimeSpan), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeResult(typeof(DateTime)), MakeResult(typeof(DateTime))));
			AssertType(typeof(TimeSpan?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeResult(typeof(DateTime?)), MakeResult(typeof(DateTime))));
			AssertType(typeof(TimeSpan?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeResult(typeof(DateTime)), MakeResult(typeof(DateTime?))));
			AssertType(typeof(TimeSpan?), resolver.ResolveBinaryOperator(
				BinaryOperatorType.Subtract, MakeResult(typeof(DateTime?)), MakeResult(typeof(DateTime?))));
		}
		
		[Test]
		public void ByteEnumSubtraction()
		{
			string program = @"enum E : byte {
  A = 1,
  B = 2
}
class Test {
	const int $j = E.A - E.B$;
}
";
			// result is 255 in C# 2.0 and later (was -1 in C# 1.x)
			var rr = Resolve<MemberResolveResult>(program);
			Assert.AreEqual(255, rr.ConstantValue);
		}
		
		[Test]
		public void UserDefinedNeedsLiftingDueToImplicitConversion()
		{
			string program = @"struct S {}
struct A {
	public static implicit operator S?(A a) { return null; }
	
	public static S operator +(A a, S s) { return s; }
}
class Test {
	void M(A a) {
		var s = $a + a$;
	}
}
";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.IsTrue(irr.IsLiftedOperator);
			Assert.IsTrue(irr.UserDefinedOperatorMethod is OverloadResolution.ILiftedOperator);
			Assert.AreEqual("A.op_Addition", irr.UserDefinedOperatorMethod.FullName);
			Assert.AreEqual("System.Nullable`1[[S]]", irr.Type.ReflectionName);
			Assert.AreEqual("System.Nullable`1[[S]]", irr.UserDefinedOperatorMethod.ReturnType.ReflectionName);
			
			Conversion lhsConv = ((ConversionResolveResult)irr.Operands[0]).Conversion;
			Conversion rhsConv = ((ConversionResolveResult)irr.Operands[1]).Conversion;
			Assert.AreEqual(Conversion.ImplicitNullableConversion, lhsConv);
			Assert.IsTrue(rhsConv.IsUserDefined);
			Assert.AreEqual("A.op_Implicit", rhsConv.Method.FullName);
		}
		
		[Test]
		public void ThereAreNoLiftedOperatorsForClasses()
		{
			string program = @"struct S {}
class A {
	public static implicit operator S?(A a) { return null; }
	
	public static S operator +(A a, S s) { return s; }
}
class Test {
	void M(A a) {
		var s = $a + a$;
	}
}
";
			var irr = Resolve<CSharpInvocationResolveResult>(program);
			Assert.IsTrue(irr.IsError); // cannot convert from A to S
			Assert.AreEqual("A.op_Addition", irr.Member.FullName);
			Assert.AreEqual("S", irr.Type.ReflectionName);
		}
		
		[Test]
		public void CompoundAssign_String_Char()
		{
			string program = @"
class Test {
	string text;
	void Append(char c) {
		$text += c$;
	}
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.AreEqual(System.Linq.Expressions.ExpressionType.AddAssign, irr.OperatorType);
			Assert.IsNull(irr.UserDefinedOperatorMethod);
			Assert.AreEqual("System.String", irr.Type.ReflectionName);
		}
		
		[Test]
		public void CompoundAssign_Byte_Literal1()
		{
			string program = @"
class Test {
	byte c;
	void Inc() {
		$c += 1$;
	}
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.AreEqual(System.Linq.Expressions.ExpressionType.AddAssign, irr.OperatorType);
			Assert.IsNull(irr.UserDefinedOperatorMethod);
			Assert.AreEqual("System.Byte", irr.Type.ReflectionName);
		}
		
		[Test]
		public void CompareDateTimeWithNullLiteral()
		{
			string program = @"using System;
class Test {
	static void Inc(DateTime x) {
		var c = $x == null$;
	}
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.IsTrue(irr.IsLiftedOperator);
			Assert.IsNotNull(irr.UserDefinedOperatorMethod);
			Assert.AreEqual(compilation.FindType(KnownTypeCode.Boolean), irr.Type);
		}
		
		[Test]
		public void CompareStructWithNullLiteral()
		{
			string program = @"
struct X { }
class Test {
	static void Inc(X x) {
		var c = $x == null$;
	}
}";
			var irr = Resolve(program);
			Assert.IsTrue(irr.IsError);
			Assert.AreEqual(compilation.FindType(KnownTypeCode.Boolean), irr.Type);
		}
		
		[Test]
		public void CompareNullableStructWithNullLiteral()
		{
			string program = @"
struct X { }
class Test {
	static void Inc(X? x) {
		var c = $x == null$;
	}
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.AreEqual(compilation.FindType(KnownTypeCode.Boolean), irr.Type);
		}
		
		[Test]
		public void CompareUnrestrictedTypeParameterWithNullLiteral()
		{
			string program = @"
class Test {
	static void Inc<X>(X x) {
		var c = $x == null$;
	}
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.AreEqual(compilation.FindType(KnownTypeCode.Boolean), irr.Type);
		}
		
		[Test]
		public void LiftedEqualityOperator()
		{
			string program = @"
struct X {
	public static bool operator ==(X a, X b) {}
}
class Test {
	static void Inc(X? x) {
		var c = $x == x$;
	}
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.AreEqual(compilation.FindType(KnownTypeCode.Boolean), irr.Type);
		}
		
		[Test]
		public void IsLiftedProperty()
		{
			string program = @"
class Test {
    static void Inc() {
        int? a = 0, b = 0;
        int? c = $a + b$;
    }
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.IsTrue(irr.IsLiftedOperator);
		}
		
		[Test]
		public void IsLiftedProperty2()
		{
			string program = @"
class Test {
    static void Inc() {
        int? a = 0, b = 0;
        $b += a$;
    }
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.IsTrue(irr.IsLiftedOperator);
		}
		
		[Test]
		public void TestLiftedOperatorBug()
		{
			string program = @"
using System;

struct C<T>
{
	public static C<T> operator+(C<T> u, T u2)
	{
		return u;
	}

	public C ()
	{
		int? foo = 4;
		var a = $new C<int> () + foo$;
	}
}";
			var irr = Resolve<OperatorResolveResult>(program);
			Assert.IsFalse(irr.IsError);
			Assert.IsTrue(irr.IsLiftedOperator);
			Assert.AreEqual("System.Nullable`1[[C`1[[System.Int32]]]]", irr.Type.ReflectionName);
		}

		/// <summary>
		/// Bug 12717 - Wrong type resolved for enum substraction
		/// </summary>
		[Test]
		public void TestIntEnumSubstraction()
		{
			string program = @"using System;

enum E
{
    V
}

class Test
{
    public static void Main ()
    {

        E e = 0;
        var res = $1 - e$;
    }
}";
			var rr = Resolve<OperatorResolveResult>(program);
			Assert.AreEqual("E", rr.Type.FullName);
		}

		/// <summary>
		/// Bug 12689 - Wrong type of bitwise operation with enums
		/// </summary>
		[Test]
		public void TestEnumBitwiseAndOperatorOverloading()
		{
			string program = @"using System;

struct S
{
    public static implicit operator E? (S s)
    {
        return 0;
    }
}


public enum E
{

}

class C
{
    public static void Main ()
    {
        E e = 0;
        S s;
        var res = $e & s$; // INVALID type of res XS shows int but should be E?
    }
}";
			var rr = Resolve<OperatorResolveResult>(program);
			Assert.AreEqual("System.Nullable`1[[E]]", rr.Type.ReflectionName);
		}

		/// <summary>
		/// Bug 12677 - Wrong result of constant binary result
		/// </summary>
		[Test]
		public void TestEnumSubstractionWithNull()
		{
			string program = @"using System;

public enum E
{
}

class C
{
    public static void Main ()
    {
        E? e = null;
        var res = $(e - null).Value$; // Value is E but should be int
    }
}";
			var rr = Resolve<MemberResolveResult>(program);
			Assert.AreEqual("System.Int32", rr.Type.ReflectionName);
		}

		/// <summary>
		/// Bug 12670 - Wrong type resolution for enums
		/// </summary>
		[Test]
		public void TestEnumBitwiseAndOperatorWithNull()
		{
			string program = @"public enum E {}

class C
{
    public static void Main ()
    {
        E f = 0;
        var res = $f & null$; // XS sees Value as type uint instead of E
    }
}";
			var rr = Resolve<OperatorResolveResult>(program);
			Assert.AreEqual("System.Nullable`1[[E]]", rr.Type.ReflectionName);
		}
		
		[Test]
		public void EnumSubtractionWithImplicitOperators()
		{
			string program = @"using System;
public enum E {}
struct S {
    public static implicit operator E (S s) { return 0; }
    public static implicit operator int (S s) { return 0; }
}

class C
{
    public void Test(E e, S s)
    {
        var res = $e - s$; // C# uses the conversion to E, so result will be int
    }
}";
			var rr = Resolve<OperatorResolveResult>(program);
			Assert.AreEqual("System.Int32", rr.Type.ReflectionName);
			var c = ((ConversionResolveResult)rr.Operands[1]).Conversion;
			Assert.IsTrue(c.IsUserDefined);
			Assert.AreEqual("E", c.Method.ReturnType.ReflectionName);
		}
		
		ITypeDefinition enumWithMissingBaseType = TypeSystemHelper.CreateCompilationWithoutCorlibAndResolve(
			new DefaultUnresolvedTypeDefinition("MyEnum") {
				Kind = TypeKind.Enum,
				BaseTypes = { KnownTypeReference.Int32 }
			}
		);
		
		[Test]
		public void EnumBitwiseOrWithMissingBaseType()
		{
			var resolver = new CSharpResolver(enumWithMissingBaseType.Compilation);
			var lhs = new ConstantResolveResult(enumWithMissingBaseType, 1);
			var rhs = new ConstantResolveResult(enumWithMissingBaseType, 2);
			var rr = (ConstantResolveResult)resolver.ResolveBinaryOperator(BinaryOperatorType.BitwiseOr, lhs, rhs);
			Assert.AreEqual(enumWithMissingBaseType, rr.Type);
			Assert.AreEqual(3, rr.ConstantValue);
		}
	}
}