Commit c232d6c32df90e009dcb8d79309d2c9b9f51b77a

Carlos Martín Nieto 2015-08-14T21:06:51

index: add tests around case switching We were missing tests for switching the case-sensitivity of an index in-memory and then looking up entries in it.

diff --git a/tests/index/filemodes.c b/tests/index/filemodes.c
index b390799..6442d77 100644
--- a/tests/index/filemodes.c
+++ b/tests/index/filemodes.c
@@ -239,6 +239,7 @@ void test_index_filemodes__invalid(void)
 
 	cl_git_pass(git_repository_index(&index, g_repo));
 
+	GIT_IDXENTRY_STAGE_SET(&entry, 0);
 	entry.path = "foo";
 	entry.mode = GIT_OBJ_BLOB;
 	cl_git_fail(git_index_add(index, &entry));
diff --git a/tests/index/tests.c b/tests/index/tests.c
index e1ff12a..f1a0578 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -792,10 +792,43 @@ void test_index_tests__reload_while_ignoring_case(void)
 	cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEXCAP_IGNORE_CASE));
 	cl_git_pass(git_index_read(index, true));
 	cl_git_pass(git_vector_verify_sorted(&index->entries));
+	cl_assert(git_index_get_bypath(index, ".HEADER", 0));
+	cl_assert_equal_p(NULL, git_index_get_bypath(index, ".header", 0));
 
 	cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
 	cl_git_pass(git_index_read(index, true));
 	cl_git_pass(git_vector_verify_sorted(&index->entries));
+	cl_assert(git_index_get_bypath(index, ".HEADER", 0));
+	cl_assert(git_index_get_bypath(index, ".header", 0));
+
+	git_index_free(index);
+}
+
+void test_index_tests__change_icase_on_instance(void)
+{
+	git_index *index;
+	unsigned int caps;
+	const git_index_entry *e;
+
+	cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+	cl_git_pass(git_vector_verify_sorted(&index->entries));
+
+	caps = git_index_caps(index);
+	cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEXCAP_IGNORE_CASE));
+	cl_assert_equal_i(false, index->ignore_case);
+	cl_git_pass(git_vector_verify_sorted(&index->entries));
+	cl_assert(e = git_index_get_bypath(index, "src/common.h", 0));
+	cl_assert_equal_p(NULL, e = git_index_get_bypath(index, "SRC/Common.h", 0));
+	cl_assert(e = git_index_get_bypath(index, "COPYING", 0));
+	cl_assert_equal_p(NULL, e = git_index_get_bypath(index, "copying", 0));
+
+	cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
+	cl_assert_equal_i(true, index->ignore_case);
+	cl_git_pass(git_vector_verify_sorted(&index->entries));
+	cl_assert(e = git_index_get_bypath(index, "COPYING", 0));
+	cl_assert_equal_s("COPYING", e->path);
+	cl_assert(e = git_index_get_bypath(index, "copying", 0));
+	cl_assert_equal_s("COPYING", e->path);
 
 	git_index_free(index);
 }