# Path: terminaltables/build.py
# def build_border(outer_widths, horizontal, left, intersect, right, title=None):
#     """Build the top/bottom/middle row. Optionally embed the table title within the border.
# 
#     Title is hidden if it doesn't fit between the left/right characters/edges.
# 
#     Example return value:
#     ('<', '-----', '+', '------', '+', '-------', '>')
#     ('<', 'My Table', '----', '+', '------->')
# 
#     :param iter outer_widths: List of widths (with padding) for each column.
#     :param str horizontal: Character to stretch across each column.
#     :param str left: Left border.
#     :param str intersect: Column separator.
#     :param str right: Right border.
#     :param title: Overlay the title on the border between the left and right characters.
# 
#     :return: Returns a generator of strings representing a border.
#     :rtype: iter
#     """
#     length = 0
# 
#     # Hide title if it doesn't fit.
#     if title is not None and outer_widths:
#         try:
#             length = visible_width(title)
#         except TypeError:
#             title = str(title)
#             length = visible_width(title)
#         if length > sum(outer_widths) + len(intersect) * (len(outer_widths) - 1):
#             title = None
# 
#     # Handle no title.
#     if title is None or not outer_widths or not horizontal:
#         return combine((horizontal * c for c in outer_widths), left, intersect, right)
# 
#     # Handle title fitting in the first column.
#     if length == outer_widths[0]:
#         return combine([title] + [horizontal * c for c in outer_widths[1:]], left, intersect, right)
#     if length < outer_widths[0]:
#         columns = [title + horizontal * (outer_widths[0] - length)] + [horizontal * c for c in outer_widths[1:]]
#         return combine(columns, left, intersect, right)
# 
#     # Handle wide titles/narrow columns.
#     columns_and_intersects = [title]
#     for width in combine(outer_widths, None, bool(intersect), None):
#         # If title is taken care of.
#         if length < 1:
#             columns_and_intersects.append(intersect if width is True else horizontal * width)
#         # If title's last character overrides an intersect character.
#         elif width is True and length == 1:
#             length = 0
#         # If this is an intersect character that is overridden by the title.
#         elif width is True:
#             length -= 1
#         # If title's last character is within a column.
#         elif width >= length:
#             columns_and_intersects[0] += horizontal * (width - length)  # Append horizontal chars to title.
#             length = 0
#         # If remainder of title won't fit in a column.
#         else:
#             length -= width
# 
#     return combine(columns_and_intersects, left, None, right)


import pytest
from colorama import Fore, Style
from colorclass import Color
from termcolor import colored
from terminaltables.build import build_border
])
def test_colors(outer_widths, left, intersect, right, title, expected):
    """Test with color title characters.

    :param iter outer_widths: List of integers representing column widths with padding.
    :param str left: Left border.
    :param str intersect: Column separator.
    :param str right: Right border.
    :param title: Title in border with color codes.
    :param str expected: Expected output.
    """
    if left and right:
        expected = left + expected + right
    actual = build_border(outer_widths, '-', left, intersect, right, title=title)
    assert ''.join(actual) == expected


@pytest.mark.parametrize('outer_widths,title,expected', [
    ([3, 3, 3], 123, '<123+---+--->'),
    ([3, 3, 3], 0.9, '<0.9+---+--->'),
    ([3, 3, 3], True, '<True---+--->'),
    ([3, 3, 3], False, '<False--+--->'),
])
def test_non_string(outer_widths, title, expected):
    """Test with non-string values.

    :param iter outer_widths: List of integers representing column widths with padding.
    :param title: Title in border.
    :param str expected: Expected output.
    """

# Path: terminaltables/build.py
# def build_border(outer_widths, horizontal, left, intersect, right, title=None):
#     """Build the top/bottom/middle row. Optionally embed the table title within the border.
# 
#     Title is hidden if it doesn't fit between the left/right characters/edges.
# 
#     Example return value:
#     ('<', '-----', '+', '------', '+', '-------', '>')
#     ('<', 'My Table', '----', '+', '------->')
# 
#     :param iter outer_widths: List of widths (with padding) for each column.
#     :param str horizontal: Character to stretch across each column.
#     :param str left: Left border.
#     :param str intersect: Column separator.
#     :param str right: Right border.
#     :param title: Overlay the title on the border between the left and right characters.
# 
#     :return: Returns a generator of strings representing a border.
#     :rtype: iter
#     """
#     length = 0
# 
#     # Hide title if it doesn't fit.
#     if title is not None and outer_widths:
#         try:
#             length = visible_width(title)
#         except TypeError:
#             title = str(title)
#             length = visible_width(title)
#         if length > sum(outer_widths) + len(intersect) * (len(outer_widths) - 1):
#             title = None
# 
#     # Handle no title.
#     if title is None or not outer_widths or not horizontal:
#         return combine((horizontal * c for c in outer_widths), left, intersect, right)
# 
#     # Handle title fitting in the first column.
#     if length == outer_widths[0]:
#         return combine([title] + [horizontal * c for c in outer_widths[1:]], left, intersect, right)
#     if length < outer_widths[0]:
#         columns = [title + horizontal * (outer_widths[0] - length)] + [horizontal * c for c in outer_widths[1:]]
#         return combine(columns, left, intersect, right)
# 
#     # Handle wide titles/narrow columns.
#     columns_and_intersects = [title]
#     for width in combine(outer_widths, None, bool(intersect), None):
#         # If title is taken care of.
#         if length < 1:
#             columns_and_intersects.append(intersect if width is True else horizontal * width)
#         # If title's last character overrides an intersect character.
#         elif width is True and length == 1:
#             length = 0
#         # If this is an intersect character that is overridden by the title.
#         elif width is True:
#             length -= 1
#         # If title's last character is within a column.
#         elif width >= length:
#             columns_and_intersects[0] += horizontal * (width - length)  # Append horizontal chars to title.
#             length = 0
#         # If remainder of title won't fit in a column.
#         else:
#             length -= width
# 
#     return combine(columns_and_intersects, left, None, right)


# Path: tests/test_build/test_build_border.py
import pytest
from colorama import Fore, Style
from colorclass import Color
from termcolor import colored
from terminaltables.build import build_border

])
def test_colors(outer_widths, left, intersect, right, title, expected):
    """Test with color title characters.

    :param iter outer_widths: List of integers representing column widths with padding.
    :param str left: Left border.
    :param str intersect: Column separator.
    :param str right: Right border.
    :param title: Title in border with color codes.
    :param str expected: Expected output.
    """
    if left and right:
        expected = left + expected + right
    actual = build_border(outer_widths, '-', left, intersect, right, title=title)
    assert ''.join(actual) == expected


@pytest.mark.parametrize('outer_widths,title,expected', [
    ([3, 3, 3], 123, '<123+---+--->'),
    ([3, 3, 3], 0.9, '<0.9+---+--->'),
    ([3, 3, 3], True, '<True---+--->'),
    ([3, 3, 3], False, '<False--+--->'),
])
def test_non_string(outer_widths, title, expected):
    """Test with non-string values.

    :param iter outer_widths: List of integers representing column widths with padding.
    :param title: Title in border.
    :param str expected: Expected output.
    """

    actual = build_border(outer_widths, '-', '<', '+', '>', title=title)