go-whisper-api/config/punctuation_test.go
admin b5c083e06f
Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
first commit
2026-06-04 18:10:52 +07:00

59 lines
1.5 KiB
Go

package config
import (
"net/http/httptest"
"testing"
)
func TestPunctuation_Active(t *testing.T) {
if (Punctuation{Enabled: false, Engine: "heuristic"}).Active() {
t.Fatal("disabled should be inactive")
}
if (Punctuation{Enabled: true, Engine: "off"}).Active() {
t.Fatal("engine off should be inactive")
}
if !(Punctuation{Enabled: true, Engine: "heuristic"}).Active() {
t.Fatal("enabled heuristic should be active")
}
}
func TestPunctuation_ShouldApplyAPI(t *testing.T) {
p := Punctuation{Enabled: true, Engine: "heuristic"}
req := httptest.NewRequest("GET", "/?punctuation=1", nil)
if !p.ShouldApplyAPI(req, false) {
t.Fatal("query 1 should enable")
}
req = httptest.NewRequest("GET", "/?punctuation=0", nil)
if p.ShouldApplyAPI(req, true) {
t.Fatal("query 0 should disable")
}
req = httptest.NewRequest("GET", "/", nil)
if !p.ShouldApplyAPI(req, false) {
t.Fatal("enabled in config => apply when query omitted")
}
if !p.ShouldApplyAPI(req, true) {
t.Fatal("api default true")
}
off := Punctuation{Enabled: false, Engine: "heuristic"}
if off.ShouldApplyAPI(req, true) {
t.Fatal("master disabled must never apply")
}
}
func TestParsePunctuationQuery(t *testing.T) {
if !parsePunctuationQuery("1", false) {
t.Fatal("1 => true")
}
if parsePunctuationQuery("0", true) {
t.Fatal("0 => false")
}
if !parsePunctuationQuery("", true) {
t.Fatal("empty => default")
}
}