Skip to content

Commit e953053

Browse files
author
Bryan C. Mills
committed
modfile: remove end-of-line comments in removeLine
I added this test case while updating documentation for golang/go#45965, and it failed. This CL fixes the behavior, and the next CL in the stack documents it. For golang/go#45965 Change-Id: Ia68dbd33530eec138745c6e291b096a9fa1e1d58 Reviewed-on: https://go-review.googlesource.com/c/mod/+/323170 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 6088ed8 commit e953053

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

modfile/read.go

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func (x *FileSyntax) updateLine(line *Line, tokens ...string) {
196196

197197
func (x *FileSyntax) removeLine(line *Line) {
198198
line.Token = nil
199+
line.Comments.Suffix = nil
199200
}
200201

201202
// Cleanup cleans up the file syntax x after any edit operations.

modfile/rule_test.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@ var addRequireTests = []struct {
3232
require x.y/z v1.5.6
3333
`,
3434
},
35+
{
36+
`existing2`,
37+
`
38+
module m
39+
require (
40+
x.y/z v1.2.3 // first
41+
x.z/a v0.1.0 // first-a
42+
)
43+
require x.y/z v1.4.5 // second
44+
require (
45+
x.y/z v1.6.7 // third
46+
x.z/a v0.2.0 // third-a
47+
)
48+
`,
49+
"x.y/z", "v1.8.9",
50+
`
51+
module m
52+
53+
require (
54+
x.y/z v1.8.9 // first
55+
x.z/a v0.1.0 // first-a
56+
)
57+
58+
require x.z/a v0.2.0 // third-a
59+
`,
60+
},
3561
{
3662
`new`,
3763
`
@@ -892,7 +918,9 @@ func TestAddRequire(t *testing.T) {
892918
for _, tt := range addRequireTests {
893919
t.Run(tt.desc, func(t *testing.T) {
894920
testEdit(t, tt.in, tt.out, true, func(f *File) error {
895-
return f.AddRequire(tt.path, tt.vers)
921+
err := f.AddRequire(tt.path, tt.vers)
922+
f.Cleanup()
923+
return err
896924
})
897925
})
898926
}

0 commit comments

Comments
 (0)