-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Improve code coverage for System.Text.Json with targeted unit tests #120731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
24
commits into
main
Choose a base branch
from
copilot/maximize-code-coverage-json
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
48609a2
Initial plan
Copilot edead34
Improve code coverage for System.Text.Json with targeted unit tests
Copilot ea52bce
Mark DeepEquals_TooDeepJsonDocument test as OuterLoop
Copilot eace0c3
Add tests for SerializeToDocument/Element/Node with JsonTypeInfo and …
Copilot 6aa1f88
Add tests for null value scenarios with JsonTypeInfo
Copilot 24dc39a
Fix tests to use DefaultJsonTypeInfoResolver
Copilot 40a1e92
Add 15 more tests for JsonSerializer Deserialize/Serialize methods wi…
Copilot 0b52f02
Add 13 tests using JsonSerializerContext for various Serialize/Deseri…
Copilot f91acf7
Add async PipeWriter tests and numeric edge case tests for Utf8JsonRe…
Copilot 563cffa
Add 8 validation and edge case tests for JsonWriter and JsonNode
Copilot 7f36446
Add 4 tests for PreferredObjectCreationHandling and JsonElement Get m…
Copilot 14b20a5
Add 8 tests for JsonArray Clear, Utf8JsonWriter minimized formatting,…
Copilot 54d0c37
Add 8 tests for JsonValue Create methods and Utf8JsonWriter minimized…
Copilot f72a942
Add 6 tests for TypeInfoResolverChain and immutable collections (Stac…
Copilot 349f455
Add 6 tests for JsonValue with JsonTypeInfo, JsonElement Try methods,…
Copilot 84d5129
Add 6 tests for Utf8JsonWriter indented formatting and JsonDocument P…
Copilot e17b78e
Add 6 tests for JsonNode operations and JsonSerializerOptions propert…
Copilot 2e10b10
Add 9 multi-segment Utf8JsonReader tests for complex edge cases
Copilot f0a2ce7
Fix OutOfMemoryException in extremely long string validation tests
Copilot d274260
Add 30 JsonNamingPolicy tests covering all naming policy variants
Copilot 31fddfe
Convert JSON string literals to raw string literals
Copilot 3e625d8
Use JsonSerializerOptions.Default instead of creating new instances t…
Copilot dc39876
Revert line 613 to use options variable instead of JsonSerializerOpti…
Copilot a0641ea
Convert remaining JSON strings to raw string literals in DomTests.cs
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonNamingPolicyTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
|
||
namespace System.Text.Json.Tests | ||
{ | ||
public static class JsonNamingPolicyTests | ||
{ | ||
[Theory] | ||
[InlineData("MyProperty", "myProperty")] | ||
[InlineData("PropertyName", "propertyName")] | ||
[InlineData("ABC", "aBC")] | ||
[InlineData("A", "a")] | ||
[InlineData("", "")] | ||
public static void CamelCase_ConvertName(string input, string expected) | ||
{ | ||
string result = JsonNamingPolicy.CamelCase.ConvertName(input); | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("MyProperty", "my_property")] | ||
[InlineData("PropertyName", "property_name")] | ||
[InlineData("ABC", "a_b_c")] | ||
[InlineData("HTMLParser", "h_t_m_l_parser")] | ||
[InlineData("A", "a")] | ||
[InlineData("", "")] | ||
public static void SnakeCaseLower_ConvertName(string input, string expected) | ||
{ | ||
string result = JsonNamingPolicy.SnakeCaseLower.ConvertName(input); | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("MyProperty", "MY_PROPERTY")] | ||
[InlineData("PropertyName", "PROPERTY_NAME")] | ||
[InlineData("ABC", "A_B_C")] | ||
[InlineData("HTMLParser", "H_T_M_L_PARSER")] | ||
[InlineData("A", "A")] | ||
[InlineData("", "")] | ||
public static void SnakeCaseUpper_ConvertName(string input, string expected) | ||
{ | ||
string result = JsonNamingPolicy.SnakeCaseUpper.ConvertName(input); | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("MyProperty", "my-property")] | ||
[InlineData("PropertyName", "property-name")] | ||
[InlineData("ABC", "a-b-c")] | ||
[InlineData("HTMLParser", "h-t-m-l-parser")] | ||
[InlineData("A", "a")] | ||
[InlineData("", "")] | ||
public static void KebabCaseLower_ConvertName(string input, string expected) | ||
{ | ||
string result = JsonNamingPolicy.KebabCaseLower.ConvertName(input); | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("MyProperty", "MY-PROPERTY")] | ||
[InlineData("PropertyName", "PROPERTY-NAME")] | ||
[InlineData("ABC", "A-B-C")] | ||
[InlineData("HTMLParser", "H-T-M-L-PARSER")] | ||
[InlineData("A", "A")] | ||
[InlineData("", "")] | ||
public static void KebabCaseUpper_ConvertName(string input, string expected) | ||
{ | ||
string result = JsonNamingPolicy.KebabCaseUpper.ConvertName(input); | ||
Assert.Equal(expected, result); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.