You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
|
1 week ago
|
package pathrule_test
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
"unicode/utf8"
|
||
|
|
|
||
|
|
"g.activething.com/go/DateKeys/internal/pathrule"
|
||
|
|
"g.activething.com/go/DateKeys/internal/testkit"
|
||
|
|
)
|
||
|
|
|
||
|
|
// FuzzCheckPath: the rules of one entry and the decoder of the head agree on
|
||
|
|
// every path: a head that holds it alone decodes exactly when the path is
|
||
|
|
// valid UTF-8 of 1 to 1024 bytes (R1, layer 3) that CheckPath accepts, since
|
||
|
|
// one path collides with none and makes at most 31 folders (spec §29.5).
|
||
|
|
func FuzzCheckPath(f *testing.F) {
|
||
|
|
var paths testkit.PathVectorFile
|
||
|
|
if err := testkit.ReadJSON("../../testdata/vectors/paths.json", &paths); err != nil {
|
||
|
|
f.Fatal(err)
|
||
|
|
}
|
||
|
|
for _, v := range paths.Paths {
|
||
|
|
f.Add(v.Path)
|
||
|
|
}
|
||
|
|
f.Fuzz(func(t *testing.T, p string) {
|
||
|
|
err := pathrule.CheckPath(p)
|
||
|
|
var e *pathrule.Error
|
||
|
|
if err != nil && !errors.As(err, &e) {
|
||
|
|
t.Fatalf("an error that is not a pathrule.Error: %v", err)
|
||
|
|
}
|
||
|
|
valid := err == nil && utf8.ValidString(p) && len(p) >= 1 && len(p) <= pathrule.MaxPathLen
|
||
|
|
head, merr := testkit.TreeHead([]string{p})
|
||
|
|
if merr != nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if got, _ := testkit.HeadResult(head); (got == testkit.ResultOK) != valid {
|
||
|
|
t.Fatalf("path %+q: CheckPath %v, the head decodes to %s", p, err, got)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|