1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestParseVersionRow(t *testing.T) {
24 row: "pkg archive/tar, type Writer struct",
32 row: "pkg archive/tar, type Header struct, AccessTime time.Time",
41 row: "pkg archive/tar, method (*Reader) Read([]uint8) (int, error)",
50 row: "pkg archive/zip, func FileInfoHeader(os.FileInfo) (*FileHeader, error)",
54 name: "FileInfoHeader",
58 row: "pkg encoding/base32, method (Encoding) WithPadding(int32) *Encoding",
60 pkg: "encoding/base32",
68 for i, tt := range tests {
69 got, ok := parseRow(tt.row)
74 t.Errorf("%d. parseRow(%q) = %+v; want %+v", i, tt.row, got, tt.want)
79 // hasTag checks whether a given release tag is contained in the current version
81 func hasTag(t string) bool {
82 for _, v := range build.Default.ReleaseTags {
90 func TestAPIVersion(t *testing.T) {
91 av, err := parsePackageAPIInfo()
95 for _, tc := range []struct {
102 // Things that were added post-1.0 should appear
103 {"func", "archive/tar", "FileInfoHeader", "", "1.1"},
104 {"type", "bufio", "Scanner", "", "1.1"},
105 {"method", "bufio", "WriteTo", "*Reader", "1.1"},
107 {"func", "bytes", "LastIndexByte", "", "1.5"},
108 {"type", "crypto", "Decrypter", "", "1.5"},
109 {"method", "crypto/rsa", "Decrypt", "*PrivateKey", "1.5"},
110 {"method", "debug/dwarf", "GoString", "Class", "1.5"},
112 {"func", "os", "IsTimeout", "", "1.10"},
113 {"type", "strings", "Builder", "", "1.10"},
114 {"method", "strings", "WriteString", "*Builder", "1.10"},
116 // Things from package syscall should never appear
117 {"func", "syscall", "FchFlags", "", ""},
118 {"type", "syscall", "Inet4Pktinfo", "", ""},
120 // Things added in Go 1 should never appear
121 {"func", "archive/tar", "NewReader", "", ""},
122 {"type", "archive/tar", "Header", "", ""},
123 {"method", "archive/tar", "Next", "*Reader", ""},
125 if tc.want != "" && !hasTag("go"+tc.want) {
128 if got := av.sinceVersionFunc(tc.kind, tc.receiver, tc.name, tc.pkg); got != tc.want {
129 t.Errorf(`sinceFunc("%s", "%s", "%s", "%s") = "%s"; want "%s"`, tc.kind, tc.receiver, tc.name, tc.pkg, got, tc.want)