"""Additional tests to improve code coverage."""

from retroflow import FlowchartGenerator
from retroflow.layout import NetworkXLayout
from retroflow.renderer import ARROW_CHARS, LINE_CHARS, Canvas, LineRenderer


class TestLayoutEdgeCases:
    """Additional tests for layout edge cases."""

    def test_layout_empty_result_handling(self):
        """Test layout handles edge cases in layer assignment."""
        layout = NetworkXLayout()

        # Graph with nodes that all have predecessors (fully connected cycle)
        connections = [("A", "B"), ("B", "A")]
        result = layout.layout(connections)

        assert len(result.nodes) == 2
        assert result.has_cycles is True

    def test_layout_exception_in_cycle_detection(self):
        """Test layout handles cycle detection gracefully."""
        layout = NetworkXLayout()

        # Simple graph that shouldn't cause issues
        connections = [("A", "B"), ("B", "C")]
        result = layout.layout(connections)

        assert len(result.nodes) == 3
        assert result.has_cycles is False


class TestLineRendererEdgeCases:
    """Additional tests for LineRenderer edge cases."""

    def test_vertical_line_overwrites_corner_top_left(self):
        """Test vertical line handling when crossing corner_top_left."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        # Set a corner first
        canvas.set(5, 5, LINE_CHARS["corner_top_left"])

        # Draw vertical line through it
        lr.draw_vertical_line(canvas, 5, 4, 7, arrow_at_end=False)

        # Should become tee_right
        assert canvas.get(5, 5) == LINE_CHARS["tee_right"]

    def test_vertical_line_overwrites_corner_top_right(self):
        """Test vertical line handling when crossing corner_top_right."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["corner_top_right"])
        lr.draw_vertical_line(canvas, 5, 4, 7, arrow_at_end=False)

        assert canvas.get(5, 5) == LINE_CHARS["tee_left"]

    def test_vertical_line_overwrites_corner_bottom_left(self):
        """Test vertical line handling when crossing corner_bottom_left."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["corner_bottom_left"])
        lr.draw_vertical_line(canvas, 5, 4, 7, arrow_at_end=False)

        assert canvas.get(5, 5) == LINE_CHARS["tee_right"]

    def test_vertical_line_overwrites_corner_bottom_right(self):
        """Test vertical line handling when crossing corner_bottom_right."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["corner_bottom_right"])
        lr.draw_vertical_line(canvas, 5, 4, 7, arrow_at_end=False)

        assert canvas.get(5, 5) == LINE_CHARS["tee_left"]

    def test_vertical_line_preserves_down_arrow(self):
        """Test vertical line doesn't overwrite existing down arrow."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, ARROW_CHARS["down"])
        lr.draw_vertical_line(canvas, 5, 4, 7, arrow_at_end=False)

        # Arrow should be preserved
        assert canvas.get(5, 5) == ARROW_CHARS["down"]

    def test_vertical_line_preserves_up_arrow(self):
        """Test vertical line doesn't overwrite existing up arrow."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, ARROW_CHARS["up"])
        lr.draw_vertical_line(canvas, 5, 4, 7, arrow_at_end=False)

        assert canvas.get(5, 5) == ARROW_CHARS["up"]

    def test_horizontal_line_overwrites_corner_top_left(self):
        """Test horizontal line handling when crossing corner_top_left."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["corner_top_left"])
        lr.draw_horizontal_line(canvas, 4, 7, 5, arrow_at_end=False)

        assert canvas.get(5, 5) == LINE_CHARS["tee_down"]

    def test_horizontal_line_overwrites_corner_top_right(self):
        """Test horizontal line handling when crossing corner_top_right."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["corner_top_right"])
        lr.draw_horizontal_line(canvas, 4, 7, 5, arrow_at_end=False)

        assert canvas.get(5, 5) == LINE_CHARS["tee_down"]

    def test_horizontal_line_overwrites_corner_bottom_left(self):
        """Test horizontal line handling when crossing corner_bottom_left."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["corner_bottom_left"])
        lr.draw_horizontal_line(canvas, 4, 7, 5, arrow_at_end=False)

        assert canvas.get(5, 5) == LINE_CHARS["tee_up"]

    def test_horizontal_line_overwrites_corner_bottom_right(self):
        """Test horizontal line handling when crossing corner_bottom_right."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["corner_bottom_right"])
        lr.draw_horizontal_line(canvas, 4, 7, 5, arrow_at_end=False)

        assert canvas.get(5, 5) == LINE_CHARS["tee_up"]

    def test_horizontal_line_preserves_left_arrow(self):
        """Test horizontal line doesn't overwrite existing left arrow."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, ARROW_CHARS["left"])
        lr.draw_horizontal_line(canvas, 4, 7, 5, arrow_at_end=False)

        assert canvas.get(5, 5) == ARROW_CHARS["left"]

    def test_horizontal_line_preserves_right_arrow(self):
        """Test horizontal line doesn't overwrite existing right arrow."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, ARROW_CHARS["right"])
        lr.draw_horizontal_line(canvas, 4, 7, 5, arrow_at_end=False)

        assert canvas.get(5, 5) == ARROW_CHARS["right"]

    def test_corner_on_existing_corner_becomes_cross(self):
        """Test drawing corner on existing corner becomes cross."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        # Draw first corner
        canvas.set(5, 5, LINE_CHARS["corner_top_left"])

        # Drawing any corner should result in cross
        lr.draw_corner(canvas, 5, 5, "bottom_right")

        assert canvas.get(5, 5) == LINE_CHARS["cross"]

    def test_corner_bottom_on_horizontal(self):
        """Test bottom corners on horizontal line."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["horizontal"])
        lr.draw_corner(canvas, 5, 5, "bottom_left")

        assert canvas.get(5, 5) == LINE_CHARS["tee_up"]

    def test_corner_right_on_vertical(self):
        """Test right corners on vertical line."""
        canvas = Canvas(20, 20)
        lr = LineRenderer()

        canvas.set(5, 5, LINE_CHARS["vertical"])
        lr.draw_corner(canvas, 5, 5, "top_right")

        assert canvas.get(5, 5) == LINE_CHARS["tee_left"]


