当前位置: 首页>>代码示例>>Golang>>正文


Golang asserter.Using函数代码示例

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


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


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