OLD | NEW |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package atom | 5 package atom |
6 | 6 |
7 import ( | 7 import ( |
8 "sort" | 8 "sort" |
9 "testing" | 9 "testing" |
10 ) | 10 ) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 "\x00\x00\x00\x00\x00\x50\x18\xae\x38\xd0\xb7", | 58 "\x00\x00\x00\x00\x00\x50\x18\xae\x38\xd0\xb7", |
59 } | 59 } |
60 for _, tc := range testCases { | 60 for _, tc := range testCases { |
61 got := Lookup([]byte(tc)) | 61 got := Lookup([]byte(tc)) |
62 if got != 0 { | 62 if got != 0 { |
63 t.Errorf("Lookup(%q): got %d, want 0", tc, got) | 63 t.Errorf("Lookup(%q): got %d, want 0", tc, got) |
64 } | 64 } |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
| 68 func TestForeignObject(t *testing.T) { |
| 69 const ( |
| 70 afo = Foreignobject |
| 71 afO = ForeignObject |
| 72 sfo = "foreignobject" |
| 73 sfO = "foreignObject" |
| 74 ) |
| 75 if got := Lookup([]byte(sfo)); got != afo { |
| 76 t.Errorf("Lookup(%q): got %#v, want %#v", sfo, got, afo) |
| 77 } |
| 78 if got := Lookup([]byte(sfO)); got != afO { |
| 79 t.Errorf("Lookup(%q): got %#v, want %#v", sfO, got, afO) |
| 80 } |
| 81 if got := afo.String(); got != sfo { |
| 82 t.Errorf("Atom(%#v).String(): got %q, want %q", afo, got, sfo) |
| 83 } |
| 84 if got := afO.String(); got != sfO { |
| 85 t.Errorf("Atom(%#v).String(): got %q, want %q", afO, got, sfO) |
| 86 } |
| 87 } |
| 88 |
68 func BenchmarkLookup(b *testing.B) { | 89 func BenchmarkLookup(b *testing.B) { |
69 sortedTable := make([]string, 0, len(table)) | 90 sortedTable := make([]string, 0, len(table)) |
70 for _, a := range table { | 91 for _, a := range table { |
71 if a != 0 { | 92 if a != 0 { |
72 sortedTable = append(sortedTable, a.String()) | 93 sortedTable = append(sortedTable, a.String()) |
73 } | 94 } |
74 } | 95 } |
75 sort.Strings(sortedTable) | 96 sort.Strings(sortedTable) |
76 | 97 |
77 x := make([][]byte, 1000) | 98 x := make([][]byte, 1000) |
78 for i := range x { | 99 for i := range x { |
79 x[i] = []byte(sortedTable[i%len(sortedTable)]) | 100 x[i] = []byte(sortedTable[i%len(sortedTable)]) |
80 } | 101 } |
81 | 102 |
82 b.ResetTimer() | 103 b.ResetTimer() |
83 for i := 0; i < b.N; i++ { | 104 for i := 0; i < b.N; i++ { |
84 for _, s := range x { | 105 for _, s := range x { |
85 Lookup(s) | 106 Lookup(s) |
86 } | 107 } |
87 } | 108 } |
88 } | 109 } |
OLD | NEW |