webidl: make writing new tests really easy

This commit is contained in:
Nick Fitzgerald
2018-05-30 15:00:57 -07:00
parent c773b29d6d
commit a3d91bdd7c
9 changed files with 262 additions and 39 deletions

View File

@ -1,21 +1,41 @@
extern crate diff;
extern crate proc_macro2;
extern crate syn;
extern crate wasm_bindgen_backend as backend;
extern crate wasm_bindgen_webidl as wb_webidl;
pub fn assert_parse(webidl: &str, expected: backend::ast::Program) {
let actual = wb_webidl::parse(webidl).expect("should parse the webidl source OK");
assert_eq!(expected, actual);
}
#[macro_use]
mod util;
use util::*;
macro_rules! assert_parse {
($test_name:ident, $webidl_source:expr, $expected_ast:expr) => {
#[test]
fn $test_name() {
$crate::assert_parse($webidl_source, $expected_ast);
/// Tests for parsing WebIDL into an expected wasm-bindgen AST.
mod parse {
use super::*;
assert_parse!(empty, backend::ast::Program::default());
assert_parse!(
Event,
backend::ast::Program {
exports: vec![],
imports: vec![backend::ast::Import {
module: None,
version: None,
js_namespace: None,
kind: backend::ast::ImportKind::Type(backend::ast::ImportType {
vis: syn::Visibility::Public(syn::VisPublic {
pub_token: Default::default(),
}),
name: syn::Ident::new("Event", proc_macro2::Span::call_site()),
}),
}],
enums: vec![],
structs: vec![],
}
};
);
}
mod event;
mod simple;
/// Tests for compiling WebIDL into Rust bindings.
mod compile {
assert_compile!(Event);
}