當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.Equal函數代碼示例

本文整理匯總了Golang中github.com/stretchrcom/testify/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestExecute

func TestExecute(t *testing.T) {
	conn := ConnectToTestDb(t)
	if conn == nil {
		return
	}
	defer conn.Close()

	rst, err := conn.Exec("select 1")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst))
	rst, err = conn.Exec("select missing")
	assert.NotNil(t, err)
	assert.Nil(t, rst)
	rst, err = conn.Exec("print 'pero'")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.True(t, strings.Contains(conn.Message, "pero"))
	assert.Equal(t, 1, len(rst))
	assert.Equal(t, 0, len(rst[0].Rows))
	rst, err = conn.Exec("sp_help 'authors'")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 9, len(rst))
}
開發者ID:upstartmobile,項目名稱:gofreetds,代碼行數:25,代碼來源:conn_test.go

示例2: Test_EnableDebugTopics

func Test_EnableDebugTopics(t *testing.T) {
	assert.Equal(t, 0, int(defaultlogger.debug))
	EnableDebugTopics([]string{"ast", "build"})
	assert.Equal(t, AST|BUILD, defaultlogger.debug)
	EnableDebugTopics([]string{"  dag", ""})
	assert.Equal(t, AST|DAG|BUILD, defaultlogger.debug)
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:7,代碼來源:log_test.go

示例3: Test_SequenceAction_create

func Test_SequenceAction_create(t *testing.T) {
	rt := &Runtime{}
	action := NewSequenceAction()
	assert.Equal(t, 0, len(action.subactions))

	// Execute() on an empty SequenceAction does nothing, silently
	assert.Nil(t, action.Execute(rt))

	// action 1 is a bare string: "ls -lR foo/bar"
	cmd := dsl.NewASTString("\"ls -lR foo/bar\"")
	action.AddCommand(cmd)

	// action 2: a = "foo"
	assign := dsl.NewASTAssignment(
		"a",
		dsl.NewASTString("foo"))
	action.AddAssignment(assign)

	// action 3: remove("*.o")
	fcall := dsl.NewASTFunctionCall(
		dsl.NewASTString("remove"),
		[]dsl.ASTExpression{dsl.NewASTString("\"*.c\"")})
	action.AddFunctionCall(fcall)

	assert.Equal(t, 3, len(action.subactions))
	assert.Equal(t,
		"ls -lR foo/bar",
		action.subactions[0].(*CommandAction).raw.ValueString())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:29,代碼來源:action_test.go

示例4: TestMethodString

func TestMethodString(t *testing.T) {

	responseWriter := new(http_test.TestResponseWriter)
	testRequest, _ := http.NewRequest("get", "http://goweb.org/people/123", nil)

	codecService := new(codecservices.WebCodecService)

	c := NewWebContext(responseWriter, testRequest, codecService)

	assert.Equal(t, "GET", c.MethodString())

	responseWriter = new(http_test.TestResponseWriter)
	testRequest, _ = http.NewRequest("put", "http://goweb.org/people/123", nil)

	c = NewWebContext(responseWriter, testRequest, codecService)

	assert.Equal(t, "PUT", c.MethodString())

	responseWriter = new(http_test.TestResponseWriter)
	testRequest, _ = http.NewRequest("DELETE", "http://goweb.org/people/123", nil)

	c = NewWebContext(responseWriter, testRequest, codecService)

	assert.Equal(t, "DELETE", c.MethodString())

	responseWriter = new(http_test.TestResponseWriter)
	testRequest, _ = http.NewRequest("anything", "http://goweb.org/people/123", nil)

	c = NewWebContext(responseWriter, testRequest, codecService)

	assert.Equal(t, "ANYTHING", c.MethodString())

}
開發者ID:smw,項目名稱:goweb,代碼行數:33,代碼來源:web_context_test.go

示例5: TestPPUWriteMask

func TestPPUWriteMask(t *testing.T) {
	p := NewPPU()

	assert.Equal(t, p.Masks.Grayscale, false)
	p.Write(0xff, PPUMASK)
	assert.Equal(t, p.Masks.Grayscale, true)
}
開發者ID:samfoo,項目名稱:gones,代碼行數:7,代碼來源:ppu_test.go

示例6: Test_BuildState_BuildTargets_one_failure

// full build (all targets), one action fails
func Test_BuildState_BuildTargets_one_failure(t *testing.T) {
	sig := []byte{0}
	graph, executed := setupBuild(false, sig)
	db := makeFakeDB(graph, sig)

	// fail to build misc.{c,h} -> misc.o: that will stop the build
	rule := graph.Lookup("misc.o").BuildRule().(*dag.StubRule)
	rule.SetFail(true)

	expect := []buildexpect{
		{"tool1.o", dag.BUILT},
		{"misc.o", dag.FAILED},
	}

	opts := BuildOptions{}
	bstate := NewBuildState(graph, db, opts)
	goal := graph.MakeNodeSet("tool1", "tool2")
	err := bstate.BuildTargets(goal)
	assert.NotNil(t, err)
	assertBuild(t, graph, expect, *executed)

	// we didn't even think about building util.o, tool1, etc: an
	// earlier node failed and the build terminates on first failure
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("util.o").State())
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("tool1").State())
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("tool2").State())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:28,代碼來源:build_test.go

示例7: TestImpossibleComputer_Move

func TestImpossibleComputer_Move(t *testing.T) {
	var computer = NewImpossibleComputer()
	var board = NewBoard()
	computer.SetMark("X")

	t.Log("#Move returns any winning move")
	AddMarks(board, "X", 1, 4)
	AddMarks(board, "O", 0, 2, 3)
	assert.Equal(t, computer.Move(*board), 7)

	t.Log("#Move blocks any winning move")
	board.Reset()
	AddMarks(board, "X", 0, 6)
	AddMarks(board, "O", 3, 4)
	assert.Equal(t, computer.Move(*board), 5)

	fakeMinimax := new(FakeMinimax)
	computer.Minimax = fakeMinimax

	t.Log("#Move uses the highest of Minimax scores")
	board.Reset()
	fakeMinimax.StubScores = map[int]int{1: 0, 3: 1, 4: -1, 5: 0}
	assert.Equal(t, computer.Move(*board), 3)
	fakeMinimax.StubScores = map[int]int{1: -1, 3: -1, 4: -1, 5: 0}
	assert.Equal(t, computer.Move(*board), 5)
}
開發者ID:jneander,項目名稱:tic-tac-toe-go,代碼行數:26,代碼來源:impossible_computer_test.go

示例8: Test_FileNode_Expand

