golang.org/x/build@v0.0.0-20240506185731-218518f32b70/devapp/title_test.go (about) 1 // Copyright 2019 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 package main_test 6 7 import ( 8 "reflect" 9 "testing" 10 11 devapp "golang.org/x/build/devapp" 12 ) 13 14 func TestParsePrefixedChangeTitle(t *testing.T) { 15 tests := []struct { 16 inRoot string 17 in string 18 wantPaths []string 19 wantTitle string 20 }{ 21 { 22 in: "import/path: Change title.", 23 wantPaths: []string{"import/path"}, wantTitle: "Change title.", 24 }, 25 { 26 inRoot: "root", 27 in: "import/path: Change title.", 28 wantPaths: []string{"root/import/path"}, wantTitle: "Change title.", 29 }, 30 { 31 inRoot: "root", 32 in: "[release-branch.go1.11] import/path: Change title.", 33 wantPaths: []string{"root/import/path"}, wantTitle: "[release-branch.go1.11] Change title.", 34 }, 35 36 // Multiple comma-separated paths. 37 { 38 in: "path1, path2: Change title.", 39 wantPaths: []string{"path1", "path2"}, wantTitle: "Change title.", 40 }, 41 { 42 inRoot: "root", 43 in: "path1, path2: Change title.", 44 wantPaths: []string{"root/path1", "root/path2"}, wantTitle: "Change title.", 45 }, 46 { 47 inRoot: "root", 48 in: "[release-branch.go1.11] path1, path2: Change title.", 49 wantPaths: []string{"root/path1", "root/path2"}, wantTitle: "[release-branch.go1.11] Change title.", 50 }, 51 52 // No path prefix. 53 { 54 in: "Change title.", 55 wantPaths: []string{""}, wantTitle: "Change title.", 56 }, 57 { 58 inRoot: "root", 59 in: "Change title.", 60 wantPaths: []string{"root"}, wantTitle: "Change title.", 61 }, 62 { 63 inRoot: "root", 64 in: "[release-branch.go1.11] Change title.", 65 wantPaths: []string{"root"}, wantTitle: "[release-branch.go1.11] Change title.", 66 }, 67 } 68 for i, tc := range tests { 69 gotPaths, gotTitle := devapp.ParsePrefixedChangeTitle(tc.inRoot, tc.in) 70 if !reflect.DeepEqual(gotPaths, tc.wantPaths) { 71 t.Errorf("%d: got paths: %q, want: %q", i, gotPaths, tc.wantPaths) 72 } 73 if gotTitle != tc.wantTitle { 74 t.Errorf("%d: got title: %q, want: %q", i, gotTitle, tc.wantTitle) 75 } 76 } 77 }