Example returns a random example value.
(r *ExampleGenerator)
| 576 | |
| 577 | // Example returns a random example value. |
| 578 | func (m *Map) Example(r *ExampleGenerator) any { |
| 579 | if IsObject(m.KeyType.Type) || IsArray(m.KeyType.Type) || IsMap(m.KeyType.Type) { |
| 580 | // not much we can do for non hashable Go types |
| 581 | return nil |
| 582 | } |
| 583 | count := r.Int()%3 + 1 |
| 584 | pair := map[any]any{} |
| 585 | for range count { |
| 586 | k := m.KeyType.Example(r) |
| 587 | v := m.ElemType.Example(r) |
| 588 | if k != nil && v != nil { |
| 589 | pair[k] = v |
| 590 | } |
| 591 | } |
| 592 | return m.MakeMap(pair) |
| 593 | } |
| 594 | |
| 595 | // MakeMap examines the key type from a Map and create a map with builtin type |
| 596 | // if possible. The idea is to avoid generating map[any]any, |