-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor improvements for JSON node extensions
- Loading branch information
1 parent
3889fe2
commit b37147b
Showing
6 changed files
with
75 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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
49 changes: 49 additions & 0 deletions
49
src/Cotopaxi.Cosmos.PackageManagement.UnitTests/JsonNodeExtensionsTest.cs
This file contains 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,49 @@ | ||
using System.Text.Json.Nodes; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Cotopaxi.Cosmos.PackageManagement.UnitTests; | ||
|
||
[TestClass] | ||
public sealed class JsonNodeExtensionsTest | ||
{ | ||
[DataTestMethod] | ||
[DataRow("", "$")] | ||
[DataRow("/foo", "$.foo")] | ||
[DataRow("/foo/0", "$.foo[0]")] | ||
[DataRow("/", "$.")] | ||
[DataRow("/a~1b", "$['a/b']")] | ||
[DataRow("/c%d", "$.c%d")] | ||
[DataRow("/e^f", "$.e^f")] | ||
[DataRow("/g|h", "$.g|h")] | ||
[DataRow("/i\\\\j", "$['i\\\\j']")] | ||
[DataRow("/k\\\"l", "$['k\\\"l']")] | ||
[DataRow("/ ", "$[' ']")] | ||
[DataRow("/m~0n", "$.m~n")] | ||
public void TryGetValue(string jsonPointerValue, string jsonPath) | ||
{ | ||
var jsonObject = new JsonObject | ||
{ | ||
["foo"] = new JsonArray | ||
{ | ||
"bar", | ||
"baz", | ||
}, | ||
[""] = 0, | ||
["a/b"] = 1, | ||
["c%d"] = 2, | ||
["e^f"] = 3, | ||
["g|h"] = 4, | ||
["i\\\\j"] = 5, | ||
["k\\\"l"] = 6, | ||
[" "] = 7, | ||
["m~n"] = 8, | ||
}; | ||
|
||
var jsonPointer = new JsonPointer(jsonPointerValue); | ||
var result = jsonObject.TryGetValue(jsonPointer, out var value); | ||
|
||
Assert.IsTrue(result); | ||
Assert.IsNotNull(value); | ||
Assert.AreEqual(jsonPath, value.GetPath()); | ||
} | ||
} |
This file contains 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 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 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