libxml / tests /tests_HTMLparser_htmlCheckAutoClose.c
AryaWu's picture
Upload folder using huggingface_hub
6baed57 verified
#include "unity/unity.h"
#include <libxml/HTMLparser.h>
#include <string.h>
#include <stdlib.h>
/* External wrapper for the static function under test */
extern int test_htmlCheckAutoClose(const xmlChar * newtag, const xmlChar * oldtag);
void setUp(void) {
/* Setup code here, or leave empty */
}
void tearDown(void) {
/* Cleanup code here, or leave empty */
}
/* Positive tests: well-known auto-close pairs */
/* Starting a new <p> closes a previous <p> */
void test_htmlCheckAutoClose_p_closes_p(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"p",
(const xmlChar *)"p"));
}
/* Starting a new <li> closes a previous <li> */
void test_htmlCheckAutoClose_li_closes_li(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"li",
(const xmlChar *)"li"));
}
/* Starting a new <option> closes a previous <option> */
void test_htmlCheckAutoClose_option_closes_option(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"option",
(const xmlChar *)"option"));
}
/* Starting a new <tr> closes a previous <tr> */
void test_htmlCheckAutoClose_tr_closes_tr(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"tr",
(const xmlChar *)"tr"));
}
/* Starting a new <td> closes a previous <td> */
void test_htmlCheckAutoClose_td_closes_td(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"td",
(const xmlChar *)"td"));
}
/* Starting a new <th> closes a previous <th> */
void test_htmlCheckAutoClose_th_closes_th(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"th",
(const xmlChar *)"th"));
}
/* Cross-closures within table rows: td <-> th */
void test_htmlCheckAutoClose_td_closes_th_and_th_closes_td(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"td",
(const xmlChar *)"th"));
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"th",
(const xmlChar *)"td"));
}
/* Definition list cross-closures: dt <-> dd */
void test_htmlCheckAutoClose_dt_dd_cross_closures(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"dt",
(const xmlChar *)"dd"));
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"dd",
(const xmlChar *)"dt"));
}
/* Block-level element like <div> closes an open <p> */
void test_htmlCheckAutoClose_div_closes_p(void) {
TEST_ASSERT_EQUAL_INT(1, test_htmlCheckAutoClose((const xmlChar *)"div",
(const xmlChar *)"p"));
}
/* Negative tests: non-auto-close cases */
/* Inline formatting elements typically don't auto-close themselves */
void test_htmlCheckAutoClose_b_does_not_close_b(void) {
TEST_ASSERT_EQUAL_INT(0, test_htmlCheckAutoClose((const xmlChar *)"b",
(const xmlChar *)"b"));
}
/* Inline element <span> should not auto-close <p> */
void test_htmlCheckAutoClose_span_does_not_close_p(void) {
TEST_ASSERT_EQUAL_INT(0, test_htmlCheckAutoClose((const xmlChar *)"span",
(const xmlChar *)"p"));
}
/* Unknown tags should not be in the auto-close table */
void test_htmlCheckAutoClose_unknown_tags_return_zero(void) {
TEST_ASSERT_EQUAL_INT(0, test_htmlCheckAutoClose((const xmlChar *)"customnew",
(const xmlChar *)"customold"));
TEST_ASSERT_EQUAL_INT(0, test_htmlCheckAutoClose((const xmlChar *)"custom",
(const xmlChar *)"p"));
}
/* Non-symmetric: starting <p> should not auto-close an open <div> */
void test_htmlCheckAutoClose_p_does_not_close_div(void) {
TEST_ASSERT_EQUAL_INT(0, test_htmlCheckAutoClose((const xmlChar *)"p",
(const xmlChar *)"div"));
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_htmlCheckAutoClose_p_closes_p);
RUN_TEST(test_htmlCheckAutoClose_li_closes_li);
RUN_TEST(test_htmlCheckAutoClose_option_closes_option);
RUN_TEST(test_htmlCheckAutoClose_tr_closes_tr);
RUN_TEST(test_htmlCheckAutoClose_td_closes_td);
RUN_TEST(test_htmlCheckAutoClose_th_closes_th);
RUN_TEST(test_htmlCheckAutoClose_td_closes_th_and_th_closes_td);
RUN_TEST(test_htmlCheckAutoClose_dt_dd_cross_closures);
RUN_TEST(test_htmlCheckAutoClose_div_closes_p);
RUN_TEST(test_htmlCheckAutoClose_b_does_not_close_b);
RUN_TEST(test_htmlCheckAutoClose_span_does_not_close_p);
RUN_TEST(test_htmlCheckAutoClose_unknown_tags_return_zero);
RUN_TEST(test_htmlCheckAutoClose_p_does_not_close_div);
return UNITY_END();
}