Commit 10ca9612 authored by Jeff Smits's avatar Jeff Smits

First test: fails

parent 2aa37697
Specification([Signature([Constructors([OpDecl("Nil",ConstType(Sort("Term",[]))),OpDecl("Cons",FunType([ConstType(Sort("Term",[])),ConstType(Sort("Term",[]))],ConstType(Sort("Term",[]))))])]),Strategies([SDefT("main_0_0",[],[],Scope(["k_0","l_0"],Seq(Match(Var("l_0")),Seq(Match(Var("k_0")),Seq(Build(Var("l_0")),Build(Anno(Op("Cons",[Var("k_0"),Anno(Op("Nil",[]),Op("Nil",[]))]),Op("Nil",[]))))))))])])
\ No newline at end of file
......@@ -564,3 +564,29 @@ impl<'s> CTreeOptimize for preprocess::BuildTerm<'s> {
}
}
}
#[cfg(test)]
mod test {
use super::*;
use aterm::parse::ATermRead;
use aterm::print::ATermWrite;
fn string_optimize(program: &'static str) -> String {
let factory = ATermFactory::new();
let program = factory.read_ascii_string(&program).expect("ATerm representation of CTree").0;
let program: ctree::Module = (&program).try_into().expect("Typed CTree");
let program: preprocess_ext::Module = program.try_into().expect("Preprocessed CTree");
let program = program.optimize(&mut ());
program.to_ascii_string().expect("Printed CTree")
}
// Based on example-inputs/term_wrap.str
#[test]
fn term_wrap() {
let input = r#"Specification([Signature([Constructors([OpDecl("Nil",ConstType(Sort("Term",[]))),OpDecl("Cons",FunType([ConstType(Sort("Term",[])),ConstType(Sort("Term",[]))],ConstType(Sort("Term",[]))))])]),Strategies([SDefT("main_0_0",[],[],Scope(["k_0","l_0"],Seq(Match(Var("l_0")),Seq(Match(Var("k_0")),Seq(Build(Var("l_0")),Build(Anno(Op("Cons",[Var("k_0"),Anno(Op("Nil",[]),Op("Nil",[]))]),Op("Nil",[]))))))))])])"#;
let expected = r#"Specification([Signature([Constructors([OpDecl("Nil",ConstType(Sort("Term",[]))),OpDecl("Cons",FunType([ConstType(Sort("Term",[])),ConstType(Sort("Term",[]))],ConstType(Sort("Term",[]))))])]),Strategies([SDefT("main_0_0",[],[],Scope(["l_0"],Seq(Match(Var("l_0")),Build(Anno(Op("Cons",[Var("l_0"),Anno(Op("Nil",[]),Op("Nil",[]))]),Op("Nil",[]))))))])])"#;
assert_eq!(expected, string_optimize(input));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment