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

Unicode string test failure output #47

Merged
merged 4 commits into from
May 3, 2019

Conversation

drathier
Copy link
Collaborator

@drathier drathier commented Oct 31, 2018

This adds a unicode-escaped copy of any failing string that contains non-standard ascii characters.

I'm not completely happy with the formatting, so if you have suggestions, please do tell. Otherwise, I think it's still much better than what we currently have. I'm comparing the escaped strings, not character by character, which is why we're getting diffs that cover part of an escape sequence.

Solves elm-community/elm-test#225 and #38.

↓ Expectations
↓ Expect.equal on unicode strings should show pretty output
✗ ascii
           ▼        ▼▼       ▼▼  
    "\u{1f63b}\u{1f640}\u{1f47b}" (same string but with unicode characters escaped)
     ▼   
    "😻🙀👻"
    |> Expect.equal
    "🙀👻😻🙈"
       ▲▲ 
    "\u{1f640}\u{1f47b}\u{1f63b}\u{1f648}" (same string but with unicode characters escaped)
           ▲▲▲▲▲▲▲▲▲▲        ▲▲      ▲ ▲  


↓ Expectations
↓ Expect.equal on unicode strings should show pretty output
✗ ascii space vs nbsp
        ▼    
    "asd qwe"
    ╵
    │ |> Expect.equal
    ╷
    "asd qwe"
        ▲    
    "asd\u{00a0}qwe" (same string but with unicode characters escaped)
        ▲▲▲▲▲▲    


↓ Expectations
↓ Expect.equal on unicode strings should show pretty output
✗ ascii only
         ▼   
    "asd qwe"
    ╵
    │ |> Expect.equal
    ╷
    "asd dwe"
         ▲   


↓ Expectations
↓ Expect.equal on unicode strings should show pretty output
✗ newline diff
                   
    "first\nsecond"
    ╵
    │ |> Expect.equal
    ╷
    "first\r\nsecond"
           ▲▲        


↓ Expectations
↓ Expect.equal on unicode strings should show pretty output
✗ long lines
                                                                                                                                                                                                                                                                                                                                                                                                            ▼▼▼▼▼▼▼▼▼▼                                                                                                                                                                                                                                                                                                     
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in scelerisque arcu. Curabitur cursus efficitur turpis sed porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc eu cursus ex. Proin accumsan quam quis dui semper finibus. Nunc vel nibh at tellus finibus rhoncus eu eget dolor. Sed eget neque ut lorem imperdiet fermentum. \u{1f63b} Morbi iaculis ante euismod, vulputate velit ut, varius velit. Nulla tempus dapibus mattis. In tempus, nisi a porta lobortis, nulla lacus iaculis quam, vel euismod magna risus at tortor. Integer porta urna odio. Nulla pellentesque dictum maximus. Donec auctor urna nec tortor imperdiet varius." (same string but with unicode characters escaped)
                                                                                                                                                                                                                                                                                                                                                                                                            ▼▼                                                                                                                                                                                                                                                                                                     
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in scelerisque arcu. Curabitur cursus efficitur turpis sed porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc eu cursus ex. Proin accumsan quam quis dui semper finibus. Nunc vel nibh at tellus finibus rhoncus eu eget dolor. Sed eget neque ut lorem imperdiet fermentum. 😻 Morbi iaculis ante euismod, vulputate velit ut, varius velit. Nulla tempus dapibus mattis. In tempus, nisi a porta lobortis, nulla lacus iaculis quam, vel euismod magna risus at tortor. Integer porta urna odio. Nulla pellentesque dictum maximus. Donec auctor urna nec tortor imperdiet varius."
    ╵
    │ |> Expect.equal
    ╷
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in scelerisque arcu. Curabitur cursus efficitur turpis sed porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc eu cursus ex. Proin accumsan quam quis dui semper finibus. Nunc vel nibh at tellus finibus rhoncus eu eget dolor. Sed eget neque ut lorem imperdiet fermentum. Morbi iaculis ante euismod, vulputate velit ut, varius velit. Nulla tempus dapibus mattis. In tempus, nisi a porta lobortis, nulla lacus iaculis quam, vel euismod magna risus at tortor. Integer porta urna odio. Nulla pellentesque dictum maximus. Donec auctor urna nec tortor imperdiet varius."
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 


