use graphs_tui::{render_d2_to_tui, render_mermaid_to_tui, render_timeline, RenderOptions};
#[test]
fn test_issue_3_timeline_pied_piper() {
let input = r#"timeline
title Pied Piper Journey (2014-2019)
2014 : DEC-001 Peter Gregory Seed Funding
: DEC-002 Anti-Hooli Principle ⭐
: ADR-001 Middle-Out Algorithm ⭐
: INC-001 Hooli IP Lawsuit
2015 : DEC-004 Hanneman Bridge Funding
: ADR-002 Enterprise Platform
: ADR-003 The Box
2016 : INC-002 COPPA Violation
2018 : POL-001 Tethics Framework ⭐
: ADR-004 PiperNet Architecture
: INC-003 51% Attack
2019 : INC-004 AI Encryption Discovery
: DEC-005 Sabotage Launch
"#;
let result = render_timeline(input, RenderOptions::default()).unwrap();
println!("Issue #3 Timeline output:\n{}", result.output);
assert!(result.output.contains("Pied Piper Journey"));
assert!(result.output.contains("2014"));
assert!(result.output.contains("2015"));
assert!(result.output.contains("2016"));
assert!(result.output.contains("2018"));
assert!(result.output.contains("2019"));
assert!(result.output.contains("Peter Gregory Seed Funding"));
assert!(result.output.contains("Middle-Out Algorithm"));
assert!(result.output.contains("Tethics Framework"));
assert!(result.output.contains("Sabotage Launch"));
}
#[test]
fn test_issue_4_cyclical_d2_simple() {
let input = r#"
A <-> B: P2P
B <-> C: P2P
C <-> A: P2P
"#;
let result = render_d2_to_tui(input, RenderOptions::default()).unwrap();
println!("Issue #4 Cyclical D2 output:\n{}", result.output);
assert!(result.output.contains("A"));
assert!(result.output.contains("B"));
assert!(result.output.contains("C"));
assert!(result.output.contains("P2P"));
}
#[test]
fn test_issue_4_cyclical_d2_with_containers() {
let input = r#"direction: down
mesh: PiperNet Mesh {
phone1: Phone Node
laptop: Laptop Node
iot: IoT Node
phone2: Phone Node
phone1 <-> laptop: P2P
laptop <-> iot: P2P
iot <-> phone2: P2P
phone2 <-> phone1: P2P
}
ledger: Distributed Ledger
mesh -> ledger: Shard metadata
"#;
let result = render_d2_to_tui(input, RenderOptions::default()).unwrap();
println!("Issue #4 Cyclical D2 with containers:\n{}", result.output);
assert!(result.output.contains("Phone Node") || result.output.contains("phone1"));
assert!(result.output.contains("Laptop Node") || result.output.contains("laptop"));
}
#[test]
fn test_issue_5_edge_labels_not_truncated() {
let input = r#"
phone1: Phone Node
laptop: Laptop Node
iot: IoT Node
phone2: Phone Node
phone1 <-> laptop: P2P
laptop <-> iot: P2P
iot <-> phone2: P2P
phone2 <-> phone1: P2P
"#;
let result = render_d2_to_tui(input, RenderOptions::default()).unwrap();
println!("Issue #5 Edge labels output:\n{}", result.output);
let p2p_count = result.output.matches("P2P").count();
println!("P2P count: {}", p2p_count);
assert!(p2p_count >= 1, "Expected at least one P2P label, found {}", p2p_count);
}
#[test]
fn test_issue_5_no_corrupted_edge_labels() {
let input = r#"
A: Phone Node
B: Laptop Node
A <-> B: P2P
"#;
let result = render_d2_to_tui(input, RenderOptions::default()).unwrap();
println!("Issue #5 Simple edge label:\n{}", result.output);
assert!(result.output.contains("P2P"), "Edge label 'P2P' should be visible");
let lines: Vec<&str> = result.output.lines().collect();
for line in &lines {
if line.contains("P2") && !line.contains("P2P") {
panic!("Found truncated label 'P2' without full 'P2P' in line: {}", line);
}
}
}
#[test]
fn test_issue_7_cycle_warning_in_result() {
let input = r#"flowchart LR
A --> B
B --> C
C --> A"#;
let result = render_mermaid_to_tui(input, RenderOptions::default()).unwrap();
assert!(!result.warnings.is_empty(), "Cycle should produce a warning");
assert!(
result.warnings[0].contains("Cycle"),
"Warning should mention cycle"
);
assert!(result.output.contains("A"));
assert!(result.output.contains("B"));
assert!(result.output.contains("C"));
}
#[test]
fn test_issue_7_no_warning_without_cycle() {
let input = "flowchart LR\nA --> B --> C";
let result = render_mermaid_to_tui(input, RenderOptions::default()).unwrap();
assert!(result.warnings.is_empty(), "No cycle means no warnings");
}
#[test]
fn test_issue_7_d2_cycle_warning() {
let input = r#"
A <-> B: link
B <-> C: link
C <-> A: link
"#;
let result = render_d2_to_tui(input, RenderOptions::default()).unwrap();
assert!(!result.warnings.is_empty(), "D2 cycle should produce a warning");
}