use crate::tests_common::test_format;
use crate::{format, parse_normalized};
fn roundtrip(input: &str) {
let ast1 = parse_normalized(input).expect("input must parse");
let f1 = format(input).expect("format must succeed");
let ast2 = parse_normalized(&f1)
.unwrap_or_else(|e| panic!("formatted output must re-parse: {e:?}\n{f1}"));
assert_eq!(
ast1, ast2,
"AST changed after format\ninput: {input:?}\nformatted: {f1:?}"
);
let f2 = format(&f1).expect("second format must succeed");
assert_eq!(f1, f2, "format not idempotent\nf1: {f1:?}\nf2: {f2:?}");
}
#[test]
fn fuzz_or_without_selectors_dropped() {
roundtrip("t or a");
}
#[test]
fn fuzz_integer_selection_relex_as_float() {
roundtrip("1\n.a");
assert_eq!(format("1 .a").unwrap(), "1 .a\n");
test_format("1.5.x");
test_format("1..x");
}
#[test]
fn fuzz_indented_string_escape_newline_grows() {
roundtrip("''''\\\nX''");
}
#[test]
fn fuzz_indented_string_blank_line_indent() {
roundtrip("[''\n \n h'']");
}
#[test]
fn fuzz_indented_string_blank_line_preserves_excess() {
test_format("''\n \n b''");
test_format("''\n \nb''");
}
#[test]
fn fuzz_block_comment_with_cr_reparses() {
roundtrip("2/*\0\r\0");
roundtrip("/*a\r\0*/3");
roundtrip("/*a\rb*/3");
roundtrip("2 /* x\r */\n");
}