class TestGeneratorEdgeRouting:
    """Tests for edge cases in generator's edge routing."""

    def test_generator_horizontal_routing(self):
        """Test generator handles horizontal edge routing."""
        gen = FlowchartGenerator()

        # Diamond pattern forces horizontal routing
        input_text = """
        A -> B
        A -> C
        B -> D
        C -> D
        """
        result = gen.generate(input_text)

        assert "A" in result
        assert "D" in result
        # Should render properly regardless of routing details
        assert len(result) > 0

    def test_generator_multiple_back_edges(self):
        """Test generator handles multiple back edges."""
        gen = FlowchartGenerator()

        input_text = """
        A -> B
        B -> C
        C -> D
        D -> B
        D -> A
        """
        result = gen.generate(input_text)

        assert "A" in result
        assert "D" in result
        # Should render all nodes
        for node in ["A", "B", "C", "D"]:
            assert node in result

    def test_generator_deep_back_edge(self):
        """Test generator handles back edge spanning many layers."""
        gen = FlowchartGenerator()

        input_text = """
        A -> B
        B -> C
        C -> D
        D -> E
        E -> A
        """
        result = gen.generate(input_text)

        for node in ["A", "B", "C", "D", "E"]:
            assert node in result


class TestRouterEdgeCases:
    """Additional tests for router edge cases."""

    def test_waypoints_upward_same_x(self):
        """Test waypoints for upward edge with same x."""
        from retroflow.router import BoxInfo, EdgeRouter

        router = EdgeRouter()
        boxes = {
            "A": BoxInfo(name="A", x=10, y=0, width=10, height=5, layer=0, position=0),
            "B": BoxInfo(name="B", x=10, y=20, width=10, height=5, layer=1, position=0),
        }
        router.set_boxes(boxes)

        edges = [("B", "A")]  # Upward edge
        layers = [["A"], ["B"]]

        routes = router.route_edges(edges, layers)

        assert len(routes) == 1
        route = routes[0]
        # Upward edge, should have 2 waypoints for direct path
        assert len(route.waypoints) == 2

    def test_waypoints_upward_different_x(self):
        """Test waypoints for upward edge with different x."""
        from retroflow.router import BoxInfo, EdgeRouter

        router = EdgeRouter()
        boxes = {
            "A": BoxInfo(name="A", x=0, y=0, width=10, height=5, layer=0, position=0),
            "B": BoxInfo(name="B", x=30, y=20, width=10, height=5, layer=1, position=0),
        }
        router.set_boxes(boxes)

        edges = [("B", "A")]  # Upward edge
        layers = [["A"], ["B"]]

        routes = router.route_edges(edges, layers)

        assert len(routes) == 1
        route = routes[0]
        # Upward edge with different x needs more waypoints
        assert len(route.waypoints) >= 4


