Move comments test to wasm

This commit is contained in:
Alex Crichton 2018-08-06 11:46:23 -07:00
parent 1dd8bc078e
commit c82c8e7acb
5 changed files with 46 additions and 64 deletions

View File

@ -1,62 +0,0 @@
use super::project;
#[test]
fn works() {
let mut p = project();
p.file(
"src/lib.rs",
r#"
#![feature(use_extern_macros)]
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()
}
}
"#,
);
p.gen_bindings();
let js = p.read_js();
let comments = extract_doc_comments(&js);
assert!(comments.iter().all(|c| c == "This comment should exist" ||
c.starts_with("@")));
}
/// 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()
}

View File

@ -3,5 +3,3 @@
extern crate wasm_bindgen_test_project_builder as project_builder;
use project_builder::project;
mod comments;

11
tests/wasm/comments.js Normal file
View File

@ -0,0 +1,11 @@
const fs = require('fs');
const assert = require('assert');
exports.assert_comments_exist = function() {
const bindings_file = require.resolve('wasm-bindgen-test');
const contents = fs.readFileSync(bindings_file);
assert.ok(contents.includes("* annotated function"));
assert.ok(contents.includes("* annotated struct type"));
assert.ok(contents.includes("* annotated struct field"));
assert.ok(contents.includes("* annotated struct method"));
};

34
tests/wasm/comments.rs Normal file
View File

@ -0,0 +1,34 @@
use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(module = "tests/wasm/comments.js")]
extern {
fn assert_comments_exist();
}
#[wasm_bindgen]
/// annotated function
pub fn annotated() -> String {
String::new()
}
#[wasm_bindgen]
/// annotated struct type
pub struct Annotated {
a: String,
/// annotated struct field
pub b: u32
}
#[wasm_bindgen]
impl Annotated {
/// annotated struct method
pub fn get_a(&self) -> String {
self.a.clone()
}
}
#[wasm_bindgen_test]
fn works() {
assert_comments_exist();
}

View File

@ -14,6 +14,7 @@ pub mod api;
pub mod char;
pub mod classes;
pub mod closures;
pub mod comments;
pub mod duplicate_deps;
pub mod duplicates;
pub mod enums;