feat(parser/diff): option to hide common prefix
This commit is contained in:
parent
7f7eead5f7
commit
ab41926fc0
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user