blob: 831262d029e723c5a55e8216b6cab02d5ff9279a (
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
32
33
34
35
36
37
38
39
|
package gotest
import "testing"
func TestParsePackageName(t *testing.T) {
lines := []string{"// comment", "package mypkg // trailing"}
if got := ParsePackageName(lines); got != "mypkg" {
t.Fatalf("got %q", got)
}
if got := ParsePackageName([]string{"no package"}); got != "" {
t.Fatalf("expected empty package name")
}
}
func TestFindFunctionAtLine_NoBody(t *testing.T) {
lines := []string{"func X(a int)", "// comment"}
start, end := FindFunctionAtLine(lines, 0)
if start != 0 || end != 0 {
t.Fatalf("expected single-line prototype, got %d,%d", start, end)
}
}
func TestDeriveFuncName(t *testing.T) {
if got := DeriveFuncName("func Sum(a int) int { return a }"); got != "Sum" {
t.Fatalf("got %q", got)
}
if got := DeriveFuncName("func (t *Type) Method(x int) {}"); got != "Method" {
t.Fatalf("got %q", got)
}
}
func TestExportName(t *testing.T) {
if got := ExportName("sum"); got != "Sum" {
t.Fatalf("got %q", got)
}
if got := ExportName("Sum"); got != "Sum" {
t.Fatalf("got %q", got)
}
}
|