Skip to content
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

Possible assertEquals output enhancement #83

Open
premek opened this issue Dec 5, 2016 · 4 comments
Open

Possible assertEquals output enhancement #83

premek opened this issue Dec 5, 2016 · 4 comments

Comments

@premek
Copy link

premek commented Dec 5, 2016

When comparing very long strings where only a small part of it is different it is quite difficult to see in the output what the difference is.

  • It may be useful to omit some part of the string at the beginning and at the end of the string that is equal
  • mark the part of the string that is different with [...] for example
  • use colors if terminal supports it? Or enable colors with commandline param

FYI JUnit does it this way (note the three dots and braces):

assertEquals("1111111111111111111111111111111111111111111114111111111111111","1111111111111111111111111111111111111111111111411111111111111");
expected:<...11111111111111111111[41]11111111111111> but was:<...11111111111111111111[14]11111111111111>

Something similar would be very useful when comparing big tables.

@bluebird75
Copy link
Owner

I have something along those lines in mind for comparing strings. I was also thinking about a full diff but abbreviatting the output is also an interesting path.

For lists, the git version of LuaUnit (unreleased at the moment) does some diff analysis of the list to simplify the analysis. See https://github.com/bluebird75/luaunit/blob/master/test/ref/some_lists_comparisons.txt .

I'll have a look a JUnit for more inspiration.

Do you have any real world example of comparison implying big lists and/or big strings ? Such data would be really useful.

@premek
Copy link
Author

premek commented Dec 6, 2016

yes, i just started to use it to test a simple text parser. Some example data here:
https://github.com/premek/pink/blob/29b40f7a968db0fe38eb8230d10803fafba46c92/test/branching.lua

In my case, if the test fails, it is usually just one node missing or nested on a different level. Or a space missing in one of the strings etc.

@n1tehawk
Copy link
Contributor

We could possibly re-use some code/logic from the "list" comparison (mismatchFormattingPureList) to help with this. I'm thinking of breaking down multiple line strings into a table of strings, and single-line strings into a table of characters. A list_compare() helper could then work with these (sequential) tables...

Regards, NiteHawk

@bluebird75
Copy link
Owner

Why not...

The most challenging part is to make the output readable, especially in case of multi-line strings. The output should probably be different for single line comparison and multi-line strings. I was thinking about using the unified diff syntax.

Example for one line comparison :

Expected : the dog jumps over the cat
               ---
               +++
Received : the fox jumps over the cat

Example for multi-line comparison

Expected (---) / Received (+++)
The
- dog
+ fox
jumps
over
the
cat

I have in mind for a long time to use a diff library to perform really intelligent string and lists comparisons. See : https://github.com/paulgb/simplediff/tree/master/lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants