From 8c5c8bf35bc4edd59e0e50a159ac67f34091402a Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Fri, 11 Oct 2024 00:16:39 -0400 Subject: [PATCH] feat(parser/diff)!: use compare space --- internal/parser/diff/parser.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/parser/diff/parser.go b/internal/parser/diff/parser.go index 7faf1c2..d5df1a2 100644 --- a/internal/parser/diff/parser.go +++ b/internal/parser/diff/parser.go @@ -24,11 +24,11 @@ type Conf struct { Cases []struct { IgnoreResultStatus bool Outputs []struct { - Score int - FileName string - AnswerPath string - IgnoreWhitespace bool `default:"true"` - AlwaysHide bool + Score int + FileName string + AnswerPath string + CompareSpace bool + AlwaysHide bool } } } @@ -70,7 +70,7 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) ( "answer", string(answer)) // If no difference, assign score if compareChars(string(answer), result.Files[output.FileName], - output.IgnoreWhitespace) { + output.CompareSpace) { score += output.Score } else { 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. -func compareChars(stdout, result string, ignoreWhitespace bool) bool { - if ignoreWhitespace { - stdout = removeWhitespace(stdout) - result = removeWhitespace(result) +func compareChars(stdout, result string, compareSpace bool) bool { + if !compareSpace { + stdout = removeSpace(stdout) + result = removeSpace(result) } return stdout == result } -// removeWhitespace removes all whitespace characters from the string. -func removeWhitespace(s string) string { +// removeSpace removes all whitespace characters from the string. +func removeSpace(s string) string { var b strings.Builder for _, r := range s { if !unicode.IsSpace(r) {