Files
polaris/vendor/gitlab.com/golang-commonmark/html/html_test.go
Bobby Brennan 2c1c4c2cca add new deps
2019-05-08 14:54:06 +00:00

109 lines
2.4 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright 2015 The 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"
)
var parseEntityTests = []struct {
in string
length int
str string
}{
{in: "&;"},
{in: "&"},
{in: "&@;"},
{in: "&@"},
{in: "&#;"},
{in: "&#"},
{in: "&##;"},
{in: "&##"},
{in: "&#0"},
{in: "&#09"},
{in: "&#0a;"},
{in: "&#0a"},
{in: """, length: 5, str: `"`},
{in: "�", length: 11, str: BadEntity},
{in: "	", length: 4, str: "\t"},
{in: "&ffffffffffffffffuuuuuuuuuuuuuuuu;"},
{in: "&ffffffffffffffffuuuuuuuuuuuuuuuu"},
{in: "&q;"},
{in: "&q"},
{in: "&q#;"},
{in: "&q#"},
{in: "&Q"},
{in: "&q0;"},
{in: "&q0"},
{in: "&qu;"},
{in: "&qu"},
{in: """, length: 6, str: `"`},
{in: "&#x;"},
{in: "&#x"},
{in: "&#X;"},
{in: "&#X"},
{in: "&#x0"},
{in: "&#x0@;"},
{in: "&#x0@"},
{in: "&#X0"},
{in: ""},
{in: "&#x000000001"},
{in: "&#x09"},
{in: "	", length: 6, str: "\t"},
{in: "	", length: 6, str: "\t"},
{in: "
", length: 6, str: "\n"},
{in: "
", length: 6, str: "\n"},
{in: "
", length: 6, str: "\n"},
{in: "
", length: 6, str: "\n"},
{in: """, length: 6, str: `"`},
{in: "�", length: 12, str: BadEntity},
{in: "&#xa"},
{in: "&#xA"},
{in: "&#Xa"},
{in: "&#XA"},
{in: "&#xffffffff"},
{in: "&#xfffffffff"},
{in: "�", length: 12, str: BadEntity},
{in: "&#xG;"},
{in: "&#xG"},
{in: "&#XG;"},
{in: "&#XG"},
}
var replaceEntitiesTests = []struct {
in string
out string // empty means == in
}{
{"", ""},
{"a b c d e f g h i j k l m n o p q r s t u v w x y z", ""},
{"&", ""},
{"  & © "", `  & © "`},
{"" " "", `" " "`},
{"&x; &#; &#x; &ThisIsWayTooLongToBeAnEntityIsntIt; &hi?; &copy &MadeUpEntity;", ""},
}
func TestParseEntity(t *testing.T) {
for _, tc := range parseEntityTests {
str, length := ParseEntity(tc.in)
if str != tc.str || length != tc.length {
t.Errorf("ParseEntity(%q): want %d,%q, got %d,%q", tc.in,
tc.length, tc.str, length, str)
}
}
}
func TestUnescapeString(t *testing.T) {
for _, tc := range replaceEntitiesTests {
got := UnescapeString(tc.in)
want := tc.out
if want == "" {
want = tc.in
}
if got != want {
t.Errorf("UnescapeString(%q): want %q, got %q", tc.in, want, got)
}
}
}