Replace godep with dep

This commit is contained in:
Manuel de Brito Fontes 2017-10-06 17:26:14 -03:00
parent 1e7489927c
commit bf5616c65b
14883 changed files with 3937406 additions and 361781 deletions

View file

@ -0,0 +1,82 @@
// Copyright 2015 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.
// +build go1.7
package precis
import (
"testing"
"golang.org/x/text/internal/testtext"
)
var benchData = []struct{ name, str string }{
{"ASCII", "Malvolio"},
{"NotNormalized", "abcdefg\u0301\u031f"},
{"Arabic", "دبي"},
{"Hangul", "동일조건변경허락"},
}
var benchProfiles = []struct {
name string
p *Profile
}{
{"FreeForm", NewFreeform()},
{"Nickname", Nickname},
{"OpaqueString", OpaqueString},
{"UsernameCaseMapped", UsernameCaseMapped},
{"UsernameCasePreserved", UsernameCasePreserved},
}
func doBench(b *testing.B, f func(b *testing.B, p *Profile, s string)) {
for _, bp := range benchProfiles {
for _, d := range benchData {
testtext.Bench(b, bp.name+"/"+d.name, func(b *testing.B) {
f(b, bp.p, d.str)
})
}
}
}
func BenchmarkString(b *testing.B) {
doBench(b, func(b *testing.B, p *Profile, s string) {
for i := 0; i < b.N; i++ {
p.String(s)
}
})
}
func BenchmarkBytes(b *testing.B) {
doBench(b, func(b *testing.B, p *Profile, s string) {
src := []byte(s)
b.ResetTimer()
for i := 0; i < b.N; i++ {
p.Bytes(src)
}
})
}
func BenchmarkAppend(b *testing.B) {
doBench(b, func(b *testing.B, p *Profile, s string) {
src := []byte(s)
dst := make([]byte, 0, 4096)
b.ResetTimer()
for i := 0; i < b.N; i++ {
p.Append(dst, src)
}
})
}
func BenchmarkTransform(b *testing.B) {
doBench(b, func(b *testing.B, p *Profile, s string) {
src := []byte(s)
dst := make([]byte, 2*len(s))
t := p.NewTransformer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
t.Transform(dst, src, true)
}
})
}

50
vendor/golang.org/x/text/secure/precis/class_test.go generated vendored Normal file
View file

@ -0,0 +1,50 @@
// Copyright 2015 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 (
"testing"
"golang.org/x/text/runes"
)
// Compile-time regression test to ensure that Class is a Set
var _ runes.Set = (*class)(nil)
// Ensure that certain characters are (or are not) in the identifer class.
func TestClassContains(t *testing.T) {
tests := []struct {
name string
class *class
allowed []rune
disallowed []rune
}{
{
name: "Identifier",
class: identifier,
allowed: []rune("Aa0\u0021\u007e\u00df\u3007"),
disallowed: []rune("\u2150\u2100\u2200\u3164\u2190\u2600\u303b\u1e9b"),
},
{
name: "Freeform",
class: freeform,
allowed: []rune("Aa0\u0021\u007e\u00df\u3007 \u2150\u2100\u2200\u2190\u2600\u1e9b"),
disallowed: []rune("\u3164\u303b"),
},
}
for _, rt := range tests {
for _, r := range rt.allowed {
if !rt.class.Contains(r) {
t.Errorf("Class %s should contain %U", rt.name, r)
}
}
for _, r := range rt.disallowed {
if rt.class.Contains(r) {
t.Errorf("Class %s should not contain %U", rt.name, r)
}
}
}
}

View file

@ -9,6 +9,6 @@
//
// BE ADVISED: This package is under construction and the API may change in
// backwards incompatible ways and without notice.
package precis
package precis // import "golang.org/x/text/secure/precis"
//go:generate go run gen.go gen_trieval.go

393
vendor/golang.org/x/text/secure/precis/enforce_test.go generated vendored Normal file
View file

