Created
February 15, 2017 19:29
-
-
Save haya14busa/1ae4f9014f28a6a2f2f17c9154b54e10 to your computer and use it in GitHub Desktop.
godebug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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