# Path: uqbar/strings.py
# def normalize(string: str) -> str:
#     """
#     Normalizes whitespace.
# 
#     Strips leading and trailing blank lines, dedents, and removes trailing
#     whitespace from the result.
#     """
#     string = string.replace("\t", "    ")
#     lines = string.split("\n")
#     while lines and (not lines[0] or lines[0].isspace()):
#         lines.pop(0)
#     while lines and (not lines[-1] or lines[-1].isspace()):
#         lines.pop()
#     for i, line in enumerate(lines):
#         lines[i] = line.rstrip()
#     string = "\n".join(lines)
#     string = textwrap.dedent(string)
#     return string


import pathlib
import pytest
from uqbar.strings import normalize




@pytest.mark.sphinx("text", testroot="uqbar-sphinx-api-1")
def test_sphinx_api_1(app, status, warning):
    app.build()
    index_source = pathlib.Path(app.srcdir) / "api" / "index.rst"
    assert index_source.exists()
    assert "build succeeded" in status.getvalue()
    assert "8 added, 0 changed, 0 removed" in status.getvalue()
    assert "0 added, 0 changed, 0 removed" not in status.getvalue()
    assert not warning.getvalue().strip()
    path = pathlib.Path(app.srcdir) / "_build" / "text" / "api" / "index.txt"
    with path.open() as file_pointer:

# Path: uqbar/strings.py
# def normalize(string: str) -> str:
#     """
#     Normalizes whitespace.
# 
#     Strips leading and trailing blank lines, dedents, and removes trailing
#     whitespace from the result.
#     """
#     string = string.replace("\t", "    ")
#     lines = string.split("\n")
#     while lines and (not lines[0] or lines[0].isspace()):
#         lines.pop(0)
#     while lines and (not lines[-1] or lines[-1].isspace()):
#         lines.pop()
#     for i, line in enumerate(lines):
#         lines[i] = line.rstrip()
#     string = "\n".join(lines)
#     string = textwrap.dedent(string)
#     return string


# Path: tests/test_sphinx_api.py
import pathlib
import pytest
from uqbar.strings import normalize





@pytest.mark.sphinx("text", testroot="uqbar-sphinx-api-1")
def test_sphinx_api_1(app, status, warning):
    app.build()
    index_source = pathlib.Path(app.srcdir) / "api" / "index.rst"
    assert index_source.exists()
    assert "build succeeded" in status.getvalue()
    assert "8 added, 0 changed, 0 removed" in status.getvalue()
    assert "0 added, 0 changed, 0 removed" not in status.getvalue()
    assert not warning.getvalue().strip()
    path = pathlib.Path(app.srcdir) / "_build" / "text" / "api" / "index.txt"
    with path.open() as file_pointer:

        assert normalize(file_pointer.read()) == normalize(