diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2022-12-03 13:14:38 +0000 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2023-02-09 12:31:16 +0000 |
| commit | 4083e46f475cd3026a3c65a1e46c4b73d5c22513 (patch) | |
| tree | c374cfce7e78db967db116492e165f089c6a1cef /tests | |
| parent | f02bcf721105d3dfb0a7d12dec2816b495451c45 (diff) | |
| download | libgit2-4083e46f475cd3026a3c65a1e46c4b73d5c22513.tar.gz | |
oid: provide type lookups by enum value or name
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/libgit2/core/oid.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/libgit2/core/oid.c b/tests/libgit2/core/oid.c index 90fb37514..a405b3344 100644 --- a/tests/libgit2/core/oid.c +++ b/tests/libgit2/core/oid.c @@ -192,3 +192,22 @@ void test_core_oid__fmt_substr_sha1(void) git_oid_fmt_substr(buf, &id_sha1, 5, 6); cl_assert_equal_s(buf, "12eea6"); } + +void test_core_oid__type_lookup(void) +{ + cl_assert_equal_i(GIT_OID_SHA1, git_oid_type_fromstr("sha1")); + cl_assert_equal_i(GIT_OID_SHA1, git_oid_type_fromstrn("sha1...", 4)); + cl_assert_equal_s("sha1", git_oid_type_name(GIT_OID_SHA1)); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_assert_equal_i(GIT_OID_SHA256, git_oid_type_fromstr("sha256")); + cl_assert_equal_i(GIT_OID_SHA256, git_oid_type_fromstrn("sha256...", 6)); + cl_assert_equal_s("sha256", git_oid_type_name(GIT_OID_SHA256)); +#endif + + cl_assert_equal_i(0, git_oid_type_fromstr("sha42")); + cl_assert_equal_i(0, git_oid_type_fromstrn("sha1", 3)); + cl_assert_equal_i(0, git_oid_type_fromstrn("sha1...", 5)); + cl_assert_equal_s("unknown", git_oid_type_name(0)); + cl_assert_equal_s("unknown", git_oid_type_name(42)); +} |
