summaryrefslogtreecommitdiff
path: root/tests/diff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-02-10 13:20:08 -0800
committerRussell Belfer <rb@github.com>2014-04-17 14:43:45 -0700
commit3b4c401a38ce912d5be8c9bf4ab1c4912a4f08bd (patch)
tree4961b64fd558e1e55e9d1d96b37ca575c42ce008 /tests/diff
parentdac160489bbf8de90d2f1ae152df68ded2603598 (diff)
downloadlibgit2-3b4c401a38ce912d5be8c9bf4ab1c4912a4f08bd.tar.gz
Decouple index iterator sort from index
This makes the index iterator honor the GIT_ITERATOR_IGNORE_CASE and GIT_ITERATOR_DONT_IGNORE_CASE flags without modifying the index data itself. To take advantage of this, I had to export a number of the internal index entry comparison functions. I also wrote some new tests to exercise the capability.
Diffstat (limited to 'tests/diff')
-rw-r--r--tests/diff/iterator.c58
1 files changed, 51 insertions, 7 deletions
diff --git a/tests/diff/iterator.c b/tests/diff/iterator.c
index 891d8a6e5..19a9a0077 100644
--- a/tests/diff/iterator.c
+++ b/tests/diff/iterator.c
@@ -355,6 +355,7 @@ static void index_iterator_test(
const char *sandbox,
const char *start,
const char *end,
+ git_iterator_flag_t flags,
int expected_count,
const char **expected_names,
const char **expected_oids)
@@ -364,9 +365,12 @@ static void index_iterator_test(
const git_index_entry *entry;
int error, count = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
+ unsigned int caps;
cl_git_pass(git_repository_index(&index, repo));
- cl_git_pass(git_iterator_for_index(&i, index, 0, start, end));
+ caps = git_index_caps(index);
+
+ cl_git_pass(git_iterator_for_index(&i, index, flags, start, end));
while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry);
@@ -388,6 +392,8 @@ static void index_iterator_test(
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
+
+ cl_assert(caps == git_index_caps(index));
git_index_free(index);
}
@@ -446,7 +452,8 @@ static const char *expected_index_oids_0[] = {
void test_diff_iterator__index_0(void)
{
index_iterator_test(
- "attr", NULL, NULL, 23, expected_index_0, expected_index_oids_0);
+ "attr", NULL, NULL, 0, ARRAY_SIZE(expected_index_0),
+ expected_index_0, expected_index_oids_0);
}
static const char *expected_index_range[] = {
@@ -466,25 +473,26 @@ static const char *expected_index_oids_range[] = {
void test_diff_iterator__index_range(void)
{
index_iterator_test(
- "attr", "root", "root", 4, expected_index_range, expected_index_oids_range);
+ "attr", "root", "root", 0, ARRAY_SIZE(expected_index_range),
+ expected_index_range, expected_index_oids_range);
}
void test_diff_iterator__index_range_empty_0(void)
{
index_iterator_test(
- "attr", "empty", "empty", 0, NULL, NULL);
+ "attr", "empty", "empty", 0, 0, NULL, NULL);
}
void test_diff_iterator__index_range_empty_1(void)
{
index_iterator_test(
- "attr", "z_empty_after", NULL, 0, NULL, NULL);
+ "attr", "z_empty_after", NULL, 0, 0, NULL, NULL);
}
void test_diff_iterator__index_range_empty_2(void)
{
index_iterator_test(
- "attr", NULL, ".aaa_empty_before", 0, NULL, NULL);
+ "attr", NULL, ".aaa_empty_before", 0, 0, NULL, NULL);
}
static const char *expected_index_1[] = {
@@ -522,9 +530,45 @@ static const char* expected_index_oids_1[] = {
void test_diff_iterator__index_1(void)
{
index_iterator_test(
- "status", NULL, NULL, 13, expected_index_1, expected_index_oids_1);
+ "status", NULL, NULL, 0, ARRAY_SIZE(expected_index_1),
+ expected_index_1, expected_index_oids_1);
}
+static const char *expected_index_cs[] = {
+ "B", "D", "F", "H", "J", "L/1", "L/B", "L/D", "L/a", "L/c",
+ "a", "c", "e", "g", "i", "k/1", "k/B", "k/D", "k/a", "k/c",
+};
+
+static const char *expected_index_ci[] = {
+ "a", "B", "c", "D", "e", "F", "g", "H", "i", "J",
+ "k/1", "k/a", "k/B", "k/c", "k/D", "L/1", "L/a", "L/B", "L/c", "L/D",
+};
+
+void test_diff_iterator__index_case_folding(void)
+{
+ git_buf path = GIT_BUF_INIT;
+ int fs_is_ci = 0;
+
+ cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
+ fs_is_ci = git_path_exists(path.ptr);
+ git_buf_free(&path);
+
+ index_iterator_test(
+ "icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
+ fs_is_ci ? expected_index_ci : expected_index_cs, NULL);
+
+ cl_git_sandbox_cleanup();
+
+ index_iterator_test(
+ "icase", NULL, NULL, GIT_ITERATOR_IGNORE_CASE,
+ ARRAY_SIZE(expected_index_ci), expected_index_ci, NULL);
+
+ cl_git_sandbox_cleanup();
+
+ index_iterator_test(
+ "icase", NULL, NULL, GIT_ITERATOR_DONT_IGNORE_CASE,
+ ARRAY_SIZE(expected_index_cs), expected_index_cs, NULL);
+}
/* -- WORKDIR ITERATOR TESTS -- */