This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Writable Json DOM - JsonNumber implementation and tests #39917
Merged
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
8013865
Json prototype (#1)
kasiabulat 0f7df28
Json prototype - transformation API (#2)
kasiabulat 6cd2efb
Json prototype (#1)
kasiabulat 409e575
Json prototype - transformation API (#2)
kasiabulat 25109c3
Merge branch 'master' of https://github.com/kasiabulat/corefx
kasiabulat 9dcfc4b
JsonNumber implementation and tests (#3)
kasiabulat 38af6d9
Merge remote-tracking branch 'upstream/master'
kasiabulat 08f4734
all unimplemented classes and methods with accompanying tests removed
kasiabulat 63ff329
First part of documentation added
kasiabulat 0e0fb7c
documentation completed
kasiabulat 47666ce
missing exceptions added
kasiabulat d856681
JsonElement changes removed
kasiabulat 22e6558
part of the review comments included
kasiabulat 04441f1
work on review comments
kasiabulat 30c5dd0
code refactor
kasiabulat 8f3e510
more decimal tests added using MemberData
kasiabulat c6ab148
more decimal tests added using MemberData
kasiabulat 259590b
more test cases added
kasiabulat c4d6ef2
equals summary adjusted, equals tests added
kasiabulat 01c230f
more Equals tests added, GetHashCode tests added, minor changes
kasiabulat 392142a
scientifing notation support added, rational numbers tests fixes
kasiabulat 310a5a6
rational overflow tests added
kasiabulat e03b803
ulong maxvalue tests added to rational types
kasiabulat 95a9401
presision problems fixes
kasiabulat 2bd6871
exception strings fixed
kasiabulat f0c4814
CI failing fixes (hopefully), review comments included
kasiabulat c22b36d
missing == tests added to achieve 100% branch coverage
kasiabulat 7dfc891
review comments included
kasiabulat 07746d8
Merge remote-tracking branch 'upstream/master' into kasiabulat/json-n…
kasiabulat d479fa7
Merge remote-tracking branch 'upstream/master' into kasiabulat/json-n…
kasiabulat ab1401a
trailing whitespaces fixes
kasiabulat 217bade
equals comments added
kasiabulat 40a6649
equals object refactored to call quals json number
kasiabulat af4aed3
Merge conflicts resolved
kasiabulat f534415
merge fix
kasiabulat 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
Json prototype - transformation API (#2)
* transformation API added * assertions to existing scenarios added
- Loading branch information
commit 409e57503c60f1fee88f17db510088903749cdd1
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
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
146 changes: 146 additions & 0 deletions
146
src/System.Text.Json/tests/WritableJsonApiTests.TestAccessingNestedMembers.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,146 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace System.Text.Json | ||
| { | ||
| #pragma warning disable xUnit1000 | ||
| internal static partial class WritableJsonApiTests | ||
| #pragma warning enable xUnit1000 | ||
| { | ||
| /// <summary> | ||
| /// Accesing nested Json object - casting with as operator | ||
| /// </summary> | ||
| [Fact] | ||
| public static void TestAccesingNestedJsonObjectCastWithAs() | ||
| { | ||
| JsonObject manager = EmployeesDatabase.GetManager(); | ||
|
|
||
| // Should not throw any exceptions: | ||
|
|
||
| var reportingEmployees = manager["reporting employees"] as JsonObject; | ||
| if (reportingEmployees == null) | ||
| throw new InvalidCastException(); | ||
|
|
||
| var softwareDevelopers = reportingEmployees["software developers"] as JsonObject; | ||
| if (softwareDevelopers == null) | ||
| throw new InvalidCastException(); | ||
|
|
||
| var internDevelopers = softwareDevelopers["intern employees"] as JsonObject; | ||
| if (internDevelopers == null) | ||
| throw new InvalidCastException(); | ||
|
|
||
| internDevelopers.Add(EmployeesDatabase.GetNextEmployee()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accesing nested Json object - casting with is operator | ||
| /// </summary> | ||
| [Fact] | ||
| public static void TestAccesingNestedJsonObjectCastWithIs() | ||
| { | ||
| JsonObject manager = EmployeesDatabase.GetManager(); | ||
|
|
||
| static bool AddEmployee(JsonObject manager) | ||
| { | ||
|
|
||
| if (manager["reporting employees"] is JsonObject reportingEmployees) | ||
| { | ||
| if (reportingEmployees["software developers"] is JsonObject softwareDevelopers) | ||
| { | ||
| if (softwareDevelopers["full time employees"] is JsonObject fullTimeEmployees) | ||
| { | ||
| fullTimeEmployees.Add(EmployeesDatabase.GetNextEmployee()); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool success = AddEmployee(manager); | ||
| Assert.True(success); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accesing nested Json object - explicit casting | ||
| /// </summary> | ||
| [Fact] | ||
| public static void TestAccesingNestedJsonObjectExplicitCast() | ||
| { | ||
| JsonObject manager = EmployeesDatabase.GetManager(); | ||
|
|
||
| // Should not throw any exceptions: | ||
| ((JsonObject)((JsonObject)manager["reporting employees"])["HR"]).Add(EmployeesDatabase.GetNextEmployee()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accesing nested Json object - GetObjectProperty method | ||
| /// </summary> | ||
| [Fact] | ||
| public static void TestAccesingNestedJsonObjectGetPropertyMethod() | ||
| { | ||
| JsonObject manager = EmployeesDatabase.GetManager(); | ||
|
|
||
| // Should not throw any exceptions: | ||
|
|
||
| JsonObject internDevelopers = manager.GetJsonObjectProperty("reporting employees") | ||
| .GetJsonObjectProperty("software developers") | ||
| .GetJsonObjectProperty("intern employees"); | ||
| internDevelopers.Add(EmployeesDatabase.GetNextEmployee()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accesing nested Json object - TryGetObjectProperty method | ||
| /// </summary> | ||
| [Fact] | ||
| public static void TestAccesingNestedJsonObjectTryGetPropertyMethod() | ||
| { | ||
| JsonObject manager = EmployeesDatabase.GetManager(); | ||
|
|
||
| static bool AddEmployee(JsonObject manager) | ||
| { | ||
| if (manager.TryGetObjectProperty("reporting employees", out JsonObject reportingEmployees)) | ||
| { | ||
| if (reportingEmployees.TryGetObjectProperty("software developers", out JsonObject softwareDevelopers)) | ||
| { | ||
| if (softwareDevelopers.TryGetObjectProperty("full time employees", out JsonObject fullTimeEmployees)) | ||
| { | ||
| fullTimeEmployees.Add(EmployeesDatabase.GetNextEmployee()); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| bool success = AddEmployee(manager); | ||
| Assert.True(success); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accesing nested Json array - GetArrayProperty method | ||
| /// </summary> | ||
| [Fact] | ||
| public static void TestAccesingNestedJsonArrayGetPropertyMethod() | ||
| { | ||
| var issues = new JsonObject() | ||
| { | ||
| { "features", new JsonArray{ "new functionality 1", "new functionality 2" } }, | ||
| { "bugs", new JsonArray{ "bug 123", "bug 4566", "bug 821" } }, | ||
| { "tests", new JsonArray{ "code coverage" } }, | ||
| }; | ||
|
|
||
| issues.GetJsonArrayProperty("bugs").Add("bug 12356"); | ||
| ((JsonString)issues.GetJsonArrayProperty("features")[0]).Value = "feature 1569"; | ||
| ((JsonString)issues.GetJsonArrayProperty("features")[1]).Value = "feature 56134"; | ||
|
|
||
| Assert.True(((JsonArray)issues["bugs"]).Contains("bug 12356")); | ||
| Assert.Equal((JsonString)((JsonArray)issues["features"])[0], "feature 1569"); | ||
| Assert.Equal((JsonString)((JsonArray)issues["features"])[1], "feature 56134"); | ||
| } | ||
| } | ||
| } |
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.