-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Enable xUnit analyzer for System.Memory.Tests project
#38701
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,11 @@ public partial class StringTests | |
| private const string SoftHyphen = "\u00AD"; | ||
| private static readonly char[] s_whiteSpaceCharacters = { '\u0009', '\u000a', '\u000b', '\u000c', '\u000d', '\u0020', '\u0085', '\u00a0', '\u1680' }; | ||
|
|
||
| #pragma warning disable xUnit2009 // Do not use Assert.True/False to check for Substrings | ||
| // This warning is irrelevant for the majority of this test, since we want to test the functionality of the methods themselves, | ||
| // rather than checking for substrings. If we enable the warning, we have to depend on the assertion methods calling these methods | ||
| // internally, which is not ideal. | ||
|
|
||
| [Theory] | ||
| [InlineData(new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '\0' }, "abcdefgh")] | ||
| [InlineData(new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '\0', 'i', 'j' }, "abcdefgh")] | ||
|
|
@@ -78,7 +83,9 @@ public static unsafe void Ctor_CharPtr_OddAddressShouldStillWork() | |
| [InlineData(new char[] { '\0' }, 0, 1, "\0")] | ||
| [InlineData(new char[] { 'a', 'b', 'c' }, 0, 0, "")] | ||
| [InlineData(new char[] { 'a', 'b', 'c' }, 1, 0, "")] | ||
| #pragma warning disable xUnit1026 // Unused parameter | ||
| public static unsafe void Ctor_CharPtr_Int_Int(char[] valueArray, int startIndex, int length, string expected) | ||
| #pragma warning restore xUnit1026 // Unused parameter | ||
| { | ||
| fixed (char* value = valueArray) | ||
| { | ||
|
|
@@ -549,9 +556,7 @@ public static void CopyTo_Invalid() | |
| [InlineData("HELLO", 2, "hello", 2, 3, StringComparison.Ordinal, -1)] | ||
| [InlineData("Hello", 2, "Goodbye", 2, 3, StringComparison.Ordinal, -1)] | ||
| [InlineData("Hello", 0, "Hello", 0, 0, StringComparison.Ordinal, 0)] | ||
| [InlineData("Hello", 0, "Hello", 0, 5, StringComparison.Ordinal, 0)] | ||
| [InlineData("Hello", 0, "Hello", 0, 3, StringComparison.Ordinal, 0)] | ||
| [InlineData("Hello", 2, "Hello", 2, 3, StringComparison.Ordinal, 0)] | ||
| [InlineData("Hello", 0, "He" + SoftHyphen + "llo", 0, 5, StringComparison.Ordinal, -1)] | ||
| [InlineData("Hello", 0, "-=<Hello>=-", 3, 5, StringComparison.Ordinal, 0)] | ||
| [InlineData("\uD83D\uDD53Hello\uD83D\uDD50", 1, "\uD83D\uDD53Hello\uD83D\uDD54", 1, 7, StringComparison.Ordinal, 0)] // Surrogate split | ||
|
|
@@ -982,7 +987,7 @@ public static void CompareToNoMatch_StringComparison() | |
|
|
||
| string s1 = new string(first); | ||
| string s2 = new string(second); | ||
| Assert.True(0 > string.Compare(s1, s2, StringComparison.Ordinal)); | ||
| Assert.True(0 > string.Compare(s1, s2, StringComparison.Ordinal)); | ||
|
|
||
| var firstSpan = new ReadOnlySpan<char>(first); | ||
| var secondSpan = new ReadOnlySpan<char>(second); | ||
|
|
@@ -1208,7 +1213,7 @@ public static void ContainsMatch_StringComparison() | |
| Assert.True(s1.Contains(s2)); | ||
|
|
||
| ReadOnlySpan<char> span = value.AsSpan(0, 3); | ||
| ReadOnlySpan<char> slice = value.AsSpan(0 ,2); | ||
| ReadOnlySpan<char> slice = value.AsSpan(0, 2); | ||
| Assert.True(span.Contains(slice, StringComparison.Ordinal)); | ||
|
|
||
| Assert.True(span.Contains(slice, StringComparison.CurrentCulture)); | ||
|
|
@@ -1796,7 +1801,7 @@ public static void SameSpanEndsWith_Char() | |
| [Fact] | ||
| public static void LengthMismatchEndsWith_Char() | ||
| { | ||
| string value = "456";; | ||
| string value = "456"; | ||
|
|
||
| string s1 = value.Substring(0, 2); | ||
| string s2 = value.Substring(0, 3); | ||
|
|
@@ -1837,7 +1842,7 @@ public static void EndsWithMatchDifferentSpans_Char() | |
| Assert.True(c); | ||
|
|
||
| ReadOnlySpan<char> span = value1.AsSpan(0, 3); | ||
| ReadOnlySpan<char> slice = value2.AsSpan(0 ,3); | ||
| ReadOnlySpan<char> slice = value2.AsSpan(0, 3); | ||
| c = span.EndsWith(slice); | ||
| Assert.True(c); | ||
| } | ||
|
|
@@ -1982,7 +1987,7 @@ public static void LengthMismatchEndsWith_StringComparison() | |
| Assert.False(s1.EndsWith(s2, StringComparison.InvariantCultureIgnoreCase)); | ||
| Assert.False(s1.EndsWith(s2, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| ReadOnlySpan<char> span = value.AsSpan(0 ,2); | ||
| ReadOnlySpan<char> span = value.AsSpan(0, 2); | ||
| ReadOnlySpan<char> slice = value.AsSpan(0, 3); | ||
| Assert.False(span.EndsWith(slice, StringComparison.Ordinal)); | ||
|
|
||
|
|
@@ -2009,7 +2014,7 @@ public static void EndsWithMatch_StringComparison() | |
| Assert.True(s1.EndsWith(s2, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| ReadOnlySpan<char> span = value.AsSpan(0, 3); | ||
| ReadOnlySpan<char> slice = value.AsSpan(1 ,2); | ||
| ReadOnlySpan<char> slice = value.AsSpan(1, 2); | ||
| Assert.True(span.EndsWith(slice, StringComparison.Ordinal)); | ||
|
|
||
| Assert.True(span.EndsWith(slice, StringComparison.CurrentCulture)); | ||
|
|
@@ -2494,7 +2499,7 @@ public static void GetHashCode_EmbeddedNull_ReturnsDifferentHashCodes() | |
| [InlineData("", "", StringComparison.OrdinalIgnoreCase, true)] | ||
| [InlineData("123", 123, StringComparison.OrdinalIgnoreCase, false)] // Not a string | ||
| [InlineData("\0AAAAAAAAA", "\0BBBBBBBBBBBB", StringComparison.OrdinalIgnoreCase, false)] | ||
| public static void Equals(string s1, object obj, StringComparison comparisonType, bool expected) | ||
| public static void Equals_Test(string s1, object obj, StringComparison comparisonType, bool expected) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the name of this purely because the analyser complained that this becomes an overload of |
||
| { | ||
| string s2 = obj as string; | ||
| if (s1 != null) | ||
|
|
@@ -2622,6 +2627,7 @@ public static void Format_Invalid() | |
| Assert.Throws<FormatException>(() => string.Format(formatter, "{-1}", obj1, obj2, obj3, obj4)); | ||
|
|
||
| // Format has out of range value | ||
| #pragma warning disable IDE0043 // Format string contains invalid placeholder | ||
| Assert.Throws<FormatException>(() => string.Format("{1}", obj1)); | ||
| Assert.Throws<FormatException>(() => string.Format("{2}", obj1, obj2)); | ||
| Assert.Throws<FormatException>(() => string.Format("{3}", obj1, obj2, obj3)); | ||
|
|
@@ -2630,6 +2636,7 @@ public static void Format_Invalid() | |
| Assert.Throws<FormatException>(() => string.Format(formatter, "{2}", obj1, obj2)); | ||
| Assert.Throws<FormatException>(() => string.Format(formatter, "{3}", obj1, obj2, obj3)); | ||
| Assert.Throws<FormatException>(() => string.Format(formatter, "{4}", obj1, obj2, obj3, obj4)); | ||
| #pragma warning restore IDE0043 // Format string contains invalid placeholder | ||
| } | ||
|
|
||
| [Theory] | ||
|
|
@@ -2642,8 +2649,6 @@ public static void Format_Invalid() | |
| [InlineData("Hello", 'l', 3, 0, -1)] | ||
| [InlineData("Hello", 'l', 0, 2, -1)] | ||
| [InlineData("Hello", 'l', 0, 3, 2)] | ||
| [InlineData("Hello", 'l', 4, 1, -1)] | ||
| [InlineData("Hello", 'x', 1, 4, -1)] | ||
| [InlineData("Hello", 'o', 5, 0, -1)] | ||
| [InlineData("H" + SoftHyphen + "ello", 'e', 0, 3, 2)] | ||
| // For some reason, this is failing on *nix with ordinal comparisons. | ||
|
|
@@ -3841,13 +3846,9 @@ public static void Join_ObjectArray_Null_ThrowsArgumentNullException() | |
| [InlineData("Hello", 'l', 1, 2, -1)] | ||
| [InlineData("Hello", 'l', 0, 1, -1)] | ||
| [InlineData("Hello", 'x', 3, 4, -1)] | ||
| [InlineData("Hello", 'l', 3, 4, 3)] | ||
| [InlineData("Hello", 'l', 1, 2, -1)] | ||
| [InlineData("Hello", 'l', 1, 0, -1)] | ||
| [InlineData("Hello", 'l', 4, 2, 3)] | ||
| [InlineData("Hello", 'l', 4, 3, 3)] | ||
| [InlineData("Hello", 'l', 0, 1, -1)] | ||
| [InlineData("Hello", 'x', 3, 4, -1)] | ||
| [InlineData("H" + SoftHyphen + "ello", 'H', 2, 3, 0)] | ||
| [InlineData("", 'H', 0, 0, -1)] | ||
| public static void LastIndexOf_SingleLetter(string s, char value, int startIndex, int count, int expected) | ||
|
|
@@ -5242,7 +5243,7 @@ public static void LengthMismatchToLower() | |
| } | ||
|
|
||
| [Fact] | ||
| public static void ToLower() | ||
| public static void ToLower_Span() | ||
| { | ||
| var expectedSource = new char[3] { 'a', 'B', 'c' }; | ||
| var expectedDestination = new char[3] { 'a', 'b', 'c' }; | ||
|
|
@@ -5448,7 +5449,7 @@ public static void LengthMismatchToUpper() | |
| } | ||
|
|
||
| [Fact] | ||
| public static void ToUpper() | ||
| public static void ToUpper_Span() | ||
| { | ||
| var expectedSource = new char[3] { 'a', 'B', 'c' }; | ||
| var expectedDestination = new char[3] { 'A', 'B', 'C' }; | ||
|
|
@@ -5558,7 +5559,7 @@ public static void Test_ToUpper_Culture(string actual, string expected, CultureI | |
| [Theory] | ||
| [InlineData("")] | ||
| [InlineData("hello")] | ||
| public static void ToString(string s) | ||
| public static void ToString_Test(string s) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed because it creates an overload of |
||
| { | ||
| Assert.Same(s, s.ToString()); | ||
| Assert.Same(s, s.ToString(null)); | ||
|
|
@@ -7203,17 +7204,17 @@ public static unsafe void Ctor_SByte_InvalidArguments() | |
| [Fact] | ||
| public static unsafe void Ctor_SByte_NullPointer_ReturnsEmptyString() | ||
| { | ||
| Assert.Equal(string.Empty, new string((sbyte*) null)); | ||
| Assert.Equal(string.Empty, new string((sbyte*)null)); | ||
|
|
||
| Assert.Equal(string.Empty, new string((char*) null, 0, 0)); | ||
| Assert.Equal(string.Empty, new string((char*)null, 0, 0)); | ||
|
|
||
| Assert.Equal(string.Empty, new string((sbyte*) null, 0, 0)); | ||
| Assert.Equal(string.Empty, new string((sbyte*)null, 0, 0)); | ||
|
|
||
| Assert.Equal(string.Empty, new string((sbyte*) null, 0, 0, Encoding.Default)); | ||
| Assert.Equal(string.Empty, new string((sbyte*) null, 1, 0, Encoding.Default)); | ||
| Assert.Equal(string.Empty, new string((sbyte*)null, 0, 0, Encoding.Default)); | ||
| Assert.Equal(string.Empty, new string((sbyte*)null, 1, 0, Encoding.Default)); | ||
|
|
||
| Assert.Equal(string.Empty, new string((sbyte*) null, 0, 0, null)); | ||
| Assert.Equal(string.Empty, new string((sbyte*) null, 1, 0, null)); | ||
| Assert.Equal(string.Empty, new string((sbyte*)null, 0, 0, null)); | ||
| Assert.Equal(string.Empty, new string((sbyte*)null, 1, 0, null)); | ||
| } | ||
|
|
||
| [Fact] | ||
|
|
@@ -7232,7 +7233,7 @@ private sealed class AsciiEncodingWithZeroReturningGetCharCount : ASCIIEncoding | |
| public static unsafe void CloneTest() | ||
| { | ||
| string s = "some string to clone"; | ||
| string cloned = (string) s.Clone(); | ||
| string cloned = (string)s.Clone(); | ||
| Assert.Equal(s, cloned); | ||
| Assert.True(object.ReferenceEquals(s, cloned), "cloned object should return same instance of the string"); | ||
| } | ||
|
|
@@ -7293,7 +7294,7 @@ public static void InternalTestAotSubset() | |
| // U+0301 COMBINING ACUTE ACCENT | ||
| // U+0327 COMBINING CEDILLA | ||
| // U+00BE VULGAR FRACTION THREE QUARTERS | ||
| string s = new string( new char[] {'\u0063', '\u0301', '\u0327', '\u00BE'}); | ||
| string s = new string(new char[] { '\u0063', '\u0301', '\u0327', '\u00BE' }); | ||
|
|
||
| Assert.False(s.IsNormalized(), "String should be not normalized when checking with the default which same as FormC"); | ||
| Assert.False(s.IsNormalized(NormalizationForm.FormC), "String should be not normalized when checking with FormC"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,9 @@ public static void MemoryExtensions_Trim_Single(int[] values, int trim, int[] ex | |
| [InlineData(new int[0], new int[0], new int[0])] | ||
| [InlineData(new int[0], new int[] { 1 }, new int[0])] | ||
| [InlineData(new int[] { 1 }, new int[0], new int[] { 1 })] | ||
| #pragma warning disable xUnit1025 // InlineData duplicates | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like an analyser bug unless I can't see properly.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rest of the same suppressions are for the same reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 I didn't see a duplicate of this; consider filing an issue
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing issue, left a comment there: xunit/xunit#1877 |
||
| [InlineData(new int[] { 1 }, new int[] { 1 }, new int[0])] | ||
| #pragma warning restore xUnit1025 // InlineData duplicates | ||
| [InlineData(new int[] { 2 }, new int[] { 1 }, new int[] { 2 })] | ||
| [InlineData(new int[] { 1, 2, 1 }, new int[] { 1 }, new int[] { 2, 1 })] | ||
| [InlineData(new int[] { 1, 1, 2, 1 }, new int[] { 1 }, new int[] { 2, 1 })] | ||
|
|
@@ -120,7 +122,9 @@ public static void MemoryExtensions_TrimStart_Multi(int[] values, int[] trims, i | |
| [InlineData(new int[0], new int[0], new int[0])] | ||
| [InlineData(new int[0], new int[] { 1 }, new int[0])] | ||
| [InlineData(new int[] { 1 }, new int[0], new int[] { 1 })] | ||
| #pragma warning disable xUnit1025 // InlineData duplicates | ||
| [InlineData(new int[] { 1 }, new int[] { 1 }, new int[0])] | ||
| #pragma warning restore xUnit1025 // InlineData duplicates | ||
| [InlineData(new int[] { 2 }, new int[] { 1 }, new int[] { 2 })] | ||
| [InlineData(new int[] { 1, 2, 1 }, new int[] { 1 }, new int[] { 1, 2 })] | ||
| [InlineData(new int[] { 1, 2, 1, 1 }, new int[] { 1 }, new int[] { 1, 2 })] | ||
|
|
@@ -150,13 +154,17 @@ public static void MemoryExtensions_TrimEnd_Multi(int[] values, int[] trims, int | |
| [InlineData(new int[0], new int[0], new int[0])] | ||
| [InlineData(new int[0], new int[] { 1 }, new int[0])] | ||
| [InlineData(new int[] { 1 }, new int[0], new int[] { 1 })] | ||
| #pragma warning disable xUnit1025 // InlineData duplicates | ||
| [InlineData(new int[] { 1 }, new int[] { 1 }, new int[0])] | ||
| #pragma warning restore xUnit1025 // InlineData duplicates | ||
| [InlineData(new int[] { 2 }, new int[] { 1 }, new int[] { 2 })] | ||
| [InlineData(new int[] { 1, 2, 1 }, new int[] { 1 }, new int[] { 2 })] | ||
| [InlineData(new int[] { 1, 2, 1, 1 }, new int[] { 1 }, new int[] { 2 })] | ||
| [InlineData(new int[] { 1, 2, 1, 1 }, new int[] { 2 }, new int[] { 1, 2, 1, 1 })] | ||
| [InlineData(new int[] { 1, 2, 1, 1 }, new int[] { 3 }, new int[] { 1, 2, 1, 1 })] | ||
| #pragma warning disable xUnit1025 // InlineData duplicates | ||
| [InlineData(new int[] { 1, 2, 1, 1 }, new int[] { 1, 2 }, new int[0])] | ||
| #pragma warning restore xUnit1025 // InlineData duplicates | ||
| [InlineData(new int[] { 2, 1, 3, 2, 1, 1 }, new int[] { 1, 2 }, new int[] { 3 })] | ||
| [InlineData(new int[] { 2, 1, 3, 2, 1, 1 }, new int[] { 1, 2, 4 }, new int[] { 3 })] | ||
| [InlineData(new int[] { 1, 2, 1, 1, 1 }, new int[] { 1 }, new int[] { 2 })] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a bug in the analyser. Suppressed for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see a bug report for this; consider filing it at https://github.com/xunit/xunit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xunit/xunit#1969