Source file
src/html/entity_test.go
1
2
3
4
5 package html
6
7 import (
8 "testing"
9 "unicode/utf8"
10 )
11
12 func TestEntityLength(t *testing.T) {
13 entity, entity2 := entityMaps()
14
15 if len(entity) == 0 || len(entity2) == 0 {
16 t.Fatal("maps not loaded")
17 }
18
19
20
21
22 for k, v := range entity {
23 if 1+len(k) < utf8.RuneLen(v) {
24 t.Error("escaped entity &" + k + " is shorter than its UTF-8 encoding " + string(v))
25 }
26 if len(k) > longestEntityWithoutSemicolon && k[len(k)-1] != ';' {
27 t.Errorf("entity name %s is %d characters, but longestEntityWithoutSemicolon=%d", k, len(k), longestEntityWithoutSemicolon)
28 }
29 }
30 for k, v := range entity2 {
31 if 1+len(k) < utf8.RuneLen(v[0])+utf8.RuneLen(v[1]) {
32 t.Error("escaped entity &" + k + " is shorter than its UTF-8 encoding " + string(v[0]) + string(v[1]))
33 }
34 }
35 }
36
View as plain text