12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package shared
- import (
- "testing"
- "github.com/stretchr/testify/assert"
- )
- func TestDecodeEntities(t *testing.T) {
- tests := []struct {
- str string
- res string
- }{
- {"", ""},
- {"foo", "foo"},
- {"<foo>", "<foo>"},
- {"a "b" 'c'", "a \"b\" 'c'"},
- {"foo && bar", "foo && bar"},
- {""foo"", "\"foo\""},
- {"abc", "abc"},
- {"résumé", "résumé"},
- }
- for _, test := range tests {
- res, err := DecodeEntities(test.str)
- assert.Nil(t, err, "cannot decode %q", test.str)
- assert.Equal(t, res, test.res,
- "%q was decoded to %q instead of %q",
- test.str, res, test.res)
- }
- }
- func TestDecodeEntitiesInvalid(t *testing.T) {
- tests := []string{
- // Predefined entities
- "&", // truncated
- "&foo", // truncated
- "&foo;", // unknown
- "<", // known but truncated
- // Numerical character references
- "&#", // truncated
- "&#;", // missing number
- "&#x;", // missing hexadecimal number
- "a;", // invalid decimal number
- "oo;", // invalid hexadecimal number
- }
- for _, test := range tests {
- res, err := DecodeEntities(test)
- assert.NotNil(t, err, "%q was decoded to %q", test, res)
- }
- }
|