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

Output of comparing two Japanese words is unreadable #314

Open
k3forx opened this issue Dec 9, 2022 · 1 comment
Open

Output of comparing two Japanese words is unreadable #314

k3forx opened this issue Dec 9, 2022 · 1 comment
Labels
reporter Improvements in the difference reporter

Comments

@k3forx
Copy link

k3forx commented Dec 9, 2022

Summary

When I want to compare two Japanese words and there is diff, the returned value of Diff method is unreadable.

Detail

Here is an example.

func Echo() string {
	return "プライベート ブランド シャツ"
}

test code

func TestEcho(t *testing.T) {
	expected := "プライベート ブランド ジャケット"
	actual := Echo()
	if diff := cmp.Diff(expected, actual); diff != "" {
		t.Errorf("%s result mismatch (-want, +got):\n%s", t.Name(), diff)
	}
}

cmp.Diff produces

--- FAIL: TestEcho (0.00s)
    main_test.go:13: TestEcho result mismatch (-want, +got):
          strings.Join({
                "プライベート ブランド \xe3\x82",
        -       "\xb8ャケット",
        +       "\xb7ャツ",
          }, "")
FAIL
FAIL    cmpbug  0.347s
FAIL

the above output is not readable. I expect the following output

❯ go test ./...
--- FAIL: TestEcho (0.00s)
    main_test.go:13: TestEcho result mismatch (-want, +got):
          string(
                 "プライベート ブランド ",
        -       "ジャケット",
        +       "シャツ",
          )
FAIL
FAIL    cmpbug  0.229s
FAIL

version info

  • go: 1.19.2
  • cmp: v0.5.9
@dsnet
Copy link
Collaborator

dsnet commented Dec 9, 2022

Thanks for the bug report. We're performing a diff on byte boundaries rather than rune boundaries. We can fix the heuristic for this where we use rune diffing if the strings are valid UTF-8.

@dsnet dsnet added the reporter Improvements in the difference reporter label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reporter Improvements in the difference reporter
Projects
None yet
Development

No branches or pull requests

2 participants