MCPcopy
hub / github.com/rs/xid / TestFromStringQuick

Function TestFromStringQuick

id_test.go:278–303  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

276}
277
278func TestFromStringQuick(t *testing.T) {
279 f := func(id1 ID, c byte) bool {
280 s1 := id1.String()
281 for i := range s1 {
282 s2 := []byte(s1)
283 s2[i] = c
284 id2, err := FromString(string(s2))
285 if id1 == id2 && err == nil && c != s1[i] {
286 t.Logf("comparing XIDs:\na: %q\nb: %q (index %d changed to %c)", s1, s2, i, c)
287 return false
288 }
289 }
290 return true
291 }
292 err := quick.Check(f, &quick.Config{
293 Values: func(args []reflect.Value, r *rand.Rand) {
294 i := r.Intn(len(encoding))
295 args[0] = reflect.ValueOf(New())
296 args[1] = reflect.ValueOf(byte(encoding[i]))
297 },
298 MaxCount: 1000,
299 })
300 if err != nil {
301 t.Error(err)
302 }
303}
304
305func TestFromStringQuickInvalidChars(t *testing.T) {
306 f := func(id1 ID, c byte) bool {

Callers

nothing calls this directly

Calls 4

FromStringFunction · 0.85
NewFunction · 0.85
StringMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…