# 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 shutil
import sys
import pytest
import uqbar.apis
from uqbar.strings import normalize
                fake_package.empty_package/
                    fake_package.empty_package.empty
                fake_package.enums
                fake_package.module
                fake_package.multi/
                    fake_package.multi.one
                    fake_package.multi.two
        """
    )
    documenters = list(builder.collect_module_documenters(node_tree))
    assert isinstance(documenters[0], uqbar.apis.RootDocumenter)
    assert [documenter.package_path for documenter in documenters[1:]] == [
        "fake_package",
        "fake_package.empty_module",
        "fake_package.empty_package",
        "fake_package.empty_package.empty",
        "fake_package.enums",
        "fake_package.module",
        "fake_package.multi",
        "fake_package.multi.one",
        "fake_package.multi.two",
    ]


def test_collection_02(test_path):
    builder = uqbar.apis.APIBuilder(
        [test_path / "fake_package"], test_path / "docs", document_private_modules=True
    )
    source_paths = uqbar.apis.collect_source_paths(builder._initial_source_paths)
    node_tree = builder.build_node_tree(source_paths)

# 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_apis_APIBuilder.py
import pathlib
import shutil
import sys
import pytest
import uqbar.apis
from uqbar.strings import normalize

                fake_package.empty_package/
                    fake_package.empty_package.empty
                fake_package.enums
                fake_package.module
                fake_package.multi/
                    fake_package.multi.one
                    fake_package.multi.two
        """
    )
    documenters = list(builder.collect_module_documenters(node_tree))
    assert isinstance(documenters[0], uqbar.apis.RootDocumenter)
    assert [documenter.package_path for documenter in documenters[1:]] == [
        "fake_package",
        "fake_package.empty_module",
        "fake_package.empty_package",
        "fake_package.empty_package.empty",
        "fake_package.enums",
        "fake_package.module",
        "fake_package.multi",
        "fake_package.multi.one",
        "fake_package.multi.two",
    ]


def test_collection_02(test_path):
    builder = uqbar.apis.APIBuilder(
        [test_path / "fake_package"], test_path / "docs", document_private_modules=True
    )
    source_paths = uqbar.apis.collect_source_paths(builder._initial_source_paths)
    node_tree = builder.build_node_tree(source_paths)

    assert normalize(str(node_tree)) == normalize(