-
Notifications
You must be signed in to change notification settings - Fork 8
/
change.go
59 lines (52 loc) · 1.14 KB
/
change.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package gompatible
import (
"go/types"
)
// ChangeKind represents the kind of a change of an API between two revisions.
type ChangeKind int
const (
ChangeUnchanged ChangeKind = iota
ChangeAdded
ChangeRemoved
ChangeCompatible
ChangeBreaking
)
func (ck ChangeKind) String() string {
switch ck {
case ChangeUnchanged:
return "Unchanged"
case ChangeAdded:
return "Added"
case ChangeRemoved:
return "Removed"
case ChangeCompatible:
return "Compatible"
case ChangeBreaking:
return "Breaking"
}
return ""
}
// A Change represents a change of an API between two revisions.
type Change interface {
TypesObject() types.Object
ShowBefore() string
ShowAfter() string
Kind() ChangeKind
}
// ShowChange returns a string represnetation of an API change.
func ShowChange(c Change) string {
switch c.Kind() {
case ChangeAdded:
return "+ " + c.ShowAfter()
case ChangeRemoved:
return "- " + c.ShowBefore()
case ChangeUnchanged:
return "= " + c.ShowBefore()
case ChangeCompatible:
return "* " + c.ShowBefore() + " -> " + c.ShowAfter()
case ChangeBreaking:
fallthrough
default:
return "! " + c.ShowBefore() + " -> " + c.ShowAfter()
}
}