Mercurial > python-compiler.rs
comparison src/tests/tests_convert_dump.rs @ 23:5a7c3393382b
Add a simple test for ast.Assign.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Fri, 03 Jun 2016 19:06:57 +0200 |
parents | |
children | 199ba034e4af |
comparison
equal
deleted
inserted
replaced
22:25b202005d1d | 23:5a7c3393382b |
---|---|
1 use ast_convert; | |
2 use ast_dump; | |
3 use python_tb; | |
4 use python_parse; | |
5 use std::io::Read; | |
6 use std::fs::File; | |
7 | |
8 fn test_parse_file(filename: &str){ | |
9 let code = { | |
10 let mut file = match File::open(filename) { | |
11 Ok(file) => file, | |
12 Err(err) => { | |
13 panic!(format!("Can't find {}", filename)); | |
14 } | |
15 }; | |
16 let mut code = String::new(); | |
17 file.read_to_string(&mut code).unwrap(); | |
18 code | |
19 }; | |
20 | |
21 let module = match python_parse::parse_ast(code.clone()) { | |
22 Ok(module) => module, | |
23 Err(err) => { | |
24 python_tb::traceback(err); | |
25 panic!(format!("Error while parsing file “{}”:", filename)); | |
26 } | |
27 }; | |
28 | |
29 let module_ast = ast_convert::convert_ast("__main__".to_string(), &module); | |
30 let dumped_ast = ast_dump::dump_ast(&module_ast); | |
31 assert_eq!(code, dumped_ast + "\n"); | |
32 } | |
33 | |
34 #[test] | |
35 fn test_assign(){ | |
36 test_parse_file("tests/test_parse_files/test_assign.py"); | |
37 } |