ok going to get to work on the minimizer now

This commit is contained in:
Paul R. Tagliamonte
2025-01-16 15:14:21 -05:00
parent 3eb4625b8f
commit c162f2909f

View File

@ -3,6 +3,7 @@ mod walk;
use crate::{
parsing::ast::types,
walk::{Node, Visitable},
FormatOptions,
};
use std::sync::{Arc, Mutex};
@ -15,8 +16,6 @@ type Reference<'tree> = (Vec<Node<'tree>>, &'tree types::Identifier);
///
type RefEdge<'tree> = (Option<Declaration<'tree>>, Reference<'tree>);
// TODO change to a list of all parents of the node instead
///
#[derive(Clone, Debug)]
pub struct Scope<'tree> {
@ -253,4 +252,45 @@ fn myfn = () => {
.as_slice()
);
}
#[test]
fn ast_eq() {
const program_str: &str = "\
foo = 1
bar = 2
fn myfn() {
sin(foo)
}
baz = myfn()
";
let program = kcl!(program_str);
// if this fails its because the code above is no longer of the
// style of the day
assert_eq!(program_str, program.recast(&FormatOptions::new(), 0));
let refgraph = extract_refgraph(&program).unwrap();
let edges = refgraph.edges().into_iter().collect::<Vec<_>>();
// lets say "foo" changed here
let tainted_node = program.body.get(0).unwrap();
let program_min = &program; // minimize_ast(&program, &[tainted_node]);
assert_eq!(
"\
foo = 1
bar = 2
fn myfn() {
sin(foo)
}
baz = myfn()
",
program_min.recast(&FormatOptions::new(), 0)
);
}
}