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") } }