...
1 package main
2
3 import (
4 "go/ast"
5 "go/token"
6 "testing"
7
8 "gotest.tools/v3/assert"
9 )
10
11 func TestCall_String(t *testing.T) {
12 c := &call{
13 expr: &ast.CallExpr{Fun: ast.NewIdent("myFunc")},
14 }
15 assert.Equal(t, c.String(), "myFunc()")
16 }
17
18 func TestCall_StringWithFileInfo(t *testing.T) {
19 c := &call{
20 fileset: token.NewFileSet(),
21 expr: &ast.CallExpr{
22 Fun: &ast.Ident{
23 Name: "myFunc",
24 NamePos: 17,
25 }},
26 }
27 t.Run("unknown file", func(t *testing.T) {
28 assert.Equal(t, c.StringWithFileInfo(), "myFunc() at unknown file")
29 })
30
31 t.Run("at position", func(t *testing.T) {
32 c.fileset.AddFile("source.go", 10, 100)
33 assert.Equal(t, c.StringWithFileInfo(), "myFunc() at source.go:1")
34 })
35 }
36
View as plain text