123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package language
- import (
- "flag"
- "testing"
- )
- var verbose = flag.Bool("verbose", false, "set to true to print the internal tables of matchers")
- func TestAddLikelySubtags(t *testing.T) {
- tests := []struct{ in, out string }{
- {"aa", "aa-Latn-ET"},
- {"aa-Latn", "aa-Latn-ET"},
- {"aa-Arab", "aa-Arab-ET"},
- {"aa-Arab-ER", "aa-Arab-ER"},
- {"kk", "kk-Cyrl-KZ"},
- {"kk-CN", "kk-Arab-CN"},
- {"cmn", "cmn"},
- {"zh-AU", "zh-Hant-AU"},
- {"zh-VN", "zh-Hant-VN"},
- {"zh-SG", "zh-Hans-SG"},
- {"zh-Hant", "zh-Hant-TW"},
- {"zh-Hani", "zh-Hani-CN"},
- {"und-Hani", "zh-Hani-CN"},
- {"und", "en-Latn-US"},
- {"und-GB", "en-Latn-GB"},
- {"und-CW", "pap-Latn-CW"},
- {"und-YT", "fr-Latn-YT"},
- {"und-Arab", "ar-Arab-EG"},
- {"und-AM", "hy-Armn-AM"},
- {"und-TW", "zh-Hant-TW"},
- {"und-002", "en-Latn-NG"},
- {"und-Latn-002", "en-Latn-NG"},
- {"en-Latn-002", "en-Latn-NG"},
- {"en-002", "en-Latn-NG"},
- {"en-001", "en-Latn-US"},
- {"und-003", "en-Latn-US"},
- {"und-GB", "en-Latn-GB"},
- {"Latn-001", "en-Latn-US"},
- {"en-001", "en-Latn-US"},
- {"es-419", "es-Latn-419"},
- {"he-145", "he-Hebr-IL"},
- {"ky-145", "ky-Latn-TR"},
- {"kk", "kk-Cyrl-KZ"},
-
- {"kk-034", "kk-Arab-034"},
- {"ku-145", "ku-Latn-TR"},
- {"und-Arab-CC", "ms-Arab-CC"},
- {"und-Arab-GB", "ks-Arab-GB"},
- {"und-Hans-CC", "zh-Hans-CC"},
- {"und-CC", "en-Latn-CC"},
- {"sr", "sr-Cyrl-RS"},
- {"sr-151", "sr-Latn-151"},
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {"und-Latn-BJ", "fr-Latn-BJ"},
- {"und-Bugi-ID", "bug-Bugi-ID"},
-
- {"und-Arab-AA", "ar-Arab-AA"},
- {"und-Afak-RE", "fr-Afak-RE"},
- {"und-Arab-GB", "ks-Arab-GB"},
- {"abp-Arab-GB", "abp-Arab-GB"},
-
- {"und-Arab-NL", "ar-Arab-NL"},
- {"zza", "zza-Latn-TR"},
-
- {"de-1901", "de-Latn-DE-1901"},
- {"de-x-abc", "de-Latn-DE-x-abc"},
- {"de-1901-x-abc", "de-Latn-DE-1901-x-abc"},
- {"x-abc", "x-abc"},
- }
- for i, tt := range tests {
- in, _ := Parse(tt.in)
- out, _ := Parse(tt.out)
- in, _ = in.addLikelySubtags()
- if in.String() != out.String() {
- t.Errorf("%d: add(%s) was %s; want %s", i, tt.in, in, tt.out)
- }
- }
- }
- func TestMinimize(t *testing.T) {
- tests := []struct{ in, out string }{
- {"aa", "aa"},
- {"aa-Latn", "aa"},
- {"aa-Latn-ET", "aa"},
- {"aa-ET", "aa"},
- {"aa-Arab", "aa-Arab"},
- {"aa-Arab-ER", "aa-Arab-ER"},
- {"aa-Arab-ET", "aa-Arab"},
- {"und", "und"},
- {"und-Latn", "und"},
- {"und-Latn-US", "und"},
- {"en-Latn-US", "en"},
- {"cmn", "cmn"},
- {"cmn-Hans", "cmn-Hans"},
- {"cmn-Hant", "cmn-Hant"},
- {"zh-AU", "zh-AU"},
- {"zh-VN", "zh-VN"},
- {"zh-SG", "zh-SG"},
- {"zh-Hant", "zh-Hant"},
- {"zh-Hant-TW", "zh-TW"},
- {"zh-Hans", "zh"},
- {"zh-Hani", "zh-Hani"},
- {"und-Hans", "und-Hans"},
- {"und-Hani", "und-Hani"},
- {"und-CW", "und-CW"},
- {"und-YT", "und-YT"},
- {"und-Arab", "und-Arab"},
- {"und-AM", "und-AM"},
- {"und-Arab-CC", "und-Arab-CC"},
- {"und-CC", "und-CC"},
- {"und-Latn-BJ", "und-BJ"},
- {"und-Bugi-ID", "und-Bugi"},
- {"bug-Bugi-ID", "bug-Bugi"},
-
- {"und-Arab-AA", "und-Arab-AA"},
-
- {"de-Latn-1901", "de-1901"},
- {"de-Latn-x-abc", "de-x-abc"},
- {"de-DE-1901-x-abc", "de-1901-x-abc"},
- {"x-abc", "x-abc"},
- }
- for i, tt := range tests {
- in, _ := Parse(tt.in)
- out, _ := Parse(tt.out)
- min, _ := in.minimize()
- if min.String() != out.String() {
- t.Errorf("%d: min(%s) was %s; want %s", i, tt.in, min, tt.out)
- }
- max, _ := min.addLikelySubtags()
- if x, _ := in.addLikelySubtags(); x.String() != max.String() {
- t.Errorf("%d: max(min(%s)) = %s; want %s", i, tt.in, max, x)
- }
- }
- }
|