@drathier drathier added the expectations Concerns assertions and comparisons label Oct 31, 2018
@drathier drathier self-assigned this Oct 31, 2018
@drathier
Copy link
Collaborator Author

We seem to have multiple copies of verticalBar etc., and this only updates the ones used in npm test. I'm wondering a bit why we have multiple copies of them?

@drathier drathier changed the title Unicode string test failure output WIP: Unicode string test failure output Oct 31, 2018
@harrysarson
Copy link
Collaborator

How does it look if the strings are long or contain new lines?

@drathier
Copy link
Collaborator Author

Added a newline test (\n vs \r\n), those are typed out as their backslash escapes (this is how elm types them out in toString). Also added a very long line, hard to read test output in my terminal because of word wrap, but very easy without word wrap.

Copy link
Collaborator

@mgold mgold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small nits, otherwise looks good.

"f"

_ ->
String.fromInt (i |> remainderBy 16)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to call remainderBy again. decimalDigit -> String.fromInt decimalDigit

|> List.map Char.toCode
|> List.map
(\c ->
if isAsciiChar c == False then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use if not (isAsciiChar c) then or flip the conditional.

@drathier drathier changed the base branch from remove-expect-true-false to master May 2, 2019 15:37
@drathier
Copy link
Collaborator Author

drathier commented May 2, 2019

Better late than never, I guess.

@drathier drathier changed the title WIP: Unicode string test failure output Unicode string test failure output May 2, 2019
@drathier drathier requested a review from mgold May 2, 2019 15:38
Copy link
Collaborator

@mgold mgold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@drathier drathier merged commit e8fe199 into master May 3, 2019
@drathier drathier deleted the unicode-string-test-failure-output branch May 3, 2019 08:46
-- \_ -> "first\u{000a}second" |> Expect.equal "first\r\nsecond"
-- , test "long lines" <|
-- \_ -> "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in scelerisque arcu. Curabitur cursus efficitur turpis sed porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc eu cursus ex. Proin accumsan quam quis dui semper finibus. Nunc vel nibh at tellus finibus rhoncus eu eget dolor. Sed eget neque ut lorem imperdiet fermentum. 😻 Morbi iaculis ante euismod, vulputate velit ut, varius velit. Nulla tempus dapibus mattis. In tempus, nisi a porta lobortis, nulla lacus iaculis quam, vel euismod magna risus at tortor. Integer porta urna odio. Nulla pellentesque dictum maximus. Donec auctor urna nec tortor imperdiet varius." |> Expect.equal "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in scelerisque arcu. Curabitur cursus efficitur turpis sed porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc eu cursus ex. Proin accumsan quam quis dui semper finibus. Nunc vel nibh at tellus finibus rhoncus eu eget dolor. Sed eget neque ut lorem imperdiet fermentum. Morbi iaculis ante euismod, vulputate velit ut, varius velit. Nulla tempus dapibus mattis. In tempus, nisi a porta lobortis, nulla lacus iaculis quam, vel euismod magna risus at tortor. Integer porta urna odio. Nulla pellentesque dictum maximus. Donec auctor urna nec tortor imperdiet varius."
-- ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these tests commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're the tests used to show the output of failed string equality expectations. I don't know how to write meaningful automatic tests that check that the output remains the same.

@@ -135,29 +203,64 @@ equalityToString : { operation : String, expected : String, actual : String } ->
equalityToString { operation, expected, actual } =
-- TODO make sure this looks reasonable for multiline strings
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pull request solves this TODO. 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not :/ Long strings with automatic line wrapping still look weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expectations Concerns assertions and comparisons
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants