use proptest::prelude::*;
use scheme_edit::Document;
fn arb_form() -> impl Strategy<Value = String> {
let leaf = prop_oneof![
"[a-z][a-z0-9-]{0,8}".prop_map(|s| s),
"\"[ !#-\\[\\]-~]{0,12}\"".prop_map(|s| s.replace('\\', "").replace("\\\"", "")),
Just("#t".to_string()),
Just("'sym".to_string()),
];
leaf.prop_recursive(4, 32, 6, |inner| {
(
prop::collection::vec(inner, 0..6),
prop_oneof![Just(" "), Just("\n "), Just(" ;; c\n ")],
)
.prop_map(|(kids, sep)| format!("({})", kids.join(sep.as_ref())))
})
}
proptest! {
#[test]
fn parse_emit_is_identity(src in arb_form()) {
let doc = Document::parse(&src).unwrap();
prop_assert_eq!(doc.to_string(), src);
}
#[test]
fn emit_reparse_is_stable(src in arb_form()) {
let doc = Document::parse(&src).unwrap();
let emitted = doc.to_string();
let doc2 = Document::parse(&emitted).unwrap();
prop_assert_eq!(doc2.to_string(), emitted);
}
}