mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
Add test for custom values in enums
This commit is contained in:
parent
f783876192
commit
3ae6614738
@ -42,3 +42,46 @@ fn c_style_enum() {
|
|||||||
"#)
|
"#)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn c_style_enum_with_custom_values() {
|
||||||
|
test_support::project()
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub enum Color {
|
||||||
|
Green = 21,
|
||||||
|
Yellow = 34,
|
||||||
|
Red,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub extern fn cycle(color: Color) -> Color {
|
||||||
|
match color {
|
||||||
|
Color::Green => Color::Yellow,
|
||||||
|
Color::Yellow => Color::Red,
|
||||||
|
Color::Red => Color::Green,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
assert.strictEqual(wasm.Color.Green, 21);
|
||||||
|
assert.strictEqual(wasm.Color.Yellow, 34);
|
||||||
|
assert.strictEqual(wasm.Color.Red, 2);
|
||||||
|
assert.strictEqual(Object.keys(wasm.Color).length, 3);
|
||||||
|
|
||||||
|
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user