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


Golang assert.True函数代码示例

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


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

示例1: Test_diffHalfmatchTest

func Test_diffHalfmatchTest(t *testing.T) {
	dmp := New()
	dmp.DiffTimeout = 1
	// No match.
	assert.True(t, dmp.DiffHalfMatch("1234567890", "abcdef") == nil, "")
	assert.True(t, dmp.DiffHalfMatch("12345", "23") == nil, "")

	// Single Match.
	assertStrEqual(t,
		[]string{"12", "90", "a", "z", "345678"},
		dmp.DiffHalfMatch("1234567890", "a345678z"))

	assertStrEqual(t, []string{"a", "z", "12", "90", "345678"}, dmp.DiffHalfMatch("a345678z", "1234567890"))

	assertStrEqual(t, []string{"abc", "z", "1234", "0", "56789"}, dmp.DiffHalfMatch("abc56789z", "1234567890"))

	assertStrEqual(t, []string{"a", "xyz", "1", "7890", "23456"}, dmp.DiffHalfMatch("a23456xyz", "1234567890"))

	// Multiple Matches.
	assertStrEqual(t, []string{"12123", "123121", "a", "z", "1234123451234"}, dmp.DiffHalfMatch("121231234123451234123121", "a1234123451234z"))

	assertStrEqual(t, []string{"", "-=-=-=-=-=", "x", "", "x-=-=-=-=-=-=-="}, dmp.DiffHalfMatch("x-=-=-=-=-=-=-=-=-=-=-=-=", "xx-=-=-=-=-=-=-="))

	assertStrEqual(t, []string{"-=-=-=-=-=", "", "", "y", "-=-=-=-=-=-=-=y"}, dmp.DiffHalfMatch("-=-=-=-=-=-=-=-=-=-=-=-=y", "-=-=-=-=-=-=-=yy"))

	// Non-optimal halfmatch.
	// Optimal diff would be -q+x=H-i+e=lloHe+Hu=llo-Hew+y not -qHillo+x=HelloHe-w+Hulloy
	assertStrEqual(t, []string{"qHillo", "w", "x", "Hulloy", "HelloHe"}, dmp.DiffHalfMatch("qHilloHelloHew", "xHelloHeHulloy"))

	// Optimal no halfmatch.
	dmp.DiffTimeout = 0
	assert.True(t, dmp.DiffHalfMatch("qHilloHelloHew", "xHelloHeHulloy") == nil, "")
}
开发者ID:jwatt,项目名称:kythe,代码行数:33,代码来源:dmp_test.go

示例2: Test_ListNode_basics

func Test_ListNode_basics(t *testing.T) {
	node0 := NewStubNode("foo")
	node1 := NewStubNode("bar baz")
	node2 := NewStubNode("qux")
	list1 := newListNode(node0, node1, node2)
	assert.Equal(t, "ListNode", list1.Typename())
	assert.Equal(t, "foo,bar baz,qux", list1.Name())
	assert.Equal(t, `["foo", "bar baz", "qux"]`, list1.String())
	assert.Equal(t, "foo,bar baz,qux", list1.ValueString())
	assert.Equal(t, "foo 'bar baz' qux", list1.CommandString())

	expect1 := []types.FuObject{node0, node1, node2}
	assert.Equal(t, expect1, list1.List())

	expect2 := []Node{node0, node1, node2}
	assert.Equal(t, expect2, list1.Nodes())

	list2 := newListNode(node0, node1, node2)
	assert.True(t, list1.Equal(list2))

	list3 := newListNode(node1, node0, node2)
	assert.False(t, list1.Equal(list3))

	list4 := list3.copy().(*ListNode)
	assert.False(t, list3 == list4)
	assert.True(t, list3.Equal(list4))
}
开发者ID:sbinet,项目名称:fubsy,代码行数:27,代码来源:listnode_test.go

示例3: TestPathMatchHandler

