Skip to content

Commit d14fd69

Browse files
committed
Update CSharpFileBuilderTests to include the NullableContext
.. attributes. Prompted by dotnet/runtime#87857 .
1 parent afc401e commit d14fd69

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/Tests/Microsoft.DotNet.GenAPI.Tests/CSharpFileBuilderTests.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public interface IPoint
190190
expected: """
191191
namespace Foo
192192
{
193+
[System.Runtime.CompilerServices.NullableContext(1)]
193194
public partial interface IPoint
194195
{
195196
// Property signatures:
@@ -344,10 +345,16 @@ public class Node5<T, U> : BaseNodeMultiple<T, U> { }
344345
expected: """
345346
namespace Foo
346347
{
348+
[System.Runtime.CompilerServices.NullableContext(2)]
349+
[System.Runtime.CompilerServices.Nullable(0)]
347350
public partial class BaseNodeMultiple <T, U> { }
348351
352+
[System.Runtime.CompilerServices.NullableContext(2)]
353+
[Nullable(new[] { 0, 1 })]
349354
public partial class Node4 <T> : BaseNodeMultiple<T, int> { }
350355
356+
[System.Runtime.CompilerServices.NullableContext(2)]
357+
[Nullable(new[] { 0, 1, 1 })]
351358
public partial class Node5 <T, U> : BaseNodeMultiple<T, U> { }
352359
}
353360
""");
@@ -463,11 +470,15 @@ public event System.EventHandler<string> OnNewMessage { add { } remove { } }
463470
expected: """
464471
namespace Foo
465472
{
473+
[System.Runtime.CompilerServices.NullableContext(1)]
474+
[System.Runtime.CompilerServices.Nullable(0)]
466475
public abstract partial class AbstractEvents
467476
{
468477
public abstract event System.EventHandler<bool> TextChanged;
469478
}
470479
480+
[System.Runtime.CompilerServices.NullableContext(1)]
481+
[System.Runtime.CompilerServices.Nullable(0)]
471482
public partial class Events
472483
{
473484
public event System.EventHandler<string> OnNewMessage { add { } remove { } }
@@ -611,9 +622,13 @@ public class Car : System.IEquatable<Car>
611622
expected: """
612623
namespace Foo
613624
{
625+
[System.Runtime.CompilerServices.NullableContext(1)]
626+
[System.Runtime.CompilerServices.Nullable(0)]
614627
public partial class Car : System.IEquatable<Car>
615628
{
629+
[System.Runtime.CompilerServices.NullableContext(2)]
616630
public bool Equals(Car? c) { throw null; }
631+
[System.Runtime.CompilerServices.NullableContext(2)]
617632
public override bool Equals(object? o) { throw null; }
618633
public override int GetHashCode() { throw null; }
619634
public static bool operator ==(Car lhs, Car rhs) { throw null; }
@@ -694,6 +709,8 @@ public class Bar
694709
expected: """
695710
namespace Foo
696711
{
712+
[System.Runtime.CompilerServices.NullableContext(2)]
713+
[System.Runtime.CompilerServices.Nullable(0)]
697714
public partial class Bar
698715
{
699716
public int? AMember { get { throw null; } set { } }
@@ -722,6 +739,7 @@ namespace Foo
722739
{
723740
public static partial class MyExtensions
724741
{
742+
[System.Runtime.CompilerServices.NullableContext(1)]
725743
public static int WordCount(this string str) { throw null; }
726744
}
727745
}
@@ -745,6 +763,7 @@ namespace Foo
745763
{
746764
public partial class Bar
747765
{
766+
[System.Runtime.CompilerServices.NullableContext(1)]
748767
public void Execute(params int[] list) { }
749768
}
750769
}
@@ -912,6 +931,7 @@ public partial interface IAsyncEnumerable<out T>
912931
namespace Foo
913932
{
914933
public delegate void Action<in T>(T obj);
934+
[System.Runtime.CompilerServices.NullableContext(2)]
915935
public partial interface IAsyncEnumerable<out T>
916936
{
917937
}
@@ -939,6 +959,8 @@ public class Bar<T>
939959
expected: """
940960
namespace Foo
941961
{
962+
[System.Runtime.CompilerServices.NullableContext(1)]
963+
[System.Runtime.CompilerServices.Nullable(0)]
942964
public partial class Bar<T>
943965
{
944966
#pragma warning disable CS8597
@@ -976,12 +998,14 @@ namespace Foo
976998
{
977999
public abstract partial class A
9781000
{
1001+
[System.Runtime.CompilerServices.NullableContext(2)]
9791002
public abstract TResult? Accept<TResult>(int a);
9801003
}
9811004
9821005
public sealed partial class B : A
9831006
{
9841007
#pragma warning disable CS8597
1008+
[System.Runtime.CompilerServices.NullableContext(2)]
9851009
public override TResult? Accept<TResult>(int a) where TResult : default { throw null; }
9861010
#pragma warning restore CS8597
9871011
}
@@ -1083,6 +1107,8 @@ public struct Bar<T> where T : notnull
10831107
expected: """
10841108
namespace Foo
10851109
{
1110+
[System.Runtime.CompilerServices.NullableContext(1)]
1111+
[System.Runtime.CompilerServices.Nullable(0)]
10861112
public partial struct Bar<T>
10871113
{
10881114
private System.Collections.Generic.Dictionary<int, System.Collections.Generic.List<T>> _field;
@@ -1115,6 +1141,7 @@ public readonly partial struct Bar<T>
11151141
private readonly System.Collections.Generic.List<Bar<T>> _Baz_k__BackingField;
11161142
private readonly object _dummy;
11171143
private readonly int _dummyPrimitive;
1144+
[Nullable(new[] { 1, 0, 1 })]
11181145
public System.Collections.Generic.List<Bar<T>> Baz { get { throw null; } }
11191146
}
11201147
}
@@ -1295,6 +1322,8 @@ public partial class D : B
12951322
internal D() : base(default) {}
12961323
}
12971324
1325+
[System.Runtime.CompilerServices.NullableContext(1)]
1326+
[System.Runtime.CompilerServices.Nullable(0)]
12981327
public partial class E
12991328
{
13001329
internal E() {}
@@ -1353,6 +1382,8 @@ public partial class D : B
13531382
internal D(int i) : base(default) { }
13541383
}
13551384
1385+
[System.Runtime.CompilerServices.NullableContext(1)]
1386+
[System.Runtime.CompilerServices.Nullable(0)]
13561387
public partial class E
13571388
{
13581389
internal E(P p) { }
@@ -1434,6 +1465,7 @@ public partial class A
14341465
14351466
public partial class B
14361467
{
1468+
[System.Runtime.CompilerServices.NullableContext(1)]
14371469
public B(int p1, string p2, A p3) { }
14381470
}
14391471
@@ -1475,6 +1507,8 @@ public partial class A
14751507
{
14761508
}
14771509
1510+
[System.Runtime.CompilerServices.NullableContext(1)]
1511+
[System.Runtime.CompilerServices.Nullable(0)]
14781512
public partial class B
14791513
{
14801514
public B(int p1, string p2, A p3) { }
@@ -1516,6 +1550,7 @@ public partial class A
15161550
{
15171551
public A(char c) { }
15181552
public A(int i) { }
1553+
[System.Runtime.CompilerServices.NullableContext(1)]
15191554
public A(string s) { }
15201555
}
15211556
@@ -1554,6 +1589,8 @@ public class V { }
15541589
expected: """
15551590
namespace Foo
15561591
{
1592+
[System.Runtime.CompilerServices.NullableContext(1)]
1593+
[System.Runtime.CompilerServices.Nullable(0)]
15571594
public partial class A
15581595
{
15591596
public A(Id id, System.Collections.Generic.IEnumerable<D> deps) { }
@@ -1598,6 +1635,7 @@ namespace Foo
15981635
{
15991636
public partial class B
16001637
{
1638+
[System.Runtime.CompilerServices.NullableContext(1)]
16011639
public B(int p1, string p2) { }
16021640
[System.Obsolete("Constructor is deprecated.", true)]
16031641
public B(int p1) { }
@@ -1635,6 +1673,7 @@ namespace Foo
16351673
{
16361674
public partial class B
16371675
{
1676+
[System.Runtime.CompilerServices.NullableContext(1)]
16381677
public B(int p1, string p2) { }
16391678
[System.Obsolete("Constructor is deprecated.")]
16401679
public B(int p1) { }
@@ -1672,6 +1711,7 @@ namespace Foo
16721711
{
16731712
public partial class B
16741713
{
1714+
[System.Runtime.CompilerServices.NullableContext(1)]
16751715
public B(int p1, string p2) { }
16761716
[System.Obsolete(null)]
16771717
public B(int p1) { }
@@ -2137,6 +2177,7 @@ public class PerLanguageOption : AreEqual<IOption2>, IOption
21372177
expected: """
21382178
namespace A
21392179
{
2180+
[System.Runtime.CompilerServices.NullableContext(1)]
21402181
public partial interface AreEqual<T>
21412182
{
21422183
bool Compare(T other);
@@ -2243,14 +2284,17 @@ public partial class C : IFun, IExplicit, IExplicit2
22432284
public int Foo;
22442285
public int Baz { get { throw null; } }
22452286
public int ExplicitProperty { get { throw null; } }
2287+
[System.Runtime.CompilerServices.Nullable(1)]
22462288
public C this[int i] { get { throw null; } set {} }
2289+
[System.Runtime.CompilerServices.Nullable(1)]
22472290
public event System.EventHandler MyEvent { add {} remove {} }
22482291
void IExplicit.Explicit() {}
22492292
public void Do() {}
22502293
public void Do(float f) {}
22512294
public static void DoStatic() {}
22522295
public void Explicit2() {}
22532296
public void Fun() {}
2297+
[System.Runtime.CompilerServices.NullableContext(2)]
22542298
public void Gen<T>() {}
22552299
public void Zoo() {}
22562300
public partial class MyNestedClass {}
@@ -2264,7 +2308,9 @@ public partial class D : C, IExplicit, IExplicit2
22642308
public new int Foo;
22652309
int IExplicit2.ExplicitProperty { get { throw null; } }
22662310
public new int Baz { get { throw null; } set {} }
2311+
[System.Runtime.CompilerServices.NullableContext(1)]
22672312
public new D this[int i] { get { throw null; } set {} }
2313+
[System.Runtime.CompilerServices.NullableContext(1)]
22682314
public new event System.EventHandler MyEvent { add {} remove {} }
22692315
void IExplicit2.Explicit2() {}
22702316
public new void Do() {}
@@ -2284,6 +2330,7 @@ public partial class E : C, IExplicit, IExplicit2
22842330
public new const int Do = 30;
22852331
int IExplicit2.ExplicitProperty { get { throw null; } }
22862332
public new int Foo { get { throw null; } set {} }
2333+
[System.Runtime.CompilerServices.NullableContext(1)]
22872334
public new event System.EventHandler MyNestedClass { add {} remove {} }
22882335
void IExplicit.Explicit() {}
22892336
void IExplicit2.Explicit2() {}
@@ -2313,6 +2360,8 @@ public void TestAttributeWithInternalTypeArgumentOmitted(bool includeInternalSym
23132360
string expected = includeInternalSymbols ? """
23142361
namespace A
23152362
{
2363+
[System.Runtime.CompilerServices.NullableContext(1)]
2364+
[System.Runtime.CompilerServices.Nullable(0)]
23162365
public partial class AnyTestAttribute : System.Attribute
23172366
{
23182367
public AnyTestAttribute(System.Type xType) { }
@@ -2333,6 +2382,8 @@ public partial class PublicClass
23332382
""" : """
23342383
namespace A
23352384
{
2385+
[System.Runtime.CompilerServices.NullableContext(1)]
2386+
[System.Runtime.CompilerServices.Nullable(0)]
23362387
public partial class AnyTestAttribute : System.Attribute
23372388
{
23382389
public AnyTestAttribute(System.Type xType) { }
@@ -2377,6 +2428,8 @@ public void TestGenericClassImplementsGenericInterface()
23772428
using System;
23782429
namespace A
23792430
{
2431+
[System.Runtime.CompilerServices.NullableContext(1)]
2432+
[System.Runtime.CompilerServices.Nullable(0)]
23802433
public class Foo<T> : System.Collections.ICollection, System.Collections.Generic.ICollection<T>
23812434
{
23822435
int System.Collections.Generic.ICollection<T>.Count => throw new NotImplementedException();

0 commit comments

Comments
 (0)