Add test to cover issue with unstable array sort
parent
831ec94400
commit
8cd59b6532
|
@ -1,3 +1,4 @@
|
|||
using System.Linq;
|
||||
using JsonDiffPatchDotNet.Formatters.JsonPatch;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
|
@ -121,6 +122,51 @@ namespace JsonDiffPatchDotNet.UnitTests
|
|||
AssertOperation(operations[1], OperationTypes.Remove, "/1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Format_SortsRemoveOperations_Success()
|
||||
{
|
||||
const string patchJson = @"
|
||||
{
|
||||
""a"": {
|
||||
""a"": [0,0,0],
|
||||
""b"": [0,0,0],
|
||||
""c"": {
|
||||
""a"": {
|
||||
""a"": [0,0,0],
|
||||
""b"": [0,0,0],
|
||||
""c"": [0,0,0],
|
||||
""d"": [0,0,0],
|
||||
""e"": [0,0,0],
|
||||
""f"": [0,0,0]
|
||||
}
|
||||
}
|
||||
},
|
||||
""b"": [0,0,0],
|
||||
""c"": [0,0,0],
|
||||
""d"": [0,0,0],
|
||||
""e"": [0,0,0],
|
||||
""f"": [0,0,0],
|
||||
""g"": [0,0,0],
|
||||
""h"": [0,0,0],
|
||||
""i"": {
|
||||
""a"": {
|
||||
""a"": {
|
||||
""_t"": ""a"",
|
||||
""_0"": [0,0,0],
|
||||
""_1"": [0,0,0]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
var patch = JToken.Parse(patchJson);
|
||||
var operations = Formatter.Format(patch);
|
||||
|
||||
var paths = operations.Select(o => o.Path).ToList();
|
||||
// removal of the array item at index 1 should come before the item at index 0
|
||||
Assert.Less(paths.IndexOf("/i/a/a/1"), paths.IndexOf("/i/a/a/0"));
|
||||
}
|
||||
|
||||
private void AssertOperation(Operation operation, string expectedOp, string expectedPath, JValue expectedValue = null)
|
||||
{
|
||||
Assert.AreEqual(expectedOp, operation.Op);
|
||||
|
|
Loading…
Reference in New Issue