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

Golang format.Object函数代码示例

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

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



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

示例1: expectedValues

func (m *OneOfMatcher) expectedValues() string {
	expectedValues := make([]string, len(m.Elements), len(m.Elements))
	for i, matcher := range m.Elements {
		expectedValues[i] = format.Object(matcher, 1)
	}
	return strings.Join(expectedValues, "\nor\n")
}
开发者ID:vestel,项目名称:bosh-init,代码行数:7,代码来源:one_of_matcher.go


示例2: Match

func (matcher *BeTrueMatcher) Match(actual interface{}) (success bool, err error) {
	if !isBool(actual) {
		return false, fmt.Errorf("Expected a boolean.  Got:\n%s", format.Object(actual, 1))
	}

	return actual.(bool), nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:7,代码来源:be_true_matcher.go


示例3: Match

func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err error) {
	if isNil(actual) {
		return false, fmt.Errorf("Expected an error, got nil")
	}

	if !isError(actual) {
		return false, fmt.Errorf("Expected an error.  Got:\n%s", format.Object(actual, 1))
	}

	actualErr := actual.(error)

	if isString(matcher.Expected) {
		return reflect.DeepEqual(actualErr.Error(), matcher.Expected), nil
	}

	if isError(matcher.Expected) {
		return reflect.DeepEqual(actualErr, matcher.Expected), nil
	}

	var subMatcher omegaMatcher
	var hasSubMatcher bool
	if matcher.Expected != nil {
		subMatcher, hasSubMatcher = (matcher.Expected).(omegaMatcher)
		if hasSubMatcher {
			return subMatcher.Match(actualErr.Error())
		}
	}

	return false, fmt.Errorf("MatchError must be passed an error, string, or Matcher that can match on strings.  Got:\n%s", format.Object(matcher.Expected, 1))
}
开发者ID:vestel,项目名称:bosh-init,代码行数:30,代码来源:match_error_matcher.go


示例4: Match

