fix(parser/diff): try n-1
All checks were successful
submodules sync / sync (push) Successful in 1m41s
build / build (push) Successful in 4m15s
build / trigger-build-image (push) Successful in 25s

This commit is contained in:
张泊明518370910136 2025-07-15 09:22:24 -07:00
parent 787aa0e0e8
commit c3ba14d321

View File

@ -85,7 +85,7 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
} }
answerLines := strings.Split(answerStr, "\n") answerLines := strings.Split(answerStr, "\n")
resultLines := strings.Split(resultStr, "\n") resultLines := strings.Split(resultStr, "\n")
commonPreixLineCount := 0 commonPrefixLineCount := 0
if output.HideCommonPrefix { if output.HideCommonPrefix {
n := 0 n := 0
for ; n < len(answerLines) && for ; n < len(answerLines) &&
@ -97,9 +97,9 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
); n += 1 { ); n += 1 {
} }
if n > 0 { if n > 0 {
answerLines = answerLines[n:] answerLines = answerLines[n-1:]
resultLines = resultLines[n:] resultLines = resultLines[n-1:]
commonPreixLineCount = n commonPrefixLineCount = n
} }
} }
if len(answerLines) > output.MaxDiffLines { if len(answerLines) > output.MaxDiffLines {
@ -121,10 +121,10 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
if truncated { if truncated {
diffOutput += "\n\n(truncated)" diffOutput += "\n\n(truncated)"
} }
if commonPreixLineCount > 0 { if commonPrefixLineCount > 0 {
diffOutput = fmt.Sprintf( diffOutput = fmt.Sprintf(
"(%d line(s) of common prefix hidden)\n\n", "(%d line(s) of common prefix hidden)\n\n",
commonPreixLineCount, commonPrefixLineCount,
) + diffOutput ) + diffOutput
} }
comment += fmt.Sprintf( comment += fmt.Sprintf(