本文整理汇总了Golang中github.com/interactiv/expect.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestReverse
func TestReverse(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{1, 2, 3}).Reverse().Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result[0]).ToEqual(3)
}
示例2: TestLastIndexOf
func TestLastIndexOf(t *testing.T) {
e := expect.New(t)
var result int = -1
err := pipeline.In("abba").LastIndexOf('a', 0).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToEqual(3)
}
示例3: TestConcat
func TestConcat(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{}).Concat([]int{1, 2, 3}, []int{4, 5, 6}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(6)
}
示例4: TestCompact
func TestCompact(t *testing.T) {
e := expect.New(t)
var result1 []interface{}
err := pipeline.In([]interface{}{1, nil, 2, 'a', nil}).Compact().Out(&result1)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result1)).ToEqual(fmt.Sprint([]interface{}{1, 2, 'a'}))
}
示例5: TestUnion
func TestUnion(t *testing.T) {
e := expect.New(t)
var res []int
err := pipeline.In([]int{1, 2}).Union([]int{2, 3}, []int{3, 4}).Out(&res)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(res)).ToEqual(fmt.Sprint([]int{1, 2, 3, 4}))
}
示例6: TestIntersection
func TestIntersection(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{1, 2, 4}).Intersection([]int{3, 2, 1}, []int{2, 5, 6}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result)).ToEqual(fmt.Sprint([]int{2}))
}
示例7: TestGroupBy
func TestGroupBy(t *testing.T) {
e := expect.New(t)
var result map[int][]Person
err := pipeline.In([]Person{{12, "John"}, {12, "Jane"}, {20, "Joe"}}).
GroupBy(func(el interface{}, i int) interface{} {
return el.(Person).Age
}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(2)
e.Expect(len(result[12])).ToEqual(2)
e.Expect(result[12][0].Age).ToEqual(12)
var result1 map[string][]map[string]string
err = pipeline.In([]map[string]string{
{"product": "trousers", "category": "clothes"},
{"product": "beer", "category": "drinks"},
{"product": "coat", "category": "clothes"},
}).
GroupBy(func(el interface{}, i int) interface{} {
return el.(map[string]string)["category"]
}).Out(&result1)
e.Expect(err).ToBeNil()
e.Expect(len(result1)).ToEqual(2)
e.Expect(len(result1["clothes"])).ToEqual(2)
e.Expect(len(result1["drinks"])).ToEqual(1)
}
示例8: TestMap
func TestMap(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{1, 2, 3}).Map(func(element interface{}, index int) interface{} {
return element.(int) * 2
}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(3)
e.Expect(result[0]).ToEqual(2)
var result2 *[]int
err = pipeline.In(&[]int{1, 2, 3}).Out(&result2)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result2)).ToEqual(fmt.Sprint(&[]int{1, 2, 3}))
var result3 string
err = pipeline.In("foo").Out(&result3)
e.Expect(err).ToBeNil()
e.Expect(result3).ToBe("foo")
var result4 []string
err = pipeline.In([]int{1, 2, 3}).Out(&result4)
e.Expect(err).Not().ToBeNil()
t.Log(err)
}
示例9: TestLast
func TestLast(t *testing.T) {
e := expect.New(t)
var result int
err := pipeline.In([]int{1, 3, 6}).Last().Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToEqual(6)
}
示例10: TestCompositeExpression
func TestCompositeExpression(t *testing.T) {
e := expect.New(t)
expr := &expression.Composite{expression.OR, []string{"u.group_id = 1"}}
e.Expect(expr.Length()).ToBe(1)
expr.Add("u.group_id = 2")
e.Expect(expr.Length()).ToBe(2)
}
示例11: TestComparison
func TestComparison(t *testing.T) {
e := expect.New(t)
for _, fixture := range provideDataForComparison() {
part := expr().Comparison(fixture.x, fixture.Type, fixture.y)
e.Expect(part).ToEqual(fixture.expected)
}
}
示例12: TestUnique
func TestUnique(t *testing.T) {
e := expect.New(t)
var result []string
err := pipeline.In([]string{"a", "b", "b", "a"}).Unique().Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(2)
e.Expect(result[1]).ToEqual("b")
}
示例13: TestToMap
func TestToMap(t *testing.T) {
e := expect.New(t)
in := map[string]string{"a": "angel", "b": "bookmark", "c": "card"}
result := pipeline.In(in).ToMap(func(val interface{}, key interface{}) (interface{}, interface{}) {
return key, val
}).MustOut()
e.Expect(result.(map[interface{}]interface{})["angel"]).ToEqual("a")
}
示例14: TestFlatten
func TestFlatten(t *testing.T) {
e := expect.New(t)
var result []int
Error := pipeline.In([]interface{}{[]int{1, 2}, 3, []int{4, 5}}).Flatten().Out(&result)
e.Expect(Error).ToBeNil()
e.Expect(len(result)).ToEqual(5)
t.Log(result)
}
示例15: TestChunk
func TestChunk(t *testing.T) {
e := expect.New(t)
var result [][]int
err := pipeline.In([]int{1, 2, 3, 4, 5}).Chunk(2).Out(&result)
e.Expect(err).ToBeNil()
t.Log(result)
e.Expect(fmt.Sprint(result)).ToEqual(fmt.Sprint([][]int{{1, 2}, {3, 4}, {5}}))
}