use ftb::TableFormatter;
fn format_table(input: &str) -> String {
let mut formatter = TableFormatter::new();
formatter
.format_table(input)
.expect("Table formatting should succeed")
}
#[test]
fn test_simple_table() {
let input = include_str!("fixtures/input/simple.txt");
let expected = include_str!("fixtures/expected/simple.txt");
let output = format_table(input);
assert_eq!(output, expected);
}
#[test]
fn test_irregular_table() {
let input = include_str!("fixtures/input/irregular.txt");
let expected = include_str!("fixtures/expected/irregular.txt");
let output = format_table(input);
assert_eq!(output, expected);
}
#[test]
fn test_complex_table() {
let input = include_str!("fixtures/input/complex.txt");
let expected = include_str!("fixtures/expected/complex.txt");
let output = format_table(input);
assert_eq!(output, expected);
}
#[test]
fn test_simple_table_structure() {
let input = include_str!("fixtures/input/simple.txt");
let output = format_table(input);
assert!(output.contains("| h1 | h2 | h3 |"));
assert!(output.contains("|-"));
assert!(output.contains("| data1 | data2 | data3 |"));
let lines: Vec<&str> = output.lines().collect();
assert_eq!(lines.len(), 3);
for line in &lines {
assert_eq!(line.matches('|').count(), 4);
}
}
#[test]
fn test_complex_table_handles_missing_cells() {
let input = include_str!("fixtures/input/complex.txt");
let output = format_table(input);
for line in output.lines() {
assert_eq!(line.matches('|').count(), 4, "Line: {}", line);
}
assert!(output
.lines()
.any(|line| line.contains("d1b") && line.contains("add a cell")));
}
#[test]
fn test_unicode_emoji_table() {
let input = include_str!("fixtures/input/unicode_emoji.txt");
let expected = include_str!("fixtures/expected/unicode_emoji.txt");
let output = format_table(input);
assert_eq!(output, expected);
}
#[test]
fn test_unicode_cjk_table() {
let input = include_str!("fixtures/input/unicode_cjk.txt");
let expected = include_str!("fixtures/expected/unicode_cjk.txt");
let output = format_table(input);
assert_eq!(output, expected);
}
#[test]
fn test_unicode_mixed_table() {
let input = include_str!("fixtures/input/unicode_mixed.txt");
let expected = include_str!("fixtures/expected/unicode_mixed.txt");
let output = format_table(input);
assert_eq!(output, expected);
}
#[test]
fn test_formatter_reuse_integration() {
let mut formatter = TableFormatter::new();
let input1 = include_str!("fixtures/input/simple.txt");
let expected1 = include_str!("fixtures/expected/simple.txt");
let output1 = formatter
.format_table(input1)
.expect("Should format successfully");
assert_eq!(output1, expected1);
let input2 = include_str!("fixtures/input/irregular.txt");
let expected2 = include_str!("fixtures/expected/irregular.txt");
let output2 = formatter
.format_table(input2)
.expect("Should format successfully");
assert_eq!(output2, expected2);
let input3 = include_str!("fixtures/input/unicode_emoji.txt");
let expected3 = include_str!("fixtures/expected/unicode_emoji.txt");
let output3 = formatter
.format_table(input3)
.expect("Should format successfully");
assert_eq!(output3, expected3);
}
#[test]
fn test_document_with_multiple_tables() {
let input = include_str!("fixtures/input/document_with_tables.txt");
let expected = include_str!("fixtures/expected/document_with_tables.txt");
let mut formatter = TableFormatter::new();
let output = formatter.format_document(input);
assert_eq!(output, expected);
}