func Test_FileNode_Expand(t *testing.T) {
	ns := types.NewValueMap()
	node := NewFileNode("foobar")
	xnode, err := node.ActionExpand(ns, nil)
	assert.Nil(t, err)
	assert.Equal(t, node, xnode)

	err = node.NodeExpand(ns)
	assert.Nil(t, err)
	assert.Equal(t, "foobar", node.Name())

	// test that ActionExpand() follows variable references
	node = NewFileNode("$foo$bar")
	xnode, err = node.ActionExpand(ns, nil)
	assert.Equal(t, "undefined variable 'foo' in string", err.Error())

	// make it so "$foo$bar" expands to "$foo", and ensure that
	// expansion stops there
	// XXX argh: currently this expands to "'$'foo": hmmmmm
	// ns.Assign("foo", types.MakeFuString("$"))
	// ns.Assign("bar", types.MakeFuString("foo"))
	// xnode, err = node.ActionExpand(ns, nil)
	// assert.Nil(t, err)
	// assert.Equal(t, "$foo", xnode.String())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:25,代碼來源:fsnodes_test.go

示例9: TestCleanSegmentName

func TestCleanSegmentName(t *testing.T) {

	assert.Equal(t, "id", cleanSegmentName("id"))
	assert.Equal(t, "id", cleanSegmentName("{id}"))
	assert.Equal(t, "id", cleanSegmentName("[id]"))

}
開發者ID:smw,項目名稱:goweb,代碼行數:7,代碼來源:segments_test.go

示例10: TestRegexPath

func TestRegexPath(t *testing.T) {

	pattern := `^[a-z]+\[[0-9]+\]$`
	matcherFunc := RegexPath(pattern)

	var ctx context.Context
	var decision MatcherFuncDecision

	ctx = context_test.MakeTestContextWithPath("adam[23]")
	decision, _ = matcherFunc(ctx)
	assert.Equal(t, Match, decision, "adam[23] should match")

	ctx = context_test.MakeTestContextWithPath("eve[7]")
	decision, _ = matcherFunc(ctx)
	assert.Equal(t, Match, decision, "eve[7] should match")

	ctx = context_test.MakeTestContextWithPath("Job[23]")
	decision, _ = matcherFunc(ctx)
	assert.Equal(t, NoMatch, decision, "Job[23] should NOT match")

	ctx = context_test.MakeTestContextWithPath("snakey")
	decision, _ = matcherFunc(ctx)
	assert.Equal(t, NoMatch, decision, "snakey should NOT match")

}
開發者ID:smw,項目名稱:goweb,代碼行數:25,代碼來源:regexp_matcher_func_test.go

示例11: Test_diffCharsToLines

func Test_diffCharsToLines(t *testing.T) {
	dmp := New()
	// Convert chars up to lines.
	diffs := []Diff{
		Diff{DiffEqual, "\u0001\u0002\u0001"},
		Diff{DiffInsert, "\u0002\u0001\u0002"}}

	tmpVector := []string{"", "alpha\n", "beta\n"}
	actual := dmp.DiffCharsToLines(diffs, tmpVector)
	assertDiffEqual(t, []Diff{
		Diff{DiffEqual, "alpha\nbeta\nalpha\n"},
		Diff{DiffInsert, "beta\nalpha\nbeta\n"}}, actual)

	// More than 256 to reveal any 8-bit limitations.
	n := 257
	tmpVector = []string{}
	lineList := []rune{}
	charList := []rune{}

	for x := 1; x <= n; x++ {
		tmpVector = append(tmpVector, string(x)+"\n")
		lineList = append(lineList, rune(x), '\n')
		charList = append(charList, rune(x))
	}

	assert.Equal(t, n, len(tmpVector))
	assert.Equal(t, n, len(charList))

	tmpVector = append([]string{""}, tmpVector...)
	diffs = []Diff{Diff{DiffDelete, string(charList)}}
	actual = dmp.DiffCharsToLines(diffs, tmpVector)
	assertDiffEqual(t, []Diff{
		Diff{DiffDelete, string(lineList)}}, actual)
}
開發者ID:peterpeerdeman,項目名稱:dcms,代碼行數:34,代碼來源:dmp_test.go

示例12: Test_FinderNode_Add_CommandString

// hmmmm: interface-wise, this tests that FinderNode.Add() returns an
// object whose CommandString() behaves sensibly... but in
// implementation terms, it's really a test of FuList.CommandString()
func Test_FinderNode_Add_CommandString(t *testing.T) {
	finder1 := NewFinderNode("*.c", "*.h")
	finder2 := NewFinderNode("doc/???.txt")
	finder3 := NewFinderNode()

	sum1, err := finder1.Add(finder2)
	assert.Nil(t, err)
	assert.Equal(t, "'*.c' '*.h' 'doc/???.txt'", sum1.CommandString())

	sum2, err := finder3.Add(sum1)
	assert.Nil(t, err)
	assert.Equal(t, "'*.c' '*.h' 'doc/???.txt'", sum2.CommandString())

	assert.False(t, sum1.Equal(sum2))

	sum2b, err := finder3.Add(sum1)
	assert.Nil(t, err)
	assert.True(t, sum2.Equal(sum2b),
		"expected equal ListNodes:\nsum2  = %T %v\nsum2b = %T %v",
		sum2, sum2, sum2b, sum2b)

	// This is a silly thing to do, and perhaps we should filter out
	// the duplicate patterns... but I don't think so. If the user
	// constructs something silly, we do something silly.
	sum3, err := sum1.Add(sum2)
	assert.Nil(t, err)
	assert.Equal(t,
		"'*.c' '*.h' 'doc/???.txt' '*.c' '*.h' 'doc/???.txt'",
		sum3.CommandString())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:33,代碼來源:findernode_test.go

示例13: Test_FuFunction_CheckArgs_minmax

func Test_FuFunction_CheckArgs_minmax(t *testing.T) {
	fn := NewVariadicFunction("bar", 2, 4, nil)
	val := MakeFuString("a")
	args := MakeBasicArgs(nil, []FuObject{val}, nil)
	err := fn.CheckArgs(args)
	assert.Equal(t,
		"function bar() requires at least 2 arguments (got 1)", err.Error())

	// 2 args are good
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	// 3 args are good
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	// 4 args are good
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	// but 5 args is *right out*
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function bar() takes at most 4 arguments (got 5)", err.Error())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:29,代碼來源:callables_test.go

示例14: Test_FuFunction_CheckArgs_fixed

func Test_FuFunction_CheckArgs_fixed(t *testing.T) {
	val := MakeFuString("a")
	args := MakeBasicArgs(nil, []FuObject{}, nil)
	fn := NewFixedFunction("meep", 0, nil)

	err := fn.CheckArgs(args)
	assert.Nil(t, err)

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function meep() takes no arguments (got 1)", err.Error())

	fn = NewFixedFunction("foo", 2, nil)
	args.args = args.args[:0]
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function foo() takes exactly 2 arguments (got 0)", err.Error())

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function foo() takes exactly 2 arguments (got 1)", err.Error())

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function foo() takes exactly 2 arguments (got 3)", err.Error())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:33,代碼來源:callables_test.go

示例15: Test_BuiltinList

func Test_BuiltinList(t *testing.T) {
	blist := BuiltinList{}
	fn, ok := blist.Lookup("foo")
	assert.False(t, ok)
	assert.Nil(t, fn)

	callable := types.NewFixedFunction("foo", 3, nil)
	blist.builtins = append(blist.builtins, callable)
	fn, ok = blist.Lookup("foo")
	assert.True(t, ok)
	assert.Equal(t, callable, fn)

	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("bar", 0, nil))
	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("bop", 0, nil))
	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("bam", 0, nil))
	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("pow", 0, nil))

	assert.Equal(t, 5, blist.NumBuiltins())
	actual := make([]string, 0, 5)
	visit := func(name string, code types.FuObject) error {
		actual = append(actual, name)
		if name == "bam" {
			return errors.New("bam!")
		}
		return nil
	}
	err := blist.ForEach(visit)
	assert.Equal(t, []string{"foo", "bar", "bop", "bam"}, actual)
	assert.Equal(t, "bam!", err.Error())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:34,代碼來源:builtins_test.go


注:本文中的github.com/stretchrcom/testify/assert.Equal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。