#![cfg(not(target_arch = "wasm32"))]
use anytomd::{ConversionOptions, convert_bytes, convert_file};
fn opts() -> ConversionOptions {
ConversionOptions::default()
}
#[test]
fn test_plain_text_csv_no_table_markers() {
let csv_data = b"Name,Age,City\nAlice,30,Seoul\nBob,25,Tokyo";
let result = convert_bytes(csv_data, "csv", &opts()).unwrap();
let plain = result.plain_text.clone();
assert!(plain.contains("Alice"), "missing Alice");
assert!(plain.contains("Seoul"), "missing Seoul");
assert!(plain.contains("Bob"), "missing Bob");
assert!(plain.contains("Tokyo"), "missing Tokyo");
assert!(!plain.contains("|---"), "table separator not stripped");
assert!(!plain.contains("| "), "table pipe markers not stripped");
}
#[test]
fn test_plain_text_html_no_markdown_markers() {
let html = b"<html><body><h1>Title</h1><p>Hello <b>world</b></p></body></html>";
let result = convert_bytes(html, "html", &opts()).unwrap();
let plain = result.plain_text.clone();
assert!(plain.contains("Title"), "missing title");
assert!(plain.contains("Hello"), "missing text");
assert!(plain.contains("world"), "missing bold text");
assert!(!plain.contains("# "), "heading marker not stripped");
assert!(!plain.contains("**"), "bold marker not stripped");
}
#[test]
fn test_plain_text_docx_content_preserved() {
let result = convert_file("tests/fixtures/sample.docx", &opts()).unwrap();
let plain = result.plain_text.clone();
assert!(!plain.trim().is_empty(), "plain text should not be empty");
assert!(
!plain.contains("# ") || plain.contains("C# "),
"heading markers should be stripped (allowing C# as content)"
);
}
#[test]
fn test_plain_text_xlsx_tab_separated() {
let result = convert_file("tests/fixtures/sample.xlsx", &opts()).unwrap();
let plain = result.plain_text.clone();
assert!(!plain.trim().is_empty(), "plain text should not be empty");
assert!(!plain.contains("|---"), "table separator not stripped");
assert!(plain.contains('\t'), "table rows should be tab-separated");
}
#[test]
fn test_plain_text_unicode_preserved() {
let csv_data = "Name,City\n다영,서울\n太郎,東京\n🚀,🎉".as_bytes();
let result = convert_bytes(csv_data, "csv", &opts()).unwrap();
let plain = result.plain_text.clone();
assert!(plain.contains("다영"), "Korean not preserved");
assert!(plain.contains("서울"), "Korean city not preserved");
assert!(plain.contains("太郎"), "Japanese not preserved");
assert!(plain.contains("東京"), "Japanese city not preserved");
assert!(plain.contains("🚀"), "emoji not preserved");
assert!(plain.contains("🎉"), "emoji not preserved");
}
#[test]
fn test_plain_text_json_code_block_preserved() {
let json_data = br#"{"name": "Alice", "age": 30}"#;
let result = convert_bytes(json_data, "json", &opts()).unwrap();
let plain = result.plain_text.clone();
assert!(plain.contains("\"name\""), "JSON key not preserved");
assert!(plain.contains("\"Alice\""), "JSON value not preserved");
assert!(!plain.contains("```"), "code fence not stripped");
}
#[test]
fn test_plain_text_file_vs_bytes_consistent() {
let result_file = convert_file("tests/fixtures/sample.csv", &opts()).unwrap();
let data = std::fs::read("tests/fixtures/sample.csv").unwrap();
let result_bytes = convert_bytes(&data, "csv", &opts()).unwrap();
assert_eq!(result_file.plain_text, result_bytes.plain_text);
}