diff options
| author | Russell Belfer <rb@github.com> | 2013-03-06 13:58:21 -0800 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-03-06 13:58:21 -0800 |
| commit | 1b405a232fc97b8d692e62e73d29c453e44a2970 (patch) | |
| tree | 6ab7ad2cbafa2d794627c9f6a8a21102454d7516 /tests-clar/notes/notes.c | |
| parent | 69c28b75dfb0a3edefa4d4a8616624f856b15533 (diff) | |
| parent | aa518c709c8caa6577822e073e7f27733eb6aaa3 (diff) | |
| download | libgit2-1b405a232fc97b8d692e62e73d29c453e44a2970.tar.gz | |
Merge pull request #1396 from cholin/features/note-iterator
[RFC] basic note iterator implementation
Diffstat (limited to 'tests-clar/notes/notes.c')
| -rw-r--r-- | tests-clar/notes/notes.c | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c index ee0b6c2f8..82dcaf8ca 100644 --- a/tests-clar/notes/notes.c +++ b/tests-clar/notes/notes.c @@ -40,7 +40,8 @@ static void create_note(git_oid *note_oid, const char *canonical_namespace, cons static struct { const char *note_sha; const char *annotated_object_sha; -} list_expectations[] = { +} +list_expectations[] = { { "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" }, { "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "9fd738e8f7967c078dceed8190330fc8648ee56a" }, { "257b43746b6b46caa4aa788376c647cce0a33e2b", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" }, @@ -317,3 +318,70 @@ void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(voi cl_git_fail(error); cl_assert_equal_i(GIT_ENOTFOUND, error); } + +void test_notes_notes__can_iterate_default_namespace(void) +{ + git_note_iterator *iter; + git_note *note; + git_oid note_id, annotated_id; + git_oid note_created[2]; + const char* note_message[] = { + "I decorate a65f\n", + "I decorate c478\n" + }; + int i, err; + + create_note(¬e_created[0], "refs/notes/commits", + "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", note_message[0]); + create_note(¬e_created[1], "refs/notes/commits", + "c47800c7266a2be04c571c04d5a6614691ea99bd", note_message[1]); + + cl_git_pass(git_note_iterator_new(&iter, _repo, NULL)); + + for (i = 0; (err = git_note_next(¬e_id, &annotated_id, iter)) >= 0; ++i) { + cl_git_pass(git_note_read(¬e, _repo, NULL, &annotated_id)); + cl_assert_equal_s(git_note_message(note), note_message[i]); + git_note_free(note); + } + + cl_assert_equal_i(GIT_ITEROVER, err); + cl_assert_equal_i(2, i); + git_note_iterator_free(iter); +} + +void test_notes_notes__can_iterate_custom_namespace(void) +{ + git_note_iterator *iter; + git_note *note; + git_oid note_id, annotated_id; + git_oid note_created[2]; + const char* note_message[] = { + "I decorate a65f\n", + "I decorate c478\n" + }; + int i, err; + + create_note(¬e_created[0], "refs/notes/beer", + "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", note_message[0]); + create_note(¬e_created[1], "refs/notes/beer", + "c47800c7266a2be04c571c04d5a6614691ea99bd", note_message[1]); + + cl_git_pass(git_note_iterator_new(&iter, _repo, "refs/notes/beer")); + + for (i = 0; (err = git_note_next(¬e_id, &annotated_id, iter)) >= 0; ++i) { + cl_git_pass(git_note_read(¬e, _repo, "refs/notes/beer", &annotated_id)); + cl_assert_equal_s(git_note_message(note), note_message[i]); + git_note_free(note); + } + + cl_assert_equal_i(GIT_ITEROVER, err); + cl_assert_equal_i(2, i); + git_note_iterator_free(iter); +} + +void test_notes_notes__empty_iterate(void) +{ + git_note_iterator *iter; + + cl_git_fail(git_note_iterator_new(&iter, _repo, "refs/notes/commits")); +} |
