Skip to content

Commit

Permalink
modfile: remove end-of-line comments in removeLine
Browse files Browse the repository at this point in the history
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 <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
  • Loading branch information
Bryan C. Mills committed May 27, 2021
1 parent 6088ed8 commit e953053
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions modfile/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (x *FileSyntax) updateLine(line *Line, tokens ...string) {

func (x *FileSyntax) removeLine(line *Line) {
line.Token = nil
line.Comments.Suffix = nil
}

// Cleanup cleans up the file syntax x after any edit operations.
Expand Down
30 changes: 29 additions & 1 deletion modfile/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ var addRequireTests = []struct {
require x.y/z v1.5.6
`,
},
{
`existing2`,
`
module m
require (
x.y/z v1.2.3 // first
x.z/a v0.1.0 // first-a
)
require x.y/z v1.4.5 // second
require (
x.y/z v1.6.7 // third
x.z/a v0.2.0 // third-a
)
`,
"x.y/z", "v1.8.9",
`
module m
require (
x.y/z v1.8.9 // first
x.z/a v0.1.0 // first-a
)
require x.z/a v0.2.0 // third-a
`,
},
{
`new`,
`
Expand Down Expand Up @@ -892,7 +918,9 @@ func TestAddRequire(t *testing.T) {
for _, tt := range addRequireTests {
t.Run(tt.desc, func(t *testing.T) {
testEdit(t, tt.in, tt.out, true, func(f *File) error {
return f.AddRequire(tt.path, tt.vers)
err := f.AddRequire(tt.path, tt.vers)
f.Cleanup()
return err
})
})
}
Expand Down

0 comments on commit e953053

Please sign in to comment.