Switch from glide to govendor

This commit is contained in:
Manfred Touron
2017-12-19 13:55:52 +01:00
parent ccffd8bfe2
commit 230480afd1
1871 changed files with 302 additions and 801202 deletions

View File

@@ -1,24 +0,0 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof

View File

@@ -1 +0,0 @@
language: go

View File

@@ -1,163 +0,0 @@
// Copyright 2015 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package xstrings
import (
"sort"
"strings"
"testing"
)
func TestToSnakeCase(t *testing.T) {
runTestCases(t, ToSnakeCase, _M{
"HTTPServer": "http_server",
"_camelCase": "_camel_case",
"NoHTTPS": "no_https",
"Wi_thF": "wi_th_f",
"_AnotherTES_TCaseP": "_another_tes_t_case_p",
"ALL": "all",
"_HELLO_WORLD_": "_hello_world_",
"HELLO_WORLD": "hello_world",
"HELLO____WORLD": "hello____world",
"TW": "tw",
"_C": "_c",
" sentence case ": "__sentence_case__",
" Mixed-hyphen case _and SENTENCE_case and UPPER-case": "_mixed_hyphen_case__and_sentence_case_and_upper_case",
})
}
func TestToCamelCase(t *testing.T) {
runTestCases(t, ToCamelCase, _M{
"http_server": "HttpServer",
"_camel_case": "_CamelCase",
"no_https": "NoHttps",
"_complex__case_": "_Complex_Case_",
"all": "All",
})
}
func TestSwapCase(t *testing.T) {
runTestCases(t, SwapCase, _M{
"swapCase": "SWAPcASE",
"Θ~λa云Ξπ": "θ~ΛA云ξΠ",
})
}
func TestFirstRuneToUpper(t *testing.T) {
runTestCases(t, FirstRuneToUpper, _M{
"hello, world!": "Hello, world!",
"Hello, world!": "Hello, world!",
"你好,世界!": "你好,世界!",
})
}
func TestFirstRuneToLower(t *testing.T) {
runTestCases(t, FirstRuneToLower, _M{
"hello, world!": "hello, world!",
"Hello, world!": "hello, world!",
"你好,世界!": "你好,世界!",
})
}
func TestShuffle(t *testing.T) {
// It seems there is no reliable way to test shuffled string.
// Runner just make sure shuffled string has the same runes as origin string.
runner := func(str string) string {
s := Shuffle(str)
slice := sort.StringSlice(strings.Split(s, ""))
slice.Sort()
return strings.Join(slice, "")
}
runTestCases(t, runner, _M{
"": "",
"facgbheidjk": "abcdefghijk",
"尝试中文": "中尝文试",
"zh英文hun排": "hhnuz排文英",
})
}
type testShuffleSource int
// A generated random number sequance just for testing.
var testShuffleTable = []int64{
1874068156324778273,
3328451335138149956,
5263531936693774911,
7955079406183515637,
2703501726821866378,
2740103009342231109,
6941261091797652072,
1905388747193831650,
7981306761429961588,
6426100070888298971,
4831389563158288344,
261049867304784443,
1460320609597786623,
5600924393587988459,
8995016276575641803,
732830328053361739,
5486140987150761883,
545291762129038907,
6382800227808658932,
2781055864473387780,
1598098976185383115,
4990765271833742716,
5018949295715050020,
2568779411109623071,
3902890183311134652,
4893789450120281907,
2338498362660772719,
2601737961087659062,
7273596521315663110,
3337066551442961397,
8121576815539813105,
2740376916591569721,
8249030965139585917,
898860202204764712,
9010467728050264449,
685213522303989579,
2050257992909156333,
6281838661429879825,
2227583514184312746,
2873287401706343734,
}
func (src testShuffleSource) Int63() int64 {
n := testShuffleTable[int(src)%len(testShuffleTable)]
src++
return n
}
func (src testShuffleSource) Seed(int64) {}
func TestShuffleSource(t *testing.T) {
var src testShuffleSource
runner := func(str string) string {
return ShuffleSource(str, src)
}
runTestCases(t, runner, _M{
"": "",
"facgbheidjk": "bakefjgichd",
"尝试中文怎么样": "怎试中样尝么文",
"zh英文hun排": "hh英nzu文排",
})
}
func TestSuccessor(t *testing.T) {
runTestCases(t, Successor, _M{
"": "",
"abcd": "abce",
"THX1138": "THX1139",
"<<koala>>": "<<koalb>>",
"1999zzz": "2000aaa",
"ZZZ9999": "AAAA0000",
"***": "**+",
"来点中文试试": "来点中文试诖",
"中cZ英ZZ文zZ混9zZ9杂99进z位": "中dA英AA文aA混0aA0杂00进a位",
})
}

