mirror of
https://github.com/golang/net.git
synced 2026-03-31 02:17:08 +09:00
sub-repo. It's a straight copy, except for these modifications: * "exp/html" and "exp/html/atom" imports were renamed, and * the "TODO... When this package moves out of exp" comment was deleted from atom/atom.go. The matching change is at https://golang.org/cl/7317043 The rationale was discussed at https://groups.google.com/d/topic/golang-nuts/Qq5hTQyPuLg/discussion R=adg, remyoudompheng, dave CC=golang-dev https://golang.org/cl/7310063
30 lines
1022 B
Go
30 lines
1022 B
Go
// Copyright 2010 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package html
|
|
|
|
import (
|
|
"testing"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
func TestEntityLength(t *testing.T) {
|
|
// We verify that the length of UTF-8 encoding of each value is <= 1 + len(key).
|
|
// The +1 comes from the leading "&". This property implies that the length of
|
|
// unescaped text is <= the length of escaped text.
|
|
for k, v := range entity {
|
|
if 1+len(k) < utf8.RuneLen(v) {
|
|
t.Error("escaped entity &" + k + " is shorter than its UTF-8 encoding " + string(v))
|
|
}
|
|
if len(k) > longestEntityWithoutSemicolon && k[len(k)-1] != ';' {
|
|
t.Errorf("entity name %s is %d characters, but longestEntityWithoutSemicolon=%d", k, len(k), longestEntityWithoutSemicolon)
|
|
}
|
|
}
|
|
for k, v := range entity2 {
|
|
if 1+len(k) < utf8.RuneLen(v[0])+utf8.RuneLen(v[1]) {
|
|
t.Error("escaped entity &" + k + " is shorter than its UTF-8 encoding " + string(v[0]) + string(v[1]))
|
|
}
|
|
}
|
|
}
|