feat(parser/diff)!: use compare space
This commit is contained in:
parent
3882a311e7
commit
8c5c8bf35b
|
@ -27,7 +27,7 @@ type Conf struct {
|
||||||
Score int
|
Score int
|
||||||
FileName string
|
FileName string
|
||||||
AnswerPath string
|
AnswerPath string
|
||||||
IgnoreWhitespace bool `default:"true"`
|
CompareSpace bool
|
||||||
AlwaysHide bool
|
AlwaysHide bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
"answer", string(answer))
|
"answer", string(answer))
|
||||||
// If no difference, assign score
|
// If no difference, assign score
|
||||||
if compareChars(string(answer), result.Files[output.FileName],
|
if compareChars(string(answer), result.Files[output.FileName],
|
||||||
output.IgnoreWhitespace) {
|
output.CompareSpace) {
|
||||||
score += output.Score
|
score += output.Score
|
||||||
} else {
|
} else {
|
||||||
comment += fmt.Sprintf("Difference found in `%s`.\n",
|
comment += fmt.Sprintf("Difference found in `%s`.\n",
|
||||||
|
@ -106,16 +106,16 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// compareChars compares two strings character by character, optionally ignoring whitespace.
|
// compareChars compares two strings character by character, optionally ignoring whitespace.
|
||||||
func compareChars(stdout, result string, ignoreWhitespace bool) bool {
|
func compareChars(stdout, result string, compareSpace bool) bool {
|
||||||
if ignoreWhitespace {
|
if !compareSpace {
|
||||||
stdout = removeWhitespace(stdout)
|
stdout = removeSpace(stdout)
|
||||||
result = removeWhitespace(result)
|
result = removeSpace(result)
|
||||||
}
|
}
|
||||||
return stdout == result
|
return stdout == result
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeWhitespace removes all whitespace characters from the string.
|
// removeSpace removes all whitespace characters from the string.
|
||||||
func removeWhitespace(s string) string {
|
func removeSpace(s string) string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
if !unicode.IsSpace(r) {
|
if !unicode.IsSpace(r) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user