本文整理汇总了Golang中github.com/cosiner/gohper/testing2.Wrap函数的典型用法代码示例。如果您正苦于以下问题:Golang Wrap函数的具体用法?Golang Wrap怎么用?Golang Wrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Wrap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestIndexDistance
func TestIndexDistance(t *testing.T) {
tt := testing2.Wrap(t)
index, indexUsed, remains := SegmentIndex([]int{2, 3}, 6)
tt.Eq(-1, index)
tt.Eq(0, indexUsed)
tt.Eq(-1, remains)
}
示例2: TestSearch
func TestSearch(t *testing.T) {
tt := testing2.Wrap(t)
strings := []string{"a", "b", "c", "d", "e"}
tt.Eq(1, Search(strings, "b", 0))
tt.Eq(-1, Search(strings, "b", 1))
}
示例3: TestRedis
func TestRedis(t *testing.T) {
tt := testing2.Wrap(t)
r := NewRedis(os2.EnvDef("WERCKER_REDIS_HOST", "localhost")+":6379", nil)
tt.Nil(r.Set("User1", EncVal(User{
Id: "1",
Name: "User1",
})))
tt.Nil(r.Set("User2", EncVal(User{
Id: "2",
Name: "User2",
})))
u1 := User{}
tt.Nil(r.DecodeGet("User1", &u1))
tt.Eq("1", u1.Id)
tt.Eq("User1", u1.Name)
u2 := User{}
tt.Nil(r.DecodeGet("User2", &u2))
tt.Eq("2", u2.Id)
tt.Eq("User2", u2.Name)
c, err := r.Del("User1", "User2")
tt.Eq(2, c)
tt.Nil(err)
}
示例4: TestMonthDays
func TestMonthDays(t *testing.T) {
tt := testing2.Wrap(t)
type YearMonth struct {
Year, Month int
Days int
IsLeap bool
}
tests := []YearMonth{
YearMonth{2000, 3, 31, true},
YearMonth{2000, 4, 30, true},
YearMonth{2000, 2, 29, true},
YearMonth{2001, 2, 28, false},
YearMonth{2300, 2, 28, false},
YearMonth{2400, 2, 29, true},
}
for _, t := range tests {
tt.Eq(t.Days, MonthDays(t.Year, t.Month))
tt.Eq(t.IsLeap, IsLeapYear(t.Year))
}
defer tt.Recover()
MonthDays(2014, 13)
}
示例5: TestConflictWildcardCatchall
func TestConflictWildcardCatchall(t *testing.T) {
tt := testing2.Wrap(t)
rt := new(router)
tt.True(rt.HandleFunc("/:user/:id", GET, EmptyHandlerFunc) == nil)
e := rt.HandleFunc("/*user", GET, EmptyHandlerFunc)
tt.True(e != nil)
}
示例6: TestFilter
func TestFilter(t *testing.T) {
tt := testing2.Wrap(t)
s := NewServer()
var n int
ft := func(req Request, resp Response, chain FilterChain) {
n++
chain(req, resp)
}
s.Handle("/", ft)
s.Handle("/user", ft)
s.Handle("/user/info", ft)
s.Get("/user/info/aaa", Intercept(func(Request, Response) {
n++
}, ft, ft, ft))
s.ResMaster.DefUse(resource.RES_JSON, resource.JSON{})
s.ServeHTTP(NewMockWriter(os.Stdout), &http.Request{
Method: "Get",
URL: &url.URL{
Path: "/user/info/aaa",
},
})
tt.Eq(7, n)
}
示例7: TestUnmarshalPrimitive
func TestUnmarshalPrimitive(t *testing.T) {
tt := testing2.Wrap(t)
bs := "tzz"
var b bool
tt.True(UnmarshalPrimitive(bs, reflect.ValueOf(&b)) == nil)
tt.True(b)
}
示例8: TestMarshalStruct
func TestMarshalStruct(t *testing.T) {
tt := testing2.Wrap(t)
st := struct {
Name string `fd:"nm"`
Age int `fd:"Age"`
}{
"aaa",
123,
}
mp := make(map[string]string)
MarshalStruct(&st, mp, "fd")
tt.DeepEq(map[string]string{
"nm": "aaa",
"Age": "123",
}, mp)
mp["nm"] = "bbb"
mp["age"] = "234"
UnmarshalStruct(&st, StringMap(mp), "fd")
tt.Eq("bbb", st.Name)
tt.Eq(123, st.Age)
}
示例9: TestStrings
func TestStrings(t *testing.T) {
tt := testing2.Wrap(t)
slice := Strings{}
strings := Strings{"1", "2", "3", "4", "5", "6", "7", "8"}
for _, s := range strings {
slice = slice.IncrAppend(s)
tt.Eq(len(slice), cap(slice))
}
slice = slice.FitCapToLen()
tt.Eq(len(slice), cap(slice))
slice = append(slice, "9", "10")
tt.NE(len(slice), cap(slice))
slice = slice.FitCapToLen()
tt.Eq(len(slice), cap(slice))
slice = slice.Remove(0)
tt.DeepEq(Strings{"2", "3", "4", "5", "6", "7", "8", "9", "10"}, slice)
slice = slice.Remove(slice.Len() - 1)
tt.DeepEq(Strings{"2", "3", "4", "5", "6", "7", "8", "9"}, slice.Append("2").RmDups())
tt.Eq("23456789", slice.Join("", ""))
tt.Eq("2=?, 3=?, 4=?, 5=?, 6=?, 7=?, 8=?, 9=?", slice.Join("=?", ", "))
}
示例10: TestFormat
func TestFormat(t *testing.T) {
tt := testing2.Wrap(t)
code := `package main
func TestExport(t *testing.T) {
tt := testing2.Wrap(t)
tt.True(IsExported("Name"))
tt.True(ToSameExported("Abcd", "abc") == "Abc")
tt.True(ToSameExported("dbcd", "Abc") == "abc");tt.True(ToExported("aaa") == "Aaa")
tt.True(ToExported("") == "")
tt.True(ToUnexported("Aaa") == "aaa")
tt.True(ToUnexported("") == "")
}
`
out := bytes.NewBuffer(make([]byte, 0, 1024))
tt.True(Format("test", strings.NewReader(code), out) == nil)
tt.Eq(strings2.RemoveSpace(`package main
func TestExport(t *testing.T) {
tt := testing2.Wrap(t)
tt.True(IsExported("Name"))
tt.True(ToSameExported("Abcd", "abc") == "Abc")
tt.True(ToSameExported("dbcd", "Abc") == "abc")
tt.True(ToExported("aaa") == "Aaa")
tt.True(ToExported("") == "")
tt.True(ToUnexported("Aaa") == "aaa")
tt.True(ToUnexported("") == "")
}
`), strings2.RemoveSpace(out.String()))
}
示例11: TestCond
func TestCond(t *testing.T) {
tt := testing2.Wrap(t)
tt.True(Cond(true).String("1", "2") == "1")
tt.True(Cond(true).Int(1, 2) == 1)
tt.True(Cond(true).Int8(1, 2) == 1)
tt.True(Cond(true).Int16(1, 2) == 1)
tt.True(Cond(true).Int32(1, 2) == 1)
tt.True(Cond(true).Int64(1, 2) == 1)
tt.True(Cond(true).Uint(1, 2) == 1)
tt.True(Cond(true).Uint8(1, 2) == 1)
tt.True(Cond(true).Uint16(1, 2) == 1)
tt.True(Cond(true).Uint32(1, 2) == 1)
tt.True(Cond(true).Uint64(1, 2) == 1)
tt.True(Cond(false).String("1", "2") == "2")
tt.True(Cond(false).Int(1, 2) == 2)
tt.True(Cond(false).Int8(1, 2) == 2)
tt.True(Cond(false).Int16(1, 2) == 2)
tt.True(Cond(false).Int32(1, 2) == 2)
tt.True(Cond(false).Int64(1, 2) == 2)
tt.True(Cond(false).Uint(1, 2) == 2)
tt.True(Cond(false).Uint8(1, 2) == 2)
tt.True(Cond(false).Uint16(1, 2) == 2)
tt.True(Cond(false).Uint32(1, 2) == 2)
tt.True(Cond(false).Uint64(1, 2) == 2)
}
示例12: TestReverseBits
func TestReverseBits(t *testing.T) {
tt := testing2.Wrap(t)
// 0000 0 0001 1 0010 2 0100 4 1000 8
// 0011 3 0110 6 1100 C 1001 9
tt.Eq(uint(0xcccccccc), ReverseBits(0x3333333300000000))
tt.Eq(uint(0x48484848), ReverseBits(0x1212121200000000))
}
示例13: TestPrefix
func TestPrefix(t *testing.T) {
tt := testing2.Wrap(t)
tree := Trie{}
tree.AddPath("1234", 1)
tree.AddPath("234", 2)
tree.AddPath("12", 3)
tree.AddPath("347", 4)
tree.AddPath("00", 5)
tt.Nil(tree.PrefixMatchValue(""))
tt.Nil(tree.PrefixMatchValue("1"))
tt.Nil(tree.PrefixMatchValue("2"))
tt.Nil(tree.PrefixMatchValue("3"))
tt.Nil(tree.PrefixMatchValue("0"))
tt.Nil(tree.PrefixMatchValue("13"))
tt.Nil(tree.PrefixMatchValue("01"))
tt.Eq(1, tree.PrefixMatchValue("1234").(int))
tt.Eq(1, tree.PrefixMatchValue("12345").(int))
tt.Eq(3, tree.PrefixMatchValue("12").(int))
tt.Eq(3, tree.PrefixMatchValue("123").(int))
tt.Eq(3, tree.PrefixMatchValue("124").(int))
}
示例14: TestFunc
func TestFunc(t *testing.T) {
tt := testing2.Wrap(t)
type Test struct {
Time int64
Human string
}
tests := []Test{
Test{0, "0ns"},
Test{999, "999ns"},
Test{1000, "1us"},
Test{1499, "1us"},
Test{1500, "2us"},
Test{1000 * 1000, "1ms"},
Test{1000 * 1499, "1ms"},
Test{1000 * 1500, "2ms"},
Test{1000 * 1000 * 1000, "1s"},
Test{1000 * 1000 * 1499, "1s"},
Test{1000 * 1000 * 1500, "2s"},
Test{1000 * 1000 * 1000 * 10000, "10000s"},
}
for _, test := range tests {
tt.Eq(test.Human, ToHuman(test.Time))
}
}
示例15: TestBinaryTree
func TestBinaryTree(t *testing.T) {
tt := testing2.Wrap(t)
bt := Binary{}
bt.Add(1, 'A', false)
bt.Add(2, 'B', false)
bt.Add(3, 'C', false)
bt.Add(4, 'D', false)
bt.Add(5, 'E', false)
bt.Add(6, 'F', false)
bt.Add(7, 'G', false)
tt.Eq('A', bt.Search(1).(int32))
tt.Eq('B', bt.Search(2).(int32))
tt.Eq('C', bt.Search(3).(int32))
tt.Eq('D', bt.Search(4).(int32))
tt.Eq('E', bt.Search(5).(int32))
tt.Eq('F', bt.Search(6).(int32))
tt.Eq('G', bt.Search(7).(int32))
tt.Nil(bt.Search(8))
tt.Nil(bt.Search(9))
bt.Add(7, 'H', true)
tt.Eq('H', bt.Search(7).(int32))
bt.Add(7, 'I', false)
tt.Eq('H', bt.Search(7).(int32))
}