1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
12
func TestKnown(t *testing.T) {
13
for _, s := range testAtomList {
14
if atom := Lookup([]byte(s)); atom.String() != s {
15
t.Errorf("Lookup(%q) = %#x (%q)", s, uint32(atom), atom.String())
20
func TestHits(t *testing.T) {
21
for _, a := range table {
25
got := Lookup([]byte(a.String()))
27
t.Errorf("Lookup(%q) = %#x, want %#x", a.String(), uint32(got), uint32(a))
32
func TestMisses(t *testing.T) {
33
testCases := []string{
57
// The following string has the same hash (0xa1d7fab7) as "onmouseover".
58
"\x00\x00\x00\x00\x00\x50\x18\xae\x38\xd0\xb7",
60
for _, tc := range testCases {
61
got := Lookup([]byte(tc))
63
t.Errorf("Lookup(%q): got %d, want 0", tc, got)
68
func TestForeignObject(t *testing.T) {
75
if got := Lookup([]byte(sfo)); got != afo {
76
t.Errorf("Lookup(%q): got %#v, want %#v", sfo, got, afo)
78
if got := Lookup([]byte(sfO)); got != afO {
79
t.Errorf("Lookup(%q): got %#v, want %#v", sfO, got, afO)
81
if got := afo.String(); got != sfo {
82
t.Errorf("Atom(%#v).String(): got %q, want %q", afo, got, sfo)
84
if got := afO.String(); got != sfO {
85
t.Errorf("Atom(%#v).String(): got %q, want %q", afO, got, sfO)
89
func BenchmarkLookup(b *testing.B) {
90
sortedTable := make([]string, 0, len(table))
91
for _, a := range table {
93
sortedTable = append(sortedTable, a.String())
96
sort.Strings(sortedTable)
98
x := make([][]byte, 1000)
100
x[i] = []byte(sortedTable[i%len(sortedTable)])
104
for i := 0; i < b.N; i++ {
105
for _, s := range x {