Files
validate/chars_test.go
T
claudeandClaude Sonnet 5 da971f4df5 fix incorrect and vague doc comments
Audit ahead of the README/doc.go work (issue #3):

- number.go: Min, MinFloat32, MinFloat64 all said "less than or equal to a
  given maximum" -- copy-pasted from the Max family. They check the
  minimum. Fixed.
- chars_test.go: ExampleExceptChars called Chars, not ExceptChars, so it
  never exercised the function it documents.
- chars.go: "does not contain disallowed characters" was circular.
- in.go: NotIn's parameter was named "allow"; renamed to "disallow".
- length.go: note that length is bytes (len), not runes -- the "%d
  characters" messages imply otherwise.
- url.go: spell out that ParseRequestURI wants an absolute URL or path.
- uuid.go: note lowercase-hex only, version/variant not checked.
- error.go: explain Err (the match-anything sentinel), how Error() formats
  with Data, and what With does. all.go: point at Collect.

Comments only; no behaviour change. go vet + go test ./... pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-07 13:59:59 +01:00

62 lines
1.3 KiB
Go

package validate
import (
"errors"
"fmt"
"testing"
)
func ExampleChars() {
testChars := Chars("0123456789abcdef")
fmt.Println(testChars("invalid input"))
// Output: contains disallowed characters
}
func ExampleExceptChars() {
testExceptChars := ExceptChars("0123456789abcdef")
fmt.Println(testExceptChars("invalid input"))
// Output: contains disallowed characters
}
func TestChars(t *testing.T) {
testCases := map[string]map[string]error{
"0123456789abcdef": {"abcd1234": nil, "abcd 1234": ErrDisallowedChars, "ghijklmno": ErrDisallowedChars},
}
for setup, values := range testCases {
testChars := Chars(setup)
for input, want := range values {
t.Run(input, func(t *testing.T) {
got := testChars(input)
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
}
}
}
func TestExceptChars(t *testing.T) {
testCases := map[string]map[string]error{
"0123456789abcdef": {"abcd1234": ErrDisallowedChars, "abcd 1234": ErrDisallowedChars, "ghijklmno": nil},
}
for setup, values := range testCases {
testExceptChars := ExceptChars(setup)
for input, want := range values {
t.Run(input, func(t *testing.T) {
got := testExceptChars(input)
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
}
}
}