language: fixed test breakage
Missed some adjustments in the move from en-US-x-posix to
en-US-u-va-posix.
Fixes #12987.
Change-Id: Ie422598c955359556b4d0d244062b0bf267c022c
Reviewed-on: https://go-review.googlesource.com/16011
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/internal/gen_test.go b/internal/gen_test.go
index d2e1265..01f015c 100644
--- a/internal/gen_test.go
+++ b/internal/gen_test.go
@@ -19,7 +19,7 @@
{"en-001", "en"},
{"en-AU", "en-001"},
{"en-US", "en"},
- {"en-US-x-posix", "en-US"},
+ {"en-US-u-va-posix", "en-US"},
{"ca-ES-valencia", "ca"}, // ca-ES has no data.
}
for _, tc := range testCases {
diff --git a/language/language.go b/language/language.go
index 3352cd6..548a9ae 100644
--- a/language/language.go
+++ b/language/language.go
@@ -691,26 +691,33 @@
// CompactIndex returns an index, where 0 <= index < NumCompactTags, for tags
// for which data exists in the text repository. The index will change over time
-// and should not be stored in persistent storage. Extensions other than 'x' are
-// not considered for determining the index. It will return 0, false if no
+// and should not be stored in persistent storage. Extensions, except for the
+// 'va' type of the 'u' extension, are ignored. It will return 0, false if no
// compact tag exists, where 0 is the index for the root language (Und).
func CompactIndex(t Tag) (index int, ok bool) {
// TODO: perhaps give more frequent tags a lower index.
// TODO: we could make the indexes stable. This will excluded some
// possibilities for optimization, so don't do this quite yet.
+ b, s, r := t.Raw()
if len(t.str) > 0 {
- // We have variants or extensions.
- if x, ok := t.Extension('x'); ok || uint16(t.pVariant) != t.pExt {
- // Strip all but variants and the x extension.
- if uint16(t.pVariant) != t.pExt {
- b, s, r := t.Raw()
- if ok {
- t, _ = Raw.Compose(b, s, r, t.Variants(), x)
- } else {
- t, _ = Raw.Compose(b, s, r, t.Variants())
- }
+ if strings.HasPrefix(t.str, "x-") {
+ // We have no entries for user-defined tags.
+ return 0, false
+ }
+ if uint16(t.pVariant) != t.pExt {
+ // There are no tags with variants and an u-va type.
+ if t.TypeForKey("va") != "" {
+ return 0, false
}
- // We have variants or an x extension.
+ t, _ = Raw.Compose(b, s, r, t.Variants())
+ } else if _, ok := t.Extension('u'); ok {
+ // Strip all but the 'va' entry.
+ variant := t.TypeForKey("va")
+ t, _ = Raw.Compose(b, s, r)
+ t, _ = t.SetTypeForKey("va", variant)
+ }
+ if len(t.str) > 0 {
+ // We have some variants.
for i, s := range specialTags {
if s == t {
return i + 1, true
@@ -718,9 +725,8 @@
}
return 0, false
}
- // We only have non-x extensions, which we ignore, and no variants.
}
- b, s, r := t.Raw()
+ // No variants specified: just compare core components.
x, ok := coreTags[coreKey{base: b, script: s, region: r}]
return int(x), ok
}
diff --git a/language/language_test.go b/language/language_test.go
index f8bd20f..dcf7207 100644
--- a/language/language_test.go
+++ b/language/language_test.go
@@ -85,12 +85,12 @@
// will be solved if we decide to fix the indexes.
{"und", 0, true},
{"ca-ES-valencia", 1, true},
- {"ca-ES-valencia-x-posix", 0, false},
+ {"ca-ES-valencia-u-va-posix", 0, false},
{"ca-ES-valencia-u-co-phonebk", 1, true},
- {"ca-ES-valencia-u-co-phonebk-x-posix", 0, false},
+ {"ca-ES-valencia-u-co-phonebk-va-posix", 0, false},
{"x-klingon", 0, false},
{"en-US", 140, true},
- {"en-US-x-posix", 2, true},
+ {"en-US-u-va-posix", 2, true},
{"en", 65, true},
{"en-u-co-phonebk", 65, true},
{"en-001", 66, true},