~ubuntu-branches/ubuntu/wily/golang-x-text/wily

« back to all changes in this revision

Viewing changes to language/lookup_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-10-19 22:03:07 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20151019220307-06qbha67qp4yf5gn
Tags: 0+git20151019.0fe7e68-0ubuntu1
New upstream snapshot, resolving FTBFS with golang 1.5 and supporting
MIR of juju (see http://pad.lv/1267393).

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import (
8
8
        "strings"
9
9
        "testing"
 
10
 
 
11
        "golang.org/x/text/internal/tag"
10
12
)
11
13
 
12
 
var strdata = []string{
13
 
        "aa  ",
14
 
        "aaa ",
15
 
        "aaaa",
16
 
        "aaab",
17
 
        "aab ",
18
 
        "ab  ",
19
 
        "ba  ",
20
 
        "xxxx",
21
 
}
22
 
 
23
 
func strtests() map[string]int {
24
 
        return map[string]int{
25
 
                "    ": 0,
26
 
                "a":    0,
27
 
                "aa":   0,
28
 
                "aaa":  4,
29
 
                "aa ":  0,
30
 
                "aaaa": 8,
31
 
                "aaab": 12,
32
 
                "aaax": 16,
33
 
                "b":    24,
34
 
                "ba":   24,
35
 
                "bbbb": 28,
36
 
        }
37
 
}
38
 
 
39
 
func TestSearch(t *testing.T) {
40
 
        for k, v := range strtests() {
41
 
                if i := search(strings.Join(strdata, ""), []byte(k)); i != v {
42
 
                        t.Errorf("%s: found %d; want %d", k, i, v)
43
 
                }
44
 
        }
45
 
}
46
 
 
47
 
func TestIndex(t *testing.T) {
48
 
        strtests := strtests()
49
 
        strtests["    "] = -1
50
 
        strtests["aaax"] = -1
51
 
        strtests["bbbb"] = -1
52
 
        for k, v := range strtests {
53
 
                if i := index(strings.Join(strdata, ""), []byte(k)); i != v {
54
 
                        t.Errorf("%s: found %d; want %d", k, i, v)
55
 
                }
56
 
        }
57
 
}
58
 
 
59
14
func b(s string) []byte {
60
15
        return []byte(s)
61
16
}
62
17
 
63
 
func TestFixCase(t *testing.T) {
64
 
        tests := []string{
65
 
                "aaaa", "AbCD", "abcd",
66
 
                "Zzzz", "AbCD", "Abcd",
67
 
                "Zzzz", "AbC", "Zzzz",
68
 
                "XXX", "ab ", "XXX",
69
 
                "XXX", "usd", "USD",
70
 
                "cmn", "AB ", "cmn",
71
 
                "gsw", "CMN", "cmn",
72
 
        }
73
 
        for i := 0; i+3 < len(tests); i += 3 {
74
 
                tt := tests[i:]
75
 
                buf := [4]byte{}
76
 
                b := buf[:copy(buf[:], tt[1])]
77
 
                res := fixCase(tt[0], b)
78
 
                if res && cmp(tt[2], b) != 0 || !res && tt[0] != tt[2] {
79
 
                        t.Errorf("%s+%s: found %q; want %q", tt[0], tt[1], b, tt[2])
80
 
                }
81
 
        }
82
 
}
83
 
 
84
18
func TestLangID(t *testing.T) {
85
19
        tests := []struct {
86
20
                id, bcp47, iso3, norm string
168
102
                {"sgn-BE-FR", "sfb"},
169
103
                {"sgn-BE-NL", "vgt"},
170
104
                {"sgn-CH-DE", "sgg"},
 
105
                {"sgn-ch-de", "sgg"},
171
106
                {"zh-guoyu", "cmn"},
172
107
                {"zh-hakka", "hak"},
173
108
                {"zh-min-nan", "nan"},
176
111
                // Grandfathered tags with no modern replacement will be converted as follows:
177
112
                {"cel-gaulish", "xtg-x-cel-gaulish"},
178
113
                {"en-GB-oed", "en-GB-x-oed"},
 
114
                {"en-gb-oed", "en-GB-x-oed"},
179
115
                {"i-default", "en-x-i-default"},
180
116
                {"i-enochian", "und-x-i-enochian"},
181
117
                {"i-mingo", "see-x-i-mingo"},
182
118
                {"zh-min", "nan-x-zh-min"},
 
119
 
 
120
                {"root", "und"},
 
121
                {"en_US_POSIX", "en-US-u-va-posix"},
 
122
                {"en_us_posix", "en-US-u-va-posix"},
 
123
                {"en-us-posix", "en-US-u-va-posix"},
183
124
        } {
184
125
                got := Raw.Make(tt.in)
185
126
                want := Raw.MustParse(tt.out)
427
368
}
428
369
 
429
370
func TestGetScriptID(t *testing.T) {
430
 
        idx := "0000BbbbDdddEeeeZzzz\xff\xff\xff\xff"
 
371
        idx := tag.Index("0000BbbbDdddEeeeZzzz\xff\xff\xff\xff")
431
372
        tests := []struct {
432
373
                in  string
433
374
                out scriptID
454
395
}
455
396
 
456
397
func TestCurrency(t *testing.T) {
457
 
        idx := strings.Join([]string{
 
398
        idx := tag.Index(strings.Join([]string{
458
399
                "   \x00",
459
400
                "BBB" + mkCurrencyInfo(5, 2),
460
401
                "DDD\x00",
461
402
                "XXX\x00",
462
403
                "ZZZ\x00",
463
404
                "\xff\xff\xff\xff",
464
 
        }, "")
 
405
        }, ""))
465
406
        tests := []struct {
466
407
                in         string
467
408
                out        currencyID