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

Human-readable output of unicode characters in expectation results #384

Closed
artempyanykh opened this issue Nov 2, 2018 · 2 comments
Closed

Human-readable output of unicode characters in expectation results #384

artempyanykh opened this issue Nov 2, 2018 · 2 comments

Comments

@artempyanykh
Copy link

@artempyanykh artempyanykh commented Nov 2, 2018

When there are non-ascii chars in strings, the resulting output shows codes of those chars instead of their human-readable representation, e.g.

expected: "\1084\1072\1075\1072\1079\1080\1085"
  but got: "\1052\1072\1075\1072\1079\1080\1085"

In GHCi there is a way to specify a different show function, e.g. :set -interactive-print Text.Show.Unicode.uprint.

Is there a way to similarly alter Hspec's output function to properly handle unicode chars?

@sol
Copy link
Member

@sol sol commented Nov 2, 2018

Hey! Thanks for opening this issue!

Currently this is not supported and I'm not sure how deep we need to dig to add it. I like the idea though and I'm happy to look into it eventually, but can't commit to a timeline.

As a workaround, you can use a newtype on your strings for now, that alter the show instance, e.g. (untested):

newtype UString = UString String

instance Show UString where
  show (UString s) = ushow s

@artempyanykh
Copy link
Author

@artempyanykh artempyanykh commented Nov 5, 2018

Hey @sol ! Got it, thank you! And thanks for the workaround, much better then decoding utf-8 codes 😃

@sol sol added this to the later milestone Apr 18, 2021
@sol sol removed this from the later milestone May 12, 2021
ncaq added a commit to ncaq/hspec that referenced this issue Sep 10, 2021
relation: [Human-readable output of unicode characters in expectation results · Issue hspec#384 · hspec/hspec](hspec#384)

Show promotes string escaping, so it is not used in unnecessary parts.

This will result in the following display improvements.

> To rerun use: --match "/FooBar/\30333\12356\29356\12364\36208\12427\12290/"

to

> To rerun use: --match "/FooBar/白い犬が走る。/"
ncaq added a commit to ncaq/hspec that referenced this issue Sep 10, 2021
relation: [Human-readable output of unicode characters in expectation results · Issue hspec#384 · hspec/hspec](hspec#384)

Show promotes string escaping, so it is not used in unnecessary parts.

This will result in the following display improvements.

> To rerun use: --match "/FooBar/\30333\12356\29356\12364\36208\12427\12290/"

to

> To rerun use: --match "/FooBar/白い犬が走る。/"
ncaq added a commit to ncaq/hspec that referenced this issue Nov 4, 2021
sol added a commit that referenced this issue Nov 16, 2021
This turns e.g.

    expected: "\956"
     but got: "\955"

into

    expected: "μ"
     but got: "λ"
sol added a commit that referenced this issue Nov 16, 2021
This turns e.g.

    expected: "\956"
     but got: "\955"

into

    expected: "μ"
     but got: "λ"
sol added a commit that referenced this issue Nov 16, 2021
This turns e.g.

    expected: "\956"
     but got: "\955"

into

    expected: "μ"
     but got: "λ"
@sol sol closed this as completed in f46664c Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants