Skip to content

Commit

Permalink
Update CSharpFileBuilderTests to include the NullableContext
Browse files Browse the repository at this point in the history
.. attributes. Prompted by dotnet/runtime#87857
.
  • Loading branch information
radical committed Jul 7, 2023
1 parent afc401e commit d14fd69
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Tests/Microsoft.DotNet.GenAPI.Tests/CSharpFileBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public interface IPoint
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(1)]
public partial interface IPoint
{
// Property signatures:
Expand Down Expand Up @@ -344,10 +345,16 @@ public class Node5<T, U> : BaseNodeMultiple<T, U> { }
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(2)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class BaseNodeMultiple <T, U> { }

[System.Runtime.CompilerServices.NullableContext(2)]
[Nullable(new[] { 0, 1 })]
public partial class Node4 <T> : BaseNodeMultiple<T, int> { }

[System.Runtime.CompilerServices.NullableContext(2)]
[Nullable(new[] { 0, 1, 1 })]
public partial class Node5 <T, U> : BaseNodeMultiple<T, U> { }
}
""");
Expand Down Expand Up @@ -463,11 +470,15 @@ public event System.EventHandler<string> OnNewMessage { add { } remove { } }
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract partial class AbstractEvents
{
public abstract event System.EventHandler<bool> TextChanged;
}

[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class Events
{
public event System.EventHandler<string> OnNewMessage { add { } remove { } }
Expand Down Expand Up @@ -611,9 +622,13 @@ public class Car : System.IEquatable<Car>
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class Car : System.IEquatable<Car>
{
[System.Runtime.CompilerServices.NullableContext(2)]
public bool Equals(Car? c) { throw null; }
[System.Runtime.CompilerServices.NullableContext(2)]
public override bool Equals(object? o) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(Car lhs, Car rhs) { throw null; }
Expand Down Expand Up @@ -694,6 +709,8 @@ public class Bar
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(2)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class Bar
{
public int? AMember { get { throw null; } set { } }
Expand Down Expand Up @@ -722,6 +739,7 @@ namespace Foo
{
public static partial class MyExtensions
{
[System.Runtime.CompilerServices.NullableContext(1)]
public static int WordCount(this string str) { throw null; }
}
}
Expand All @@ -745,6 +763,7 @@ namespace Foo
{
public partial class Bar
{
[System.Runtime.CompilerServices.NullableContext(1)]
public void Execute(params int[] list) { }
}
}
Expand Down Expand Up @@ -912,6 +931,7 @@ public partial interface IAsyncEnumerable<out T>
namespace Foo
{
public delegate void Action<in T>(T obj);
[System.Runtime.CompilerServices.NullableContext(2)]
public partial interface IAsyncEnumerable<out T>
{
}
Expand Down Expand Up @@ -939,6 +959,8 @@ public class Bar<T>
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class Bar<T>
{
#pragma warning disable CS8597
Expand Down Expand Up @@ -976,12 +998,14 @@ namespace Foo
{
public abstract partial class A
{
[System.Runtime.CompilerServices.NullableContext(2)]
public abstract TResult? Accept<TResult>(int a);
}

public sealed partial class B : A
{
#pragma warning disable CS8597
[System.Runtime.CompilerServices.NullableContext(2)]
public override TResult? Accept<TResult>(int a) where TResult : default { throw null; }
#pragma warning restore CS8597
}
Expand Down Expand Up @@ -1083,6 +1107,8 @@ public struct Bar<T> where T : notnull
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial struct Bar<T>
{
private System.Collections.Generic.Dictionary<int, System.Collections.Generic.List<T>> _field;
Expand Down Expand Up @@ -1115,6 +1141,7 @@ public readonly partial struct Bar<T>
private readonly System.Collections.Generic.List<Bar<T>> _Baz_k__BackingField;
private readonly object _dummy;
private readonly int _dummyPrimitive;
[Nullable(new[] { 1, 0, 1 })]
public System.Collections.Generic.List<Bar<T>> Baz { get { throw null; } }
}
}
Expand Down Expand Up @@ -1295,6 +1322,8 @@ public partial class D : B
internal D() : base(default) {}
}

[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class E
{
internal E() {}
Expand Down Expand Up @@ -1353,6 +1382,8 @@ public partial class D : B
internal D(int i) : base(default) { }
}

[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class E
{
internal E(P p) { }
Expand Down Expand Up @@ -1434,6 +1465,7 @@ public partial class A

public partial class B
{
[System.Runtime.CompilerServices.NullableContext(1)]
public B(int p1, string p2, A p3) { }
}

Expand Down Expand Up @@ -1475,6 +1507,8 @@ public partial class A
{
}

[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class B
{
public B(int p1, string p2, A p3) { }
Expand Down Expand Up @@ -1516,6 +1550,7 @@ public partial class A
{
public A(char c) { }
public A(int i) { }
[System.Runtime.CompilerServices.NullableContext(1)]
public A(string s) { }
}

Expand Down Expand Up @@ -1554,6 +1589,8 @@ public class V { }
expected: """
namespace Foo
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class A
{
public A(Id id, System.Collections.Generic.IEnumerable<D> deps) { }
Expand Down Expand Up @@ -1598,6 +1635,7 @@ namespace Foo
{
public partial class B
{
[System.Runtime.CompilerServices.NullableContext(1)]
public B(int p1, string p2) { }
[System.Obsolete("Constructor is deprecated.", true)]
public B(int p1) { }
Expand Down Expand Up @@ -1635,6 +1673,7 @@ namespace Foo
{
public partial class B
{
[System.Runtime.CompilerServices.NullableContext(1)]
public B(int p1, string p2) { }
[System.Obsolete("Constructor is deprecated.")]
public B(int p1) { }
Expand Down Expand Up @@ -1672,6 +1711,7 @@ namespace Foo
{
public partial class B
{
[System.Runtime.CompilerServices.NullableContext(1)]
public B(int p1, string p2) { }
[System.Obsolete(null)]
public B(int p1) { }
Expand Down Expand Up @@ -2137,6 +2177,7 @@ public class PerLanguageOption : AreEqual<IOption2>, IOption
expected: """
namespace A
{
[System.Runtime.CompilerServices.NullableContext(1)]
public partial interface AreEqual<T>
{
bool Compare(T other);
Expand Down Expand Up @@ -2243,14 +2284,17 @@ public partial class C : IFun, IExplicit, IExplicit2
public int Foo;
public int Baz { get { throw null; } }
public int ExplicitProperty { get { throw null; } }
[System.Runtime.CompilerServices.Nullable(1)]
public C this[int i] { get { throw null; } set {} }
[System.Runtime.CompilerServices.Nullable(1)]
public event System.EventHandler MyEvent { add {} remove {} }
void IExplicit.Explicit() {}
public void Do() {}
public void Do(float f) {}
public static void DoStatic() {}
public void Explicit2() {}
public void Fun() {}
[System.Runtime.CompilerServices.NullableContext(2)]
public void Gen<T>() {}
public void Zoo() {}
public partial class MyNestedClass {}
Expand All @@ -2264,7 +2308,9 @@ public partial class D : C, IExplicit, IExplicit2
public new int Foo;
int IExplicit2.ExplicitProperty { get { throw null; } }
public new int Baz { get { throw null; } set {} }
[System.Runtime.CompilerServices.NullableContext(1)]
public new D this[int i] { get { throw null; } set {} }
[System.Runtime.CompilerServices.NullableContext(1)]
public new event System.EventHandler MyEvent { add {} remove {} }
void IExplicit2.Explicit2() {}
public new void Do() {}
Expand All @@ -2284,6 +2330,7 @@ public partial class E : C, IExplicit, IExplicit2
public new const int Do = 30;
int IExplicit2.ExplicitProperty { get { throw null; } }
public new int Foo { get { throw null; } set {} }
[System.Runtime.CompilerServices.NullableContext(1)]
public new event System.EventHandler MyNestedClass { add {} remove {} }
void IExplicit.Explicit() {}
void IExplicit2.Explicit2() {}
Expand Down Expand Up @@ -2313,6 +2360,8 @@ public void TestAttributeWithInternalTypeArgumentOmitted(bool includeInternalSym
string expected = includeInternalSymbols ? """
namespace A
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class AnyTestAttribute : System.Attribute
{
public AnyTestAttribute(System.Type xType) { }
Expand All @@ -2333,6 +2382,8 @@ public partial class PublicClass
""" : """
namespace A
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public partial class AnyTestAttribute : System.Attribute
{
public AnyTestAttribute(System.Type xType) { }
Expand Down Expand Up @@ -2377,6 +2428,8 @@ public void TestGenericClassImplementsGenericInterface()
using System;
namespace A
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class Foo<T> : System.Collections.ICollection, System.Collections.Generic.ICollection<T>
{
int System.Collections.Generic.ICollection<T>.Count => throw new NotImplementedException();
Expand Down

0 comments on commit d14fd69

Please sign in to comment.