OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / internal / tag / tag_test.go
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
5 package tag
6
7 import (
8         "strings"
9         "testing"
10 )
11
12 var strdata = []string{
13         "aa  ",
14         "aaa ",
15         "aaaa",
16         "aaab",
17         "aab ",
18         "ab  ",
19         "ba  ",
20         "xxxx",
21         "\xff\xff\xff\xff",
22 }
23
24 var testCases = map[string]int{
25         "a":    0,
26         "aa":   0,
27         "aaa":  1,
28         "aa ":  0,
29         "aaaa": 2,
30         "aaab": 3,
31         "b":    6,
32         "ba":   6,
33         "    ": -1,
34         "aaax": -1,
35         "bbbb": -1,
36         "zzzz": -1,
37 }
38
39 func TestIndex(t *testing.T) {
40         index := Index(strings.Join(strdata, ""))
41         for k, v := range testCases {
42                 if i := index.Index([]byte(k)); i != v {
43                         t.Errorf("%s: got %d; want %d", k, i, v)
44                 }
45         }
46 }
47
48 func TestFixCase(t *testing.T) {
49         tests := []string{
50                 "aaaa", "AbCD", "abcd",
51                 "Zzzz", "AbCD", "Abcd",
52                 "Zzzz", "AbC", "",
53                 "XXX", "ab ", "",
54                 "XXX", "usd", "USD",
55                 "cmn", "AB ", "",
56                 "gsw", "CMN", "cmn",
57         }
58         for tc := tests; len(tc) > 0; tc = tc[3:] {
59                 b := []byte(tc[1])
60                 if !FixCase(tc[0], b) {
61                         b = nil
62                 }
63                 if string(b) != tc[2] {
64                         t.Errorf("FixCase(%q, %q) = %q; want %q", tc[0], tc[1], b, tc[2])
65                 }
66         }
67 }