Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-04-29 19:59:46 +0400
committerRussell Belfer <rb@github.com>2013-04-29 19:59:46 +0400
commitaa8f010120577e61715f3ae1286a03055815f9c3 (patch)
treec6e8f4c96797675040e45e4b420705f5f3c21454 /tests-clar/core
parent8564a0224abe09beaacb2d2e7a54b16f8fcea7d1 (diff)
Add git_oid_strcmp and use it for git_oid_streq
Add a new git_oid_strcmp that compares a string OID with a hex oid for sort order, and then reimplement git_oid_streq using it. This actually should speed up git_oid_streq because it only reads as far into the string as it needs to, whereas previously it would convert the whole string into an OID and then use git_oid_cmp.
Diffstat (limited to 'tests-clar/core')
-rw-r--r--tests-clar/core/oid.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/tests-clar/core/oid.c b/tests-clar/core/oid.c
index d863a3e85..7ee6fb67d 100644
--- a/tests-clar/core/oid.c
+++ b/tests-clar/core/oid.c
@@ -16,17 +16,39 @@ void test_core_oid__initialize(void)
void test_core_oid__streq(void)
{
- cl_assert(git_oid_streq(&id, str_oid) == 0);
- cl_assert(git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
+ cl_assert_equal_i(0, git_oid_streq(&id, str_oid));
+ cl_assert_equal_i(-1, git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
- cl_assert(git_oid_streq(&id, "deadbeef") == -1);
- cl_assert(git_oid_streq(&id, "I'm not an oid.... :)") == -1);
-
- cl_assert(git_oid_streq(&idp, "ae90f12eea699729ed0000000000000000000000") == 0);
- cl_assert(git_oid_streq(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
+ cl_assert_equal_i(-1, git_oid_streq(&id, "deadbeef"));
+ cl_assert_equal_i(-1, git_oid_streq(&id, "I'm not an oid.... :)"));
- cl_assert(git_oid_streq(&idp, "deadbeef") == -1);
- cl_assert(git_oid_streq(&idp, "I'm not an oid.... :)") == -1);
+ cl_assert_equal_i(0, git_oid_streq(&idp, "ae90f12eea699729ed0000000000000000000000"));
+ cl_assert_equal_i(0, git_oid_streq(&idp, "ae90f12eea699729ed"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "ae90f12eea699729ed1"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "ae90f12eea699729ec"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
+
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "deadbeef"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "I'm not an oid.... :)"));
+}
+
+void test_core_oid__strcmp(void)
+{
+ cl_assert_equal_i(0, git_oid_strcmp(&id, str_oid));
+ cl_assert(git_oid_strcmp(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0);
+
+ cl_assert(git_oid_strcmp(&id, "deadbeef") < 0);
+ cl_assert_equal_i(-1, git_oid_strcmp(&id, "I'm not an oid.... :)"));
+
+ cl_assert_equal_i(0, git_oid_strcmp(&idp, "ae90f12eea699729ed0000000000000000000000"));
+ cl_assert_equal_i(0, git_oid_strcmp(&idp, "ae90f12eea699729ed"));
+ cl_assert(git_oid_strcmp(&idp, "ae90f12eea699729ed1") < 0);
+ cl_assert(git_oid_strcmp(&idp, "ae90f12eea699729ec") > 0);
+ cl_assert(git_oid_strcmp(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0);
+
+ cl_assert(git_oid_strcmp(&idp, "deadbeef") < 0);
+ cl_assert_equal_i(-1, git_oid_strcmp(&idp, "I'm not an oid.... :)"));
+}
void test_core_oid__ncmp(void)
{