View File

@@ -1,62 +0,0 @@
// Copyright 2015 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package xstrings
import (
"fmt"
"testing"
)
func TestLen(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(Len(str))
}
runTestCases(t, runner, _M{
"abcdef": "6",
"中文": "2",
"中yin文hun排": "9",
"": "0",
})
}
func TestWordCount(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(WordCount(str))
}
runTestCases(t, runner, _M{
"one word: λ": "3",
"中文": "0",
"你好sekai": "1",
"oh, it's super-fancy!!a": "4",
"": "0",
"-": "0",
"it's-'s": "1",
})
}
func TestWidth(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(Width(str))
}
runTestCases(t, runner, _M{
"abcd\t0123\n7890": "12",
"中zh英eng文混排": "15",
"": "0",
})
}
func TestRuneWidth(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(RuneWidth([]rune(str)[0]))
}
runTestCases(t, runner, _M{
"a": "1",
"中": "2",
"\x11": "0",
})
}

View File

@@ -1,100 +0,0 @@
// Copyright 2015 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package xstrings
import (
"strconv"
"strings"
"testing"
)
func TestExpandTabs(t *testing.T) {
runner := func(str string) (result string) {
defer func() {
if e := recover(); e != nil {
result = e.(string)
}
}()
input := strings.Split(str, separator)
n, _ := strconv.Atoi(input[1])
return ExpandTabs(input[0], n)
}
runTestCases(t, runner, _M{
sep("a\tbc\tdef\tghij\tk", "4"): "a bc def ghij k",
sep("abcdefg\thij\nk\tl", "4"): "abcdefg hij\nk l",
sep("z中\t文\tw", "4"): "z中 文 w",
sep("abcdef", "4"): "abcdef",
sep("abc\td\tef\tghij\nk\tl", "3"): "abc d ef ghij\nk l",
sep("abc\td\tef\tghij\nk\tl", "1"): "abc d ef ghij\nk l",
sep("abc", "0"): "tab size must be positive",
sep("abc", "-1"): "tab size must be positive",
})
}
func TestLeftJustify(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
n, _ := strconv.Atoi(input[1])
return LeftJustify(input[0], n, input[2])
}
runTestCases(t, runner, _M{
sep("hello", "4", " "): "hello",
sep("hello", "10", " "): "hello ",
sep("hello", "10", "123"): "hello12312",
sep("hello中文test", "4", " "): "hello中文test",
sep("hello中文test", "12", " "): "hello中文test ",
sep("hello中文test", "18", "测试!"): "hello中文test测试测试测",
sep("hello中文test", "0", "123"): "hello中文test",
sep("hello中文test", "18", ""): "hello中文test",
})
}
func TestRightJustify(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
n, _ := strconv.Atoi(input[1])
return RightJustify(input[0], n, input[2])
}
runTestCases(t, runner, _M{
sep("hello", "4", " "): "hello",
sep("hello", "10", " "): " hello",
sep("hello", "10", "123"): "12312hello",
sep("hello中文test", "4", " "): "hello中文test",
sep("hello中文test", "12", " "): " hello中文test",
sep("hello中文test", "18", "测试!"): "测试测试测hello中文test",
sep("hello中文test", "0", "123"): "hello中文test",
sep("hello中文test", "18", ""): "hello中文test",
})
}
func TestCenter(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
n, _ := strconv.Atoi(input[1])
return Center(input[0], n, input[2])
}
runTestCases(t, runner, _M{
sep("hello", "4", " "): "hello",
sep("hello", "10", " "): " hello ",
sep("hello", "10", "123"): "12hello123",
sep("hello中文test", "4", " "): "hello中文test",
sep("hello中文test", "12", " "): "hello中文test ",
sep("hello中文test", "18", "测试!"): "测试hello中文test测试测",
sep("hello中文test", "0", "123"): "hello中文test",
sep("hello中文test", "18", ""): "hello中文test",
})
}