func TestPathMatchHandler(t *testing.T) {

	pathPattern, _ := paths.NewPathPattern("collection/{id}/name")
	var called bool = false
	h := NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
		called = true
		return nil
	}))

	ctx1 := context_test.MakeTestContextWithPath("/collection/123/name")
	will, _ := h.WillHandle(ctx1)
	assert.True(t, will)
	h.Handle(ctx1)
	assert.True(t, called, "Method should be called")
	assert.Equal(t, "123", ctx1.Data().Get(context.DataKeyPathParameters).(objects.Map).Get("id"))

	ctx2 := context_test.MakeTestContextWithPath("/collection")
	will, _ = h.WillHandle(ctx2)
	assert.False(t, will)
	assert.Nil(t, ctx2.Data().Get(context.DataKeyPathParameters))

	h.BreakCurrentPipeline = true
	shouldStop, handleErr := h.Handle(ctx2)
	assert.Nil(t, handleErr)
	assert.True(t, shouldStop)
	assert.True(t, called, "Handler func should get called")

}
开发者ID:smw,项目名称:goweb,代码行数:28,代码来源:path_match_handler_test.go

示例4: Test_FileNode_Add

func Test_FileNode_Add(t *testing.T) {
	node0 := NewFileNode("foo/bar")
	node1 := NewFileNode("foo/baz")
	obj0 := types.MakeFuString(".c")
	obj1 := types.MakeStringList("a", "b")

	var err error
	var expect types.FuObject
	var actual types.FuObject

	// node + node = list of nodes
	expect = types.MakeFuList(node0, node1)
	actual, err = node0.Add(node1)
	assert.Nil(t, err)
	assert.True(t, expect.Equal(actual))

	// node + string = new node
	expect = NewFileNode("foo/bar.c")
	actual, err = node0.Add(obj0)
	assert.Nil(t, err)
	assert.True(t, expect.Equal(actual))

	// node + list = flattened list
	expect = types.MakeFuList(
		node0, types.MakeFuString("a"), types.MakeFuString("b"))
	actual, err = node0.Add(obj1)
	assert.Nil(t, err)
	assert.True(t, expect.Equal(actual))
}
开发者ID:sbinet,项目名称:fubsy,代码行数:29,代码来源:fsnodes_test.go

示例5: TestGame_IsOver

func TestGame_IsOver(t *testing.T) {
	var game Game = NewGame()
	var board = game.Board()

	t.Log("New Game is not over")
	assert.False(t, game.IsOver())

	t.Log("Game with two-in-a-row is not over")
	AddMarks(board, "X", 4, 8)
	assert.False(t, game.IsOver())

	t.Log("Game with three-in-a-row \"X\" is over")
	board.Mark(0, "X")
	assert.True(t, game.IsOver())

	t.Log("Game with three-in-a-row \"O\" is over")
	board.Reset()
	AddMarks(board, "O", 2, 4, 6)
	assert.True(t, game.IsOver())

	t.Log("Game with three-in-a-row mismatched is not over")
	board.Mark(2, "X")
	assert.False(t, game.IsOver())

	t.Log("Game with nearly-full, non-winning board is not over")
	board.Reset()
	AddMarks(board, "X", 0, 1, 4, 5)
	AddMarks(board, "O", 2, 3, 7, 8)
	assert.False(t, game.IsOver())

	t.Log("Game with full, non-winning board is over")
	board.Mark(6, "X")
	assert.True(t, game.IsOver())
}
开发者ID:jneander,项目名称:tic-tac-toe-go,代码行数:34,代码来源:game_test.go

示例6: Test_ASTInline_Equal

func Test_ASTInline_Equal(t *testing.T) {
	node1 := &ASTInline{}
	node2 := &ASTInline{}
	assert.True(t, node1.Equal(node1),
		"ASTInline not equal to itself")
	assert.True(t, node1.Equal(node2),
		"empty ASTInlines not equal")

	node1.lang = "foo"
	node2.lang = "bar"
	assert.False(t, node1.Equal(node2),
		"ASTInlines equal despite different lang")

	node2.lang = "foo"
	assert.True(t, node1.Equal(node2),
		"ASTInlines not equal")

	node1.content = "hello\nworld\n"
	node2.content = "hello\nworld"
	assert.False(t, node1.Equal(node2),
		"ASTInlines equal despite different content")

	node2.content += "\n"
	assert.True(t, node1.Equal(node2),
		"ASTInlines not equal")
}
开发者ID:sbinet,项目名称:fubsy,代码行数:26,代码来源:ast_test.go

示例7: Test_PythonPlugin_Run

func Test_PythonPlugin_Run(t *testing.T) {
	pp, err := NewPythonPlugin()
	testutils.NoError(t, err)
	values, err := pp.Run(`
import os
foo = ["abc", "def"]
bar = "!".join(foo)
def visible():
    pass
def _hidden():
    pass
pjoin = os.path.join
`)
	testutils.NoError(t, err)

	for _, name := range []string{"os", "foo", "bar", "_hidden", "basdf"} {
		value, ok := values.Lookup(name)
		assert.True(t, value == nil && !ok,
			"expected nothing for name '%s', but got: %v (%T)", name, value, value)
	}
	for _, name := range []string{"visible", "pjoin"} {
		value, ok := values.Lookup(name)
		callable := value.(PythonCallable)
		assert.True(t, ok && callable.Name() == name,
			"expected a PythonCallable for name '%s'", name)
	}

	values, err = pp.Run("foo = 1/0")
	assert.Equal(t, "inline Python plugin raised an exception", err.Error())
}
开发者ID:sbinet,项目名称:fubsy,代码行数:30,代码来源:python_test.go

示例8: Test_CreateDeleteFile

func Test_CreateDeleteFile(t *testing.T) {
	test_dir := os.TempDir()
	file_store, err := New(test_dir)
	if err != nil {
		assert.Fail(t, fmt.Sprintf("file store failed to create: %s", err))
	}
	full_test_path := ""
	// Create file
	test_file := `invalid/\:jargon`
	file, err := file_store.OpenFile(test_file, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
	assert.True(t, err == nil, fmt.Sprintf("%s", err))
	if file != nil {
		t.Logf("File generated \"%s\" from \"%s\"", file.Name(), test_file)
		assert.Equal(t, test_file, file.Original_Name(),
			fmt.Sprintf("File mapping name mismatch, original name %s, original name on file %s", test_file, file.Original_Name()))
		full_test_path = file.Name()
		file.Close()
	}

	// Delete file
	err = file_store.DeleteFile(test_file)
	assert.True(t, err == nil, fmt.Sprintf("%s", err))
	_, exist_err := os.Stat(full_test_path)
	assert.True(t, exist_err != nil)

	// Cleanup in failure case
	if err != nil {
		os.Remove(full_test_path)
	}
}
开发者ID:ThatRubenAguilar,项目名称:go-sitemaps,代码行数:30,代码来源:datastore_test.go

示例9: Test_ASTRoot_Phase

func Test_ASTRoot_Phase(t *testing.T) {
	root := &ASTRoot{
		children: []ASTNode{
			&ASTImport{},
			&ASTPhase{name: "meep"},
			&ASTInline{},
			&ASTPhase{name: "meep"}, // duplicate is invisible
			&ASTPhase{name: "bong"},
		}}
	var expect *ASTPhase
	var actual *ASTPhase
	actual = root.FindPhase("main")
	assert.Nil(t, actual)

	expect = root.children[1].(*ASTPhase)
	actual = root.FindPhase("meep")
	assert.True(t, expect == actual,
		"expected %p (%v)\nbut got %p (%v)",
		expect, expect, actual, actual)

	expect = root.children[4].(*ASTPhase)
	actual = root.FindPhase("bong")
	assert.True(t, expect == actual,
		"expected %p\n%#v\nbut got %p\n%#v",
		expect, expect, actual, actual)
}
开发者ID:sbinet,项目名称:fubsy,代码行数:26,代码来源:ast_test.go

示例10: Test_InvalidPathNew

func Test_InvalidPathNew(t *testing.T) {
	invalid_path := "barf"
	file_store, err := New(invalid_path)

	assert.True(t, err != nil, fmt.Sprintf("Accepted bogus path: %s", err))
	assert.True(t, file_store == nil, fmt.Sprintf("No nil on error: %s", err))
}
开发者ID:ThatRubenAguilar,项目名称:go-sitemaps,代码行数:7,代码来源:datastore_test.go

示例11: Test_PythonCallable_callPython

func Test_PythonCallable_callPython(t *testing.T) {
	plugin, err := NewPythonPlugin()
	testutils.NoError(t, err)

	// Setup: define a Python function and make sure that Run() finds
	// it, so it can be added to a Fubsy namespace and used from Fubsy
	// code.
	pycode := `
def reverse_strings(*args):
    '''takes N strings, reverses each one, then returns the reversed
    strings concatenated into a single string with + between each
    one'''
    return '+'.join(''.join(reversed(arg)) for arg in args)`
	values, err := plugin.Run(pycode)
	testutils.NoError(t, err)
	value, ok := values.Lookup("reverse_strings")
	assert.True(t, ok)
	pycallable := value.(PythonCallable)
	assert.Equal(t, "reverse_strings", pycallable.Name())

	// Call the Python function with 3 strings.
	args := types.MakeStringList("foo", "blob", "pingpong").List()
	argsource := types.MakeBasicArgs(nil, args, nil)
	value, errs := pycallable.callPython(argsource)
	testutils.NoErrors(t, errs)

	// And test the returned value.
	expect := types.MakeFuString("oof+bolb+gnopgnip")
	assert.True(t, expect.Equal(value),
		"expected %s, but got %s", expect, value)
}
开发者ID:sbinet,项目名称:fubsy,代码行数:31,代码来源:python_test.go

示例12: TestMapStaticFile

func TestMapStaticFile(t *testing.T) {

	codecService := new(codecservices.WebCodecService)
	h := NewHttpHandler(codecService)

	h.MapStaticFile("/static-file", "/location/of/static-file")

	assert.Equal(t, 1, len(h.HandlersPipe()))

	staticHandler := h.HandlersPipe()[0].(*PathMatchHandler)

	if assert.Equal(t, 1, len(staticHandler.HttpMethods)) {
		assert.Equal(t, goweb_http.MethodGet, staticHandler.HttpMethods[0])
	}

	var ctx context.Context
	var willHandle bool

	ctx = context_test.MakeTestContextWithPath("/static-file")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.True(t, willHandle, "Static handler should handle")

	ctx = context_test.MakeTestContextWithPath("static-file")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.True(t, willHandle, "Static handler should handle")

	ctx = context_test.MakeTestContextWithPath("static-file/")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.True(t, willHandle, "Static handler should handle")

	ctx = context_test.MakeTestContextWithPath("static-file/something-else")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.False(t, willHandle, "Static handler NOT should handle")

}
开发者ID:smw,项目名称:goweb,代码行数:35,代码来源:mapping_test.go

示例13: assertPathMatchHandler

func assertPathMatchHandler(t *testing.T, handler *PathMatchHandler, path, method string, message string) bool {

	if assert.NotNil(t, handler) {

		ctx := context_test.MakeTestContextWithDetails(path, method)

		willHandle, _ := handler.WillHandle(ctx)
		if assert.True(t, willHandle, fmt.Sprintf("This handler is expected to handle it: %s", message)) {

			// make sure the method is in the list
			methodFound := false
			for _, methodInList := range handler.HttpMethods {
				if methodInList == method {
					methodFound = true
					break
				}
			}

			return assert.True(t, methodFound, "Method (%s) should be in the method list (%s)", method, handler.HttpMethods)
		}

	}

	return false

}
开发者ID:smw,项目名称:goweb,代码行数:26,代码来源:mapping_test.go

示例14: TestResultNext

func TestResultNext(t *testing.T) {
	r := testResult()
	assert.Equal(t, len(r.Rows), 3)
	assert.True(t, r.Next())
	assert.True(t, r.Next())
	assert.True(t, r.Next())
	assert.False(t, r.Next())
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:8,代码来源:result_test.go

示例15: Test_FinderNode_Equal

func Test_FinderNode_Equal(t *testing.T) {
	finder1 := NewFinderNode("*.c", "*.h")
	finder2 := NewFinderNode("*.c", "*.h")
	finder3 := NewFinderNode("*.h", "*.c")

	assert.True(t, finder1.Equal(finder1))
	assert.True(t, finder1.Equal(finder2))
	assert.False(t, finder1.Equal(finder3))
}
开发者ID:sbinet,项目名称:fubsy,代码行数:9,代码来源:findernode_test.go


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