feat(parser/diff): option to hide common prefix
All checks were successful
submodules sync / sync (push) Successful in 56s
build / build (push) Successful in 2m24s
build / trigger-build-image (push) Successful in 12s

This commit is contained in:
张泊明518370910136 2025-03-30 00:28:23 -04:00
parent 7f7eead5f7
commit ab41926fc0
GPG Key ID: D47306D7062CDA9D
2 changed files with 33 additions and 9 deletions

View File

@ -14,14 +14,15 @@ type Conf struct {
ForceQuitOnFailed bool `default:"false"`
Cases []struct {
Outputs []struct {
Score int
FileName string
AnswerPath string
CompareSpace bool
AlwaysHide bool
ForceQuitOnDiff bool
MaxDiffLength int `default:"2048"` // just for reference
MaxDiffLines int `default:"50"` // just for reference
Score int
FileName string
AnswerPath string
CompareSpace bool
AlwaysHide bool
ForceQuitOnDiff bool
MaxDiffLength int `default:"2048"` // just for reference
MaxDiffLines int `default:"50"` // just for reference
HideCommonPrefix bool
}
}
}

View File

@ -85,6 +85,23 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
}
answerLines := strings.Split(answerStr, "\n")
resultLines := strings.Split(resultStr, "\n")
commonPreixLineCount := 0
if output.HideCommonPrefix {
n := 0
for ; n < len(answerLines) &&
n < len(resultLines) &&
stringsEqual(
answerLines[n],
resultLines[n],
output.CompareSpace,
); n += 1 {
}
if n > 0 {
answerLines = answerLines[n:]
resultLines = resultLines[n:]
commonPreixLineCount = n
}
}
if len(answerLines) > output.MaxDiffLines {
answerLines = answerLines[:output.MaxDiffLines]
truncated = true
@ -104,12 +121,18 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
if truncated {
diffOutput += "\n\n(truncated)"
}
if commonPreixLineCount > 0 {
diffOutput = fmt.Sprintf(
"(%d line(s) of common prefix hidden)\n\n",
commonPreixLineCount,
) + diffOutput
}
comment += fmt.Sprintf(
"```diff\n%s\n```\n",
diffOutput,
)
} else {
comment += "(Content hidden.)\n"
comment += "(content hidden)\n"
}
}
}