diff options
author | Jyun-Yan You <jyyou.tw@gmail.com> | 2015-01-01 00:05:49 +0800 |
---|---|---|
committer | Jyun-Yan You <jyyou.tw@gmail.com> | 2015-01-01 00:05:49 +0800 |
commit | 4482a25cb4657cf1ce280999db37b7beb843f6bc (patch) | |
tree | 0ce2ea417532f552503b764d420a57e224c96918 /tests/util.rs | |
parent | e81f8e2420b7aff83207ec18d866c3af096da016 (diff) | |
parent | 97945161d298bb89f7f1ea015c5cc54acc9e7c43 (diff) |
Merge branch 'func_proto' of https://github.com/chris-chambers/rust-bindgen
Conflicts:
src/parser.rs
tests/forward_declared_struct.rs
tests/test_struct.rs
Diffstat (limited to 'tests/util.rs')
-rw-r--r-- | tests/util.rs | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/tests/util.rs b/tests/util.rs deleted file mode 100644 index 8ee3d213..00000000 --- a/tests/util.rs +++ /dev/null @@ -1,58 +0,0 @@ -extern crate bindgen; -extern crate regex; -extern crate syntax; - -use bindgen::{Logger, BindgenOptions}; -use regex::Regex; -use std::default::Default; -use syntax::ast; -use syntax::codemap::DUMMY_SP; -use syntax::print::pp; -use syntax::print::pprust; -use syntax::ptr::P; - -struct TestLogger; - -impl Logger for TestLogger { - fn error(&self, msg: &str) { - println!("err: {}", msg); - } - - fn warn(&self, msg: &str) { - println!("warn: {}", msg); - } -} - -pub fn generate_bindings(filename: &str) -> Result<Vec<P<ast::Item>>, ()> { - let mut options:BindgenOptions = Default::default(); - options.clang_args.push(filename.to_string()); - - let logger = TestLogger; - Ok(try!(bindgen::Bindings::generate(&options, Some(&logger as &Logger), None)).into_ast()) -} - -pub fn generate_unpretty_output(filename: &str) -> String { - let output = pprust::to_string(|s| { - // HACK: Replace the default printer with a very wide printer. This - // makes it easier to reason about how the unpretty'd output - // will look, at the cost of tying us to the implementation - // details of pprust::to_string. - s.s = pp::mk_printer(box Vec::new(), 4096); - - let items = generate_bindings(filename).unwrap(); - - let module = ast::Mod { - inner: DUMMY_SP, - view_items: Vec::new(), - items: items, - }; - s.print_mod(&module, &[]) - }); - - unpretty(output.as_slice()) -} - -pub fn unpretty(s: &str) -> String { - let re = Regex::new(r"\s+").unwrap(); - re.replace_all(s, " ") -} |