aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cover/pkgname_test.go
blob: 1c731ad779ed29ed416f6b797a826c1e0fef7121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import "testing"

func TestPackageName(t *testing.T) {
	var tests = []struct {
		fileName, pkgName string
	}{
		{"", ""},
		{"///", ""},
		{"fmt", ""}, // No Go file, improper form.
		{"fmt/foo.go", "fmt"},
		{"encoding/binary/foo.go", "binary"},
		{"encoding/binary/////foo.go", "binary"},
	}
	var tf templateFile
	for _, test := range tests {
		tf.Name = test.fileName
		td := templateData{
			Files: []*templateFile{&tf},
		}
		got := td.PackageName()
		if got != test.pkgName {
			t.Errorf("%s: got %s want %s", test.fileName, got, test.pkgName)
		}
	}
}