t-reftable-record: add tests for reftable_ref_record_compare_name()

reftable_ref_record_compare_name() is a function defined by reftable/record.{c, h} and is used to compare the refname of two ref records when sorting multiple ref records using 'qsort'. In the current testing setup, this function is left unexercised. Add a testing function for the same. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Acked-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chandra Pratap committed Jul 2, 2024 at 12:52 UTC f7ec13b53896966c233514c3906c284a40b00c3c
1 file changed +20
t/unit-tests/t-reftable-record.c
+20
@@ -95,6 +95,25 @@ static void t_reftable_ref_record_comparison(void)
95 check(!reftable_record_cmp(&in[0], &in[1]));
96 }
97
98 +static void t_reftable_ref_record_compare_name(void)
99 +{
100 + struct reftable_ref_record recs[3] = {
101 + {
102 + .refname = (char *) "refs/heads/a"
103 + },
104 + {
105 + .refname = (char *) "refs/heads/b"
106 + },
107 + {
108 + .refname = (char *) "refs/heads/a"
109 + },
110 + };
111 +
112 + check_int(reftable_ref_record_compare_name(&recs[0], &recs[1]), <, 0);
113 + check_int(reftable_ref_record_compare_name(&recs[1], &recs[0]), >, 0);
114 + check_int(reftable_ref_record_compare_name(&recs[0], &recs[2]), ==, 0);
115 +}
116 +
117 static void t_reftable_ref_record_roundtrip(void)
118 {
119 struct strbuf scratch = STRBUF_INIT;
@@ -490,6 +509,7 @@ int cmd_main(int argc, const char *argv[])
509 TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
510 TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");
511 TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record");
512 + TEST(t_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works");
513 TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
514 TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
515 TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");