Source file src/cmd/cover/pkgname_test.go

     1  // Copyright 2020 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
     6  
     7  import "testing"
     8  
     9  func TestPackageName(t *testing.T) {
    10  	var tests = []struct {
    11  		fileName, pkgName string
    12  	}{
    13  		{"", ""},
    14  		{"///", ""},
    15  		{"fmt", ""}, // No Go file, improper form.
    16  		{"fmt/foo.go", "fmt"},
    17  		{"encoding/binary/foo.go", "binary"},
    18  		{"encoding/binary/////foo.go", "binary"},
    19  	}
    20  	var tf templateFile
    21  	for _, test := range tests {
    22  		tf.Name = test.fileName
    23  		td := templateData{
    24  			Files: []*templateFile{&tf},
    25  		}
    26  		got := td.PackageName()
    27  		if got != test.pkgName {
    28  			t.Errorf("%s: got %s want %s", test.fileName, got, test.pkgName)
    29  		}
    30  	}
    31  }
    32  

View as plain text