Skip to content

Commit

Permalink
test: ensure error if source type is any signed integer with negative…
Browse files Browse the repository at this point in the history
… value and destination type is unsigned integer
  • Loading branch information
NormanFrieman committed Oct 17, 2024
1 parent 968b952 commit 8a4e23d
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1039,16 +1039,16 @@ public void TestMethod<T>(T[] a) { }
}

[Theory]
[MemberData(nameof(UnsignedInt))]
public async Task FromNegativeInt_ToUnsignedInt(string unsignedType)
[MemberData(nameof(SignedIntAndUnsignedInt))]
public async Task FromNegativeInteger_ToUnsignedInteger(string signedType, string unsignedType)
{
var source = string.Format(/* lang=c#-test */ """
public class TestClass {{
[Xunit.Theory]
[Xunit.InlineData({{|#0:-1|}})]
public void TestMethod({0} value) {{ }}
[Xunit.InlineData({{|#0:({0})-1|}})]
public void TestMethod({1} value) {{ }}
}}
""", unsignedType);
""", signedType, unsignedType);
var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("value", unsignedType);

await Verify.VerifyAnalyzer(source, expected);
Expand Down Expand Up @@ -1269,7 +1269,11 @@ public class Explicit {
public static TheoryData<string> ValueTypedValues =
new(((IEnumerable<string>)IntegerValues).Concat(FloatingPointValues).Concat(BoolValues).Append("typeof(int)"));

public static readonly TheoryData<string> UnsignedInt = ["uint", "ulong", "ushort", "byte"];
public static readonly TheoryData<string> SignedInteger = ["int", "long", "short", "sbyte"];

public static readonly TheoryData<string> UnsignedInteger = ["uint", "ulong", "ushort", "byte"];

public static readonly MatrixTheoryData<string, string> SignedIntAndUnsignedInt = new(SignedInteger, UnsignedInteger);
}

public class X1011_ExtraValue
Expand Down

0 comments on commit 8a4e23d

Please sign in to comment.