gen_test.go 923 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 compact
  5. import (
  6. "testing"
  7. "golang.org/x/text/internal/language"
  8. )
  9. func TestParents(t *testing.T) {
  10. testCases := []struct {
  11. tag, parent string
  12. }{
  13. {"af", "und"},
  14. {"en", "und"},
  15. {"en-001", "en"},
  16. {"en-AU", "en-001"},
  17. {"en-US", "en"},
  18. {"en-US-u-va-posix", "en-US"},
  19. {"ca-ES-valencia", "ca-ES"},
  20. }
  21. for _, tc := range testCases {
  22. tag, ok := LanguageID(Make(language.MustParse(tc.tag)))
  23. if !ok {
  24. t.Fatalf("Could not get index of flag %s", tc.tag)
  25. }
  26. want, ok := LanguageID(Make(language.MustParse(tc.parent)))
  27. if !ok {
  28. t.Fatalf("Could not get index of parent %s of tag %s", tc.parent, tc.tag)
  29. }
  30. if got := parents[tag]; got != want {
  31. t.Errorf("Parent[%s] = %d; want %d (%s)", tc.tag, got, want, tc.parent)
  32. }
  33. }
  34. }