def test_html_code_splitter() -> None:
    """Test case for code splitting using HTML."""
    if "CI" in os.environ:
        return

    code_splitter = CodeHierarchyNodeParser(
        language="html",
        chunk_min_characters=len("    <title>My Example Page</title>") + 1,
        skeleton=False,
    )

    text = """\
<!DOCTYPE html>
<html>
<head>
    <title>My Example Page</title>
</head>
<body>
    <h1>Welcome to My Example Page</h1>
    <p>This is a basic HTML page example.</p>
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
    </ul>
    <img src="https://example.com/image.jpg" alt="Example Image">
</body>
</html>"""

    text_node = TextNode(
        text=text,
    )
    chunks = code_splitter.get_nodes_from_documents([text_node])

    # This is the DOCTYPE scope
    assert chunks[0].text == text
    assert chunks[0].metadata["inclusive_scopes"] == []
    assert NodeRelationship.PARENT not in chunks[0].relationships
    assert [c.node_id for c in chunks[0].relationships[NodeRelationship.CHILD]] == [
        chunks[1].id_
    ]
    assert (
        cast(RelatedNodeInfo, chunks[0].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[0].relationships
    assert NodeRelationship.NEXT not in chunks[0].relationships

    # This is the html scope
    assert (
        chunks[1].text
        == """\
<html>
<head>
    <title>My Example Page</title>
</head>
<body>
    <h1>Welcome to My Example Page</h1>
    <p>This is a basic HTML page example.</p>
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
    </ul>
    <img src="https://example.com/image.jpg" alt="Example Image">
</body>
</html>"""
    )
    assert chunks[1].metadata["inclusive_scopes"] == [
        {"name": "html", "type": "element", "signature": "<html>"}
    ]
    assert (
        cast(RelatedNodeInfo, chunks[1].relationships[NodeRelationship.PARENT]).node_id
        == chunks[0].id_
    )
    assert [c.node_id for c in chunks[1].relationships[NodeRelationship.CHILD]] == [
        chunks[2].id_,
        chunks[3].id_,
    ]
    assert (
        cast(RelatedNodeInfo, chunks[1].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[1].relationships
    assert NodeRelationship.NEXT not in chunks[1].relationships

    # Head chunk
    assert (
        chunks[2].text
        == """\
<head>
    <title>My Example Page</title>
</head>"""
    )
    assert chunks[2].metadata["inclusive_scopes"] == [
        {"name": "html", "type": "element", "signature": "<html>"},
        {"name": "head", "type": "element", "signature": "<head>"},
    ]
    assert (
        cast(RelatedNodeInfo, chunks[2].relationships[NodeRelationship.PARENT]).node_id
        == chunks[1].id_
    )  # Parent should be <html>
    assert [
        c.node_id for c in chunks[2].relationships[NodeRelationship.CHILD]
    ] == []  # Child should be <title>
    assert (
        cast(RelatedNodeInfo, chunks[2].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[2].relationships
    assert NodeRelationship.NEXT not in chunks[2].relationships

    # Test the fourth chunk (<body> tag and its content)
    assert (
        chunks[3].text
        == """\
<body>
    <h1>Welcome to My Example Page</h1>
    <p>This is a basic HTML page example.</p>
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
    </ul>
    <img src="https://example.com/image.jpg" alt="Example Image">
</body>"""
    )
    assert chunks[3].metadata["inclusive_scopes"] == [
        {"name": "html", "type": "element", "signature": "<html>"},
        {"name": "body", "type": "element", "signature": "<body>"},
    ]
    assert (
        cast(RelatedNodeInfo, chunks[3].relationships[NodeRelationship.PARENT]).node_id
        == chunks[1].id_
    )  # Parent should be <html>
    assert chunks[5].id_ in [
        c.node_id for c in chunks[3].relationships[NodeRelationship.CHILD]
    ]
    assert (
        cast(RelatedNodeInfo, chunks[3].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[3].relationships
    assert NodeRelationship.NEXT not in chunks[3].relationships

    # Test the seventh chunk (<ul> tag and its content)
    assert (
        chunks[6].text
        == """\
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
    </ul>"""
    )
    assert chunks[6].metadata["inclusive_scopes"] == [
        {"name": "html", "type": "element", "signature": "<html>"},
        {"name": "body", "type": "element", "signature": "<body>"},
        {"name": "ul", "type": "element", "signature": "<ul>"},
    ]
    assert (
        cast(RelatedNodeInfo, chunks[6].relationships[NodeRelationship.PARENT]).node_id
        == chunks[3].id_
    )  # Parent should be <body>
    assert [c.node_id for c in chunks[6].relationships[NodeRelationship.CHILD]] == []
    assert (
        cast(RelatedNodeInfo, chunks[6].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[6].relationships
    assert NodeRelationship.NEXT not in chunks[6].relationships
Test case for code splitting using HTML.
llama-index-packs/llama-index-packs-code-hierarchy/tests/test_code_hierarchy_no_skeleton.py