Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8013865
Json prototype (#1)
kasiabulat Jul 17, 2019
0f7df28
Json prototype - transformation API (#2)
kasiabulat Jul 19, 2019
6cd2efb
Json prototype (#1)
kasiabulat Jul 17, 2019
409e575
Json prototype - transformation API (#2)
kasiabulat Jul 19, 2019
25109c3
Merge branch 'master' of https://github.com/kasiabulat/corefx
kasiabulat Jul 29, 2019
9dcfc4b
JsonNumber implementation and tests (#3)
kasiabulat Jul 30, 2019
38af6d9
Merge remote-tracking branch 'upstream/master'
kasiabulat Jul 30, 2019
08f4734
all unimplemented classes and methods with accompanying tests removed
kasiabulat Jul 30, 2019
63ff329
First part of documentation added
kasiabulat Jul 30, 2019
0e0fb7c
documentation completed
kasiabulat Jul 31, 2019
47666ce
missing exceptions added
kasiabulat Jul 31, 2019
d856681
JsonElement changes removed
kasiabulat Jul 31, 2019
22e6558
part of the review comments included
kasiabulat Aug 1, 2019
04441f1
work on review comments
kasiabulat Aug 1, 2019
30c5dd0
code refactor
kasiabulat Aug 5, 2019
8f3e510
more decimal tests added using MemberData
kasiabulat Aug 5, 2019
c6ab148
more decimal tests added using MemberData
kasiabulat Aug 5, 2019
259590b
more test cases added
kasiabulat Aug 5, 2019
c4d6ef2
equals summary adjusted, equals tests added
kasiabulat Aug 5, 2019
01c230f
more Equals tests added, GetHashCode tests added, minor changes
kasiabulat Aug 6, 2019
392142a
scientifing notation support added, rational numbers tests fixes
kasiabulat Aug 6, 2019
310a5a6
rational overflow tests added
kasiabulat Aug 6, 2019
e03b803
ulong maxvalue tests added to rational types
kasiabulat Aug 6, 2019
95a9401
presision problems fixes
kasiabulat Aug 6, 2019
2bd6871
exception strings fixed
kasiabulat Aug 6, 2019
f0c4814
CI failing fixes (hopefully), review comments included
kasiabulat Aug 7, 2019
c22b36d
missing == tests added to achieve 100% branch coverage
kasiabulat Aug 7, 2019
7dfc891
review comments included
kasiabulat Aug 8, 2019
07746d8
Merge remote-tracking branch 'upstream/master' into kasiabulat/json-n…
kasiabulat Aug 8, 2019
d479fa7
Merge remote-tracking branch 'upstream/master' into kasiabulat/json-n…
kasiabulat Aug 8, 2019
ab1401a
trailing whitespaces fixes
kasiabulat Aug 8, 2019
217bade
equals comments added
kasiabulat Aug 8, 2019
40a6649
equals object refactored to call quals json number
kasiabulat Aug 8, 2019
af4aed3
Merge conflicts resolved
kasiabulat Aug 8, 2019
f534415
merge fix
kasiabulat Aug 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Json prototype - transformation API (#2)
* transformation API added
* assertions to existing scenarios added
  • Loading branch information
kasiabulat committed Jul 29, 2019
commit 409e57503c60f1fee88f17db510088903749cdd1
23 changes: 18 additions & 5 deletions src/System.Text.Json/ref/System.Text.Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void Insert(int index, ushort item) { }
public void Insert(int index, uint item) { }
[System.CLSCompliantAttribute(false)]
public void Insert(int index, ulong item) { }
public int LastIndexOf(System.Text.Json.JsonNode item) { throw null; }
public bool Remove(System.Text.Json.JsonNode item) { throw null; }
public void RemoveAt(int index) { }
void System.Collections.Generic.ICollection<System.Text.Json.JsonNode>.CopyTo(System.Text.Json.JsonNode[] array, int arrayIndex) { }
Expand Down Expand Up @@ -130,6 +131,7 @@ public readonly partial struct JsonElement
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public bool IsImmutable { get { throw null; } }
public System.Text.Json.JsonElement this[int index] { get { throw null; } }
public System.Text.Json.JsonValueKind ValueKind { get { throw null; } }
public System.Text.Json.JsonElement Clone() { throw null; }
Expand Down Expand Up @@ -247,9 +249,20 @@ protected JsonNamingPolicy() { }
public static System.Text.Json.JsonNamingPolicy CamelCase { get { throw null; } }
public abstract string ConvertName(string name);
}
public partial class JsonNode
{
public JsonNode() { }
public abstract partial class JsonNode
{
internal JsonNode() { }
public System.Text.Json.JsonElement AsJsonElement() { throw null; }
public static System.Text.Json.JsonNode DeepCopy(System.Text.Json.JsonDocument jsonDocument) { throw null; }
public static System.Text.Json.JsonNode DeepCopy(System.Text.Json.JsonElement jsonElement) { throw null; }
public static System.Text.Json.JsonNode DeepCopy(System.Text.Json.JsonNode jsonNode) { throw null; }
public static System.Text.Json.JsonNode GetNode(System.Text.Json.JsonElement jsonElement) { throw null; }
public static System.Text.Json.JsonNode Parse(System.Buffers.ReadOnlySequence<byte> utf8Json) { throw null; }
public static System.Text.Json.JsonNode Parse(System.IO.Stream utf8Json) { throw null; }
public static System.Text.Json.JsonNode Parse(System.ReadOnlyMemory<byte> utf8Json) { throw null; }
public static System.Text.Json.JsonNode Parse(System.ReadOnlyMemory<char> json) { throw null; }
public static System.Text.Json.JsonNode Parse(string json) { throw null; }
public static bool TryGetNode(System.Text.Json.JsonElement jsonElement, out System.Text.Json.JsonNode jsonNode) { throw null; }
}
public partial class JsonNumber : System.Text.Json.JsonNode
{
Expand Down Expand Up @@ -360,9 +373,9 @@ public void Add(string propertyName, ulong propertyValue) { }
public void AddRange(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, System.Text.Json.JsonNode>> jsonProperties) { }
public bool ContainsProperty(string propertyName) { throw null; }
public System.Collections.Generic.IEnumerable<System.Text.Json.JsonNode> GetAllProperties(string propertyName) { throw null; }
public System.Text.Json.JsonArray GetArrayProperty(string propertyName) { throw null; }
public System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, System.Text.Json.JsonNode>> GetEnumerator() { throw null; }
public System.Text.Json.JsonObject GetObjectProperty(string propertyName) { throw null; }
public System.Text.Json.JsonArray GetJsonArrayProperty(string propertyName) { throw null; }
public System.Text.Json.JsonObject GetJsonObjectProperty(string propertyName) { throw null; }
public System.Text.Json.JsonNode GetProperty(string propertyName) { throw null; }
public bool ModifyPropertyName(string oldName, string newName) { throw null; }
public bool Remove(string propertyName) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1440,5 +1440,10 @@ private void CheckValidInstance()

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay => $"ValueKind = {ValueKind} : \"{ToString()}\"";

// for now disabling error caused by not adding documentation to methods
#pragma warning disable CS1591
public bool IsImmutable => throw null;
#pragma warning restore CS1591
}
}
5 changes: 3 additions & 2 deletions src/System.Text.Json/src/System/Text/Json/Node/JsonArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ public void Add(ulong value) { }
[CLSCompliant(false)]
public bool Contains(ulong value) { throw null; }

public int Count => throw new NotImplementedException();
public bool IsReadOnly => throw new NotImplementedException();
public int Count => throw null;
public bool IsReadOnly => throw null;

public int IndexOf(JsonNode item) { throw null; }
public int LastIndexOf(JsonNode item) { throw null; }
public void RemoveAt(int index) { throw null; }
public void Clear() { throw null; }
public bool Remove(JsonNode item) { throw null; }
Expand Down
20 changes: 19 additions & 1 deletion src/System.Text.Json/src/System/Text/Json/Node/JsonNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@
// for now disabling error caused by not adding documentation to methods
#pragma warning disable CS1591

using System.Buffers;
using System.IO;

namespace System.Text.Json
{
public partial class JsonNode
public abstract partial class JsonNode
{
private protected JsonNode() { }
public JsonElement AsJsonElement() { throw null; }

public static JsonNode GetNode(JsonElement jsonElement) { throw null; }
public static bool TryGetNode(JsonElement jsonElement, out JsonNode jsonNode) { throw null; }

public static JsonNode Parse(string json) { throw null; }
public static JsonNode Parse(ReadOnlySequence<byte> utf8Json) { throw null; }
public static JsonNode Parse(Stream utf8Json) { throw null; }
public static JsonNode Parse(ReadOnlyMemory<byte> utf8Json) { throw null; }
public static JsonNode Parse(ReadOnlyMemory<char> json) { throw null; }


public static JsonNode DeepCopy(JsonNode jsonNode) { throw null; }
public static JsonNode DeepCopy(JsonElement jsonElement) { throw null; }
public static JsonNode DeepCopy(JsonDocument jsonDocument) { throw null; }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/System.Text.Json/src/System/Text/Json/Node/JsonObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public void AddRange(IEnumerable<KeyValuePair<string, JsonNode>> jsonProperties)

public JsonNode GetProperty(string propertyName) { throw null; }
public bool TryGetProperty(string propertyName, out JsonNode jsonNode) { throw null; }
public JsonObject GetObjectProperty(string propertyName) { throw null; }
public JsonObject GetJsonObjectProperty(string propertyName) { throw null; }
public bool TryGetObjectProperty(string propertyName, out JsonObject jsonObject) { throw null; }
public JsonArray GetArrayProperty(string propertyName) { throw null; }
public JsonArray GetJsonArrayProperty(string propertyName) { throw null; }
public bool TryGetArrayProperty(string propertyName, out JsonArray jsonArray) { throw null; }
public IEnumerable<JsonNode> GetAllProperties(string propertyName) { throw null; }

Expand Down
4 changes: 4 additions & 0 deletions src/System.Text.Json/tests/System.Text.Json.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@
<Compile Include="Utf8JsonReaderTests.ValueTextEquals.cs" />
<Compile Include="Utf8JsonWriterTests.cs" />
<Compile Include="..\src\System\Text\Json\BitStack.cs" Link="BitStack.cs" />
<Compile Include="WritableJsonApiTests.TestAccessingNestedMembers.cs" />
<Compile Include="WritableJsonApiTests.TestModifying.cs" />
<Compile Include="WritableJsonApiTests.TestTransformations.cs" />
<Compile Include="WritableJsonApiTests.cs" />
<Compile Include="WritableJsonApiTests.TestData.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsNetFx)' == 'true'">
<Compile Include="$(CommonPath)\System\Buffers\ArrayBufferWriter.cs">
Expand Down
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");
}
}
}
Loading