-
Notifications
You must be signed in to change notification settings - Fork 48
Feature/issue-40 #41
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
Feature/issue-40 #41
Conversation
@@ -43,6 +42,9 @@ public virtual JsonLD.Core.JsonLdOptions Clone() | |||
|
|||
private bool produceGeneralizedRdf = false; | |||
|
|||
private bool sortGraphsFromRdf = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I've only been able to control the order with the FromRDF
method (which luckily is all that's needed to get the desired behavior), I made the option pretty narrow in scope.
@@ -16,7 +13,7 @@ namespace JsonLD.Test | |||
public class ConformanceTests | |||
{ | |||
[Theory, ClassData(typeof(ConformanceCases))] | |||
public void ConformanceTestPasses(string id, string testname, ConformanceCase conformanceCase) | |||
public void ConformanceTestPasses(string id, ConformanceCase conformanceCase) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testname
variable was never used, so removing it had no impact
@@ -77,20 +74,21 @@ public ConformanceCases() | |||
|
|||
public IEnumerator<object[]> GetEnumerator() | |||
{ | |||
var jsonFetcher = new JsonFetcher(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created the JsonFetcher
class so I could reuse some of this logic in my own test class
Codecov Report
@@ Coverage Diff @@
## master #41 +/- ##
==========================================
+ Coverage 68.38% 68.59% +0.20%
==========================================
Files 22 22
Lines 4043 4053 +10
Branches 1026 1028 +2
==========================================
+ Hits 2765 2780 +15
+ Misses 1133 1130 -3
+ Partials 145 143 -2
Continue to review full report at Codecov.
|
} | ||
} | ||
} | ||
|
||
private JToken GetJson(JToken j) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the JsonFetcher
class
@@ -0,0 +1,89 @@ | |||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After getting FromRDF
to work, I tried the same approach with Compact
, but it seemed too complicated to get it to work. Plus, if Compact
or the other methods are given input, they seem to maintain the order. I left the remnants of the test here though in case it seemed worthwhile to try again later.
Or we can just delete it.
@@ -0,0 +1,58 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the easiest way for me to create quads to provide the FromRDF
method.
@@ -0,0 +1,143 @@ | |||
using JsonLD.Core; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep the sorting tests self-contained and not mix them in with the other tests, assuming that if the other tests are serializing correctly, and this is sorting correctly, then all is well.
It's important to maintain the same API as that exposed by jsonld.js can you check what they are doing on this issue? |
@dnllowe, do you think we could move this PR forward by answering @goofballLogic's question? Looks like @xivk's review would be appreciated as well. |
Sorry--the company had ended up forking the repository for the change. But let me take a look this weekend and get back to you! |
The |
sounds like the jsonld guys are on the fence about this functionality. Is there a way we could distinguish between "conformance" tests and "extra functionality" tests in our suite - so that there's a clear distinction between the official suite's tests and this extra function? |
That sounds reasonable. Could go with either |
|
Hey, no worries at all-and no rush! You've already been a great help, and I appreciate it :) |
Moves to ExtendedFunctionalityTests Refactors to create room for more extended functionality tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems sound to me
Is this a breaking change so we should consider bumping the major version after merging this? |
I think this is adding a predictable behaviour (sorting) where previously the behaviour was, in theory, unpredictable. Is it possible that somebody could depend on things not being sorted??? |
I agree that sounds highly unlikely, @goofballLogic. Let's merge and bump minor. |
My team and I have been using this library and it's made life much easier when working with quads and the rdf format. Thanks!
However, we have a need to return jsonld where order matters. But, the
JsonLdApi.FromRDF
method sorts properties by default. We need to be able to control when to sort the top-level graphs, the child nodes, or both.The new
SortingTests
provide examples for what we're after, but as a summary, given the json below, we'd want to control whether nodes 1, 2, and 3 get sorted, and whether their children (objects 1, 2, and 3) are sorted. As of now, theJsonLdApi.FromRDF
will always sort the graph nodes and children, losing the orignal order.I've gotten this to work only with
JsonLdApi.FromRDF
, but that's the only need we have, so I've left the rest of the code alone as much as possible. Testing the same changes withCompact
revealed just how complicated it might be to try and control the order in all cases--but if the original input for the other methods (Compact
,Flatten
,Expand
, etc) is in the order that's desired, then it seems to remain unchanged. It was onlyFromRDF
the changed the order of the input.Fixes #40.