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

Golang util.Assert函数代码示例

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

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



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

示例1: Test_Or

func Test_Or(t *testing.T) {
	numbers := applyInt(numbers, FilterOr(evenNumbers, oddNumbers))
	for i := 0; i < 10; i++ {
		util.Assert(t, numbers[i] == i+1)
	}
	util.Assert(t, len(numbers) == 10)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:7,代码来源:filter_test.go


示例2: testParentlessCommit

func testParentlessCommit(t *testing.T, repo Repository, oid *objects.ObjectId) {
	rev := oid.String()
	testObjectExpected(t, repo, rev, oid, objects.ObjectCommit)
	_, err := ObjectFromRevision(repo, rev+"~1")
	util.Assert(t, err != nil)
	_, err = ObjectFromRevision(repo, rev+"^")
	util.Assert(t, err != nil)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:8,代码来源:rev_parser_git_test.go


示例3: Test_Sorting

func Test_Sorting(t *testing.T) {
	refs := make([]objects.Ref, 3)
	refs[0] = objects.NewRef("zoo", "", nil, nil)
	refs[1] = objects.NewRef("yogurt", "", nil, nil)
	refs[2] = objects.NewRef("xavier", "", nil, nil)
	sort.Sort(refByName(refs))
	util.Assert(t, refs[0].Name() == "xavier")
	util.Assert(t, refs[1].Name() == "yogurt")
	util.Assert(t, refs[2].Name() == "zoo")
}
开发者ID:jbrukh,项目名称:ggit,代码行数:10,代码来源:refs_test.go


示例4: Test_parseInvalidBlobHeader

func Test_parseInvalidBlobHeader(t *testing.T) {
	test := func(badBlob string) {
		p := ObjectParserForString(badBlob)
		hdr, e := p.ParseHeader()
		util.Assert(t, e != nil)
		util.Assert(t, hdr == nil)
	}
	test("bad 100\000dsfsdfsdfsdf")
	test("bl0b 10\000est")
	test("100\000hehe")
	test("bad \000hoho")
	test("no header at all")
}
开发者ID:jbrukh,项目名称:ggit,代码行数:13,代码来源:blobs_test.go


示例5: Test_revParse__zeros

func Test_revParse__zeros(t *testing.T) {
	testCase := test.Linear
	repo := Open(testCase.Repo())
	info := testCase.Info().(*test.InfoLinear)

	util.Assert(t, info.N > 0)
	util.Assert(t, len(info.Commits) == info.N)

	// test the first, parentless commit
	for _, c := range info.Commits {
		oid := objects.OidNow(c.CommitOid)
		testZeros(t, repo, oid)
	}
}
开发者ID:jbrukh,项目名称:ggit,代码行数:14,代码来源:rev_parser_git_test.go


示例6: Test_revParse__secondAncestor

func Test_revParse__secondAncestor(t *testing.T) {
	testCase := test.Linear
	repo := Open(testCase.Repo())
	info := testCase.Info().(*test.InfoLinear)

	util.Assert(t, info.N > 2)
	util.Assert(t, len(info.Commits) == info.N)

	// test the first, parentless commit
	for i, c := range info.Commits[2:] {
		oid, expOid := objects.OidNow(c.CommitOid), objects.OidNow(info.Commits[i].CommitOid)
		testSecondAncestor(t, repo, oid, expOid)
		testSecondAncestorVariations(t, repo, oid, expOid)
	}
}
开发者ID:jbrukh,项目名称:ggit,代码行数:15,代码来源:rev_parser_git_test.go


示例7: Test_ParseObjectId

func Test_ParseObjectId(t *testing.T) {
	var oid *objects.ObjectId
	oidStr := "ff6ccb68859fd52216ec8dadf98d2a00859f5369"
	t1 := ObjectParserForString(oidStr)
	oid = t1.ParseOid()
	util.Assert(t, oid.String() == oidStr)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:7,代码来源:object_parser_test.go


示例8: Test_revParse__firstParent

func Test_revParse__firstParent(t *testing.T) {
	testCase := test.Linear
	repo := Open(testCase.Repo())
	info := testCase.Info().(*test.InfoLinear)

	util.Assert(t, info.N > 1)
	util.Assert(t, len(info.Commits) == info.N)

	// test the first, parentless commit
	testParentlessCommit(t, repo, objects.OidNow(info.Commits[0].CommitOid))
	for _, c := range info.Commits[1:] {
		oid, expOid := objects.OidNow(c.CommitOid), objects.OidNow(c.ParentOid)
		testShortOid(t, repo, oid)
		testFirstParent(t, repo, oid, expOid)
		testFirstParentVariations(t, repo, oid, expOid)
	}
}
开发者ID:jbrukh,项目名称:ggit,代码行数:17,代码来源:rev_parser_git_test.go


示例9: Test_readTree

// Test_readCommits will compare the commit output of
// git and ggit for a string of commits.
func Test_readTree(t *testing.T) {
	testCase := test.Tree
	repo := Open(testCase.Repo())
	info := testCase.Info().(*test.InfoTree)
	f := format.NewStrFormat()

	var (
		oid = objects.OidNow(info.TreeOid)
	)
	o, err := repo.ObjectFromOid(oid)
	util.AssertNoErr(t, err)

	// check the id
	util.Assert(t, o.ObjectId().String() == info.TreeOid)

	// check the header
	util.Assert(t, o.Header().Type() == objects.ObjectTree)
	util.AssertEqualInt(t, int(o.Header().Size()), info.TreeSize)

	// get the tree
	// now convert to a tag and check the fields
	var tree *objects.Tree
	util.AssertPanicFree(t, func() {
		tree = o.(*objects.Tree)
	})

	// check entries
	entries := tree.Entries()
	util.AssertEqualInt(t, info.N, len(entries))
	util.Assert(t, info.N > 2)

	// check a file
	file := entries[0]
	util.AssertEqualString(t, info.File1Oid, file.ObjectId().String())
	util.Assert(t, file.Mode() == objects.ModeBlob)
	// TODO: add checks for type, etc.

	// check the output
	// check the whole representation, which will catch
	// most of the other stuff
	f.Reset()
	f.Object(o)
	util.AssertEqualString(t, info.TreeRepr, f.String())
}
开发者ID:themihai,项目名称:ggit,代码行数:46,代码来源:trees_git_test.go


示例10: Test_parseBlobBadSize

func Test_parseBlobBadSize(t *testing.T) {
	test := func(contents string) {
		l := len(contents)
		size := rand.Intn(l+1) - 1 + 2*rand.Intn(2)*l // never equal to l
		tb := makeTestBlobWithSize(size, contents)
		p := ObjectParserForString(tb)
		hdr, e := p.ParseHeader()
		util.AssertNoErr(t, e)
		util.Assert(t, hdr.Type() == objects.ObjectBlob)
		util.Assert(t, hdr.Size() == int64(size))

		// should not be able to parse
		_, e = p.ParsePayload()
		util.Assert(t, e != nil)
	}
	for _, v := range testCasesBlobs {
		test(v)
	}
}
开发者ID:jbrukh,项目名称:ggit,代码行数:19,代码来源:blobs_test.go


示例11: Test_assertFileMode

func Test_assertFileMode(t *testing.T) {
	m1 := uint16(0000000)
	m2 := uint16(0040000)
	m3 := uint16(0100644)
	m4 := uint16(0100755)
	m5 := uint16(0120000)
	m6 := uint16(0160000)

	test := func(m uint16, exp objects.FileMode) {
		mode, ok := assertFileMode(m)
		util.Assert(t, ok, "could not convert to file mode")
		util.Assert(t, mode == exp)
	}

	test(m1, objects.ModeNew)
	test(m2, objects.ModeTree)
	test(m3, objects.ModeBlob)
	test(m4, objects.ModeBlobExec)
	test(m5, objects.ModeLink)
	test(m6, objects.ModeCommit)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:21,代码来源:file_modes_test.go


示例12: testPackedTagDerefInfo

func testPackedTagDerefInfo(t *testing.T, repo Repository, spec string, oid *objects.ObjectId) {
	ref, err := repo.Ref(spec)
	util.AssertNoErr(t, err)
	util.AssertEqualString(t, ref.Name(), spec)
	// make sure target is symbolic and matches
	symbolic, target := ref.Target()
	util.Assert(t, !symbolic)
	if target == nil || ref.Commit() == nil {
		t.Fatalf("nil target or commit")
	}
	util.AssertEqualString(t, ref.Commit().String(), oid.String())
}
开发者ID:jbrukh,项目名称:ggit,代码行数:12,代码来源:refs_git_test.go


示例13: Test_readTree

// Test_readCommits will compare the commit output of
// git and ggit for a string of commits.
func Test_readTree(t *testing.T) {
	testCase := test.TreeDiff
	repo := api.Open(testCase.Repo())
	info, _ := testCase.Info().(*test.InfoTreeDiff)

	oid := objects.OidNow(info.TreeOid1)
	o, err := repo.ObjectFromOid(oid)
	util.AssertNoErr(t, err)
	// get the tree
	tree1, _ := o.(*objects.Tree)

	oid = objects.OidNow(info.TreeOid2)
	o, err = repo.ObjectFromOid(oid)
	util.AssertNoErr(t, err)
	// get the tree
	tree2, _ := o.(*objects.Tree)

	diff, err := NewTreeDiffer(repo, NewBlobComparator()).Diff(tree1, tree2)
	modified := diff.Modified()

	if len(modified) != 1 {
		t.Errorf("expected 1 modification in the tree diff. got %d", len(modified))
	}

	edit := modified[0]
	before, after := edit.Before, edit.After
	beforeOid, afterOid := before.ObjectId(), after.ObjectId()
	beforeName := before.Name()

	if beforeName != info.ModifiedFileName {
		t.Errorf("expected modified file name to be [%s], but got [%s]", info.ModifiedFileName, beforeName)
	}

	if beforeOid.String() != info.ModifiedFileBeforeOid {
		t.Errorf("expected modified file's initial id to be [%s], but got [%s]", info.ModifiedFileBeforeOid, beforeOid)
	}

	if afterOid.String() != info.ModifiedFileAfterOid {
		t.Errorf("expected modified file's initial id to be [%s], but got [%s]", info.ModifiedFileAfterOid, afterOid)
	}

	deleted := diff.Deleted()

	util.Assert(t, len(deleted) == 1, fmt.Sprintf("expected 1 file to be deleted, got [%d]", len(deleted)))
	entry := deleted[0]
	deletedName, deletedOid := entry.Name(), entry.ObjectId().String()
	if deletedName != info.RemovedFileName {
		t.Errorf("expected deleted file's name to be [%s], but got [%s]", info.RemovedFileName, deletedName)
	}
	if deletedOid != info.RemovedFileOid {
		t.Errorf("expected deleted file's id to be [%s], but got [%s]", info.RemovedFileOid, deletedOid)
	}
}
开发者ID:jbrukh,项目名称:ggit,代码行数:55,代码来源:trees_git_test.go


示例14: Test_parseValidFileMode

func Test_parseValidFileMode(t *testing.T) {
	p := ObjectParserForString("0000000\n0040000\n0100644\n0100755\n0120000\n0160000\n")
	util.Assert(t, p.ParseFileMode(token.LF) == objects.ModeNew)
	util.Assert(t, p.ParseFileMode(token.LF) == objects.ModeTree)
	util.Assert(t, p.ParseFileMode(token.LF) == objects.ModeBlob)
	util.Assert(t, p.ParseFileMode(token.LF) == objects.ModeBlobExec)
	util.Assert(t, p.ParseFileMode(token.LF) == objects.ModeLink)
	util.Assert(t, p.ParseFileMode(token.LF) == objects.ModeCommit)
	util.Assert(t, p.EOF())
}
开发者ID:jbrukh,项目名称:ggit,代码行数:10,代码来源:file_modes_test.go


示例15: parseAndCompareTree

// parseAndCompareTree will take a string tree representation and compare
// it with that tree from the provided repository. A tree representation
// has the following format:
//
//     <oid_of_this_tree><LF>
//     <size><LF>
//     <output_of_cat_file_p>
//
// Example:
//
// `dc5c0113b3d246da13b9d4b54861d2894da45e5a
// 348
// 100644 blob 022f0ad6583f99c3c01d0245db452e58bbb8fc8a	.gitignore
// 100644 blob 4760db634060e0f5c76eddb18031d53bff882a23	README
// 040000 tree 888fd8c9a6612c01d8f7c4e71fef114c3d3386d5	api
// 040000 tree 7ba590c4aa02ba2268f732f70b6143cd60457782	builtin
// 040000 tree bd52eecc257922f4c9008d080ad7dd5f9ac3444e	dotfiles
// 040000 tree 9ee2de084ec91660183740dacd8988c8170537e3	ggcase
// 100644 blob 82a1896a6d17e56220681fb66f94ac8a7e1d9bdc	ggit.go
// 100644 blob 3b20433fdf8544b2cff26989c5fc63327137e809	templates.go
// 040000 tree d42d8e7cf260b951e17687404031b1975ffa0b38	test
// 100644 blob 0c01aeb4856324d8487a252e32e04961bf603fad	version.go
// `
func parseAndCompareTree(t *testing.T, repo Repository, treeRepr string) {
	p := parse.ObjectParserForString(treeRepr)

	oid := p.ParseOid()
	p.ConsumeByte(token.LF)
	size := p.ParseInt(token.LF, 10, 32)

	o, err := repo.ObjectFromOid(oid)
	util.AssertNoErr(t, err)

	hdr := o.Header()
	util.Assert(t, hdr.Type() == objects.ObjectTree)
	util.Assert(t, hdr.Size() == size)

	tree := o.(*objects.Tree)
	entries := tree.Entries()

	for !p.EOF() {
		mode := p.ParseFileMode(token.SP)
		otype := objects.ObjectType(p.ConsumeStrings(token.ObjectTypes))
		p.ConsumeByte(token.SP)
		oidStr := p.ParseOid().String()
		p.ConsumeByte(token.TAB)
		name := p.ReadString(token.LF)
		util.Assert(t, len(entries) > 0)
		entry := entries[0]
		util.Assert(t, mode == entry.Mode())
		util.Assertf(t, name == entry.Name(), "expecting: `%s` got: `%s", name, entry.Name())
		util.Assert(t, otype == entry.ObjectType())
		util.Assertf(t, oidStr == entry.ObjectId().String(), "expecting: `%s` got: `%s", oidStr, entry.ObjectId())
		entries = entries[1:]
	}
	util.Assert(t, len(entries) == 0)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:57,代码来源:trees_test.go


示例16: Test_parseValidBlob

func Test_parseValidBlob(t *testing.T) {
	for _, v := range testCasesBlobs {
		tb := makeTestBlob(v)
		p := ObjectParserForString(tb)
		hdr, err := p.ParseHeader()
		util.AssertNoErr(t, err)
		util.Assert(t, hdr.Type() == objects.ObjectBlob)
		util.Assert(t, hdr.Size() == int64(len(v)))

		o, err := p.ParsePayload()
		util.AssertNoErr(t, err)
		util.Assert(t, o.Header().Type() == objects.ObjectBlob)
		util.Assert(t, o.Header().Size() == int64(len(v)))
		util.Assert(t, o.ObjectId() == nil) // wasn't set in the test scenario

		var b *objects.Blob
		util.AssertPanicFree(t, func() {
			b = o.(*objects.Blob)
		})
		util.AssertEqualString(t, string(b.Data()), v)
	}
}
开发者ID:jbrukh,项目名称:ggit,代码行数:22,代码来源:blobs_test.go


示例17: assertPeeledRef

func assertPeeledRef(t *testing.T, peeledRef objects.Ref, oid *objects.ObjectId) {
	symbolic, target := peeledRef.Target()
	util.Assert(t, !symbolic)
	if target == nil {
		t.Fatalf("nil target")
	}
	util.AssertEqualString(t, target.(*objects.ObjectId).String(), oid.String())
	util.AssertEqualString(t, peeledRef.ObjectId().String(), oid.String())
	util.AssertPanic(t, func() {
		s := target.(string)
		s += "" // for compilation
	})
}
开发者ID:jbrukh,项目名称:ggit,代码行数:13,代码来源:refs_git_test.go


示例18: Test_NotEven

func Test_NotEven(t *testing.T) {
	numbers := applyInt(numbers, FilterNot(evenNumbers))
	util.Assert(t, numbers[0] == 1)
	util.Assert(t, numbers[1] == 3)
	util.Assert(t, numbers[2] == 5)
	util.Assert(t, numbers[3] == 7)
	util.Assert(t, numbers[4] == 9)
	util.Assert(t, len(numbers) == 5)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:9,代码来源:filter_test.go


示例19: Test_NotOdd

func Test_NotOdd(t *testing.T) {
	numbers := applyInt(numbers, FilterNot(oddNumbers))
	util.Assert(t, numbers[0] == 2)
	util.Assert(t, numbers[1] == 4)
	util.Assert(t, numbers[2] == 6)
	util.Assert(t, numbers[3] == 8)
	util.Assert(t, numbers[4] == 10)
	util.Assert(t, len(numbers) == 5)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:9,代码来源:filter_test.go


示例20: Test_EvenNumbers

func Test_EvenNumbers(t *testing.T) {
	numbers := applyInt(numbers, evenNumbers)
	util.Assert(t, numbers[0] == 2)
	util.Assert(t, numbers[1] == 4)
	util.Assert(t, numbers[2] == 6)
	util.Assert(t, numbers[3] == 8)
	util.Assert(t, numbers[4] == 10)
	util.Assert(t, len(numbers) == 5)
}
开发者ID:jbrukh,项目名称:ggit,代码行数:9,代码来源:filter_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang mavlink.NameIDFromMessage函数代码示例发布时间:2022-05-23
下一篇:
Golang objects.ObjectId类代码示例发布时间: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