byexample icon indicating copy to clipboard operation
byexample copied to clipboard

Optional +norm-ws as strip (+strip-ws may be?)

Open eldipa opened this issue 8 years ago • 2 comments

The option +norm-ws ignores the whitespace during the compare phase but it does not modify neither the expected nor the got outputs in any way.

This is critical if both strings have whitespace as integral part of their (like using indentation to make the string more easier to see and understand). So preserving the whitespace is important when a test fails and we need to show a diff.

However there are cases where this is not desired.

For example:

>>> [1, 2, 3, 4, 0, 6]                                                                                                         
[1,   2,   3,                                                                                                                  
 4,   5,   6]

The example will fail and the diff (+diff ndiff) will show:

Differences:                                                                                                                   
+ [1, 2, 3, 4, 0, 6]                                                                                                           
- [1,   2,   3,                                                                                                                
-  4,   5,   6]

This is because the got output doesn't contain the extra newline between numbers 3 and 4.

If the whitespace is stripped off from the expected and got outputs (the whitespaces are not preserved), the diff should be:

Differences:                                                                                                                   
- [1, 2, 3, 4, 5, 6]                                                                                                           
?              ^                                                                                                               
                                                                                                                               
+ [1, 2, 3, 4, 0, 6]                                                                                                           
?              ^

We should allow the user to control this with a flag probably introduced in a Concern, may be in the same that in #39 .

eldipa avatar Aug 02 '18 14:08 eldipa

May be we could add this as an option for the diff

eldipa avatar Jan 09 '19 14:01 eldipa

Another alternative could be automatically detect when we should preserve or not the whitespace before the diff (when we should not-strip or strip the whitespace from the the expected and the got) based on how much complex gets the diff.

If +norm-ws is on and the example fails, do the diff and call it diffA. Then, strip off the ws from the expected and the got strings and do the diff again, name it diffB.

If diffA looks more complex than diffB (it looks more complex to interpret), choose diffB, otherwise diffA.

This automatic selection could be changed by an option and the user should be warned that the output (expected and got) was modified)

eldipa avatar Jan 31 '20 15:01 eldipa