use crate::document::Document;
#[test]
fn yaml_comments_disappear_on_round_trip() {
let src =
"---\nQUILL: q\ntitle: My Document # this is a comment\nauthor: Alice\n---\n\nBody.\n";
let doc = Document::from_markdown(src).unwrap();
let emitted = doc.to_markdown();
assert!(
!emitted.contains("# this is a comment"),
"YAML comment must be stripped on emit (proposal §5.4)\nGot:\n{}",
emitted
);
assert!(
emitted.contains("My Document"),
"value before comment must survive emit\nGot:\n{}",
emitted
);
let doc2 = Document::from_markdown(&emitted).unwrap();
assert_eq!(
doc2.frontmatter().get("title").and_then(|v| v.as_str()),
Some("My Document"),
"title value must survive round-trip even though comment is stripped"
);
}
#[test]
fn custom_tags_lose_tag_but_keep_value() {
let src = "---\nQUILL: q\nmemo_from: !fill 2d lt example\n---\n";
let doc = Document::from_markdown(src).unwrap();
let value = doc.frontmatter().get("memo_from").unwrap();
assert!(
value.as_str().is_some(),
"custom-tagged value must parse as a string after tag is dropped"
);
assert_eq!(
value.as_str().unwrap(),
"2d lt example",
"string value must survive tag stripping"
);
let emitted = doc.to_markdown();
assert!(
!emitted.contains("!fill"),
"custom tag must not reappear on emit (proposal §5.4)\nGot:\n{}",
emitted
);
assert!(
emitted.contains("\"2d lt example\""),
"value must survive emit as a double-quoted string\nGot:\n{}",
emitted
);
let doc2 = Document::from_markdown(&emitted).unwrap();
assert_eq!(
doc2.frontmatter().get("memo_from").and_then(|v| v.as_str()),
Some("2d lt example"),
"value must survive full round-trip"
);
}
#[test]
fn original_quoting_style_is_not_preserved() {
let src = "---\nQUILL: q\nsingle_q: 'hello'\nunquoted: world\ndouble_q: \"already\"\n---\n";
let doc = Document::from_markdown(src).unwrap();
let emitted = doc.to_markdown();
assert!(
!emitted.contains("'hello'"),
"single-quoted string must not be re-emitted single-quoted\nGot:\n{}",
emitted
);
assert!(
emitted.contains("\"hello\""),
"single-quoted string must be re-emitted double-quoted\nGot:\n{}",
emitted
);
assert!(
emitted.contains("\"world\""),
"unquoted string must be re-emitted double-quoted\nGot:\n{}",
emitted
);
assert!(
emitted.contains("\"already\""),
"double-quoted string must survive as double-quoted\nGot:\n{}",
emitted
);
let doc2 = Document::from_markdown(&emitted).unwrap();
assert_eq!(
doc2.frontmatter().get("single_q").and_then(|v| v.as_str()),
Some("hello")
);
assert_eq!(
doc2.frontmatter().get("unquoted").and_then(|v| v.as_str()),
Some("world")
);
assert_eq!(
doc2.frontmatter().get("double_q").and_then(|v| v.as_str()),
Some("already")
);
}