本文整理汇总了Golang中github.com/jbrukh/ggit/util.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Assert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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")
}
示例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")
}
示例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)
}
}
示例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)
}
}
示例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)
}
示例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)
}
}
示例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())
}
示例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)
}
}
示例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)
}
示例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())
}
示例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)
}
}
示例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())
}
示例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)
}