utf_test.go 515 B

123456789101112131415161718192021222324
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package dns
  4. import "testing"
  5. func TestMaybeUnUTF16(t *testing.T) {
  6. tests := []struct {
  7. in string
  8. want string
  9. }{
  10. {"abc", "abc"}, // UTF-8
  11. {"a\x00b\x00c\x00", "abc"}, // UTF-16-LE
  12. {"\x00a\x00b\x00c", "abc"}, // UTF-16-BE
  13. }
  14. for _, test := range tests {
  15. got := string(maybeUnUTF16([]byte(test.in)))
  16. if got != test.want {
  17. t.Errorf("maybeUnUTF16(%q) = %q, want %q", test.in, got, test.want)
  18. }
  19. }
  20. }