mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-25 19:43:00 +03:00
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
use super::project;
|
|
|
|
#[test]
|
|
fn works() {
|
|
let mut p = project();
|
|
p.file(
|
|
"src/lib.rs",
|
|
r#"
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
#[wasm_bindgen]
|
|
/// This comment should exist
|
|
pub fn annotated() -> String {
|
|
String::new()
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
/// This comment should exist
|
|
pub struct Annotated {
|
|
/// This comment should not exist
|
|
a: String,
|
|
/// This comment should exist
|
|
pub b: u32
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
impl Annotated {
|
|
#[wasm_bindgen(method)]
|
|
/// This comment should exist
|
|
pub fn get_a(&self) -> String {
|
|
self.a.clone()
|
|
}
|
|
}
|
|
"#,
|
|
);
|
|
|
|
let (root, target) = p.cargo_build();
|
|
p.gen_bindings(&root, &target);
|
|
let js = p.read_js();
|
|
let comments = extract_doc_comments(&js);
|
|
assert!(comments.iter().all(|c| c == "This comment should exist"));
|
|
}
|
|
/// Pull out all lines in a js string that start with
|
|
/// '* ', all other lines will either be comment start, comment
|
|
/// end or actual js lines.
|
|
fn extract_doc_comments(js: &str) -> Vec<String> {
|
|
js.lines()
|
|
.filter_map(|l| {
|
|
let trimmed = l.trim();
|
|
if trimmed.starts_with("* ") {
|
|
Some(trimmed[2..].to_owned())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.collect()
|
|
}
|