Repository navigation
Expand file tree
/
Copy pathObjectFormatterTests.cs
More file actions
1365 lines (1111 loc) · 46.6 KB
/
Copy pathObjectFormatterTests.cs
File metadata and controls
1365 lines (1111 loc) · 46.6 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 (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Roslyn.Test.Utilities;
using Xunit;
using SymbolDisplay = Microsoft.CodeAnalysis.CSharp.SymbolDisplay;
using VB = Microsoft.CodeAnalysis.VisualBasic;
using ObjectFormatterFixtures;
using Microsoft.CodeAnalysis.Scripting.CSharp;
#region Fixtures
#pragma warning disable 169 // unused field
#pragma warning disable 649 // field not set, will always be default value
namespace ObjectFormatterFixtures
{
internal class Outer
{
public class Nested<T>
{
public readonly int A = 1;
public readonly int B = 2;
public static readonly int S = 3;
}
}
internal class A<T>
{
public class B<S>
{
public class C
{
public class D<Q, R>
{
public class E
{
}
}
}
}
public static readonly B<T> X = new B<T>();
}
internal class Sort
{
public readonly byte ab = 1;
public readonly sbyte aB = -1;
public readonly short Ac = -1;
public readonly ushort Ad = 1;
public readonly int ad = -1;
public readonly uint aE = 1;
public readonly long aF = -1;
public readonly ulong AG = 1;
}
internal class RecursiveRootHidden
{
public readonly int A;
public readonly int B;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public RecursiveRootHidden C;
}
internal class RecursiveProxy
{
private class Proxy
{
public Proxy() { }
public Proxy(Node node) { x = node.value; y = node.next; }
public readonly int x;
public readonly Node y;
}
[DebuggerTypeProxy(typeof(Proxy))]
public class Node
{
public Node(int value)
{
if (value < 5)
{
next = new Node(value + 1);
}
this.value = value;
}
public readonly int value;
public readonly Node next;
}
}
internal class InvalidRecursiveProxy
{
private class Proxy
{
public Proxy() { }
public Proxy(Node c) { }
public readonly int x;
public readonly Node p = new Node();
public readonly int y;
}
[DebuggerTypeProxy(typeof(Proxy))]
public class Node
{
public readonly int a;
public readonly int b;
}
}
internal class ComplexProxyBase
{
private int Foo()
{
return 1;
}
}
internal class ComplexProxy : ComplexProxyBase
{
public ComplexProxy()
{
}
public ComplexProxy(object b)
{
}
[DebuggerDisplay("*1")]
public int _02_public_property_dd { get { return 1; } }
[DebuggerDisplay("*2")]
private int _03_private_property_dd { get { return 1; } }
[DebuggerDisplay("*3")]
protected int _04_protected_property_dd { get { return 1; } }
[DebuggerDisplay("*4")]
internal int _05_internal_property_dd { get { return 1; } }
[DebuggerDisplay("+1")]
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public readonly int _06_public_field_dd_never;
[DebuggerDisplay("+2")]
private readonly int _07_private_field_dd;
[DebuggerDisplay("+3")]
protected readonly int _08_protected_field_dd;
[DebuggerDisplay("+4")]
internal readonly int _09_internal_field_dd;
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
private readonly int _10_private_collapsed;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
private readonly int _10_private_rootHidden;
public readonly int _12_public;
private readonly int _13_private;
protected readonly int _14_protected;
internal readonly int _15_internal;
[DebuggerDisplay("==\r\n=\r\n=")]
public readonly int _16_eolns;
[DebuggerDisplay("=={==")]
public readonly int _17_braces_0;
[DebuggerDisplay("=={{==")]
public readonly int _17_braces_1;
[DebuggerDisplay("=={'{'}==")]
public readonly int _17_braces_2;
[DebuggerDisplay("=={'\\{'}==")]
public readonly int _17_braces_3;
[DebuggerDisplay("=={1/*{*/}==")]
public readonly int _17_braces_4;
[DebuggerDisplay("=={'{'/*\\}*/}==")]
public readonly int _17_braces_5;
[DebuggerDisplay("=={'{'/*}*/}==")]
public readonly int _17_braces_6;
[DebuggerDisplay("==\\{\\x\\t==")]
public readonly int _19_escapes;
[DebuggerDisplay("{1+1}")]
public readonly int _21;
[DebuggerDisplay("{\"xxx\"}")]
public readonly int _22;
[DebuggerDisplay("{\"xxx\",nq}")]
public readonly int _23;
[DebuggerDisplay("{'x'}")]
public readonly int _24;
[DebuggerDisplay("{'x',nq}")]
public readonly int _25;
[DebuggerDisplay("{new B()}")]
public readonly int _26_0;
[DebuggerDisplay("{new D()}")]
public readonly int _26_1;
[DebuggerDisplay("{new E()}")]
public readonly int _26_2;
[DebuggerDisplay("{ReturnVoid()}")]
public readonly int _26_3;
private void ReturnVoid() { }
[DebuggerDisplay("{F1(1)}")]
public readonly int _26_4;
[DebuggerDisplay("{Foo}")]
public readonly int _26_5;
[DebuggerDisplay("{foo}")]
public readonly int _26_6;
private int foo()
{
return 2;
}
private int F1(int a) { return 1; }
private int F2(short a) { return 2; }
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public readonly C _27_rootHidden = new C();
public readonly C _28 = new C();
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
public readonly C _29_collapsed = new C();
public int _31 { get; set; }
[CompilerGenerated]
public readonly int _32;
[CompilerGenerated]
private readonly int _33;
public int _34_Exception { get { throw new Exception("error1"); } }
[DebuggerDisplay("-!-")]
public int _35_Exception { get { throw new Exception("error2"); } }
public readonly object _36 = new ToStringException();
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public int _37 { get { throw new Exception("error3"); } }
public int _38_private_get_public_set { private get { return 1; } set { } }
public int _39_public_get_private_set { get { return 1; } private set { } }
private int _40_private_get_private_set { get { return 1; } set { } }
public override string ToString()
{
return "AStr";
}
}
[DebuggerTypeProxy(typeof(ComplexProxy))]
internal class TypeWithComplexProxy
{
public override string ToString()
{
return "BStr";
}
}
[DebuggerTypeProxy(typeof(Proxy))]
[DebuggerDisplay("DD")]
internal class TypeWithDebuggerDisplayAndProxy
{
public override string ToString()
{
return "<ToString>";
}
[DebuggerDisplay("pxy")]
private class Proxy
{
public Proxy(object x)
{
}
public readonly int A;
public readonly int B;
}
}
internal class C
{
public readonly int A = 1;
public readonly int B = 2;
public override string ToString()
{
return "CStr";
}
}
internal class ToStringException
{
public override string ToString()
{
throw new MyException();
}
}
internal class MyException : Exception
{
public override string ToString()
{
return "my exception";
}
}
public class ThrowingDictionary : IDictionary
{
private readonly int _throwAt;
public ThrowingDictionary(int throwAt)
{
_throwAt = throwAt;
}
public void Add(object key, object value)
{
throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(object key)
{
throw new NotImplementedException();
}
public IDictionaryEnumerator GetEnumerator()
{
return new E(_throwAt);
}
public bool IsFixedSize
{
get { throw new NotImplementedException(); }
}
public bool IsReadOnly
{
get { throw new NotImplementedException(); }
}
public ICollection Keys
{
get { return new[] { 1, 2 }; }
}
public void Remove(object key)
{
}
public ICollection Values
{
get { return new[] { 1, 2 }; }
}
public object this[object key]
{
get
{
return 1;
}
set
{
}
}
public void CopyTo(Array array, int index)
{
}
public int Count
{
get { return 10; }
}
public bool IsSynchronized
{
get { throw new NotImplementedException(); }
}
public object SyncRoot
{
get { throw new NotImplementedException(); }
}
IEnumerator IEnumerable.GetEnumerator()
{
return new E(-1);
}
private class E : IEnumerator, IDictionaryEnumerator
{
private int _i;
private readonly int _throwAt;
public E(int throwAt)
{
_throwAt = throwAt;
}
public object Current
{
get { return new DictionaryEntry(_i, _i); }
}
public bool MoveNext()
{
_i++;
if (_i == _throwAt)
{
throw new Exception();
}
return _i < 5;
}
public void Reset()
{
}
public DictionaryEntry Entry
{
get { return (DictionaryEntry)Current; }
}
public object Key
{
get { return _i; }
}
public object Value
{
get { return _i; }
}
}
}
public class ListNode
{
public ListNode next;
public object data;
}
public class LongMembers
{
public readonly string LongName0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789 = "hello";
public readonly string LongValue = "0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789";
}
}
#pragma warning restore 169 // unused field
#pragma warning restore 649 // field not set, will always be default value
#endregion
namespace Microsoft.CodeAnalysis.Scripting.UnitTests
{
public class ObjectFormatterTests
{
private static readonly ObjectFormattingOptions s_hexa = new ObjectFormattingOptions(useHexadecimalNumbers: true);
private static readonly ObjectFormattingOptions s_memberList = new ObjectFormattingOptions(memberFormat: MemberDisplayFormat.List);
private static readonly ObjectFormattingOptions s_inline = new ObjectFormattingOptions(memberFormat: MemberDisplayFormat.Inline);
private void AssertMembers(string str, params string[] expected)
{
int i = 0;
foreach (var line in str.Split(new[] { "\r\n " }, StringSplitOptions.None))
{
if (i == 0)
{
Assert.Equal(expected[i] + " {", line);
}
else if (i == expected.Length - 1)
{
Assert.Equal(expected[i] + "\r\n}\r\n", line);
}
else
{
Assert.Equal(expected[i] + ",", line);
}
i++;
}
Assert.Equal(expected.Length, i);
}
private string FilterDisplayString(string str)
{
str = System.Text.RegularExpressions.Regex.Replace(str, @"Id = \d+", "Id = *");
str = System.Text.RegularExpressions.Regex.Replace(str, @"Id=\d+", "Id=*");
str = System.Text.RegularExpressions.Regex.Replace(str, @"Id: \d+", "Id: *");
return str;
}
[Fact]
public void Objects()
{
string str;
object nested = new Outer.Nested<int>();
str = CSharpObjectFormatter.Instance.FormatObject(nested, s_inline);
Assert.Equal(@"Outer.Nested<int> { A=1, B=2 }", str);
str = CSharpObjectFormatter.Instance.FormatObject(nested, new ObjectFormattingOptions(memberFormat: MemberDisplayFormat.NoMembers));
Assert.Equal(@"Outer.Nested<int>", str);
str = CSharpObjectFormatter.Instance.FormatObject(A<int>.X, new ObjectFormattingOptions(memberFormat: MemberDisplayFormat.NoMembers));
Assert.Equal(@"A<int>.B<int>", str);
object obj = new A<int>.B<bool>.C.D<string, double>.E();
str = CSharpObjectFormatter.Instance.FormatObject(obj, new ObjectFormattingOptions(memberFormat: MemberDisplayFormat.NoMembers));
Assert.Equal(@"A<int>.B<bool>.C.D<string, double>.E", str);
var sort = new Sort();
str = CSharpObjectFormatter.Instance.FormatObject(sort, new ObjectFormattingOptions(maxLineLength: 51, memberFormat: MemberDisplayFormat.Inline));
Assert.Equal(@"Sort { aB=-1, ab=1, Ac=-1, Ad=1, ad=-1, aE=1, a ...", str);
Assert.Equal(51, str.Length);
str = CSharpObjectFormatter.Instance.FormatObject(sort, new ObjectFormattingOptions(maxLineLength: 5, memberFormat: MemberDisplayFormat.Inline));
Assert.Equal(@"S ...", str);
Assert.Equal(5, str.Length);
str = CSharpObjectFormatter.Instance.FormatObject(sort, new ObjectFormattingOptions(maxLineLength: 4, memberFormat: MemberDisplayFormat.Inline));
Assert.Equal(@"...", str);
str = CSharpObjectFormatter.Instance.FormatObject(sort, new ObjectFormattingOptions(maxLineLength: 3, memberFormat: MemberDisplayFormat.Inline));
Assert.Equal(@"...", str);
str = CSharpObjectFormatter.Instance.FormatObject(sort, new ObjectFormattingOptions(maxLineLength: 2, memberFormat: MemberDisplayFormat.Inline));
Assert.Equal(@"...", str);
str = CSharpObjectFormatter.Instance.FormatObject(sort, new ObjectFormattingOptions(maxLineLength: 1, memberFormat: MemberDisplayFormat.Inline));
Assert.Equal(@"...", str);
str = CSharpObjectFormatter.Instance.FormatObject(sort, new ObjectFormattingOptions(maxLineLength: 80, memberFormat: MemberDisplayFormat.Inline));
Assert.Equal(@"Sort { aB=-1, ab=1, Ac=-1, Ad=1, ad=-1, aE=1, aF=-1, AG=1 }", str);
}
[Fact]
public void ArrayOtInt32_NoMembers()
{
CSharpObjectFormatter formatter = CSharpObjectFormatter.Instance;
object o = new int[4] { 3, 4, 5, 6 };
var str = formatter.FormatObject(o);
Assert.Equal("int[4] { 3, 4, 5, 6 }", str);
}
#region DANGER: Debugging this method under VS2010 might freeze your machine.
[Fact]
public void RecursiveRootHidden()
{
var DO_NOT_ADD_TO_WATCH_WINDOW = new RecursiveRootHidden();
DO_NOT_ADD_TO_WATCH_WINDOW.C = DO_NOT_ADD_TO_WATCH_WINDOW;
string str = CSharpObjectFormatter.Instance.FormatObject(DO_NOT_ADD_TO_WATCH_WINDOW, s_inline);
Assert.Equal(@"RecursiveRootHidden { A=0, B=0 }", str);
}
#endregion
[Fact]
public void DebuggerDisplay_ParseSimpleMemberName()
{
Test_ParseSimpleMemberName("foo", name: "foo", callable: false, nq: false);
Test_ParseSimpleMemberName("foo ", name: "foo", callable: false, nq: false);
Test_ParseSimpleMemberName(" foo", name: "foo", callable: false, nq: false);
Test_ParseSimpleMemberName(" foo ", name: "foo", callable: false, nq: false);
Test_ParseSimpleMemberName("foo()", name: "foo", callable: true, nq: false);
Test_ParseSimpleMemberName("\nfoo (\r\n)", name: "foo", callable: true, nq: false);
Test_ParseSimpleMemberName(" foo ( \t) ", name: "foo", callable: true, nq: false);
Test_ParseSimpleMemberName("foo,nq", name: "foo", callable: false, nq: true);
Test_ParseSimpleMemberName("foo ,nq", name: "foo", callable: false, nq: true);
Test_ParseSimpleMemberName("foo(),nq", name: "foo", callable: true, nq: true);
Test_ParseSimpleMemberName(" foo \t( ) ,nq", name: "foo", callable: true, nq: true);
Test_ParseSimpleMemberName(" foo \t( ) , nq", name: "foo", callable: true, nq: true);
Test_ParseSimpleMemberName("foo, nq", name: "foo", callable: false, nq: true);
Test_ParseSimpleMemberName("foo(,nq", name: "foo(", callable: false, nq: true);
Test_ParseSimpleMemberName("foo),nq", name: "foo)", callable: false, nq: true);
Test_ParseSimpleMemberName("foo ( ,nq", name: "foo (", callable: false, nq: true);
Test_ParseSimpleMemberName("foo ) ,nq", name: "foo )", callable: false, nq: true);
Test_ParseSimpleMemberName(",nq", name: "", callable: false, nq: true);
Test_ParseSimpleMemberName(" ,nq", name: "", callable: false, nq: true);
}
private void Test_ParseSimpleMemberName(string value, string name, bool callable, bool nq)
{
bool actualNoQuotes, actualIsCallable;
string actualName = CSharpObjectFormatter.Formatter.ParseSimpleMemberName(value, 0, value.Length, out actualNoQuotes, out actualIsCallable);
Assert.Equal(name, actualName);
Assert.Equal(nq, actualNoQuotes);
Assert.Equal(callable, actualIsCallable);
actualName = CSharpObjectFormatter.Formatter.ParseSimpleMemberName("---" + value + "-", 3, 3 + value.Length, out actualNoQuotes, out actualIsCallable);
Assert.Equal(name, actualName);
Assert.Equal(nq, actualNoQuotes);
Assert.Equal(callable, actualIsCallable);
}
[Fact]
public void DebuggerDisplay()
{
string str;
var a = new ComplexProxy();
str = CSharpObjectFormatter.Instance.FormatObject(a, s_memberList);
AssertMembers(str, @"[AStr]",
@"_02_public_property_dd: *1",
@"_03_private_property_dd: *2",
@"_04_protected_property_dd: *3",
@"_05_internal_property_dd: *4",
@"_07_private_field_dd: +2",
@"_08_protected_field_dd: +3",
@"_09_internal_field_dd: +4",
@"_10_private_collapsed: 0",
@"_12_public: 0",
@"_13_private: 0",
@"_14_protected: 0",
@"_15_internal: 0",
"_16_eolns: ==\r\n=\r\n=",
@"_17_braces_0: =={==",
@"_17_braces_1: =={{==",
@"_17_braces_2: ==!<Member ''{'' not found>==",
@"_17_braces_3: ==!<Member ''\{'' not found>==",
@"_17_braces_4: ==!<Member '1/*{*/' not found>==",
@"_17_braces_5: ==!<Member ''{'/*\' not found>*/}==",
@"_17_braces_6: ==!<Member ''{'/*' not found>*/}==",
@"_19_escapes: ==\{\x\t==",
@"_21: !<Member '1+1' not found>",
@"_22: !<Member '""xxx""' not found>",
@"_23: !<Member '""xxx""' not found>",
@"_24: !<Member ''x'' not found>",
@"_25: !<Member ''x'' not found>",
@"_26_0: !<Method 'new B' not found>",
@"_26_1: !<Method 'new D' not found>",
@"_26_2: !<Method 'new E' not found>",
@"_26_3: ",
@"_26_4: !<Member 'F1(1)' not found>",
@"_26_5: 1",
@"_26_6: 2",
@"A: 1",
@"B: 2",
@"_28: [CStr]",
@"_29_collapsed: [CStr]",
@"_31: 0",
@"_32: 0",
@"_33: 0",
@"_34_Exception: !<Exception>",
@"_35_Exception: -!-",
@"_36: !<MyException>",
@"_38_private_get_public_set: 1",
@"_39_public_get_private_set: 1",
@"_40_private_get_private_set: 1"
);
var b = new TypeWithComplexProxy();
str = CSharpObjectFormatter.Instance.FormatObject(b, s_memberList);
AssertMembers(str, @"[BStr]",
@"_02_public_property_dd: *1",
@"_04_protected_property_dd: *3",
@"_08_protected_field_dd: +3",
@"_10_private_collapsed: 0",
@"_12_public: 0",
@"_14_protected: 0",
"_16_eolns: ==\r\n=\r\n=",
@"_17_braces_0: =={==",
@"_17_braces_1: =={{==",
@"_17_braces_2: ==!<Member ''{'' not found>==",
@"_17_braces_3: ==!<Member ''\{'' not found>==",
@"_17_braces_4: ==!<Member '1/*{*/' not found>==",
@"_17_braces_5: ==!<Member ''{'/*\' not found>*/}==",
@"_17_braces_6: ==!<Member ''{'/*' not found>*/}==",
@"_19_escapes: ==\{\x\t==",
@"_21: !<Member '1+1' not found>",
@"_22: !<Member '""xxx""' not found>",
@"_23: !<Member '""xxx""' not found>",
@"_24: !<Member ''x'' not found>",
@"_25: !<Member ''x'' not found>",
@"_26_0: !<Method 'new B' not found>",
@"_26_1: !<Method 'new D' not found>",
@"_26_2: !<Method 'new E' not found>",
@"_26_3: ",
@"_26_4: !<Member 'F1(1)' not found>",
@"_26_5: 1",
@"_26_6: 2",
@"A: 1",
@"B: 2",
@"_28: [CStr]",
@"_29_collapsed: [CStr]",
@"_31: 0",
@"_32: 0",
@"_34_Exception: !<Exception>",
@"_35_Exception: -!-",
@"_36: !<MyException>",
@"_38_private_get_public_set: 1",
@"_39_public_get_private_set: 1"
);
}
[Fact]
public void DebuggerProxy_DebuggerDisplayAndProxy()
{
var obj = new TypeWithDebuggerDisplayAndProxy();
var str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("TypeWithDebuggerDisplayAndProxy(DD) { A=0, B=0 }", str);
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_memberList);
AssertMembers(str, "TypeWithDebuggerDisplayAndProxy(DD)",
"A: 0",
"B: 0"
);
}
[Fact]
public void DebuggerProxy_Recursive()
{
string str;
object obj = new RecursiveProxy.Node(0);
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_memberList);
AssertMembers(str, "Node",
"x: 0",
"y: Node { x=1, y=Node { x=2, y=Node { x=3, y=Node { x=4, y=Node { x=5, y=null } } } } }"
);
obj = new InvalidRecursiveProxy.Node();
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_memberList);
// TODO: better overflow handling
Assert.Equal("!<Stack overflow while evaluating object>", str);
}
[Fact]
public void Array_Recursive()
{
string str;
ListNode n2;
ListNode n1 = new ListNode();
object[] obj = new object[5];
obj[0] = 1;
obj[1] = obj;
obj[2] = n2 = new ListNode() { data = obj, next = n1 };
obj[3] = new object[] { 4, 5, obj, 6, new ListNode() };
obj[4] = 3;
n1.next = n2;
n1.data = new object[] { 7, n2, 8, obj };
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_memberList);
AssertMembers(str, "object[5]",
"1",
"{ ... }",
"ListNode { data={ ... }, next=ListNode { data=object[4] { 7, ListNode { ... }, 8, { ... } }, next=ListNode { ... } } }",
"object[5] { 4, 5, { ... }, 6, ListNode { data=null, next=null } }",
"3"
);
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal(str, "object[5] { 1, { ... }, ListNode { data={ ... }, next=ListNode { data=object[4] { 7, ListNode { ... }, 8, { ... } }, next=ListNode { ... } } }, object[5] { 4, 5, { ... }, 6, ListNode { data=null, next=null } }, 3 }");
}
[Fact]
public void LargeGraph()
{
var list = new LinkedList<object>();
object obj = list;
for (int i = 0; i < 10000; i++)
{
var node = list.AddFirst(i);
var newList = new LinkedList<object>();
list.AddAfter(node, newList);
list = newList;
}
string output = "LinkedList<object>(2) { 0, LinkedList<object>(2) { 1, LinkedList<object>(2) { 2, LinkedList<object>(2) {";
for (int i = 100; i > 4; i--)
{
var options = new ObjectFormattingOptions(maxOutputLength: i, memberFormat: MemberDisplayFormat.Inline);
var str = CSharpObjectFormatter.Instance.FormatObject(obj, options);
var expected = output.Substring(0, i - " ...".Length);
if (!expected.EndsWith(" ", StringComparison.Ordinal))
{
expected += " ";
}
expected += "...";
Assert.Equal(expected, str);
}
}
[Fact]
public void LongMembers()
{
object obj = new LongMembers();
var options = new ObjectFormattingOptions(maxLineLength: 20, memberFormat: MemberDisplayFormat.Inline);
//str = ObjectFormatter.Instance.FormatObject(obj, options);
//Assert.Equal("LongMembers { Lo ...", str);
options = new ObjectFormattingOptions(maxLineLength: 20, memberFormat: MemberDisplayFormat.List);
var str = CSharpObjectFormatter.Instance.FormatObject(obj, options);
Assert.Equal("LongMembers {\r\n LongName012345 ...\r\n LongValue: \"01 ...\r\n}\r\n", str);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_Array()
{
var obj = new Object[] { new C(), 1, "str", 'c', true, null, new bool[] { true, false, true, false } };
var str = CSharpObjectFormatter.Instance.FormatObject(obj, s_memberList);
AssertMembers(str, "object[7]",
"[CStr]",
"1",
"\"str\"",
"'c'",
"true",
"null",
"bool[4] { true, false, true, false }"
);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_MdArray()
{
string str;
int[,,] a = new int[2, 3, 4]
{
{
{ 000, 001, 002, 003 },
{ 010, 011, 012, 013 },
{ 020, 021, 022, 023 },
},
{
{ 100, 101, 102, 103 },
{ 110, 111, 112, 113 },
{ 120, 121, 122, 123 },
}
};
str = CSharpObjectFormatter.Instance.FormatObject(a, s_inline);
Assert.Equal("int[2, 3, 4] { { { 0, 1, 2, 3 }, { 10, 11, 12, 13 }, { 20, 21, 22, 23 } }, { { 100, 101, 102, 103 }, { 110, 111, 112, 113 }, { 120, 121, 122, 123 } } }", str);
str = CSharpObjectFormatter.Instance.FormatObject(a, s_memberList);
AssertMembers(str, "int[2, 3, 4]",
"{ { 0, 1, 2, 3 }, { 10, 11, 12, 13 }, { 20, 21, 22, 23 } }",
"{ { 100, 101, 102, 103 }, { 110, 111, 112, 113 }, { 120, 121, 122, 123 } }"
);
int[][,][,,,] obj = new int[2][,][,,,];
obj[0] = new int[1, 2][,,,];
obj[0][0, 0] = new int[1, 2, 3, 4];
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("int[2][,][,,,] { int[1, 2][,,,] { { int[1, 2, 3, 4] { { { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } } } }, null } }, null }", str);
Array x = Array.CreateInstance(typeof(Object), lengths: new int[] { 2, 3 }, lowerBounds: new int[] { 2, 9 });
str = CSharpObjectFormatter.Instance.FormatObject(x, s_inline);
Assert.Equal("object[2..4, 9..12] { { null, null, null }, { null, null, null } }", str);
Array y = Array.CreateInstance(typeof(Object), lengths: new int[] { 1, 1 }, lowerBounds: new int[] { 0, 0 });
str = CSharpObjectFormatter.Instance.FormatObject(y, s_inline);
Assert.Equal("object[1, 1] { { null } }", str);
Array z = Array.CreateInstance(typeof(Object), lengths: new int[] { 0, 0 }, lowerBounds: new int[] { 0, 0 });
str = CSharpObjectFormatter.Instance.FormatObject(z, s_inline);
Assert.Equal("object[0, 0] { }", str);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_IEnumerable()
{
string str;
object obj;
obj = Enumerable.Range(0, 10);
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("RangeIterator { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }", str);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_IEnumerable_Exception()
{
string str;
object obj;
obj = Enumerable.Range(0, 10).Where(i => { if (i == 5) throw new Exception("xxx"); return i < 7; });
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("Enumerable.WhereEnumerableIterator<int> { 0, 1, 2, 3, 4, !<Exception> ... }", str);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_IDictionary()
{
string str;
object obj;
obj = new ThrowingDictionary(throwAt: -1);
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("ThrowingDictionary(10) { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 } }", str);
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_memberList);
AssertMembers(str, "ThrowingDictionary(10)",
"{ 1, 1 }",
"{ 2, 2 }",
"{ 3, 3 }",
"{ 4, 4 }"
);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_IDictionary_Exception()
{
string str;
object obj;
obj = new ThrowingDictionary(throwAt: 3);
str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("ThrowingDictionary(10) { { 1, 1 }, { 2, 2 }, !<Exception> ... }", str);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_ArrayList()
{
var obj = new ArrayList { 1, 2, true, "foo" };
var str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("ArrayList(4) { 1, 2, true, \"foo\" }", str);
}
[Fact]
public void DebuggerProxy_FrameworkTypes_BitArray()
{
// BitArray doesn't have debugger proxy/display
var obj = new System.Collections.BitArray(new int[] { 1 });
var str = CSharpObjectFormatter.Instance.FormatObject(obj, s_inline);
Assert.Equal("BitArray(32) { true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }", str);
}
[Fact]