Skip to content

improve diff for []byte values #272

Closed
@rogpeppe

Description

[]byte is commonly used to encode strings, so it's hard to read the diff when it's phrased in terms of hex bytes rather than strings.

For example, compare the two diff outputs in this example:

  []string{
- 	"hello",
  	"foo",
+ 	"foo",
  	"barbaz",
- 	"blahdieblah",
+ 	"added",
+ 	"here",
+ 	"hrmph",
  }

  [][]uint8{
- 	{0x68, 0x65, 0x6c, 0x6c, 0x6f},
  	{0x66, 0x6f, 0x6f},
+ 	{0x66, 0x6f, 0x6f},
  	{0x62, 0x61, 0x72, 0x62, ...},
+ 	{0x61, 0x64, 0x64, 0x65, 0x64},
+ 	{0x68, 0x65, 0x72, 0x65},
- 	{0x62, 0x6c, 0x61, 0x68, 0x64, 0x69, 0x65, 0x62, 0x6c, 0x61, 0x68},
+ 	{0x68, 0x72, 0x6d, 0x70, 0x68},
  }

I think it would be better to see something like this instead:

  [][]byte{
- 	[]byte("hello"),
  	[]byte("foo"),
+ 	[]byte("foo"),
  	[]byte("barbaz"),
- 	[]byte("blahdieblah"),
+ 	[]byte("added"),
+ 	[]byte("here"),
+ 	[]byte("hrmph"),
  }

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions