"""Inspect public HTML table alignment for a valid label containing a pipe."""

import html
import json
import re

from telemetry.performance import (
    CaseMeasurement,
    EvaluationCase,
    EvaluationPlan,
    PerformanceEvaluator,
    present_evaluation,
    render_html,
)


def main() -> None:
    report = PerformanceEvaluator(
        "html-columns",
        (EvaluationCase("case", 1, None),),
        (
            CaseMeasurement(
                "quality|name", lambda observation: float(observation.output), unit="ms"
            ),
        ),
        plan=EvaluationPlan(bootstrap_resamples=100),
    ).evaluate(lambda value: value, candidate="candidate")
    document = render_html(present_evaluation(report))
    headers = re.findall(r"<th\b[^>]*>(.*?)</th>", document)
    cells = re.findall(r"<td>(.*?)</td>", document)
    print(json.dumps({
        "header_count": len(headers),
        "row_cell_count": len(cells),
        "cells": [html.unescape(cell) for cell in cells],
    }, sort_keys=True))


if __name__ == "__main__":
    main()