@ -0,0 +1,393 @@
// Copyright 2015 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 (
"bytes"
"fmt"
"reflect"
"testing"
"golang.org/x/text/internal/testtext"
"golang.org/x/text/secure/bidirule"
"golang.org/x/text/transform"
)
type testCase struct {
input string
output string
err error
}
var enforceTestCases = []struct {
name string
p *Profile
cases []testCase
}{
{"Basic", NewFreeform(), []testCase{
{"e\u0301\u031f", "\u00e9\u031f", nil}, // normalize
}},
{"Context Rule 1", NewFreeform(), []testCase{
// Rule 1: zero-width non-joiner (U+200C)
// From RFC:
// False
// If Canonical_Combining_Class(Before(cp)) .eq. Virama Then True;
// If RegExpMatch((Joining_Type:{L,D})(Joining_Type:T)*\u200C
// (Joining_Type:T)*(Joining_Type:{R,D})) Then True;
//
// Example runes for different joining types:
// Join L: U+A872; PHAGS-PA SUPERFIXED LETTER RA
// Join D: U+062C; HAH WITH DOT BELOW
// Join T: U+0610; ARABIC SIGN SALLALLAHOU ALAYHE WASSALLAM
// Join R: U+0627; ALEF
// Virama: U+0A4D; GURMUKHI SIGN VIRAMA
// Virama and Join T: U+0ACD; GUJARATI SIGN VIRAMA
{"\u200c", "", errContext},
{"\u200ca", "", errContext},
{"a\u200c", "", errContext},
{"\u200c\u0627", "", errContext}, // missing JoinStart
{"\u062c\u200c", "", errContext}, // missing JoinEnd
{"\u0610\u200c\u0610\u0627", "", errContext}, // missing JoinStart
{"\u062c\u0610\u200c\u0610", "", errContext}, // missing JoinEnd
// Variants of: D T* U+200c T* R
{"\u062c\u200c\u0627", "\u062c\u200c\u0627", nil},
{"\u062c\u0610\u200c\u0610\u0627", "\u062c\u0610\u200c\u0610\u0627", nil},
{"\u062c\u0610\u0610\u200c\u0610\u0610\u0627", "\u062c\u0610\u0610\u200c\u0610\u0610\u0627", nil},
{"\u062c\u0610\u200c\u0627", "\u062c\u0610\u200c\u0627", nil},
{"\u062c\u200c\u0610\u0627", "\u062c\u200c\u0610\u0627", nil},
// Variants of: L T* U+200c T* D
{"\ua872\u200c\u062c", "\ua872\u200c\u062c", nil},
{"\ua872\u0610\u200c\u0610\u062c", "\ua872\u0610\u200c\u0610\u062c", nil},
{"\ua872\u0610\u0610\u200c\u0610\u0610\u062c", "\ua872\u0610\u0610\u200c\u0610\u0610\u062c", nil},
{"\ua872\u0610\u200c\u062c", "\ua872\u0610\u200c\u062c", nil},
{"\ua872\u200c\u0610\u062c", "\ua872\u200c\u0610\u062c", nil},
// Virama
{"\u0a4d\u200c", "\u0a4d\u200c", nil},
{"\ua872\u0a4d\u200c", "\ua872\u0a4d\u200c", nil},
{"\ua872\u0a4d\u0610\u200c", "", errContext},
{"\ua872\u0a4d\u0610\u200c", "", errContext},
{"\u0acd\u200c", "\u0acd\u200c", nil},
{"\ua872\u0acd\u200c", "\ua872\u0acd\u200c", nil},
{"\ua872\u0acd\u0610\u200c", "", errContext},
{"\ua872\u0acd\u0610\u200c", "", errContext},
// Using Virama as join T
{"\ua872\u0acd\u200c\u062c", "\ua872\u0acd\u200c\u062c", nil},
{"\ua872\u200c\u0acd\u062c", "\ua872\u200c\u0acd\u062c", nil},
}},
{"Context Rule 2", NewFreeform(), []testCase{
// Rule 2: zero-width joiner (U+200D)
{"\u200d", "", errContext},
{"\u200da", "", errContext},
{"a\u200d", "", errContext},
{"\u0a4d\u200d", "\u0a4d\u200d", nil},
{"\ua872\u0a4d\u200d", "\ua872\u0a4d\u200d", nil},
{"\u0a4da\u200d", "", errContext},
}},
{"Context Rule 3", NewFreeform(), []testCase{
// Rule 3: middle dot
{"·", "", errContext},
{"l·", "", errContext},
{"·l", "", errContext},
{"a·", "", errContext},
{"l·a", "", errContext},
{"a·a", "", errContext},
{"l·l", "l·l", nil},
{"al·la", "al·la", nil},
}},
{"Context Rule 4", NewFreeform(), []testCase{
// Rule 4: Greek lower numeral U+0375
{"͵", "", errContext},
{"͵a", "", errContext},
{"α͵", "", errContext},
{"͵α", "͵α", nil},
{"α͵α", "α͵α", nil},
{"͵͵α", "͵͵α", nil}, // The numeric sign is itself Greek.
{"α͵͵α", "α͵͵α", nil},
{"α͵͵", "", errContext},
{"α͵͵a", "", errContext},
}},
{"Context Rule 5+6", NewFreeform(), []testCase{
// Rule 5+6: Hebrew preceding
// U+05f3: Geresh
{"׳", "", errContext},
{"׳ה", "", errContext},
{"a׳b", "", errContext},
{"ש׳", "ש׳", nil}, // U+05e9 U+05f3
{"ש׳׳׳", "ש׳׳׳", nil}, // U+05e9 U+05f3
// U+05f4: Gershayim
{"״", "", errContext},
{"״ה", "", errContext},
{"a״b", "", errContext},
{"ש״", "ש״", nil}, // U+05e9 U+05f4
{"ש״״״", "ש״״״", nil}, // U+05e9 U+05f4
{"aש״״״", "aש״״״", nil}, // U+05e9 U+05f4
}},
{"Context Rule 7", NewFreeform(), []testCase{
// Rule 7: Katakana middle Dot
{"・", "", errContext},
{"abc・", "", errContext},
{"・def", "", errContext},
{"abc・def", "", errContext},
{"aヅc・def", "aヅc・def", nil},
{"abc・dぶf", "abc・dぶf", nil},
{"⺐bc・def", "⺐bc・def", nil},
}},
{"Context Rule 8+9", NewFreeform(), []testCase{
// Rule 8+9: Arabic Indic Digit
{"١٢٣٤٥۶", "", errContext},
{"۱۲۳۴۵٦", "", errContext},
{"١٢٣٤٥", "١٢٣٤٥", nil},
{"۱۲۳۴۵", "۱۲۳۴۵", nil},
}},
{"Nickname", Nickname, []testCase{
{" Swan of Avon ", "Swan of Avon", nil},
{"", "", errEmptyString},
{" ", "", errEmptyString},
{" ", "", errEmptyString},
{"a\u00A0a\u1680a\u2000a\u2001a\u2002a\u2003a\u2004a\u2005a\u2006a\u2007a\u2008a\u2009a\u200Aa\u202Fa\u205Fa\u3000a", "a a a a a a a a a a a a a a a a a", nil},
{"Foo", "Foo", nil},
{"foo", "foo", nil},
{"Foo Bar", "Foo Bar", nil},
{"foo bar", "foo bar", nil},
{"\u03A3", "\u03A3", nil},
{"\u03C3", "\u03C3", nil},
// Greek final sigma is left as is (do not fold!)
{"\u03C2", "\u03C2", nil},
{"\u265A", "♚", nil},
{"Richard \u2163", "Richard IV", nil},
{"\u212B", "Å", nil},
{"\uFB00", "ff", nil}, // because of NFKC
{"שa", "שa", nil}, // no bidi rule
{"동일조건변경허락", "동일조건변경허락", nil},
}},
{"OpaqueString", OpaqueString, []testCase{
{" Swan of Avon ", " Swan of Avon ", nil},
{"", "", errEmptyString},
{" ", " ", nil},
{" ", " ", nil},
{"a\u00A0a\u1680a\u2000a\u2001a\u2002a\u2003a\u2004a\u2005a\u2006a\u2007a\u2008a\u2009a\u200Aa\u202Fa\u205Fa\u3000a", "a a a a a a a a a a a a a a a a a", nil},
{"Foo", "Foo", nil},
{"foo", "foo", nil},
{"Foo Bar", "Foo Bar", nil},
{"foo bar", "foo bar", nil},
{"\u03C3", "\u03C3", nil},
{"Richard \u2163", "Richard \u2163", nil},
{"\u212B", "Å", nil},
{"Jack of \u2666s", "Jack of \u2666s", nil},
{"my cat is a \u0009by", "", errDisallowedRune},
{"שa", "שa", nil}, // no bidi rule
}},
{"UsernameCaseMapped", UsernameCaseMapped, []testCase{
// TODO: Should this work?
// {UsernameCaseMapped, "", "", errDisallowedRune},
{"juliet@example.com", "juliet@example.com", nil},
{"fussball", "fussball", nil},
{"fu\u00DFball", "fu\u00DFball", nil},
{"\u03C0", "\u03C0", nil},
{"\u03A3", "\u03C3", nil},
{"\u03C3", "\u03C3", nil},
// Greek final sigma is left as is (do not fold!)
{"\u03C2", "\u03C2", nil},
{"\u0049", "\u0069", nil},
{"\u0049", "\u0069", nil},
{"\u03D2", "", errDisallowedRune},
{"\u03B0", "\u03B0", nil},
{"foo bar", "", errDisallowedRune},
{"♚", "", bidirule.ErrInvalid},
{"\u007E", "~", nil},
{"a", "a", nil},
{"!", "!", nil},
{"²", "", bidirule.ErrInvalid},
{"\t", "", errDisallowedRune},
{"\n", "", errDisallowedRune},
{"\u26D6", "", bidirule.ErrInvalid},
{"\u26FF", "", bidirule.ErrInvalid},
{"\uFB00", "", errDisallowedRune},
{"\u1680", "", bidirule.ErrInvalid},
{" ", "", errDisallowedRune},
{" ", "", errDisallowedRune},
{"\u01C5", "", errDisallowedRune},
{"\u16EE", "", errDisallowedRune}, // Nl RUNIC ARLAUG SYMBOL
{"\u0488", "", bidirule.ErrInvalid}, // Me COMBINING CYRILLIC HUNDRED THOUSANDS SIGN
{"\u212B", "\u00e5", nil}, // Angstrom sign, NFC -> U+00E5
{"A\u030A", "å", nil}, // A + ring
{"\u00C5", "å", nil}, // A with ring
{"\u00E7", "ç", nil}, // c cedille
{"\u0063\u0327", "ç", nil}, // c + cedille
{"\u0158", "ř", nil},
{"\u0052\u030C", "ř", nil},
{"\u1E61", "\u1E61", nil}, // LATIN SMALL LETTER S WITH DOT ABOVE
// Confusable characters ARE allowed and should NOT be mapped.
{"\u0410", "\u0430", nil}, // CYRILLIC CAPITAL LETTER A
// Full width should be mapped to the canonical decomposition.
{"", "ab", nil},
{"שc", "", bidirule.ErrInvalid}, // bidi rule
}},
{"UsernameCasePreserved", UsernameCasePreserved, []testCase{
{"ABC", "ABC", nil},
{"", "AB", nil},
{"שc", "", bidirule.ErrInvalid}, // bidi rule
{"\uFB00", "", errDisallowedRune},
{"\u212B", "\u00c5", nil}, // Angstrom sign, NFC -> U+00E5
{"ẛ", "", errDisallowedRune}, // LATIN SMALL LETTER LONG S WITH DOT ABOVE
}},
}
func doTests(t *testing.T, fn func(t *testing.T, p *Profile, tc testCase)) {
for _, g := range enforceTestCases {
for i, tc := range g.cases {
name := fmt.Sprintf("%s:%d:%+q", g.name, i, tc.input)
testtext.Run(t, name, func(t *testing.T) {
fn(t, g.p, tc)
})
}
}
}
func TestString(t *testing.T) {
doTests(t, func(t *testing.T, p *Profile, tc testCase) {
if e, err := p.String(tc.input); tc.err != err || e != tc.output {
t.Errorf("got %+q (err: %v); want %+q (err: %v)", e, err, tc.output, tc.err)
}
})
}
func TestBytes(t *testing.T) {
doTests(t, func(t *testing.T, p *Profile, tc testCase) {
if e, err := p.Bytes([]byte(tc.input)); tc.err != err || string(e) != tc.output {
t.Errorf("got %+q (err: %v); want %+q (err: %v)", string(e), err, tc.output, tc.err)
}
})
// Test that calling Bytes with something that doesn't transform returns a
// copy.
orig := []byte("hello")
b, _ := NewFreeform().Bytes(orig)
if reflect.ValueOf(b).Pointer() == reflect.ValueOf(orig).Pointer() {
t.Error("original and result are the same slice; should be a copy")
}
}
func TestAppend(t *testing.T) {
doTests(t, func(t *testing.T, p *Profile, tc testCase) {
if e, err := p.Append(nil, []byte(tc.input)); tc.err != err || string(e) != tc.output {
t.Errorf("got %+q (err: %v); want %+q (err: %v)", string(e), err, tc.output, tc.err)
}
})
}
func TestStringMallocs(t *testing.T) {
if n := testtext.AllocsPerRun(100, func() { UsernameCaseMapped.String("helloworld") }); n > 0 {
// TODO: reduce this to 0.
t.Skipf("got %f allocs, want 0", n)
}
}
func TestAppendMallocs(t *testing.T) {
str := []byte("helloworld")
out := make([]byte, 0, len(str))
if n := testtext.AllocsPerRun(100, func() { UsernameCaseMapped.Append(out, str) }); n > 0 {
t.Errorf("got %f allocs, want 0", n)
}
}
func TestTransformMallocs(t *testing.T) {
str := []byte("helloworld")
out := make([]byte, 0, len(str))
tr := UsernameCaseMapped.NewTransformer()
if n := testtext.AllocsPerRun(100, func() {
tr.Reset()
tr.Transform(out, str, true)
}); n > 0 {
t.Errorf("got %f allocs, want 0", n)
}
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
// TestTransformerShortBuffers tests that the precis.Transformer implements the
// spirit, not just the letter (the method signatures), of the
// transform.Transformer interface.
//
// In particular, it tests that, if one or both of the dst or src buffers are
// short, so that multiple Transform calls are required to complete the overall
// transformation, the end result is identical to one Transform call with
// sufficiently long buffers.
func TestTransformerShortBuffers(t *testing.T) {
srcUnit := []byte("a\u0300cce\u0301nts") // NFD normalization form.
wantUnit := []byte("àccénts") // NFC normalization form.
src := bytes.Repeat(srcUnit, 16)
want := bytes.Repeat(wantUnit, 16)
const long = 4096
dst := make([]byte, long)
// 5, 7, 9, 11, 13, 16 and 17 are all pair-wise co-prime, which means that
// slicing the dst and src buffers into 5, 7, 13 and 17 byte chunks will
// fall at different places inside the repeated srcUnit's and wantUnit's.
if len(srcUnit) != 11 || len(wantUnit) != 9 || len(src) > long || len(want) > long {
t.Fatal("inconsistent lengths")
}
tr := NewFreeform().NewTransformer()
for _, deltaD := range []int{5, 7, 13, 17, long} {
loop:
for _, deltaS := range []int{5, 7, 13, 17, long} {
tr.Reset()
d0 := 0
s0 := 0
for {
d1 := min(len(dst), d0+deltaD)
s1 := min(len(src), s0+deltaS)
nDst, nSrc, err := tr.Transform(dst[d0:d1:d1], src[s0:s1:s1], s1 == len(src))
d0 += nDst
s0 += nSrc
if err == nil {
break
}
if err == transform.ErrShortDst || err == transform.ErrShortSrc {
continue
}
t.Errorf("deltaD=%d, deltaS=%d: %v", deltaD, deltaS, err)
continue loop
}
if s0 != len(src) {
t.Errorf("deltaD=%d, deltaS=%d: s0: got %d, want %d", deltaD, deltaS, s0, len(src))
continue
}
if d0 != len(want) {
t.Errorf("deltaD=%d, deltaS=%d: d0: got %d, want %d", deltaD, deltaS, d0, len(want))
continue
}
got := dst[:d0]
if !bytes.Equal(got, want) {
t.Errorf("deltaD=%d, deltaS=%d:\ngot %q\nwant %q", deltaD, deltaS, got, want)
continue
}
}
}
}

149
vendor/golang.org/x/text/secure/precis/profile_test.go generated vendored Normal file
View file

@ -0,0 +1,149 @@
// 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"
"math/rand"
"testing"
"unicode"
"golang.org/x/text/internal/testtext"
"golang.org/x/text/transform"
)
// copyOrbit is a Transformer for the sole purpose of testing the apply method,
// testing that apply will always call Span for the prefix of the input that
// remains identical and then call Transform for the remainder. It will produce
// inconsistent output for other usage patterns.
// Provided that copyOrbit is used this way, the first t bytes of the output
// will be identical to the input and the remaining output will be the result
// of calling caseOrbit on the remaining input bytes.
type copyOrbit int
func (t copyOrbit) Reset() {}
func (t copyOrbit) Span(src []byte, atEOF bool) (n int, err error) {
if int(t) == len(src) {
return int(t), nil
}
return int(t), transform.ErrEndOfSpan
}
// Transform implements transform.Transformer specifically for testing the apply method.
// See documentation of copyOrbit before using this method.
func (t copyOrbit) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
n := copy(dst, src)
for i, c := range dst[:n] {
dst[i] = orbitCase(c)
}
return n, n, nil
}
func orbitCase(c byte) byte {
if unicode.IsLower(rune(c)) {
return byte(unicode.ToUpper(rune(c)))
} else {
return byte(unicode.ToLower(rune(c)))
}
}
func TestBuffers(t *testing.T) {
want := "Those who cannot remember the past are condemned to compute it."
spans := rand.Perm(len(want) + 1)
// Compute the result of applying copyOrbit(span) transforms in reverse.
input := []byte(want)
for i := len(spans) - 1; i >= 0; i-- {
for j := spans[i]; j < len(input); j++ {
input[j] = orbitCase(input[j])
}
}
// Apply the copyOrbit(span) transforms.
b := buffers{src: input}
for _, n := range spans {
b.apply(copyOrbit(n))
if n%11 == 0 {
b.apply(transform.Nop)
}
}
if got := string(b.src); got != want {
t.Errorf("got %q; want %q", got, want)
}
}
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},
// After applying the Nickname profile, \u00a8 becomes \u0020\u0308,
// however because the nickname profile is not idempotent, applying it again
// to \u0020\u0308 results in \u0308. This behavior is "correct", even if it
// is unexpected.
{"\u00a8", "\u0020\u0308", false},
{"\u0020\u0308", "\u0308", true},
}},
}
func doCompareTests(t *testing.T, fn func(t *testing.T, p *Profile, tc compareTestCase)) {
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) {
fn(t, g.p, tc)
})
}
}
}
func TestCompare(t *testing.T) {
doCompareTests(t, func(t *testing.T, p *Profile, tc compareTestCase) {
if result := p.Compare(tc.a, tc.b); result != tc.result {
t.Errorf("got %v; want %v", result, tc.result)
}
})
}
func TestCompareString(t *testing.T) {
doCompareTests(t, func(t *testing.T, p *Profile, tc compareTestCase) {
a, err := p.CompareKey(tc.a)
if err != nil {
t.Errorf("Unexpected error when creating key: %v", err)
return
}
b, err := p.CompareKey(tc.b)
if err != nil {
t.Errorf("Unexpected error when creating key: %v", err)
return
}
if result := (a == b); result != tc.result {
t.Errorf("got %v; want %v", result, tc.result)
}
})
}

