summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/text/internal/colltab/contract_test.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-03-24 23:31:34 -0700
committerenahum <nahumhbl@gmail.com>2017-03-25 03:31:34 -0300
commit54d3d47daf9190275bbdaf8703b84969a4593451 (patch)
tree05899b296d0186c1a0da8a540bc486e34ad8eec9 /vendor/golang.org/x/text/internal/colltab/contract_test.go
parent7460302dec7796e01c98264e84bece8169cb6ed9 (diff)
downloadchat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.gz
chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.bz2
chat-54d3d47daf9190275bbdaf8703b84969a4593451.zip
PLT-6076 Adding viper libs for config file changes (#5871)
* Adding viper libs for config file changes * Removing the old fsnotify lib * updating some missing libs
Diffstat (limited to 'vendor/golang.org/x/text/internal/colltab/contract_test.go')
-rw-r--r--vendor/golang.org/x/text/internal/colltab/contract_test.go131
1 files changed, 131 insertions, 0 deletions
diff --git a/vendor/golang.org/x/text/internal/colltab/contract_test.go b/vendor/golang.org/x/text/internal/colltab/contract_test.go
new file mode 100644
index 000000000..ce2871dd4
--- /dev/null
+++ b/vendor/golang.org/x/text/internal/colltab/contract_test.go
@@ -0,0 +1,131 @@
+// Copyright 2012 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 colltab
+
+import (
+ "testing"
+)
+
+type lookupStrings struct {
+ str string
+ offset int
+ n int // bytes consumed from input
+}
+
+type LookupTest struct {
+ lookup []lookupStrings
+ n int
+ tries ContractTrieSet
+}
+
+var lookupTests = []LookupTest{{
+ []lookupStrings{
+ {"abc", 1, 3},
+ {"a", 0, 0},
+ {"b", 0, 0},
+ {"c", 0, 0},
+ {"d", 0, 0},
+ },
+ 1,
+ ContractTrieSet{
+ {'a', 0, 1, 0xFF},
+ {'b', 0, 1, 0xFF},
+ {'c', 'c', 0, 1},
+ },
+}, {
+ []lookupStrings{
+ {"abc", 1, 3},
+ {"abd", 2, 3},
+ {"abe", 3, 3},
+ {"a", 0, 0},
+ {"ab", 0, 0},
+ {"d", 0, 0},
+ {"f", 0, 0},
+ },
+ 1,
+ ContractTrieSet{
+ {'a', 0, 1, 0xFF},
+ {'b', 0, 1, 0xFF},
+ {'c', 'e', 0, 1},
+ },
+}, {
+ []lookupStrings{
+ {"abc", 1, 3},
+ {"ab", 2, 2},
+ {"a", 3, 1},
+ {"abcd", 1, 3},
+ {"abe", 2, 2},
+ },
+ 1,
+ ContractTrieSet{
+ {'a', 0, 1, 3},
+ {'b', 0, 1, 2},
+ {'c', 'c', 0, 1},
+ },
+}, {
+ []lookupStrings{
+ {"abc", 1, 3},
+ {"abd", 2, 3},
+ {"ab", 3, 2},
+ {"ac", 4, 2},
+ {"a", 5, 1},
+ {"b", 6, 1},
+ {"ba", 6, 1},
+ },
+ 2,
+ ContractTrieSet{
+ {'b', 'b', 0, 6},
+ {'a', 0, 2, 5},
+ {'c', 'c', 0, 4},
+ {'b', 0, 1, 3},
+ {'c', 'd', 0, 1},
+ },
+}, {
+ []lookupStrings{
+ {"bcde", 2, 4},
+ {"bc", 7, 2},
+ {"ab", 6, 2},
+ {"bcd", 5, 3},
+ {"abcd", 1, 4},
+ {"abc", 4, 3},
+ {"bcdf", 3, 4},
+ },
+ 2,
+ ContractTrieSet{
+ {'b', 3, 1, 0xFF},
+ {'a', 0, 1, 0xFF},
+ {'b', 0, 1, 6},
+ {'c', 0, 1, 4},
+ {'d', 'd', 0, 1},
+ {'c', 0, 1, 7},
+ {'d', 0, 1, 5},
+ {'e', 'f', 0, 2},
+ },
+}}
+
+func lookup(c *ContractTrieSet, nnode int, s []uint8) (i, n int) {
+ scan := c.scanner(0, nnode, s)
+ scan.scan(0)
+ return scan.result()
+}
+
+func TestLookupContraction(t *testing.T) {
+ for i, tt := range lookupTests {
+ cts := ContractTrieSet(tt.tries)
+ for j, lu := range tt.lookup {
+ str := lu.str
+ for _, s := range []string{str, str + "X"} {
+ const msg = `%d:%d: %s of "%s" %v; want %v`
+ offset, n := lookup(&cts, tt.n, []byte(s))
+ if offset != lu.offset {
+ t.Errorf(msg, i, j, "offset", s, offset, lu.offset)
+ }
+ if n != lu.n {
+ t.Errorf(msg, i, j, "bytes consumed", s, n, len(str))
+ }
+ }
+ }
+ }
+}