class TestLayoutSpecialCases:
    """Tests for special layout cases."""

    def test_layout_single_node(self):
        """Test layout with single isolated node."""
        layout = NetworkXLayout()
        # Self loop creates single node scenario
        connections = [("A", "A")]
        result = layout.layout(connections)

        assert len(result.nodes) == 1
        assert "A" in result.nodes

    def test_layout_two_node_bidirectional(self):
        """Test layout with bidirectional connection."""
        layout = NetworkXLayout()
        connections = [("A", "B"), ("B", "A")]
        result = layout.layout(connections)

        assert len(result.nodes) == 2
        assert result.has_cycles is True
        assert len(result.back_edges) >= 1


class TestEdgeRoutingAroundBoxes:
    """Tests for edge routing that avoids boxes in the path."""

    def test_tb_mode_skip_layer_routes_around(self):
        """Test that TB mode routes edges around boxes in intermediate layers."""
        gen = FlowchartGenerator(title="Test")
        # A -> C skips B in the middle, should route around B
        input_text = """
        A -> B
        B -> C
        A -> C
        """
        result = gen.generate(input_text)

        # All nodes should be present
        assert "A" in result
        assert "B" in result
        assert "C" in result
        # Edge should be drawn (arrows present)
        assert "▼" in result

    def test_lr_mode_skip_layer_routes_around(self):
        """Test that LR mode routes edges around boxes in intermediate layers."""
        gen = FlowchartGenerator(direction="LR", title="Test LR")
        # A -> C skips B in the middle, should route below boxes
        input_text = """
        A -> B
        B -> C
        A -> C
        """
        result = gen.generate(input_text)

        # All nodes should be present
        assert "A" in result
        assert "B" in result
        assert "C" in result
        # Right arrows present in LR mode
        assert "►" in result

    def test_tb_mode_multiple_skip_layers(self):
        """Test TB mode with edge skipping multiple layers."""
        gen = FlowchartGenerator(title="Skip Test")
        input_text = """
        A -> B
        B -> C
        C -> D
        A -> D
        """
        result = gen.generate(input_text)

        for node in ["A", "B", "C", "D"]:
            assert node in result

    def test_lr_mode_multiple_skip_layers(self):
        """Test LR mode with edge skipping multiple layers."""
        gen = FlowchartGenerator(direction="LR", title="Skip LR")
        input_text = """
        A -> B
        B -> C
        C -> D
        A -> D
        """
        result = gen.generate(input_text)

        for node in ["A", "B", "C", "D"]:
            assert node in result


class TestTitleWrapping:
    """Tests for title text wrapping functionality."""

    def test_title_wraps_at_15_chars(self):
        """Test that title wraps at approximately 15 characters."""
        gen = FlowchartGenerator(title="Hello there how are you doing today")
        result = gen.generate("A -> B")

        # Title should be split across multiple lines
        assert "Hello there" in result or "Hello" in result
        assert "today" in result

    def test_title_single_line_short(self):
        """Test that short titles stay on one line."""
        gen = FlowchartGenerator(title="Short")
        result = gen.generate("A -> B")

        assert "Short" in result

    def test_title_box_sized_to_content(self):
        """Test that title box width matches content."""
        gen = FlowchartGenerator(title="Test")
        result = gen.generate("A -> B")

        lines = result.split("\n")
        # Find title line (should have double border)
        title_line = None
        for line in lines:
            if "═" in line:
                title_line = line
                break

        assert title_line is not None
        # Title "Test" should have a reasonably narrow box
        assert len(title_line.strip()) < 20


class TestBackEdgeSpacing:
    """Tests for back edge spacing improvements."""

    def test_multiple_back_edges_spacing(self):
        """Test that multiple back edges have adequate spacing."""
        gen = FlowchartGenerator()
        input_text = """
        A -> B
        B -> C
        C -> D
        D -> A
        D -> B
        """
        result = gen.generate(input_text)

        # Should have back edges drawn
        for node in ["A", "B", "C", "D"]:
            assert node in result

    def test_lr_mode_back_edge_corners(self):
        """Test LR mode back edges use correct corner characters."""
        gen = FlowchartGenerator(direction="LR")
        input_text = """
        A -> B
        B -> A
        """
        result = gen.generate(input_text)

        # Back edge in LR mode should use bottom-right corner (┘)
        assert "┘" in result


class TestColumnBoundaryOffset:
    """Tests for column boundary offsetting with titles."""

    def test_lr_mode_with_title_positions_correctly(self):
        """Test LR mode with title offsets column boundaries correctly."""
        gen = FlowchartGenerator(direction="LR", title="Test Title")
        input_text = """
        A -> B
        B -> C
        C -> A
        """
        result = gen.generate(input_text)

        # Should render without errors
        assert "A" in result
        assert "B" in result
        assert "C" in result
        assert "Test Title" in result


class TestBackEdgeBoxAvoidance:
    """Tests for back edge routing that avoids boxes in the path."""

    def test_tb_mode_back_edge_avoids_boxes_in_path(self):
        """Test TB mode back edge routes around boxes in the same layer."""
        gen = FlowchartGenerator(title="Microservices")
        # This creates a scenario where Cache -> Data Service back edge
        # would cross through Auth Service and User Service
        input_text = """
        UI -> Gateway
        Gateway -> Auth
        Gateway -> User
        Gateway -> Data
        Auth -> DB
        User -> DB
        Data -> DB
        User -> Cache
        Data -> Cache
        Cache -> Data
        """
        result = gen.generate(input_text)

        # Should render without errors
        assert "UI" in result
        assert "Gateway" in result
        assert "Data" in result
        assert "Cache" in result
        # Should have back edge arrow
        assert "►" in result

    def test_lr_mode_back_edge_avoids_boxes_in_path(self):
        """Test LR mode back edge routes around boxes in the same column."""
        gen = FlowchartGenerator(direction="LR", title="Backend")
        # Same scenario as TB but in LR mode
        input_text = """
        UI -> Gateway
        Gateway -> Auth
        Gateway -> User
        Gateway -> Data
        Auth -> DB
        User -> DB
        Data -> DB
        User -> Cache
        Data -> Cache
        Cache -> Data
        """
        result = gen.generate(input_text)

        # Should render without errors
        assert "UI" in result
        assert "Gateway" in result
        assert "Data" in result
        assert "Cache" in result

    def test_tb_mode_back_edge_with_multiple_blocking_boxes(self):
        """Test TB mode back edge with multiple boxes blocking the path."""
        gen = FlowchartGenerator()
        # Creates wide layer where back edge must route around multiple boxes
        input_text = """
        A -> B1
        A -> B2
        A -> B3
        A -> B4
        B1 -> C
        B2 -> C
        B3 -> C
        B4 -> C
        C -> B4
        """
        result = gen.generate(input_text)

        # Should render all nodes
        for node in ["A", "B1", "B2", "B3", "B4", "C"]:
            assert node in result

    def test_lr_mode_back_edge_with_multiple_blocking_boxes(self):
        """Test LR mode back edge with multiple boxes blocking the path."""
        gen = FlowchartGenerator(direction="LR")
        # Creates tall column where back edge must route around multiple boxes
        input_text = """
        A -> B1
        A -> B2
        A -> B3
        A -> B4
        B1 -> C
        B2 -> C
        B3 -> C
        B4 -> C
        C -> B4
        """
        result = gen.generate(input_text)

        # Should render all nodes
        for node in ["A", "B1", "B2", "B3", "B4", "C"]:
            assert node in result

    def test_back_edge_no_boxes_in_path_direct_route(self):
        """Test back edge takes direct route when no boxes block the path."""
        gen = FlowchartGenerator()
        # Simple cycle with no boxes between margin and target
        input_text = """
        A -> B
        B -> C
        C -> A
        """
        result = gen.generate(input_text)

        # Should render with direct back edge
        for node in ["A", "B", "C"]:
            assert node in result
        # Should have corner characters from back edge
        assert "┌" in result or "└" in result

    def test_back_edge_approach_position_calculation(self):
        """Test back edge approach position is calculated correctly."""
        gen = FlowchartGenerator()
        # Graph where approach_x calculation is exercised
        input_text = """
        Start -> A
        Start -> B
        Start -> C
        A -> End
        B -> End
        C -> End
        End -> C
        """
        result = gen.generate(input_text)

        # Should render all nodes without errors
        assert "Start" in result
        assert "End" in result
        for node in ["A", "B", "C"]:
            assert node in result


class TestTitleCentering:
    """Tests for title centering functionality."""

    def test_title_centered_when_diagram_wider(self):
        """Test title is centered when diagram is wider than title."""
        gen = FlowchartGenerator(title="Hi", direction="LR")
        # Create wide diagram with long node names
        input_text = """
        VeryLongStartNodeName -> VeryLongMiddleNodeName
        VeryLongMiddleNodeName -> VeryLongEndNodeName
        """
        result = gen.generate(input_text)

        # Title should be present
        assert "Hi" in result
        # Find the title line
        lines = result.split("\n")
        title_line_idx = None
        for i, line in enumerate(lines):
            if "Hi" in line and "║" in line:
                title_line_idx = i
                break

        if title_line_idx is not None:
            title_line = lines[title_line_idx]
            # Find the position of "Hi" in the title line
            hi_pos = title_line.find("Hi")
            # Title should not be at the very start (position > 5)
            assert hi_pos > 5

    def test_title_centered_tb_mode_wide_diagram(self):
        """Test title centering in TB mode with wide diagram."""
        gen = FlowchartGenerator(title="Test", direction="TB")
        input_text = """
        A -> B
        A -> C
        A -> D
        A -> E
        B -> F
        C -> F
        D -> F
        E -> F
        """
        result = gen.generate(input_text)

        assert "Test" in result
        assert "A" in result
        assert "F" in result


class TestBackEdgeMarginCalculation:
    """Tests for back edge margin calculation."""

    def test_many_back_edges_get_sufficient_margin(self):
        """Test that many back edges get enough margin space."""
        gen = FlowchartGenerator()
        # Create many back edges
        input_text = """
        A -> B
        B -> C
        C -> D
        D -> E
        E -> A
        E -> B
        E -> C
        E -> D
        """
        result = gen.generate(input_text)

        # All nodes should render
        for node in ["A", "B", "C", "D", "E"]:
            assert node in result
        # Should have multiple back edge arrows
        count = result.count("►")
        assert count >= 3

    def test_lr_mode_many_back_edges_get_sufficient_margin(self):
        """Test LR mode with many back edges gets enough margin."""
        gen = FlowchartGenerator(direction="LR")
        input_text = """
        A -> B
        B -> C
        C -> D
        D -> E
        E -> A
        E -> B
        E -> C
        """
        result = gen.generate(input_text)

        for node in ["A", "B", "C", "D", "E"]:
            assert node in result


class TestBackEdgeBoxAvoidanceExplicit:
    """Explicit tests that trigger boxes_in_path code paths."""

    def test_tb_mode_wide_layer_with_back_edge_to_rightmost_node(self):
        """Test TB mode where back edge goes to the rightmost node in a wide layer.

        This creates a scenario where boxes are definitely in the horizontal path.
        """
        gen = FlowchartGenerator()
        # Create a wide layer with many nodes, back edge to the rightmost
        # The leftmost nodes in the layer should be in boxes_in_path
        input_text = """
        Top -> LeftMost
        Top -> MiddleLeft
        Top -> MiddleRight
        Top -> RightMost
        LeftMost -> Bottom
        MiddleLeft -> Bottom
        MiddleRight -> Bottom
        RightMost -> Bottom
        Bottom -> RightMost
        """
        result = gen.generate(input_text)

        # All nodes should render
        nodes = ["Top", "LeftMost", "MiddleLeft", "MiddleRight", "RightMost", "Bottom"]
        for node in nodes:
            assert node in result

    def test_lr_mode_tall_column_with_back_edge_to_bottommost_node(self):
        """Test LR mode where back edge goes to the bottommost node in a tall column.

        This creates a scenario where boxes are definitely in the vertical path.
        """
        gen = FlowchartGenerator(direction="LR")
        # Create a tall column with many nodes, back edge to the bottommost
        input_text = """
        Left -> TopMost
        Left -> MiddleTop
        Left -> MiddleBottom
        Left -> BottomMost
        TopMost -> Right
        MiddleTop -> Right
        MiddleBottom -> Right
        BottomMost -> Right
        Right -> BottomMost
        """
        result = gen.generate(input_text)

        # All nodes should render
        nodes = ["Left", "TopMost", "MiddleTop", "MiddleBottom", "BottomMost", "Right"]
        for node in nodes:
            assert node in result

    def test_tb_exact_microservices_layout(self):
        """Test exact microservices layout from extensive_retroflow_testing."""
        gen = FlowchartGenerator(title="Microservices Architecture Overview")
        input_text = """
        User Interface -> API Gateway
        API Gateway -> Auth Service
        API Gateway -> User Service
        API Gateway -> Data Service
        Auth Service -> Database
        User Service -> Database
        Data Service -> Database
        User Service -> Cache
        Data Service -> Cache
        Cache -> Data Service
        """
        result = gen.generate(input_text)

        # Should render all nodes (node names may be split by edge lines
        # in complex layouts, so check for presence of key parts)
        assert "User Interface" in result
        assert "API Gateway" in result
        assert "Auth Service" in result
        # Data Service may have edge crossing through it in non-compact mode
        assert "Data" in result and "Service" in result
        assert "Cache" in result

    def test_lr_exact_microservices_layout(self):
        """Test exact microservices layout in LR mode."""
        gen = FlowchartGenerator(direction="LR", title="Backend")
        input_text = """
        User Interface -> API Gateway
        API Gateway -> Auth Service
        API Gateway -> User Service
        API Gateway -> Data Service
        Auth Service -> Database
        User Service -> Database
        Data Service -> Database
        User Service -> Cache
        Data Service -> Cache
        Cache -> Data Service
        """
        result = gen.generate(input_text)

        # Should render without errors
        assert "User Interface" in result
        assert "API Gateway" in result
        # Data Service may be partially overwritten by edge routing in complex layouts
        assert "Data" in result
        assert "Cache" in result

    def test_tb_back_edge_with_very_wide_gap(self):
        """Test back edge where there's a very wide horizontal gap."""
        gen = FlowchartGenerator()
        # Force wide layout by having many nodes at each layer
        input_text = """
        Start -> A1
        Start -> A2
        Start -> A3
        Start -> A4
        Start -> A5
        Start -> A6
        A1 -> End
        A2 -> End
        A3 -> End
        A4 -> End
        A5 -> End
        A6 -> End
        End -> A6
        """
        result = gen.generate(input_text)

        # All nodes should render
        assert "Start" in result
        assert "End" in result
        for i in range(1, 7):
            assert f"A{i}" in result

    def test_lr_back_edge_with_very_tall_gap(self):
        """Test LR back edge where there's a very tall vertical gap."""
        gen = FlowchartGenerator(direction="LR")
        # Force tall layout by having many nodes at each layer
        input_text = """
        Start -> A1
        Start -> A2
        Start -> A3
        Start -> A4
        Start -> A5
        Start -> A6
        A1 -> End
        A2 -> End
        A3 -> End
        A4 -> End
        A5 -> End
        A6 -> End
        End -> A6
        """
        result = gen.generate(input_text)

        # All nodes should render
        assert "Start" in result
        assert "End" in result
        for i in range(1, 7):
            assert f"A{i}" in result
