...
1# Elementary test of each analyzer in the "go fix" suite.
2# This is simply to prove that they are running at all;
3# detailed behavior is tested in x/tools.
4#
5# Each assertion matches the expected diff.
6#
7# Tip: to see the actual stdout,
8# temporarily prefix the go command with "! ".
9
10go fix -diff example.com/x
11
12# buildtag
13stdout '-// \+build go1.26'
14
15# hostport
16stdout 'net.Dial.*net.JoinHostPort'
17
18# inline
19stdout 'var three = 1 \+ 2'
20
21# newexpr (proxy for whole modernize suite)
22stdout 'var _ = new\(123\)'
23
24-- go.mod --
25module example.com/x
26go 1.26
27
28-- x.go --
29//go:build go1.26
30// +build go1.26
31
32// β buildtag
33
34package x
35
36import (
37 "fmt"
38 "net"
39)
40
41// hostport
42var s string
43var _, _ = net.Dial("tcp", fmt.Sprintf("%s:%d", s, 80))
44
45//go:fix inline
46func add(x, y int) int { return x + y }
47
48// inline
49var three = add(1, 2)
50
51// newexpr
52func varOf(x int) *int { return &x }
53var _ = varOf(123)
View as plain text