initial commit

This commit is contained in:
2026-08-16 21:18:45 -05:00
commit 1e05a01bcf
122 changed files with 29178 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
package web
import (
"net/http/httptest"
"net/url"
"strings"
"testing"
)
func TestFormBool(t *testing.T) {
tests := []struct {
name string
values url.Values
want bool
}{
{name: "missing", values: url.Values{}, want: false},
{name: "hidden unchecked value", values: url.Values{"enabled": {"false"}}, want: false},
{name: "hidden and checked values", values: url.Values{"enabled": {"false", "true"}}, want: true},
{name: "checked value first", values: url.Values{"enabled": {"true", "false"}}, want: true},
{name: "browser checkbox value", values: url.Values{"enabled": {"on"}}, want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
body := tt.values.Encode()
req := httptest.NewRequest("POST", "/", strings.NewReader(body))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
if got := formBool(req, "enabled"); got != tt.want {
t.Fatalf("formBool() = %t, want %t for %q", got, tt.want, body)
}
})
}
}