internal_test.go 813 B

1234567891011121314151617181920212223242526272829303132333435363738
  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.
  4. package internal
  5. import (
  6. "fmt"
  7. "strings"
  8. "testing"
  9. "golang.org/x/text/language"
  10. )
  11. func TestUnique(t *testing.T) {
  12. testCases := []struct {
  13. in, want string
  14. }{
  15. {"", "[]"},
  16. {"en", "[en]"},
  17. {"en en", "[en]"},
  18. {"en en en", "[en]"},
  19. {"en-u-cu-eur en", "[en en-u-cu-eur]"},
  20. {"nl en", "[en nl]"},
  21. {"pt-Pt pt", "[pt pt-PT]"},
  22. }
  23. for _, tc := range testCases {
  24. tags := []language.Tag{}
  25. for _, s := range strings.Split(tc.in, " ") {
  26. if s != "" {
  27. tags = append(tags, language.MustParse(s))
  28. }
  29. }
  30. if got := fmt.Sprint(UniqueTags(tags)); got != tc.want {
  31. t.Errorf("Unique(%s) = %s; want %s", tc.in, got, tc.want)
  32. }
  33. }
  34. }