2018-06-15 19:20:56 +03:00
|
|
|
use super::project;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn works() {
|
|
|
|
let mut p = project();
|
2018-06-28 08:42:34 +03:00
|
|
|
p.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-07-22 05:00:20 +03:00
|
|
|
#![feature(use_extern_macros)]
|
2018-06-15 19:20:56 +03:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
);
|
2018-06-15 19:20:56 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
p.gen_bindings();
|
2018-06-28 08:42:34 +03:00
|
|
|
let js = p.read_js();
|
|
|
|
let comments = extract_doc_comments(&js);
|
2018-07-09 19:07:57 +03:00
|
|
|
assert!(comments.iter().all(|c| c == "This comment should exist" ||
|
|
|
|
c.starts_with("@")));
|
2018-06-15 19:20:56 +03:00
|
|
|
}
|
2018-07-05 06:37:09 +03:00
|
|
|
|
2018-06-15 19:20:56 +03:00
|
|
|
/// Pull out all lines in a js string that start with
|
|
|
|
/// '* ', all other lines will either be comment start, comment
|
2018-06-28 08:42:34 +03:00
|
|
|
/// end or actual js lines.
|
2018-06-15 19:20:56 +03:00
|
|
|
fn extract_doc_comments(js: &str) -> Vec<String> {
|
2018-06-28 08:42:34 +03:00
|
|
|
js.lines()
|
|
|
|
.filter_map(|l| {
|
|
|
|
let trimmed = l.trim();
|
|
|
|
if trimmed.starts_with("* ") {
|
|
|
|
Some(trimmed[2..].to_owned())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
}
|