From e53a2c40b119509356edcffc1655331c9beb6df5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 30 Oct 2012 11:23:44 +0100 Subject: cmd/api: add more tests Feature extraction was tested before, but not the final diffs. This CL breaks function main into a smaller main + testable compareAPI. No functional changes. R=golang-dev, adg CC=golang-dev https://golang.org/cl/6820057 --- src/cmd/api/goapi_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/cmd/api/goapi_test.go') diff --git a/src/cmd/api/goapi_test.go b/src/cmd/api/goapi_test.go index c7cc601b1a..b4fccdfd4e 100644 --- a/src/cmd/api/goapi_test.go +++ b/src/cmd/api/goapi_test.go @@ -5,6 +5,7 @@ package main import ( + "bytes" "flag" "fmt" "io/ioutil" @@ -73,3 +74,53 @@ func TestGolden(t *testing.T) { } } } + +func TestCompareAPI(t *testing.T) { + tests := []struct { + name string + features, required, optional, exception []string + ok bool // want + out string // want + }{ + { + name: "feature added", + features: []string{"C", "A", "B"}, + required: []string{"A", "C"}, + ok: true, + out: "+B\n", + }, + { + name: "feature removed", + features: []string{"C", "A"}, + required: []string{"A", "B", "C"}, + ok: false, + out: "-B\n", + }, + { + name: "feature added then removed", + features: []string{"A", "C"}, + optional: []string{"B"}, + required: []string{"A", "C"}, + ok: true, + out: "±B\n", + }, + { + name: "exception removal", + required: []string{"A", "B", "C"}, + features: []string{"A", "C"}, + exception: []string{"B"}, + ok: true, + out: "~B\n", + }, + } + for _, tt := range tests { + buf := new(bytes.Buffer) + gotok := compareAPI(buf, tt.features, tt.required, tt.optional, tt.exception) + if gotok != tt.ok { + t.Errorf("%s: ok = %v; want %v", tt.name, gotok, tt.ok) + } + if got := buf.String(); got != tt.out { + t.Errorf("%s: output differs\nGOT:\n%s\nWANT:\n%s", tt.name, got, tt.out) + } + } +} -- cgit v1.3