golang.org/x/tools/gopls@v0.15.3/internal/hooks/gofumpt_120_test.go (about) 1 // Copyright 2022 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. 4 5 //go:build go1.20 6 // +build go1.20 7 8 package hooks 9 10 import "testing" 11 12 func TestFixLangVersion(t *testing.T) { 13 tests := []struct { 14 input, want string 15 wantErr bool 16 }{ 17 {"", "", false}, 18 {"1.18", "1.18", false}, 19 {"v1.18", "v1.18", false}, 20 {"1.21", "1.21", false}, 21 {"1.21rc3", "1.21", false}, 22 {"1.21.0", "1.21.0", false}, 23 {"1.21.1", "1.21.1", false}, 24 {"v1.21.1", "v1.21.1", false}, 25 {"v1.21.0rc1", "v1.21.0", false}, // not technically valid, but we're flexible 26 {"v1.21.0.0", "v1.21.0", false}, // also technically invalid 27 {"1.1", "1.1", false}, 28 {"v1", "v1", false}, 29 {"1", "1", false}, 30 {"v1.21.", "v1.21", false}, // also invalid 31 {"1.21.", "1.21", false}, 32 33 // Error cases. 34 {"rc1", "", true}, 35 {"x1.2.3", "", true}, 36 } 37 38 for _, test := range tests { 39 got, err := fixLangVersion(test.input) 40 if test.wantErr { 41 if err == nil { 42 t.Errorf("fixLangVersion(%q) succeeded unexpectedly", test.input) 43 } 44 continue 45 } 46 if err != nil { 47 t.Fatalf("fixLangVersion(%q) failed: %v", test.input, err) 48 } 49 if got != test.want { 50 t.Errorf("fixLangVersion(%q) = %s, want %s", test.input, got, test.want) 51 } 52 } 53 }