mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
Move comments
test to wasm
This commit is contained in:
parent
1dd8bc078e
commit
c82c8e7acb
@ -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()
|
||||
}
|
@ -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
11
tests/wasm/comments.js
Normal 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
34
tests/wasm/comments.rs
Normal 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();
|
||||
}
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user