-
-
Notifications
You must be signed in to change notification settings - Fork 549
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
Add index to XPath information of XDocument equivalence failure message #1181
Add index to XPath information of XDocument equivalence failure message #1181
Conversation
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.
Great idea 👍
I haven't been using the xml assertions much, but having the index adds value.
Do you think that this change of error message is a breaking change? |
While it technically can be a breaking change, as in tests failing after upgrading the package, I don't recall we've considered improvements/changes to failure messages as breaking changes. |
Why would a test fail? Because somebody observe FA's failure messages in an exception assertion? |
While creating an example I found that my question is not relevant. |
I came to think of another way to combine the Some very primitive benchmarks:
10 children per node.This PR
My branch
4 children per node.This PR
My branch
|
@jnyrup do you want to do anything with those performance results? Or can this be merged? |
@lg2de You can merge the commit into this PR.
|
Currently we use a stack to keep track of the location and a dictionary to keep track of the xpath index. That has multiple downsides: * We need to keep two separate data structure in sync. * We're a lot of string allocations on each iterations when computing path as key for the dictionary. * When creating the failure message we're doing lookups in two data structures Instead we can combine their purposes in a single graph where each node has a `Name` and a `Count`, where the latter is updated each time we visit a node with the same path. On each xml traversal we now only need to find the matching sibling or insert a new child. Creating the failure message is simply the travel from the current node to the root node in reverse order.
@jnyrup why do you prefer
over
? |
The second one can trigger an |
https://intellitect.com/check-for-null-not-null/ has a nice write-up of different ways to compare against By using Here's an example of the differences for value and reference types: |
Mmh, understood. It feels overengineered to me. I've applied jnyrup improvement (leaving the mentioned statement) and did some cleanup. |
Is that
referring to this?
If so, everything looks good to me 👍 |
No, sorry. |
@dennisdoomen whenever you're ready ;) |
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 class needs a bit of love. I'll take a look after merging this one.
What do you mean? I just want to note, that I think about to provide new implementation for XDocument comparison. |
I think, the XDocument equivalence failure message is not helpful when comparing documents with repeating element names, like HTML documents. By just providing the simple XPath it may be very difficult to identify the element with difference:
/html/body/table/tr/td
This PR is a proposal to improve the failure message by writing index number (according XPath syntax) when a specific element was found at least second time on same level:
/html/body/table[2]/tr[17]/td[5]
Additionally
editorconfig
according to the current code style