File diff suppressed because it is too large Load diff

69
vendor/golang.org/x/text/secure/precis/tables_test.go generated vendored Normal file
View file

@ -0,0 +1,69 @@
// Copyright 2015 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 (
"testing"
"unicode"
"unicode/utf8"
"golang.org/x/text/runes"
"golang.org/x/text/unicode/rangetable"
)
type tableTest struct {
rangeTable *unicode.RangeTable
prop property
}
var exceptions = runes.Predicate(func(r rune) bool {
switch uint32(r) {
case 0x00DF, 0x03C2, 0x06FD, 0x06FE, 0x0F0B, 0x3007, 0x00B7, 0x0375, 0x05F3,
0x05F4, 0x30FB, 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666,
0x0667, 0x0668, 0x0669, 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5,
0x06F6, 0x06F7, 0x06F8, 0x06F9, 0x0640, 0x07FA, 0x302E, 0x302F, 0x3031,
0x3032, 0x3033, 0x3034, 0x3035, 0x303B:
return true
default:
return false
}
})
// Ensure that certain properties were generated correctly.
func TestTable(t *testing.T) {
tests := []tableTest{
tableTest{
rangetable.Merge(
unicode.Lt, unicode.Nl, unicode.No, // Other letter digits
unicode.Me, // Modifiers
unicode.Zs, // Spaces
unicode.So, // Symbols
unicode.Pi, unicode.Pf, // Punctuation
),
idDisOrFreePVal,
},
tableTest{
rangetable.New(0x30000, 0x30101, 0xDFFFF),
unassigned,
},
}
assigned := rangetable.Assigned(UnicodeVersion)
for _, test := range tests {
rangetable.Visit(test.rangeTable, func(r rune) {
if !unicode.In(r, assigned) {
return
}
b := make([]byte, 4)
n := utf8.EncodeRune(b, r)
trieval, _ := dpTrie.lookup(b[:n])
p := entry(trieval).property()
if p != test.prop && !exceptions.Contains(r) {
t.Errorf("%U: got %+x; want %+x", r, test.prop, p)
}
})
}
}