JOJ3/internal/parser/keyword/parser_test.go
张泊明518370910136 1fbc37d669
All checks were successful
submodules sync / sync (push) Successful in 59s
build / build (push) Successful in 2m16s
build / trigger-build-image (push) Successful in 6s
fix: better stage reliability (#103)
Reviewed-on: #103
Co-authored-by: Boming Zhang <bomingzh@sjtu.edu.cn>
Co-committed-by: Boming Zhang <bomingzh@sjtu.edu.cn>
2026-08-03 10:37:40 +08:00

39 lines
1.1 KiB
Go

package keyword
import (
"strings"
"testing"
"github.com/joint-online-judge/JOJ3/internal/stage"
)
func TestRunCountsCapsAndOrdersKeywords(t *testing.T) {
results, forceQuit, err := (&Keyword{}).Run([]stage.ExecutorResult{{
Files: map[string]string{"log": "error error warning"},
}}, map[string]any{
"score": 10,
"files": []any{"log"},
"forceQuitOnDeduct": true,
"matches": []any{
map[string]any{"keywords": []any{"error"}, "score": 3, "maxMatchCount": 1},
map[string]any{"keywords": []any{"warning"}, "score": 2},
},
})
if err != nil {
t.Fatal(err)
}
if len(results) != 1 || results[0].Score != 5 || !forceQuit {
t.Fatalf("Run() = %+v, %v", results, forceQuit)
}
if !strings.Contains(results[0].Comment, "`error`: 1") || !strings.Contains(results[0].Comment, "`warning`: 1") {
t.Fatalf("comment = %q", results[0].Comment)
}
}
func TestRunRejectsInvalidConfiguration(t *testing.T) {
_, forceQuit, err := (&Keyword{}).Run(nil, "invalid")
if err == nil || !forceQuit {
t.Fatalf("Run() = forceQuit %v, error %v", forceQuit, err)
}
}