github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/tok/langbase_test.go (about) 1 /* 2 * Copyright 2018 Dgraph Labs, Inc. and Contributors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package tok 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestLangBase(t *testing.T) { 26 tests := []struct { 27 in, out string 28 }{ 29 {in: "zh", out: "zh"}, 30 {in: "zh-hant", out: "zh"}, 31 {in: "zh-hans", out: "zh"}, 32 {in: "es-es", out: "es"}, 33 {in: "ar-001", out: "ar"}, 34 {in: "ca-ES-valencia", out: "ca"}, 35 {in: "ca-ES-valencia-u-va-posix", out: "ca"}, 36 {in: "ca-ES-valencia-u-co-phonebk", out: "ca"}, 37 {in: "ca-ES-valencia-u-co-phonebk-va-posix", out: "ca"}, 38 {in: "x-klingon", out: "en"}, 39 {in: "en-US", out: "en"}, 40 {in: "en-US-u-va-posix", out: "en"}, 41 {in: "en", out: "en"}, 42 {in: "en-u-co-phonebk", out: "en"}, 43 {in: "en-001", out: "en"}, 44 {in: "sh", out: "sr"}, 45 {in: "en-GB-u-rg-uszzzz", out: "en"}, 46 {in: "en-GB-u-rg-uszzzz-va-posix", out: "en"}, 47 {in: "en-GB-u-co-phonebk-rg-uszzzz", out: "en"}, 48 {in: "en-GB-u-co-phonebk-rg-uszz", out: "en"}, 49 {in: "", out: "en"}, 50 {in: "no_such_language", out: "en"}, 51 {in: "xxx_such_language", out: "en"}, 52 } 53 54 var out string 55 for _, tc := range tests { 56 out = langBase(tc.in) 57 require.Equal(t, tc.out, out) 58 } 59 }