test_skewed/
test_skewed.rs

1use ascii_dag::graph::DAG;
2
3fn main() {
4    let mut dag = DAG::new();
5
6    dag.add_node(1, "L");
7    dag.add_node(2, "R");
8    dag.add_node(3, "X");
9    dag.add_node(4, "Y");
10
11    // Create skewed children: L connects to rightmost, R connects to leftmost
12    dag.add_edge(1, 4); // L -> Y (right child)
13    dag.add_edge(2, 3); // R -> X (left child)
14
15    let output = dag.render();
16    println!("{}", output);
17
18    // Find line positions of each node
19    let lines: Vec<&str> = output.lines().collect();
20    for (idx, line) in lines.iter().enumerate() {
21        println!("Line {}: '{}'", idx, line);
22    }
23
24    let find_node = |name: &str| -> (usize, usize) {
25        for (line_idx, line) in lines.iter().enumerate() {
26            if let Some(col) = line.find(name) {
27                return (line_idx, col);
28            }
29        }
30        panic!("Node {} not found", name);
31    };
32
33    let (l_line, l_col) = find_node("[L]");
34    let (r_line, r_col) = find_node("[R]");
35    let (x_line, x_col) = find_node("[X]");
36    let (y_line, y_col) = find_node("[Y]");
37
38    println!("\nPositions:");
39    println!("L: line {}, col {}", l_line, l_col);
40    println!("R: line {}, col {}", r_line, r_col);
41    println!("X: line {}, col {}", x_line, x_col);
42    println!("Y: line {}, col {}", y_line, y_col);
43}