View File

@@ -1,142 +0,0 @@
// Copyright 2015 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package xstrings
import (
"strconv"
"strings"
"testing"
)
func TestReverse(t *testing.T) {
runTestCases(t, Reverse, _M{
"reverse string": "gnirts esrever",
"中文如何?": "?何如文中",
"中en文混~排怎样a": "a样怎排~混文ne中",
})
}
func TestSlice(t *testing.T) {
runner := func(str string) (result string) {
defer func() {
if e := recover(); e != nil {
result = e.(string)
}
}()
strs := split(str)
start, _ := strconv.ParseInt(strs[1], 10, 0)
end, _ := strconv.ParseInt(strs[2], 10, 0)
result = Slice(strs[0], int(start), int(end))
return
}
runTestCases(t, runner, _M{
sep("abcdefghijk", "3", "8"): "defgh",
sep("来点中文如何?", "2", "7"): "中文如何?",
sep("中en文混~排总是少不了的a", "2", "8"): "n文混~排总",
sep("中en文混~排总是少不了的a", "0", "0"): "",
sep("中en文混~排总是少不了的a", "14", "14"): "",
sep("中en文混~排总是少不了的a", "5", "-1"): "~排总是少不了的a",
sep("中en文混~排总是少不了的a", "14", "-1"): "",
sep("let us slice out of range", "-3", "3"): "out of range",
sep("超出范围哦", "2", "6"): "out of range",
sep("don't do this", "3", "2"): "out of range",
sep("千gan万de不piao要liang", "19", "19"): "out of range",
})
}
func TestPartition(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
head, match, tail := Partition(input[0], input[1])
return sep(head, match, tail)
}
runTestCases(t, runner, _M{
sep("hello", "l"): sep("he", "l", "lo"),
sep("中文总少不了", "少"): sep("中文总", "少", "不了"),
sep("z这个zh英文混排hao不", "h英文"): sep("z这个z", "h英文", "混排hao不"),
sep("边界tiao件zen能忘", "边界"): sep("", "边界", "tiao件zen能忘"),
sep("尾巴ye别忘le", "忘le"): sep("尾巴ye别", "忘le", ""),
sep("hello", "x"): sep("hello", "", ""),
sep("不是晩香玉", "晚"): sep("不是晩香玉", "", ""), // Hint: 晩 is not 晚 :)
sep("来ge混排ba", "e 混"): sep("来ge混排ba", "", ""),
})
}
func TestLastPartition(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
head, match, tail := LastPartition(input[0], input[1])
return sep(head, match, tail)
}
runTestCases(t, runner, _M{
sep("hello", "l"): sep("hel", "l", "o"),
sep("少量中文总少不了", "少"): sep("少量中文总", "少", "不了"),
sep("z这个zh英文ch英文混排hao不", "h英文"): sep("z这个zh英文c", "h英文", "混排hao不"),
sep("边界tiao件zen能忘边界", "边界"): sep("边界tiao件zen能忘", "边界", ""),
sep("尾巴ye别忘le", "尾巴"): sep("", "尾巴", "ye别忘le"),
sep("hello", "x"): sep("", "", "hello"),
sep("不是晩香玉", "晚"): sep("", "", "不是晩香玉"), // Hint: 晩 is not 晚 :)
sep("来ge混排ba", "e 混"): sep("", "", "来ge混排ba"),
})
}
func TestInsert(t *testing.T) {
runner := func(str string) (result string) {
defer func() {
if e := recover(); e != nil {
result = e.(string)
}
}()
strs := split(str)
index, _ := strconv.ParseInt(strs[2], 10, 0)
result = Insert(strs[0], strs[1], int(index))
return
}
runTestCases(t, runner, _M{
sep("abcdefg", "hi", "3"): "abchidefg",
sep("少量中文是必须的", "混pai", "4"): "少量中文混pai是必须的",
sep("zh英文hun排", "~", "5"): "zh英文h~un排",
sep("插在begining", "我", "0"): "我插在begining",
sep("插在ending", "我", "8"): "插在ending我",
sep("超tian出yuan边tu界po", "foo", "-1"): "out of range",
sep("超tian出yuan边tu界po", "foo", "17"): "out of range",
})
}
func TestScrub(t *testing.T) {
runner := func(str string) string {
strs := split(str)
return Scrub(strs[0], strs[1])
}
runTestCases(t, runner, _M{
sep("ab\uFFFDcd\xFF\xCEefg\xFF\xFC\xFD\xFAhijk", "*"): "ab*cd*efg*hijk",
sep("no错误です", "*"): "no错误です",
sep("", "*"): "",
})
}
func TestWordSplit(t *testing.T) {
runner := func(str string) string {
return sep(WordSplit(str)...)
}
runTestCases(t, runner, _M{
"one word": sep("one", "word"),
"一个字:把他给我拿下!": "",
"it's a super-fancy one!!!a": sep("it's", "a", "super-fancy", "one", "a"),
"a -b-c' 'd'e": sep("a", "b-c'", "d'e"),
})
}

