Skip to content

Commit

Permalink
Merge pull request #13 from bayashi/fix-beforeafter-lines-bug
Browse files Browse the repository at this point in the history
Fix beforeafter lines bug
  • Loading branch information
bayashi authored Mar 5, 2024
2 parents d9703f1 + f4faa4f commit d771f95
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ func TestRunner_OK(t *testing.T) {
5: }
`),
},
"service-c grep 56 with C2. Match 2 consecutive lines": {
opt: &options{
searchPath: "service-c",
searchGrep: "56",
contextLines: 2,
},
expect: here.Doc(`
testdata/service-c
testdata/service-c/main.go
2:
3: func main() {
4: baz := 56
5: bag := 56
6:
7: foo()
`),
},
} {
t.Run(tname, func(t *testing.T) {
var o bytes.Buffer
Expand Down
7 changes: 7 additions & 0 deletions testdata/service-c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ package c

func main() {
baz := 56
bag := 56

foo()
}

func foo() {
println("Result")
}
1 change: 1 addition & 0 deletions xfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (x *xfg) grepFile(scanner *bufio.Scanner, fPath string) ([]line, error) {
}
matchedContents = append(matchedContents, b)
}
blines = make([]line, x.options.contextLines)
}

if !x.options.noColor {
Expand Down

0 comments on commit d771f95

Please sign in to comment.