Replace godep with dep
This commit is contained in:
parent
1e7489927c
commit
bf5616c65b
14883 changed files with 3937406 additions and 361781 deletions
54
vendor/golang.org/x/text/secure/bidirule/bench_test.go
generated
vendored
Normal file
54
vendor/golang.org/x/text/secure/bidirule/bench_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// 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 bidirule
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/text/internal/testtext"
|
||||
)
|
||||
|
||||
var benchData = []struct{ name, data string }{
|
||||
{"ascii", "Scheveningen"},
|
||||
{"arabic", "دبي"},
|
||||
{"hangul", "다음과"},
|
||||
}
|
||||
|
||||
func doBench(b *testing.B, fn func(b *testing.B, data string)) {
|
||||
for _, d := range benchData {
|
||||
testtext.Bench(b, d.name, func(b *testing.B) { fn(b, d.data) })
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSpan(b *testing.B) {
|
||||
r := New()
|
||||
doBench(b, func(b *testing.B, str string) {
|
||||
b.SetBytes(int64(len(str)))
|
||||
data := []byte(str)
|
||||
for i := 0; i < b.N; i++ {
|
||||
r.Reset()
|
||||
r.Span(data, true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDirectionASCII(b *testing.B) {
|
||||
doBench(b, func(b *testing.B, str string) {
|
||||
b.SetBytes(int64(len(str)))
|
||||
data := []byte(str)
|
||||
for i := 0; i < b.N; i++ {
|
||||
Direction(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDirectionStringASCII(b *testing.B) {
|
||||
doBench(b, func(b *testing.B, str string) {
|
||||
b.SetBytes(int64(len(str)))
|
||||
for i := 0; i < b.N; i++ {
|
||||
DirectionString(str)
|
||||
}
|
||||
})
|
||||
}
|
||||
4
vendor/golang.org/x/text/secure/bidirule/bidirule.go
generated
vendored
4
vendor/golang.org/x/text/secure/bidirule/bidirule.go
generated
vendored
|
|
@ -155,6 +155,7 @@ func DirectionString(s string) bidi.Direction {
|
|||
e, sz := bidi.LookupString(s[i:])
|
||||
if sz == 0 {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
c := e.Class()
|
||||
if c == bidi.R || c == bidi.AL || c == bidi.AN {
|
||||
|
|
@ -203,9 +204,6 @@ func (t *Transformer) isRTL() bool {
|
|||
}
|
||||
|
||||
func (t *Transformer) isFinal() bool {
|
||||
if !t.isRTL() {
|
||||
return true
|
||||
}
|
||||
return t.state == ruleLTRFinal || t.state == ruleRTLFinal || t.state == ruleInitial
|
||||
}
|
||||
|
||||
|
|
|
|||
851
vendor/golang.org/x/text/secure/bidirule/bidirule_test.go
generated
vendored
Normal file
851
vendor/golang.org/x/text/secure/bidirule/bidirule_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,851 @@
|
|||
// 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 bidirule
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/text/internal/testtext"
|
||||
"golang.org/x/text/transform"
|
||||
"golang.org/x/text/unicode/bidi"
|
||||
)
|
||||
|
||||
const (
|
||||
strL = "ABC" // Left to right - most letters in LTR scripts
|
||||
strR = "עברית" // Right to left - most letters in non-Arabic RTL scripts
|
||||
strAL = "دبي" // Arabic letters - most letters in the Arabic script
|
||||
strEN = "123" // European Number (0-9, and Extended Arabic-Indic numbers)
|
||||
strES = "+-" // European Number Separator (+ and -)
|
||||
strET = "$" // European Number Terminator (currency symbols, the hash sign, the percent sign and so on)
|
||||
strAN = "\u0660" // Arabic Number; this encompasses the Arabic-Indic numbers, but not the Extended Arabic-Indic numbers
|
||||
strCS = "," // Common Number Separator (. , / : et al)
|
||||
strNSM = "\u0300" // Nonspacing Mark - most combining accents
|
||||
strBN = "\u200d" // Boundary Neutral - control characters (ZWNJ, ZWJ, and others)
|
||||
strB = "\u2029" // Paragraph Separator
|
||||
strS = "\u0009" // Segment Separator
|
||||
strWS = " " // Whitespace, including the SPACE character
|
||||
strON = "@" // Other Neutrals, including @, &, parentheses, MIDDLE DOT
|
||||
)
|
||||
|
||||
type ruleTest struct {
|
||||
in string
|
||||
dir bidi.Direction
|
||||
n int // position at which the rule fails
|
||||
err error
|
||||
|
||||
// For tests that split the string in two.
|
||||
pSrc int // number of source bytes to consume first
|
||||
szDst int // size of destination buffer
|
||||
nSrc int // source bytes consumed and bytes written
|
||||
err0 error // error after first run
|
||||
}
|
||||
|
||||
var testCases = [][]ruleTest{
|
||||
// Go-specific rules.
|
||||
// Invalid UTF-8 is invalid.
|
||||
0: []ruleTest{{
|
||||
in: "",
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: "\x80",
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: 0,
|
||||
}, {
|
||||
in: "\xcc",
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: 0,
|
||||
}, {
|
||||
in: "abc\x80",
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: 3,
|
||||
}, {
|
||||
in: "abc\xcc",
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: 3,
|
||||
}, {
|
||||
in: "abc\xccdef",
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: 3,
|
||||
}, {
|
||||
in: "\xccdef",
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: 0,
|
||||
}, {
|
||||
in: strR + "\x80",
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: len(strR),
|
||||
}, {
|
||||
in: strR + "\xcc",
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: len(strR),
|
||||
}, {
|
||||
in: strAL + "\xcc" + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: len(strAL),
|
||||
}, {
|
||||
in: "\xcc" + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 0,
|
||||
}},
|
||||
|
||||
// Rule 2.1: The first character must be a character with Bidi property L,
|
||||
// R, or AL. If it has the R or AL property, it is an RTL label; if it has
|
||||
// the L property, it is an LTR label.
|
||||
1: []ruleTest{{
|
||||
in: strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAN,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strEN,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strEN),
|
||||
}, {
|
||||
in: strES,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strES),
|
||||
}, {
|
||||
in: strET,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strET),
|
||||
}, {
|
||||
in: strCS,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strCS),
|
||||
}, {
|
||||
in: strNSM,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strNSM),
|
||||
}, {
|
||||
in: strBN,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strBN),
|
||||
}, {
|
||||
in: strB,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strB),
|
||||
}, {
|
||||
in: strS,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strS),
|
||||
}, {
|
||||
in: strWS,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strWS),
|
||||
}, {
|
||||
in: strON,
|
||||
dir: bidi.LeftToRight,
|
||||
err: ErrInvalid,
|
||||
n: len(strON),
|
||||
}, {
|
||||
in: strEN + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 3,
|
||||
}, {
|
||||
in: strES + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 2,
|
||||
}, {
|
||||
in: strET + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 1,
|
||||
}, {
|
||||
in: strCS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 1,
|
||||
}, {
|
||||
in: strNSM + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 2,
|
||||
}, {
|
||||
in: strBN + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 3,
|
||||
}, {
|
||||
in: strB + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 3,
|
||||
}, {
|
||||
in: strS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 1,
|
||||
}, {
|
||||
in: strWS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 1,
|
||||
}, {
|
||||
in: strON + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
err: ErrInvalid,
|
||||
n: 1,
|
||||
}},
|
||||
|
||||
// Rule 2.2: In an RTL label, only characters with the Bidi properties R,
|
||||
// AL, AN, EN, ES, CS, ET, ON, BN, or NSM are allowed.
|
||||
2: []ruleTest{{
|
||||
in: strR + strR + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strAL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strAN + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strEN + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strES + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strCS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strET + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strON + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strBN + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strNSM + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strB + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strS + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strWS + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strR + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strAL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strAN + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strEN + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strES + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strCS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strET + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strON + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strBN + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strNSM + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strB + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strS + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strWS + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}},
|
||||
|
||||
// Rule 2.3: In an RTL label, the end of the label must be a character with
|
||||
// Bidi property R, AL, EN, or AN, followed by zero or more characters with
|
||||
// Bidi property NSM.
|
||||
3: []ruleTest{{
|
||||
in: strR + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strAL + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strEN + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strAN,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strR + strES + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR + strES + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strCS + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR + strCS + strNSM + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strET,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR + strET),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strON + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR + strON + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strBN + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR + strBN + strNSM + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strL + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strB + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strS,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strWS,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strAL + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strEN + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strAN,
|
||||
dir: bidi.RightToLeft,
|
||||
}, {
|
||||
in: strAL + strES + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL + strES + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strCS + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL + strCS + strNSM + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strET,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL + strET),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strON + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL + strON + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strBN + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL + strBN + strNSM + strNSM),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strL + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strB + strNSM + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strS,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strWS,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL),
|
||||
err: ErrInvalid,
|
||||
}},
|
||||
|
||||
// Rule 2.4: In an RTL label, if an EN is present, no AN may be present,
|
||||
// and vice versa.
|
||||
4: []ruleTest{{
|
||||
in: strR + strEN + strAN,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR + strEN),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strR + strAN + strEN + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR + strAN),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strEN + strAN,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL + strEN),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strAL + strAN + strEN + strNSM,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strAL + strAN),
|
||||
err: ErrInvalid,
|
||||
}},
|
||||
|
||||
// Rule 2.5: In an LTR label, only characters with the Bidi properties L,
|
||||
// EN, ES, CS, ET, ON, BN, or NSM are allowed.
|
||||
5: []ruleTest{{
|
||||
in: strL + strL + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strEN + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strES + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strCS + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strET + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strON + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strBN + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strNSM + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strR + strL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strAL + strL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strAN + strL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strB + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strB + strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strB + strL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strB + strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strS + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strS + strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strS + strL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strS + strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strWS + strL,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strWS + strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strWS + strL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strWS + strL),
|
||||
err: ErrInvalid,
|
||||
}},
|
||||
|
||||
// Rule 2.6: In an LTR label, the end of the label must be a character with
|
||||
// Bidi property L or EN, followed by zero or more characters with Bidi
|
||||
// property NSM.
|
||||
6: []ruleTest{{
|
||||
in: strL,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strNSM,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strNSM + strNSM,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strEN,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strEN + strNSM,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strEN + strNSM + strNSM,
|
||||
dir: bidi.LeftToRight,
|
||||
}, {
|
||||
in: strL + strES,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strES),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strES + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strES),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strCS,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strCS),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strCS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strCS),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strET,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strET),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strET + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strET),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strON,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strON),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strON + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strON),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strBN,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strBN),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strBN + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strBN),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strAL,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strAN,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strB,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strB),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strB + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strB),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strS,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strS),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strS),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strWS,
|
||||
dir: bidi.LeftToRight,
|
||||
n: len(strL + strWS),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: strL + strWS + strR,
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strL + strWS),
|
||||
err: ErrInvalid,
|
||||
}},
|
||||
|
||||
// Incremental processing.
|
||||
9: []ruleTest{{
|
||||
in: "e\u0301", // é
|
||||
dir: bidi.LeftToRight,
|
||||
|
||||
pSrc: 2,
|
||||
nSrc: 1,
|
||||
err0: transform.ErrShortSrc,
|
||||
}, {
|
||||
in: "e\u1000f", // é
|
||||
dir: bidi.LeftToRight,
|
||||
|
||||
pSrc: 3,
|
||||
nSrc: 1,
|
||||
err0: transform.ErrShortSrc,
|
||||
}, {
|
||||
// Remain invalid once invalid.
|
||||
in: strR + "ab",
|
||||
dir: bidi.RightToLeft,
|
||||
n: len(strR),
|
||||
err: ErrInvalid,
|
||||
|
||||
pSrc: len(strR) + 1,
|
||||
nSrc: len(strR),
|
||||
err0: ErrInvalid,
|
||||
}, {
|
||||
// Short destination
|
||||
in: "abcdefghij",
|
||||
dir: bidi.LeftToRight,
|
||||
|
||||
pSrc: 10,
|
||||
szDst: 5,
|
||||
nSrc: 5,
|
||||
err0: transform.ErrShortDst,
|
||||
}, {
|
||||
in: "\U000102f7",
|
||||
dir: bidi.LeftToRight,
|
||||
n: len("\U000102f7"),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
// Short destination splitting input rune
|
||||
in: "e\u0301",
|
||||
dir: bidi.LeftToRight,
|
||||
|
||||
pSrc: 3,
|
||||
szDst: 2,
|
||||
nSrc: 1,
|
||||
err0: transform.ErrShortDst,
|
||||
}, {
|
||||
// Unicode 10.0.0 IDNA test string.
|
||||
in: "FAX\u2a77\U0001d186",
|
||||
dir: bidi.LeftToRight,
|
||||
n: len("FAX\u2a77\U0001d186"),
|
||||
err: ErrInvalid,
|
||||
}, {
|
||||
in: "\x80\u0660",
|
||||
dir: bidi.RightToLeft,
|
||||
n: 0,
|
||||
err: ErrInvalid,
|
||||
}},
|
||||
}
|
||||
|
||||
func init() {
|
||||
for rule, cases := range testCases {
|
||||
for i, tc := range cases {
|
||||
if tc.err == nil {
|
||||
testCases[rule][i].n = len(tc.in)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func doTests(t *testing.T, fn func(t *testing.T, tc ruleTest)) {
|
||||
for rule, cases := range testCases {
|
||||
for i, tc := range cases {
|
||||
name := fmt.Sprintf("%d/%d:%+q:%s", rule, i, tc.in, tc.in)
|
||||
testtext.Run(t, name, func(t *testing.T) {
|
||||
fn(t, tc)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirection(t *testing.T) {
|
||||
doTests(t, func(t *testing.T, tc ruleTest) {
|
||||
dir := Direction([]byte(tc.in))
|
||||
if dir != tc.dir {
|
||||
t.Errorf("dir was %v; want %v", dir, tc.dir)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestDirectionString(t *testing.T) {
|
||||
doTests(t, func(t *testing.T, tc ruleTest) {
|
||||
dir := DirectionString(tc.in)
|
||||
if dir != tc.dir {
|
||||
t.Errorf("dir was %v; want %v", dir, tc.dir)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestValid(t *testing.T) {
|
||||
doTests(t, func(t *testing.T, tc ruleTest) {
|
||||
got := Valid([]byte(tc.in))
|
||||
want := tc.err == nil
|
||||
if got != want {
|
||||
t.Fatalf("Valid: got %v; want %v", got, want)
|
||||
}
|
||||
|
||||
got = ValidString(tc.in)
|
||||
want = tc.err == nil
|
||||
if got != want {
|
||||
t.Fatalf("Valid: got %v; want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSpan(t *testing.T) {
|
||||
doTests(t, func(t *testing.T, tc ruleTest) {
|
||||
// Skip tests that test for limited destination buffer size.
|
||||
if tc.szDst > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
r := New()
|
||||
src := []byte(tc.in)
|
||||
|
||||
n, err := r.Span(src[:tc.pSrc], tc.pSrc == len(tc.in))
|
||||
if err != tc.err0 {
|
||||
t.Errorf("err0 was %v; want %v", err, tc.err0)
|
||||
}
|
||||
if n != tc.nSrc {
|
||||
t.Fatalf("nSrc was %d; want %d", n, tc.nSrc)
|
||||
}
|
||||
|
||||
n, err = r.Span(src[n:], true)
|
||||
if err != tc.err {
|
||||
t.Errorf("error was %v; want %v", err, tc.err)
|
||||
}
|
||||
if got := n + tc.nSrc; got != tc.n {
|
||||
t.Errorf("n was %d; want %d", got, tc.n)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestTransform(t *testing.T) {
|
||||
doTests(t, func(t *testing.T, tc ruleTest) {
|
||||
r := New()
|
||||
|
||||
src := []byte(tc.in)
|
||||
dst := make([]byte, len(tc.in))
|
||||
if tc.szDst > 0 {
|
||||
dst = make([]byte, tc.szDst)
|
||||
}
|
||||
|
||||
// First transform operates on a zero-length string for most tests.
|
||||
nDst, nSrc, err := r.Transform(dst, src[:tc.pSrc], tc.pSrc == len(tc.in))
|
||||
if err != tc.err0 {
|
||||
t.Errorf("err0 was %v; want %v", err, tc.err0)
|
||||
}
|
||||
if nDst != nSrc {
|
||||
t.Fatalf("nDst (%d) and nSrc (%d) should match", nDst, nSrc)
|
||||
}
|
||||
if nSrc != tc.nSrc {
|
||||
t.Fatalf("nSrc was %d; want %d", nSrc, tc.nSrc)
|
||||
}
|
||||
|
||||
dst1 := make([]byte, len(tc.in))
|
||||
copy(dst1, dst[:nDst])
|
||||
|
||||
nDst, nSrc, err = r.Transform(dst1[nDst:], src[nSrc:], true)
|
||||
if err != tc.err {
|
||||
t.Errorf("error was %v; want %v", err, tc.err)
|
||||
}
|
||||
if nDst != nSrc {
|
||||
t.Fatalf("nDst (%d) and nSrc (%d) should match", nDst, nSrc)
|
||||
}
|
||||
n := nSrc + tc.nSrc
|
||||
if n != tc.n {
|
||||
t.Fatalf("n was %d; want %d", n, tc.n)
|
||||
}
|
||||
if got, want := string(dst1[:n]), tc.in[:tc.n]; got != want {
|
||||
t.Errorf("got %+q; want %+q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
6
vendor/golang.org/x/text/secure/doc.go
generated
vendored
Normal file
6
vendor/golang.org/x/text/secure/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// 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.
|
||||
|
||||
// secure is a repository of text security related packages.
|
||||
package secure // import "golang.org/x/text/secure"
|
||||
82
vendor/golang.org/x/text/secure/precis/benchmark_test.go
generated
vendored
Normal file
82
vendor/golang.org/x/text/secure/precis/benchmark_test.go
generated
vendored
Normal 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
50
vendor/golang.org/x/text/secure/precis/class_test.go
generated
vendored
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
vendor/golang.org/x/text/secure/precis/doc.go
generated
vendored
2
vendor/golang.org/x/text/secure/precis/doc.go
generated
vendored
|
|
@ -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
393
vendor/golang.org/x/text/secure/precis/enforce_test.go
generated
vendored
Normal 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", "ab", nil},
|
||||
{"שc", "", bidirule.ErrInvalid}, // bidi rule
|
||||
|
||||
}},
|
||||
{"UsernameCasePreserved", UsernameCasePreserved, []testCase{
|
||||
{"ABC", "ABC", nil},
|
||||
{"AB", "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
149
vendor/golang.org/x/text/secure/precis/profile_test.go
generated
vendored
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
3127
vendor/golang.org/x/text/secure/precis/tables.go
generated
vendored
3127
vendor/golang.org/x/text/secure/precis/tables.go
generated
vendored
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
69
vendor/golang.org/x/text/secure/precis/tables_test.go
generated
vendored
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue