Skip to content

Instantly share code, notes, and snippets.

@haya14busa
Created February 15, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haya14busa/1ae4f9014f28a6a2f2f17c9154b54e10 to your computer and use it in GitHub Desktop.
Save haya14busa/1ae4f9014f28a6a2f2f17c9154b54e10 to your computer and use it in GitHub Desktop.
godebug
package main
import (
"testing"
"github.com/kylelemons/godebug/pretty"
)
type ShipManifest struct {
Name string
Crew map[string]string
// ...
}
func TestIntroduceGoDebugPretty(t *testing.T) {
// AddCrew tries to add the given crewmember to the manifest.
AddCrew := func(m *ShipManifest, name, title string) {
// ...
if m.Crew == nil {
m.Crew = make(map[string]string)
}
m.Crew[title] = name
}
tests := []struct {
desc string
before *ShipManifest
name, title string
after *ShipManifest
}{
{
desc: "add first",
before: &ShipManifest{},
name: "Zaphod Beeblebrox",
title: "Galactic President",
after: &ShipManifest{
Crew: map[string]string{
"Zaphod Beeblebrox": "Galactic President",
},
},
},
// ...
}
for _, tt := range tests {
AddCrew(tt.before, tt.name, tt.title)
if diff := pretty.Compare(tt.before, tt.after); diff != "" {
t.Errorf("%s: post-AddCrew diff: (-got +want)\n%s", tt.desc, diff)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment