JOJ3/internal/parser/keyword/parser_test.go
张泊明518370910136 e5de5b2bd6
Some checks failed
build / trigger-build-image (push) Blocked by required conditions
build / build (push) Has been cancelled
build / build (pull_request) Successful in 2m7s
build / trigger-build-image (pull_request) Has been skipped
test: expand reliability regression coverage
2026-08-02 04:28:24 -07: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)
}
}