]> git.proxmox.com Git - libgit2.git/blame - tests-clar/object/tag/list.c
Tests: reindent object/tag/list.c to use tabs
[libgit2.git] / tests-clar / object / tag / list.c
CommitLineData
f73f760e
SC
1#include "clar_libgit2.h"
2
3#include "tag.h"
4
5static git_repository *g_repo;
6
7604ddbf 7#define MAX_USED_TAGS 6
e800bbe8
SC
8
9struct pattern_match_t
10{
daa70138
SC
11 const char* pattern;
12 const size_t expected_matches;
13 const char* expected_results[MAX_USED_TAGS];
e800bbe8
SC
14};
15
f73f760e
SC
16// Helpers
17static void ensure_tag_pattern_match(git_repository *repo,
daa70138 18 const struct pattern_match_t* data)
f73f760e 19{
daa70138
SC
20 int already_found[MAX_USED_TAGS] = { 0 };
21 git_strarray tag_list;
22 int error = 0;
23 size_t sucessfully_found = 0;
24 size_t i, j;
25
26 cl_assert(data->expected_matches <= MAX_USED_TAGS);
27
28 if ((error = git_tag_list_match(&tag_list, data->pattern, repo)) < 0)
29 goto exit;
30
31 if (tag_list.count != data->expected_matches)
32 {
33 error = GIT_ERROR;
34 goto exit;
35 }
36
37 // we have to be prepared that tags come in any order.
38 for (i = 0; i < tag_list.count; i++)
39 {
40 for (j = 0; j < data->expected_matches; j++)
41 {
42 if (!already_found[j] && !strcmp(data->expected_results[j], tag_list.strings[i]))
43 {
44 already_found[j] = 1;
45 sucessfully_found++;
46 break;
47 }
48 }
49 }
50 cl_assert_equal_i((int)sucessfully_found, (int)data->expected_matches);
f73f760e
SC
51
52exit:
daa70138
SC
53 git_strarray_free(&tag_list);
54 cl_git_pass(error);
f73f760e
SC
55}
56
f73f760e
SC
57// Fixture setup and teardown
58void test_object_tag_list__initialize(void)
59{
daa70138 60 g_repo = cl_git_sandbox_init("testrepo");
f73f760e
SC
61}
62
63void test_object_tag_list__cleanup(void)
64{
daa70138 65 cl_git_sandbox_cleanup();
f73f760e
SC
66}
67
68void test_object_tag_list__list_all(void)
69{
daa70138
SC
70 // list all tag names from the repository
71 git_strarray tag_list;
f73f760e 72
daa70138 73 cl_git_pass(git_tag_list(&tag_list, g_repo));
f73f760e 74
daa70138 75 cl_assert_equal_i((int)tag_list.count, 6);
f73f760e 76
daa70138 77 git_strarray_free(&tag_list);
f73f760e
SC
78}
79
e800bbe8 80static const struct pattern_match_t matches[] = {
daa70138
SC
81 // All tags, including a packed one and two namespaced ones.
82 { "", 6, { "e90810b", "point_to_blob", "test", "packed-tag", "foo/bar", "foo/foo/bar" } },
45949b37 83
daa70138
SC
84 // beginning with
85 { "t*", 1, { "test" } },
45949b37 86
daa70138
SC
87 // ending with
88 { "*b", 2, { "e90810b", "point_to_blob" } },
45949b37 89
daa70138
SC
90 // exact match
91 { "e", 0 },
92 { "e90810b", 1, { "e90810b" } },
45949b37 93
daa70138
SC
94 // either or
95 { "e90810[ab]", 1, { "e90810b" } },
45949b37 96
daa70138
SC
97 // glob in the middle
98 { "foo/*/bar", 1, { "foo/foo/bar" } },
45949b37 99
daa70138
SC
100 // End of list
101 { NULL }
e800bbe8
SC
102};
103
f73f760e
SC
104void test_object_tag_list__list_by_pattern(void)
105{
daa70138
SC
106 // list all tag names from the repository matching a specified pattern
107 size_t i = 0;
108 while (matches[i].pattern)
109 ensure_tag_pattern_match(g_repo, &matches[i++]);
f73f760e 110}