1
// Copyright 2015 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
13
var bmpStringTests = []struct {
19
// Example from https://tools.ietf.org/html/rfc7292#appendix-B.
20
{"Beavis", "0042006500610076006900730000", false},
21
// Some characters from the "Letterlike Symbols Unicode block".
22
{"\u2115 - Double-struck N", "21150020002d00200044006f00750062006c0065002d00730074007200750063006b0020004e0000", false},
23
// any character outside the BMP should trigger an error.
24
{"\U0001f000 East wind (Mahjong)", "", true},
27
func TestBMPString(t *testing.T) {
28
for i, test := range bmpStringTests {
29
expected, err := hex.DecodeString(test.expectedHex)
31
t.Fatalf("#%d: failed to decode expectation", i)
34
out, err := bmpString(test.in)
35
if err == nil && test.shouldFail {
36
t.Errorf("#%d: expected to fail, but produced %x", i, out)
40
if err != nil && !test.shouldFail {
41
t.Errorf("#%d: failed unexpectedly: %s", i, err)
46
if !bytes.Equal(out, expected) {
47
t.Errorf("#%d: expected %s, got %x", i, test.expectedHex, out)
51
roundTrip, err := decodeBMPString(out)
53
t.Errorf("#%d: decoding output gave an error: %s", i, err)
57
if roundTrip != test.in {
58
t.Errorf("#%d: decoding output resulted in %q, but it should have been %q", i, roundTrip, test.in)