use std::fs;
use std::path::PathBuf;
use libperl_macrogen::{
Parser, Preprocessor, PPConfig, TypedSexpPrinter, ExternalDecl,
};
fn run_test_case(name: &str) {
let test_dir = PathBuf::from("tests/type_inference");
let c_file = test_dir.join(format!("{}.c", name));
let expected_file = test_dir.join(format!("{}.expected", name));
let expected = fs::read_to_string(&expected_file)
.expect(&format!("Failed to read {:?}", expected_file));
let mut pp = Preprocessor::new(PPConfig::default());
pp.add_source_file(&c_file)
.expect(&format!("Failed to preprocess {:?}", c_file));
let mut parser = Parser::new(&mut pp)
.expect("Failed to create parser");
let tu = parser.parse()
.expect("Failed to parse");
let mut output = Vec::new();
{
let mut printer = TypedSexpPrinter::new(&mut output, pp.interner());
for decl in &tu.decls {
printer.print_external_decl(decl).unwrap();
}
}
let actual = String::from_utf8(output).unwrap();
assert_eq!(
actual.trim(),
expected.trim(),
"\n=== Test: {} ===\nExpected:\n{}\nActual:\n{}",
name,
expected.trim(),
actual.trim()
);
}
#[test]
fn test_t001_int_literal() {
run_test_case("t001_int_literal");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t002_var_ref() {
run_test_case("t002_var_ref");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t003_binary_op() {
run_test_case("t003_binary_op");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t004_pointer() {
run_test_case("t004_pointer");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t005_function_scope() {
run_test_case("t005_function_scope");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t006_shadowing() {
run_test_case("t006_shadowing");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t007_function_call() {
run_test_case("t007_function_call");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t008_struct_member() {
run_test_case("t008_struct_member");
}
#[test]
#[ignore = "full AST type inference not supported with type_env-based TypedSexpPrinter"]
fn test_t009_cast() {
run_test_case("t009_cast");
}