...

Source file src/github.com/cespare/xxhash/v2/dynamic/plugin.go

Documentation: github.com/cespare/xxhash/v2/dynamic

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"log"
     9  	"testing"
    10  
    11  	"github.com/cespare/xxhash/v2"
    12  )
    13  
    14  const (
    15  	in   = "Call me Ishmael. Some years ago--never mind how long precisely-"
    16  	want = uint64(0x02a2e85470d6fd96)
    17  )
    18  
    19  func TestSum(t *testing.T) {
    20  	got := xxhash.Sum64String(in)
    21  	if got != want {
    22  		t.Fatalf("Sum64String: got 0x%x; want 0x%x", got, want)
    23  	}
    24  }
    25  
    26  func TestDigest(t *testing.T) {
    27  	for chunkSize := 1; chunkSize <= len(in); chunkSize++ {
    28  		name := fmt.Sprintf("[chunkSize=%d]", chunkSize)
    29  		t.Run(name, func(t *testing.T) {
    30  			d := xxhash.New()
    31  			for i := 0; i < len(in); i += chunkSize {
    32  				chunk := in[i:]
    33  				if len(chunk) > chunkSize {
    34  					chunk = chunk[:chunkSize]
    35  				}
    36  				n, err := d.WriteString(chunk)
    37  				if err != nil || n != len(chunk) {
    38  					t.Fatalf("Digest.WriteString: got (%d, %v); want (%d, nil)",
    39  						n, err, len(chunk))
    40  				}
    41  			}
    42  			if got := d.Sum64(); got != want {
    43  				log.Fatalf("Digest.Sum64: got 0x%x; want 0x%x", got, want)
    44  			}
    45  		})
    46  	}
    47  }
    48  

View as plain text