Skip to content

Commit

Permalink
Remove duplicated tests from System.Text.Json.Tests (#36483)
Browse files Browse the repository at this point in the history
  • Loading branch information
jozkee authored May 19, 2020
1 parent 8064936 commit 28e7864
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
3 changes: 0 additions & 3 deletions src/libraries/System.Text.Json/tests/JsonDateTimeTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static IEnumerable<object[]> ValidISO8601Tests()
yield return new object[] { "\"1997-07-16T19:20:30.6666660\"", "1997-07-16T19:20:30.666666" };

// Test fraction truncation.
yield return new object[] { "\"1997-07-16T19:20:30.0000000\"", "1997-07-16T19:20:30" };
yield return new object[] { "\"1997-07-16T19:20:30.00000001\"", "1997-07-16T19:20:30" };
yield return new object[] { "\"1997-07-16T19:20:30.000000001\"", "1997-07-16T19:20:30" };
yield return new object[] { "\"1997-07-16T19:20:30.77777770\"", "1997-07-16T19:20:30.7777777" };
Expand Down Expand Up @@ -153,7 +152,6 @@ public static IEnumerable<object[]> InvalidISO8601Tests()
// Invalid fractions.
yield return new object[] { "\"1997-07-16T19.45\"" };
yield return new object[] { "\"1997-07-16T19:20.45\"" };
yield return new object[] { "\"1997-07-16T19:20:30a\"" };
yield return new object[] { "\"1997-07-16T19:20:30,45\"" };
yield return new object[] { "\"1997-07-16T19:20:30.\"" };
yield return new object[] { "\"1997-07-16T19:20:30.a\"" };
Expand All @@ -168,7 +166,6 @@ public static IEnumerable<object[]> InvalidISO8601Tests()
yield return new object[] { "\"1997-07-16T19:20:30.4555555+01Z\"" };
yield return new object[] { "\"1997-07-16T19:20:30.4555555+01:\"" };
yield return new object[] { "\"1997-07-16T19:20:30.4555555 +01:00\"" };
yield return new object[] { "\"1997-07-16T19:20:30.4555555+01:\"" };
yield return new object[] { "\"1997-07-16T19:20:30.4555555- 01:00\"" };
yield return new object[] { "\"1997-07-16T19:20:30.4555555+04 :30\"" };
yield return new object[] { "\"1997-07-16T19:20:30.4555555-04: 30\"" };
Expand Down
55 changes: 30 additions & 25 deletions src/libraries/System.Text.Json/tests/JsonGuidTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,40 @@ public static IEnumerable<object[]> ValidHexGuidTests()

public static IEnumerable<object[]> InvalidGuidTests()
{
// Invalid formats
Guid testGuid = new Guid(s_guidStr);
yield return new object[] { testGuid.ToString("B", CultureInfo.InvariantCulture) };
yield return new object[] { testGuid.ToString("P", CultureInfo.InvariantCulture) };
yield return new object[] { testGuid.ToString("N", CultureInfo.InvariantCulture) };

yield return new object[] { new string('$', 1) };
yield return new object[] { new string(' ', 1) };
yield return new object[] { new string('$', s_guidStr.Length) };
yield return new object[] { new string(' ', s_guidStr.Length) };

for (int truncationPoint = 1; truncationPoint < s_guidStr.Length - 1; truncationPoint++)
{
string truncatedText = s_guidStr.Substring(0, truncationPoint);

// Stop short
yield return new object[] { truncatedText };

// Append junk
yield return new object[] { truncatedText.PadRight(s_guidStr.Length, '$') };
yield return new object[] { truncatedText.PadRight(s_guidStr.Length, ' ') };
yield return new object[] { truncatedText.PadRight(truncatedText.Length + 1, '$') };
yield return new object[] { truncatedText.PadRight(truncatedText.Length + 1, ' ') };
// Prepend junk
yield return new object[] { truncatedText.PadLeft(s_guidStr.Length, '$') };
yield return new object[] { truncatedText.PadLeft(s_guidStr.Length, ' ') };
yield return new object[] { truncatedText.PadLeft(truncatedText.Length + 1, '$') };
yield return new object[] { truncatedText.PadLeft(truncatedText.Length + 1, ' ') };
}

foreach (object[] guid in ValidGuidTests())
{
string guidStr = (string)guid[0];

// Invalid formats
Guid testGuid = new Guid(guidStr);
yield return new object[] { testGuid.ToString("B", CultureInfo.InvariantCulture) };
yield return new object[] { testGuid.ToString("P", CultureInfo.InvariantCulture) };
yield return new object[] { testGuid.ToString("N", CultureInfo.InvariantCulture) };

for (int i = 0; i < guidStr.Length; i++)
{
// Corrupt one character
Expand Down Expand Up @@ -72,25 +96,6 @@ public static IEnumerable<object[]> InvalidGuidTests()
}
}

for (int truncationPoint = 0; truncationPoint < guidStr.Length; truncationPoint++)
{
string truncatedText = guidStr.Substring(0, truncationPoint);

// Stop short
yield return new object[] { truncatedText };

// Append junk
yield return new object[] { truncatedText.PadRight(guidStr.Length, '$') };
yield return new object[] { truncatedText.PadRight(guidStr.Length, ' ') };
yield return new object[] { truncatedText.PadRight(truncatedText.Length + 1, '$') };
yield return new object[] { truncatedText.PadRight(truncatedText.Length + 1, ' ') };
// Prepend junk
yield return new object[] { truncatedText.PadLeft(guidStr.Length, '$') };
yield return new object[] { truncatedText.PadLeft(guidStr.Length, ' ') };
yield return new object[] { truncatedText.PadLeft(truncatedText.Length + 1, '$') };
yield return new object[] { truncatedText.PadLeft(truncatedText.Length + 1, ' ') };
}

// Too long
yield return new object[] { $"{guidStr} " };
yield return new object[] { $"{guidStr}$" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4380,7 +4380,6 @@ public static IEnumerable<object[]> InvalidJsonStrings
new object[] {"+0", 0, 0},
new object[] {"+1", 0, 0},
new object[] {"0e", 0, 2},
new object[] {"0.", 0, 2},
new object[] {"0.1e", 0, 4},
new object[] {"01", 0, 1},
new object[] {"1a", 0, 1},
Expand Down

0 comments on commit 28e7864

Please sign in to comment.