View File

@@ -1,92 +0,0 @@
// Copyright 2015 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package xstrings
import (
"fmt"
"strings"
"testing"
)
func TestTranslate(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return Translate(input[0], input[1], input[2])
}
runTestCases(t, runner, _M{
sep("hello", "aeiou", "12345"): "h2ll4",
sep("hello", "aeiou", ""): "hll",
sep("hello", "a-z", "A-Z"): "HELLO",
sep("hello", "z-a", "a-z"): "svool",
sep("hello", "aeiou", "*"): "h*ll*",
sep("hello", "^l", "*"): "**ll*",
sep("hello", "p-z", "*"): "hello",
sep("hello ^ world", `\^lo`, "*"): "he*** * w*r*d",
sep("中文字符测试", "文中谁敢试?", "123456"): "21字符测5",
sep("中文字符测试", "^文中谁敢试?", "123456"): "中文666试",
sep("中文字符测试", "字-试", "0-9"): "中90999",
sep("h1e2l3l4o, w5o6r7l8d", "a-z,0-9", `A-Z\-a-czk-p`): "HbEcLzLkO- WlOmRnLoD",
sep("h1e2l3l4o, w5o6r7l8d", "a-zoh-n", "b-zakt-z"): "t1f2x3x4k, x5k6s7x8e",
sep("h1e2l3l4o, w5o6r7l8d", "helloa-zoh-n", "99999b-zakt-z"): "t1f2x3x4k, x5k6s7x8e",
sep("hello", "e-", "p"): "hpllo",
sep("hello", "-e-", "p"): "hpllo",
sep("hello", "----e---", "p"): "hpllo",
sep("hello", "^---e----", "p"): "peppp",
sep("hel\uFFFDlo", "\uFFFD", "H"): "helHlo",
sep("hel\uFFFDlo", "^\uFFFD", "H"): "HHHHH",
sep("hel\uFFFDlo", "o-\uFFFDh", "H"): "HelHlH",
})
}
func TestDelete(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return Delete(input[0], input[1])
}
runTestCases(t, runner, _M{
sep("hello", "aeiou"): "hll",
sep("hello", "a-k"): "llo",
sep("hello", "^a-k"): "he",
sep("中文字符测试", "文中谁敢试?"): "字符测",
})
}
func TestCount(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return fmt.Sprint(Count(input[0], input[1]))
}
runTestCases(t, runner, _M{
sep("hello", "aeiou"): "2",
sep("hello", "a-k"): "2",
sep("hello", "^a-k"): "3",
sep("中文字符测试", "文中谁敢试?"): "3",
})
}
func TestSqueeze(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return Squeeze(input[0], input[1])
}
runTestCases(t, runner, _M{
sep("hello", ""): "helo",
sep("hello", "a-k"): "hello",
sep("hello", "^a-k"): "helo",
sep("hello", "^a-l"): "hello",
sep("打打打打个劫!!", ""): "打个劫!",
sep("打打打打个劫!!", "打"): "打个劫!!",
})
}

View File

@@ -1,33 +0,0 @@
// Copyright 2015 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package xstrings
import (
"strings"
"testing"
)
type _M map[string]string
const (
separator = " ¶ "
)
func runTestCases(t *testing.T, converter func(string) string, cases map[string]string) {
for k, v := range cases {
s := converter(k)
if s != v {
t.Fatalf("case fails. [case:%v]\nshould => %#v\nactual => %#v", k, v, s)
}
}
}
func sep(strs ...string) string {
return strings.Join(strs, separator)
}
func split(str string) []string {
return strings.Split(str, separator)
}