github.com/elves/elvish@v0.15.0/pkg/eval/vals/hash_test.go (about) 1 package vals 2 3 import ( 4 "math" 5 "os" 6 "testing" 7 8 . "github.com/elves/elvish/pkg/tt" 9 "github.com/xiaq/persistent/hash" 10 ) 11 12 type hasher struct{} 13 14 func (hasher) Hash() uint32 { return 42 } 15 16 type nonHasher struct{} 17 18 func TestHash(t *testing.T) { 19 Test(t, Fn("Hash", Hash), Table{ 20 Args(false).Rets(uint32(0)), 21 Args(true).Rets(uint32(1)), 22 Args(1.0).Rets(hash.UInt64(math.Float64bits(1.0))), 23 Args("foo").Rets(hash.String("foo")), 24 Args(os.Stdin).Rets(hash.UIntPtr(os.Stdin.Fd())), 25 Args(MakeList("foo", "bar")).Rets(hash.DJB(Hash("foo"), Hash("bar"))), 26 Args(MakeMap("foo", "bar")). 27 Rets(hash.DJB(Hash("foo"), Hash("bar"))), 28 Args(hasher{}).Rets(uint32(42)), 29 Args(nonHasher{}).Rets(uint32(0)), 30 }) 31 }