Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #696 from stevebob/wasm-bindgen-test
Add minimal wasm-bindgen test crate
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ members = [ | |
"rand_pcg", | ||
"rand_xorshift", | ||
"rand_xoshiro", | ||
"tests/wasm_bindgen", | ||
] | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "rand_wasm_bindgen_test" | ||
description = "Minimal crate to test that rand can be build for web assembly target" | ||
version = "0.1.0" | ||
authors = ["The Rand Project Developers"] | ||
publish = false | ||
license = "MIT/Apache-2.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
rand = { path = "../..", features = ["wasm-bindgen"] } | ||
wasm-bindgen = "0.2" | ||
wasm-bindgen-test = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
const rand_wasm_bindgen_test = require('./rand_wasm_bindgen_test'); | ||
|
||
console.log(rand_wasm_bindgen_test.generate_from_entropy()); | ||
console.log(rand_wasm_bindgen_test.generate_from_os_rand()); | ||
console.log(rand_wasm_bindgen_test.generate_from_seed()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
extern crate rand; | ||
extern crate wasm_bindgen; | ||
extern crate wasm_bindgen_test; | ||
|
||
use rand::rngs::{OsRng, StdRng}; | ||
use rand::FromEntropy; | ||
use rand::{Rng, SeedableRng}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub fn generate_from_seed(seed: u32) -> i32 { | ||
StdRng::seed_from_u64(seed as u64).gen() | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn generate_from_os_rand() -> i32 { | ||
OsRng::new().unwrap().gen() | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn generate_from_entropy() -> i32 { | ||
StdRng::from_entropy().gen() | ||
} | ||
|
||
pub mod tests { | ||
use wasm_bindgen_test::*; | ||
|
||
#[wasm_bindgen_test] | ||
fn generate_from_seed() { | ||
let _ = super::generate_from_seed(42); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
fn generate_from_os_rand() { | ||
let _ = super::generate_from_os_rand(); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
fn generate_from_entropy() { | ||
let _ = super::generate_from_entropy(); | ||
} | ||
} |