File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed
Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 66 "go/token"
77)
88
9- // Func - one go function in source with return information
9+ // Func - one go function in source
1010type Func struct {
1111 Name string
1212 Begin , End int
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "reflect"
5+ "testing"
6+ )
7+
8+ const testGolangSrc = `package somepkg
9+
10+ import "fmt"
11+
12+ type T int
13+
14+ func (r T) String() string {
15+ return fmt.Sprintf("%v", r)
16+ }
17+
18+ func fn() string {
19+ return "Hello"
20+ }
21+ `
22+
23+ func Test_getGolangFuncs (t * testing.T ) {
24+ tests := []struct {
25+ name string
26+ fileContent []byte
27+ wantResult []Func
28+ wantErr bool
29+ }{
30+ {
31+ name : "without error" ,
32+ fileContent : []byte (testGolangSrc ),
33+ wantResult : []Func {
34+ {Name : "String" , Begin : 44 , End : 103 },
35+ {Name : "fn" , Begin : 105 , End : 141 },
36+ },
37+ wantErr : false ,
38+ },
39+ {
40+ name : "with error" ,
41+ fileContent : []byte ("..." ),
42+ wantResult : nil ,
43+ wantErr : true ,
44+ },
45+ }
46+
47+ for _ , tt := range tests {
48+ t .Run (tt .name , func (t * testing.T ) {
49+ gotResult , err := getGolangFuncs (tt .fileContent )
50+ if (err != nil ) != tt .wantErr {
51+ t .Errorf ("getGolangFuncs() error = %v, wantErr %v" , err , tt .wantErr )
52+ return
53+ }
54+ if ! reflect .DeepEqual (gotResult , tt .wantResult ) {
55+ t .Errorf ("getGolangFuncs() = %#v, want %#v" , gotResult , tt .wantResult )
56+ }
57+ })
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments