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 // Should get the earliest Go version when an identifier
117 // was initially added, rather than a later version when
118 // it may have been updated. See issue 44081.
119 {"func", "os", "Chmod", "", ""}, // Go 1 era function, updated in Go 1.16.
120 {"method", "os", "Readdir", "*File", ""}, // Go 1 era method, updated in Go 1.16.
121 {"method", "os", "ReadDir", "*File", "1.16"}, // New to Go 1.16.
123 // Things from package syscall should never appear
124 {"func", "syscall", "FchFlags", "", ""},
125 {"type", "syscall", "Inet4Pktinfo", "", ""},
127 // Things added in Go 1 should never appear
128 {"func", "archive/tar", "NewReader", "", ""},
129 {"type", "archive/tar", "Header", "", ""},
130 {"method", "archive/tar", "Next", "*Reader", ""},
132 if tc.want != "" && !hasTag("go"+tc.want) {
135 if got := av.sinceVersionFunc(tc.kind, tc.receiver, tc.name, tc.pkg); got != tc.want {
136 t.Errorf(`sinceFunc("%s", "%s", "%s", "%s") = "%s"; want "%s"`, tc.kind, tc.receiver, tc.name, tc.pkg, got, tc.want)