func (matcher *BeClosedMatcher) Match(actual interface{}) (success bool, err error) {
	if !isChan(actual) {
		return false, fmt.Errorf("BeClosed matcher expects a channel.  Got:\n%s", format.Object(actual, 1))
	}

	channelType := reflect.TypeOf(actual)
	channelValue := reflect.ValueOf(actual)

	if channelType.ChanDir() == reflect.SendDir {
		return false, fmt.Errorf("BeClosed matcher cannot determine if a send-only channel is closed or open.  Got:\n%s", format.Object(actual, 1))
	}

	winnerIndex, _, open := reflect.Select([]reflect.SelectCase{
		reflect.SelectCase{Dir: reflect.SelectRecv, Chan: channelValue},
		reflect.SelectCase{Dir: reflect.SelectDefault},
	})

	var closed bool
	if winnerIndex == 0 {
		closed = !open
	} else if winnerIndex == 1 {
		closed = false
	}

	return closed, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:26,代码来源:be_closed_matcher.go


示例5: Match

func (matcher *HaveKeyWithValueMatcher) Match(actual interface{}) (success bool, err error) {
	if !isMap(actual) {
		return false, fmt.Errorf("HaveKeyWithValue matcher expects a map.  Got:%s", format.Object(actual, 1))
	}

	keyMatcher, keyIsMatcher := matcher.Key.(omegaMatcher)
	if !keyIsMatcher {
		keyMatcher = &EqualMatcher{Expected: matcher.Key}
	}

	valueMatcher, valueIsMatcher := matcher.Value.(omegaMatcher)
	if !valueIsMatcher {
		valueMatcher = &EqualMatcher{Expected: matcher.Value}
	}

	keys := reflect.ValueOf(actual).MapKeys()
	for i := 0; i < len(keys); i++ {
		success, err := keyMatcher.Match(keys[i].Interface())
		if err != nil {
			return false, fmt.Errorf("HaveKeyWithValue's key matcher failed with:\n%s%s", format.Indent, err.Error())
		}
		if success {
			actualValue := reflect.ValueOf(actual).MapIndex(keys[i])
			success, err := valueMatcher.Match(actualValue.Interface())
			if err != nil {
				return false, fmt.Errorf("HaveKeyWithValue's value matcher failed with:\n%s%s", format.Indent, err.Error())
			}
			return success, nil
		}
	}

	return false, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:33,代码来源:have_key_with_value_matcher.go


示例6: Match

func (matcher *BeNumericallyMatcher) Match(actual interface{}) (success bool, err error) {
	if len(matcher.CompareTo) == 0 || len(matcher.CompareTo) > 2 {
		return false, fmt.Errorf("BeNumerically requires 1 or 2 CompareTo arguments.  Got:\n%s", format.Object(matcher.CompareTo, 1))
	}
	if !isNumber(actual) {
		return false, fmt.Errorf("Expected a number.  Got:\n%s", format.Object(actual, 1))
	}
	if !isNumber(matcher.CompareTo[0]) {
		return false, fmt.Errorf("Expected a number.  Got:\n%s", format.Object(matcher.CompareTo[0], 1))
	}
	if len(matcher.CompareTo) == 2 && !isNumber(matcher.CompareTo[1]) {
		return false, fmt.Errorf("Expected a number.  Got:\n%s", format.Object(matcher.CompareTo[0], 1))
	}

	switch matcher.Comparator {
	case "==", "~", ">", ">=", "<", "<=":
	default:
		return false, fmt.Errorf("Unknown comparator: %s", matcher.Comparator)
	}

	if isFloat(actual) || isFloat(matcher.CompareTo[0]) {
		var secondOperand float64 = 1e-8
		if len(matcher.CompareTo) == 2 {
			secondOperand = toFloat(matcher.CompareTo[1])
		}
		success = matcher.matchFloats(toFloat(actual), toFloat(matcher.CompareTo[0]), secondOperand)
	} else if isInteger(actual) {
		var secondOperand int64 = 0
		if len(matcher.CompareTo) == 2 {
			secondOperand = toInteger(matcher.CompareTo[1])
		}
		success = matcher.matchIntegers(toInteger(actual), toInteger(matcher.CompareTo[0]), secondOperand)
	} else if isUnsignedInteger(actual) {
		var secondOperand uint64 = 0
		if len(matcher.CompareTo) == 2 {
			secondOperand = toUnsignedInteger(matcher.CompareTo[1])
		}
		success = matcher.matchUnsignedIntegers(toUnsignedInteger(actual), toUnsignedInteger(matcher.CompareTo[0]), secondOperand)
	} else {
		return false, fmt.Errorf("Failed to compare:\n%s\n%s:\n%s", format.Object(actual, 1), matcher.Comparator, format.Object(matcher.CompareTo[0], 1))
	}

	return success, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:44,代码来源:be_numerically_matcher.go


示例7: Match

func (matcher *SucceedMatcher) Match(actual interface{}) (success bool, err error) {
	if actual == nil {
		return true, nil
	}

	if isError(actual) {
		return false, nil
	}

	return false, fmt.Errorf("Expected an error-type.  Got:\n%s", format.Object(actual, 1))
}
开发者ID:vestel,项目名称:bosh-init,代码行数:11,代码来源:succeed_matcher.go


示例8: Match

func (matcher *HaveOccurredMatcher) Match(actual interface{}) (success bool, err error) {
	if isNil(actual) {
		return false, nil
	}

	if isError(actual) {
		return true, nil
	}

	return false, fmt.Errorf("Expected an error.  Got:\n%s", format.Object(actual, 1))
}
开发者ID:vestel,项目名称:bosh-init,代码行数:11,代码来源:have_occurred_matcher.go


示例9: Match

func (matcher *MatchRegexpMatcher) Match(actual interface{}) (success bool, err error) {
	actualString, ok := toString(actual)
	if !ok {
		return false, fmt.Errorf("RegExp matcher requires a string or stringer.\nGot:%s", format.Object(actual, 1))
	}

	match, err := regexp.Match(matcher.regexp(), []byte(actualString))
	if err != nil {
		return false, fmt.Errorf("RegExp match failed to compile with error:\n\t%s", err.Error())
	}

	return match, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:13,代码来源:match_regexp_matcher.go


示例10: Match

func (matcher *BeSentMatcher) Match(actual interface{}) (success bool, err error) {
	if !isChan(actual) {
		return false, fmt.Errorf("BeSent expects a channel.  Got:\n%s", format.Object(actual, 1))
	}

	channelType := reflect.TypeOf(actual)
	channelValue := reflect.ValueOf(actual)

	if channelType.ChanDir() == reflect.RecvDir {
		return false, fmt.Errorf("BeSent matcher cannot be passed a receive-only channel.  Got:\n%s", format.Object(actual, 1))
	}

	argType := reflect.TypeOf(matcher.Arg)
	assignable := argType.AssignableTo(channelType.Elem())

	if !assignable {
		return false, fmt.Errorf("Cannot pass:\n%s to the channel:\n%s\nThe types don't match.", format.Object(matcher.Arg, 1), format.Object(actual, 1))
	}

	argValue := reflect.ValueOf(matcher.Arg)

	defer func() {
		if e := recover(); e != nil {
			success = false
			err = fmt.Errorf("Cannot send to a closed channel")
			matcher.channelClosed = true
		}
	}()

	winnerIndex, _, _ := reflect.Select([]reflect.SelectCase{
		reflect.SelectCase{Dir: reflect.SelectSend, Chan: channelValue, Send: argValue},
		reflect.SelectCase{Dir: reflect.SelectDefault},
	})

	var didSend bool
	if winnerIndex == 0 {
		didSend = true
	}

	return didSend, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:41,代码来源:be_sent_matcher.go


示例11: Match

func (matcher *BeTemporallyMatcher) Match(actual interface{}) (bool, error) {
	// predicate to test for time.Time type
	isTime := func(t interface{}) bool {
		_, ok := t.(time.Time)
		return ok
	}

	if !isTime(actual) {
		return false, fmt.Errorf("Expected a time.Time.  Got:\n%s", format.Object(actual, 1))
	}

	switch matcher.Comparator {
	case "==", "~", ">", ">=", "<", "<=":
	default:
		return false, fmt.Errorf("Unknown comparator: %s", matcher.Comparator)
	}

	var threshold = time.Millisecond
	if len(matcher.Threshold) == 1 {
		threshold = matcher.Threshold[0]
	}

	return matcher.matchTimes(actual.(time.Time), matcher.CompareTo, threshold), nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:24,代码来源:be_temporally_matcher.go


示例12: Match

func (matcher *PanicMatcher) Match(actual interface{}) (success bool, err error) {
	if actual == nil {
		return false, fmt.Errorf("PanicMatcher expects a non-nil actual.")
	}

	actualType := reflect.TypeOf(actual)
	if actualType.Kind() != reflect.Func {
		return false, fmt.Errorf("PanicMatcher expects a function.  Got:\n%s", format.Object(actual, 1))
	}
	if !(actualType.NumIn() == 0 && actualType.NumOut() == 0) {
		return false, fmt.Errorf("PanicMatcher expects a function with no arguments and no return value.  Got:\n%s", format.Object(actual, 1))
	}

	success = false
	defer func() {
		if e := recover(); e != nil {
			success = true
		}
	}()

	reflect.ValueOf(actual).Call([]reflect.Value{})

	return
}
开发者ID:vestel,项目名称:bosh-init,代码行数:24,代码来源:panic_matcher.go


示例13: FailureMessage

func (matcher *SucceedMatcher) FailureMessage(actual interface{}) (message string) {
	return fmt.Sprintf("Expected success, but got an error:\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1))
}
开发者ID:vestel,项目名称:bosh-init,代码行数:3,代码来源:succeed_matcher.go


示例14: Match

func (matcher *HaveLenMatcher) Match(actual interface{}) (success bool, err error) {
	length, ok := lengthOf(actual)
	if !ok {
		return false, fmt.Errorf("HaveLen matcher expects a string/array/map/channel/slice.  Got:\n%s", format.Object(actual, 1))
	}

	return length == matcher.Count, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:8,代码来源:have_len_matcher.go


示例15: Match

func (matcher *HavePrefixMatcher) Match(actual interface{}) (success bool, err error) {
	actualString, ok := toString(actual)
	if !ok {
		return false, fmt.Errorf("HavePrefix matcher requires a string or stringer.  Got:\n%s", format.Object(actual, 1))
	}
	prefix := matcher.prefix()
	return len(actualString) >= len(prefix) && actualString[0:len(prefix)] == prefix, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:8,代码来源:have_prefix_matcher.go


示例16: Match

func (m *exitMatcher) Match(actual interface{}) (success bool, err error) {
	exiter, ok := actual.(Exiter)
	if !ok {
		return false, fmt.Errorf("Exit must be passed a gexec.Exiter (Missing method ExitCode() int) Got:\n%s", format.Object(actual, 1))
	}

	m.actualExitCode = exiter.ExitCode()

	if m.actualExitCode == -1 {
		return false, nil
	}

	if m.exitCode == -1 {
		return true, nil
	}
	return m.exitCode == m.actualExitCode, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:17,代码来源:exit_matcher.go


示例17: Match

func (m *sayMatcher) Match(actual interface{}) (success bool, err error) {
	buffer, ok := m.buffer(actual)
	if !ok {
		return false, fmt.Errorf("Say must be passed a *gbytes.Buffer or BufferProvider.  Got:\n%s", format.Object(actual, 1))
	}

	didSay, sayings := buffer.didSay(m.re)
	m.receivedSayings = sayings

	return didSay, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:11,代码来源:say_matcher.go


示例18: NegatedFailureMessage

func (matcher *HaveLenMatcher) NegatedFailureMessage(actual interface{}) (message string) {
	return fmt.Sprintf("Expected\n%s\nnot to have length %d", format.Object(actual, 1), matcher.Count)
}
开发者ID:vestel,项目名称:bosh-init,代码行数:3,代码来源:have_len_matcher.go


示例19: NegatedFailureMessage

func (m *OneOfMatcher) NegatedFailureMessage(actual interface{}) (message string) {
	return fmt.Sprintf("Expected\n%s\n%s\n%s", format.Object(actual, 1), "not to match one of", m.expectedValues())
}
开发者ID:vestel,项目名称:bosh-init,代码行数:3,代码来源:one_of_matcher.go


示例20: Match

func (matcher *ReceiveMatcher) Match(actual interface{}) (success bool, err error) {
	if !isChan(actual) {
		return false, fmt.Errorf("ReceiveMatcher expects a channel.  Got:\n%s", format.Object(actual, 1))
	}

	channelType := reflect.TypeOf(actual)
	channelValue := reflect.ValueOf(actual)

	if channelType.ChanDir() == reflect.SendDir {
		return false, fmt.Errorf("ReceiveMatcher matcher cannot be passed a send-only channel.  Got:\n%s", format.Object(actual, 1))
	}

	var subMatcher omegaMatcher
	var hasSubMatcher bool

	if matcher.Arg != nil {
		subMatcher, hasSubMatcher = (matcher.Arg).(omegaMatcher)
		if !hasSubMatcher {
			argType := reflect.TypeOf(matcher.Arg)
			if argType.Kind() != reflect.Ptr {
				return false, fmt.Errorf("Cannot assign a value from the channel:\n%s\nTo:\n%s\nYou need to pass a pointer!", format.Object(actual, 1), format.Object(matcher.Arg, 1))
			}

			assignable := channelType.Elem().AssignableTo(argType.Elem())
			if !assignable {
				return false, fmt.Errorf("Cannot assign a value from the channel:\n%s\nTo:\n%s", format.Object(actual, 1), format.Object(matcher.Arg, 1))
			}
		}
	}

	winnerIndex, value, open := reflect.Select([]reflect.SelectCase{
		reflect.SelectCase{Dir: reflect.SelectRecv, Chan: channelValue},
		reflect.SelectCase{Dir: reflect.SelectDefault},
	})

	var closed bool
	var didReceive bool
	if winnerIndex == 0 {
		closed = !open
		didReceive = open
	}
	matcher.channelClosed = closed

	if closed {
		return false, nil
	}

	if hasSubMatcher {
		if didReceive {
			matcher.receivedValue = value
			return subMatcher.Match(matcher.receivedValue.Interface())
		} else {
			return false, nil
		}
	}

	if didReceive {
		if matcher.Arg != nil {
			outValue := reflect.ValueOf(matcher.Arg)
			reflect.Indirect(outValue).Set(value)
		}

		return true, nil
	} else {
		return false, nil
	}
}
开发者ID:vestel,项目名称:bosh-init,代码行数:67,代码来源:receive_matcher.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang fakes.FakeRelease类代码示例发布时间:2022-05-23
下一篇:
Golang format.Message函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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