package markup
import (
"strings"
"testing"
)
type prefetchSpy struct {
fakeResolver
calls [][]string
}
func (p *prefetchSpy) PrefetchHashes(hs []string) { p.calls = append(p.calls, hs) }
// A resolver that can take a body's hashes at once is told them once,
// each once, before any is resolved.
func TestResolveRefsPrefetchesEachHashOnce(t *testing.T) {
a, b := strings.Repeat("a", 40), strings.Repeat("b", 64)
spy := &prefetchSpy{}
resolveRefs([]byte("<p>"+a+" then "+b+" and "+a+" again</p>"), spy)
if len(spy.calls) != 1 || strings.Join(spy.calls[0], ",") != a+","+b {
t.Errorf("FAIL: prefetch calls %v", spy.calls)
}
}