File: compare_test.go

package info (click to toggle)
golang-x-text 0.0~git20161013.0.c745997-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch, stretch-backports
  • size: 17,872 kB
  • sloc: makefile: 14
file content (53 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package precis

import (
	"fmt"
	"testing"

	"golang.org/x/text/internal/testtext"
)

type compareTestCase struct {
	a      string
	b      string
	result bool
}

var compareTestCases = []struct {
	name  string
	p     *Profile
	cases []compareTestCase
}{
	{"Nickname", Nickname, []compareTestCase{
		{"a", "b", false},
		{"  Swan  of   Avon   ", "swan of avon", true},
		{"Foo", "foo", true},
		{"foo", "foo", true},
		{"Foo Bar", "foo bar", true},
		{"foo bar", "foo bar", true},
		{"\u03A3", "\u03C3", true},
		{"\u03A3", "\u03C2", false},
		{"\u03C3", "\u03C2", false},
		{"Richard \u2163", "richard iv", true},
		{"Å", "å", true},
		{"ff", "ff", true}, // because of NFKC
		{"ß", "sS", false},
	}},
}

func TestCompare(t *testing.T) {
	for _, g := range compareTestCases {
		for i, tc := range g.cases {
			name := fmt.Sprintf("%s:%d:%+q", g.name, i, tc.a)
			testtext.Run(t, name, func(t *testing.T) {
				if result := g.p.Compare(tc.a, tc.b); result != tc.result {
					t.Errorf("got %v; want %v", result, tc.result)
				}
			})
		}
	}
}