mod declaration;
mod expression;
mod function;
mod statement;
#[cfg(test)]
fn test_formatting(source: &'static str) {
use crate::{Parser, Source};
use boa_ast::scope::Scope;
use boa_interner::{Interner, ToInternedString};
let source = &source[1..];
let first_line = &source[..source.find('\n').unwrap()];
let trimmed_first_line = first_line.trim();
let characters_to_remove = first_line.len() - trimmed_first_line.len();
let scenario = source
.lines()
.map(|l| &l[characters_to_remove..]) .collect::<Vec<&'static str>>()
.join("\n");
let source = Source::from_bytes(source);
let interner = &mut Interner::default();
let result = Parser::new(source)
.parse_script(&Scope::new_global(), interner)
.expect("parsing failed")
.to_interned_string(interner);
if scenario != result {
eprint!("========= Expected:\n{scenario}");
eprint!("========= Got:\n{result}");
eprintln!("========= Expected: {scenario:?}");
eprintln!("========= Got: {result:?}");
panic!("parsing test did not give the correct result (see above)");
}
}