• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang asserter.Using函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/rdrdr/hamcrest/asserter.Using函数的典型用法代码示例。如果您正苦于以下问题:Golang Using函数的具体用法?Golang Using怎么用?Golang Using使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Using函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Test_Int64

func Test_Int64(t *testing.T) {
	we := asserter.Using(t)
	we.CheckThat(int64(1), Is(Int64()))
	we.CheckThat(int64(1), ToType(Is(Int64Type())))
	we.CheckThat(int(1), Is(Not(Int64())))
	we.CheckThat(int(1), ToType(Is(Not(Int64Type()))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:7,代码来源:reflect_test.go


示例2: Test_Empty_onSlices

func Test_Empty_onSlices(t *testing.T) {
	we := asserter.Using(t)
	empty := []string{}
	hasTwo := []string{"itsy", "bitsy"}
	we.CheckThat(empty, Is(Empty()))
	we.CheckThat(hasTwo, Is(Not(Empty())))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:7,代码来源:collections_test.go


示例3: Test_Uint

func Test_Uint(t *testing.T) {
	we := asserter.Using(t)
	we.CheckThat(uint(1), Is(Uint()))
	we.CheckThat(uint(1), ToType(Is(UintType())))
	we.CheckThat(int(1), Is(Not(Uint())))
	we.CheckThat(int(1), ToType(Is(Not(UintType()))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:7,代码来源:reflect_test.go


示例4: Test_PanicWhen_onFunctionAcceptingTwoArgsDotDotDot

func Test_PanicWhen_onFunctionAcceptingTwoArgsDotDotDot(t *testing.T) {
	we := asserter.Using(t)

	var functionInvoked bool
	PanicOn13 := PanicWhenApplying(func(arg int, why ...string) {
		functionInvoked = true
		if arg == 13 {
			panic("Superstition")
		}
	}, "Disallow13")

	functionInvoked = false
	we.CheckThat(PanicOn13.Match("thirteen"), Matched.
		Comment("Should panic when can't invoke function"))
	we.CheckFalse(functionInvoked, "Shouldn't have invoked function")

	functionInvoked = false
	we.CheckThat(PanicOn13.Match(12), DidNotMatch)
	we.CheckTrue(functionInvoked, "Should have invoked function")

	functionInvoked = false
	we.CheckThat(PanicOn13.Match(13), Matched)
	we.CheckTrue(functionInvoked, "Should have invoked function")

	logSamples(t, PanicOn13)
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:26,代码来源:core_test.go


示例5: Test_Empty_onMaps

func Test_Empty_onMaps(t *testing.T) {
	we := asserter.Using(t)
	empty := map[string]int{}
	hasTwo := map[string]int{"foo": 1, "bar": 2}
	we.CheckThat(empty, Is(Empty()))
	we.CheckThat(hasTwo, Is(Not(Empty())))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:7,代码来源:collections_test.go


示例6: Test_ToLen_onSlices

func Test_ToLen_onSlices(t *testing.T) {
	we := asserter.Using(t)
	empty := []string{}
	hasTwo := []string{"itsy", "bitsy"}
	we.CheckThat(empty, ToLen(Is(EqualTo(0))))
	we.CheckThat(hasTwo, ToLen(Is(EqualTo(2))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:7,代码来源:collections_test.go


示例7: Test_PanicWhen_onFunctionAcceptingBool

func Test_PanicWhen_onFunctionAcceptingBool(t *testing.T) {
	we := asserter.Using(t)

	var functionInvoked bool
	PanicOnFalse := PanicWhenApplying(func(b bool) {
		functionInvoked = true
		if !b {
			panic("Must be true")
		}
	}, "PanicOnFalse")

	functionInvoked = false
	we.CheckThat(PanicOnFalse.Match("true"), Matched.
		Comment("Should panic when can't invoke function"))
	we.CheckFalse(functionInvoked, "Shouldn't have invoked function")

	functionInvoked = false
	we.CheckThat(PanicOnFalse.Match(nil), Matched.
		Comment("Can't invoke function with string"))
	we.CheckFalse(functionInvoked, "Shouldn't have invoked function")

	functionInvoked = false
	we.CheckThat(PanicOnFalse.Match(true), DidNotMatch)
	we.CheckTrue(functionInvoked, "Should have invoked function")

	functionInvoked = false
	we.CheckThat(PanicOnFalse.Match(false), Matched)
	we.CheckTrue(functionInvoked, "Should have invoked function")

	logSamples(t, PanicOnFalse)
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:31,代码来源:core_test.go


示例8: Test_DeepEqualTo

func Test_DeepEqualTo(t *testing.T) {
	we := asserter.Using(t)
	data := []interface{}{
		nil, true, false,
		int(42), uint(42), float64(42), complex128(42),
		struct{ x int }{x: 42},
		struct{ x int }{x: 42},
		&struct{ x int }{x: 42},
		struct{ y int }{y: 42},
		_DeepEqualType{x: 42},
		&_DeepEqualType{x: 42},
		[]int{42},
		[]int{42},
		map[int]int{42: 42},
		map[int]int{42: 42},
		make(chan int, 42),
		make(chan int, 42),
	}
	for _, x := range data {
		matcher := DeepEqualTo(x)
		for _, y := range data {
			message := fmt.Sprintf("%T[%v] and %T[%v]", x, x, y, y)
			if reflect.DeepEqual(x, y) {
				we.CheckThat(matcher.Match(y), Matched.Comment(message))
			} else {
				we.CheckThat(matcher.Match(y), DidNotMatch.Comment(message))
			}
		}
	}
	logSamples(t, DeepEqualTo(42))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:31,代码来源:core_test.go


示例9: Test_ToLen_onMaps

func Test_ToLen_onMaps(t *testing.T) {
	we := asserter.Using(t)
	empty := map[string]int{}
	hasTwo := map[string]int{"foo": 1, "bar": 2}
	we.CheckThat(empty, ToLen(Is(EqualTo(0))))
	we.CheckThat(hasTwo, ToLen(Is(EqualTo(2))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:7,代码来源:collections_test.go


示例10: Test_Is

func Test_Is(t *testing.T) {
	we := asserter.Using(t)
	matcher := Is(True())
	we.CheckThat(matcher.Match(true), Matched)
	we.CheckThat(matcher.Match(false), DidNotMatch)
	logSamples(t, matcher)
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:7,代码来源:core_test.go


示例11: Test_SliceTypeOf

func Test_SliceTypeOf(t *testing.T) {
	we := asserter.Using(t)
	boolSlice := make([]bool, 0, 1)
	intSlice := make([]int, 0, 1)
	intSliceSlice := make([][]int, 0, 1)

	we.CheckThat(boolSlice, Is(SliceOf(BoolType())))
	we.CheckThat(boolSlice, Is(Not(SliceOf(IntType()))))
	we.CheckThat(boolSlice, ToType(Is(SliceTypeOf(BoolType()))))
	we.CheckThat(boolSlice, ToType(Is(Not(SliceTypeOf(IntType())))))

	we.CheckThat(intSlice, Is(Not(SliceOf(BoolType()))))
	we.CheckThat(intSlice, Is(SliceOf(IntType())))
	we.CheckThat(intSlice, ToType(Is(Not(SliceTypeOf(BoolType())))))
	we.CheckThat(intSlice, ToType(Is(SliceTypeOf(IntType()))))

	we.CheckThat(intSliceSlice, Is(Not(SliceOf(IntType()))))
	we.CheckThat(intSliceSlice, Is(Not(SliceOf(SliceOf(IntType())))))
	we.CheckThat(intSliceSlice, Is(Not(SliceTypeOf(SliceOf(IntType())))))
	we.CheckThat(intSliceSlice, Is(SliceOf(SliceTypeOf(IntType()))))
	we.CheckThat(intSliceSlice, ToType(Is(SliceTypeOf(SliceTypeOf(IntType())))))

	var intArray = [3]int{1, 2, 3}
	we.CheckThat(intArray, Is(Not(SliceOf(Anything()))))
	we.CheckThat(intArray, ToType(Is(Not(SliceTypeOf(Anything())))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:26,代码来源:reflect_test.go


示例12: logSamples

func logSamples(t *testing.T, matcher *base.Matcher) {
	t.Logf("Sample results for: %v\n", matcher)
	we := asserter.Using(t)
	for index, value := range sampleValues {
		t.Logf("Sample #%v: %T[value: %v]\n", index+1, value, value)
		we.LogResult(matcher.Match(value))
	}
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:8,代码来源:core_test.go


示例13: Test_ToLen

func Test_ToLen(t *testing.T) {
	we := asserter.Using(t)
	IsLength2 := ToLen(Is(EqualTo(2)))
	we.CheckThat(IsLength2.Match([]int{}), DidNotMatch.Comment("no elements"))
	we.CheckThat(IsLength2.Match([]int{7}), DidNotMatch.Comment("too few"))
	we.CheckThat(IsLength2.Match([]int{7, 8}), Matched.Comment("just right"))
	we.CheckThat(IsLength2.Match([]int{7, 8, 9}), DidNotMatch.Comment("too many"))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:8,代码来源:slices_test.go


示例14: Test_EveryElement_ofSlice

func Test_EveryElement_ofSlice(t *testing.T) {
	we := asserter.Using(t)
	we.CheckThat([]int{1, 2, 3}, EveryElement(LessThan(4)).Comment("all elements"))
	we.CheckThat([]int{2, 1, 1}, Not(EveryElement(LessThan(2))).Comment("all but first"))
	we.CheckThat([]int{1, 2, 1}, Not(EveryElement(LessThan(2))).Comment("all but middle"))
	we.CheckThat([]int{1, 1, 2}, Not(EveryElement(LessThan(2))).Comment("all but last"))
	we.CheckThat([]int{}, EveryElement(Anything()).Comment("no elements"))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:8,代码来源:collections_test.go


示例15: Test_AnyElement_ofSlice

func Test_AnyElement_ofSlice(t *testing.T) {
	we := asserter.Using(t)
	we.CheckThat([]int{1, 2, 3}, AnyElement(EqualTo(1)).Comment("first element"))
	we.CheckThat([]int{1, 2, 3}, AnyElement(EqualTo(2)).Comment("middle element"))
	we.CheckThat([]int{1, 2, 3}, AnyElement(EqualTo(3)).Comment("last element"))
	we.CheckThat([]int{1, 2, 3}, Not(AnyElement(EqualTo(4))).Comment("none matching"))
	we.CheckThat([]int{}, Not(AnyElement(Anything())).Comment("no elements"))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:8,代码来源:collections_test.go


示例16: Test_MapTypeOf

func Test_MapTypeOf(t *testing.T) {
	we := asserter.Using(t)
	intStringMap := map[int]string{1: "one", 2: "two"}

	we.CheckThat(intStringMap, ToType(Is(MapTypeOf(IntType(), StringType()))))
	we.CheckThat(intStringMap, ToType(Is(Not(MapTypeOf(StringType(), StringType())))))
	we.CheckThat(intStringMap, ToType(Is(Not(MapTypeOf(IntType(), IntType())))))
	we.CheckThat(intStringMap, ToType(Is(Not(MapTypeOf(StringType(), IntType())))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:9,代码来源:reflect_test.go


示例17: Test_Float64

func Test_Float64(t *testing.T) {
	we := asserter.Using(t)
	we.CheckThat(float64(1.0), Is(Float64()))
	we.CheckThat(float64(1.0), ToType(Is(Float64Type())))
	we.CheckThat(float32(1.0), Is(Not(Float64())))
	we.CheckThat(float32(1.0), ToType(Is(Not(Float64Type()))))
	we.CheckThat(complex128(1.0), Is(Not(Float64())))
	we.CheckThat(complex128(1.0), ToType(Is(Not(Float64Type()))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:9,代码来源:reflect_test.go


示例18: Test_SameTypeAs

func Test_SameTypeAs(t *testing.T) {
	we := asserter.Using(t)

	we.CheckThat(SameTypeAs(false).Match(true), Matched)
	we.CheckThat(SameTypeAs(true).Match(false), Matched)

	we.CheckThat(SameTypeAs(2).Match(1), Matched)
	we.CheckThat(SameTypeAs(int(2)).Match(uint(1)), DidNotMatch)
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:9,代码来源:reflect_test.go


示例19: Test_Complex128

func Test_Complex128(t *testing.T) {
	we := asserter.Using(t)
	we.CheckThat(complex128(1.0i), Is(Complex128()))
	we.CheckThat(complex128(1.0i), ToType(Is(Complex128Type())))
	we.CheckThat(complex64(1.0i), Is(Not(Complex128())))
	we.CheckThat(complex64(1.0i), ToType(Is(Not(Complex128Type()))))
	we.CheckThat(float64(1.0), Is(Not(Complex128())))
	we.CheckThat(float64(1.0), ToType(Is(Not(Complex128Type()))))
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:9,代码来源:reflect_test.go


示例20: Test_NonNil

func Test_NonNil(t *testing.T) {
	we := asserter.Using(t)
	matcher := NonNil()
	we.CheckThat(matcher.Match(false), Matched)
	we.CheckThat(matcher.Match(0), Matched)
	we.CheckThat(matcher.Match("nil"), Matched)
	checkMatcherIsNonMatchingOnNils(t, matcher)
	logSamples(t, matcher)
}
开发者ID:rdrdr,项目名称:hamcrest,代码行数:9,代码来源:core_test.go



注:本文中的github.com/rdrdr/hamcrest/asserter.Using函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang base.NewMatcherf函数代码示例发布时间:2022-05-28
下一篇:
Golang goagain.Wait函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap