2018-04-10 01:32:06 +03:00
|
|
|
use super::project;
|
2018-02-23 19:30:18 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn c_style_enum() {
|
2018-04-10 01:32:06 +03:00
|
|
|
project()
|
2018-06-28 08:42:34 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-07-05 06:37:09 +03:00
|
|
|
#![feature(proc_macro, wasm_custom_section)]
|
2018-02-23 19:30:18 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
extern crate wasm_bindgen;
|
2018-02-23 19:30:18 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
use wasm_bindgen::prelude::*;
|
2018-02-23 19:30:18 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub enum Color {
|
|
|
|
Green,
|
|
|
|
Yellow,
|
|
|
|
Red,
|
|
|
|
}
|
2018-02-23 19:30:18 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn cycle(color: Color) -> Color {
|
|
|
|
match color {
|
|
|
|
Color::Green => Color::Yellow,
|
|
|
|
Color::Yellow => Color::Red,
|
|
|
|
Color::Red => Color::Green,
|
|
|
|
}
|
2018-02-23 19:30:18 +03:00
|
|
|
}
|
2018-07-05 06:37:09 +03:00
|
|
|
"#,
|
2018-06-28 08:42:34 +03:00
|
|
|
)
|
|
|
|
.file(
|
2018-07-05 06:37:09 +03:00
|
|
|
"test.js",
|
2018-06-28 08:42:34 +03:00
|
|
|
r#"
|
2018-07-05 06:37:09 +03:00
|
|
|
import * as assert from "assert";
|
|
|
|
import * as wasm from "./out";
|
|
|
|
|
|
|
|
export function test() {
|
|
|
|
assert.strictEqual(wasm.Color.Green, 0);
|
|
|
|
assert.strictEqual(wasm.Color.Yellow, 1);
|
|
|
|
assert.strictEqual(wasm.Color.Red, 2);
|
|
|
|
assert.strictEqual(Object.keys(wasm.Color).length, 3);
|
|
|
|
|
|
|
|
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
|
|
|
}
|
|
|
|
"#,
|
2018-06-28 08:42:34 +03:00
|
|
|
)
|
2018-02-23 19:30:18 +03:00
|
|
|
.test();
|
|
|
|
}
|
2018-02-23 19:44:48 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn c_style_enum_with_custom_values() {
|
2018-04-10 01:32:06 +03:00
|
|
|
project()
|
2018-06-28 08:42:34 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-07-05 06:37:09 +03:00
|
|
|
#![feature(proc_macro, wasm_custom_section)]
|
2018-02-23 19:44:48 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
extern crate wasm_bindgen;
|
2018-02-23 19:44:48 +03:00
|
|
|
|
2018-05-02 20:16:40 +03:00
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
pub mod inner {
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub enum Color {
|
|
|
|
Green = 21,
|
|
|
|
Yellow = 34,
|
|
|
|
Red,
|
|
|
|
}
|
2018-05-02 20:16:40 +03:00
|
|
|
}
|
2018-02-23 19:44:48 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
use inner::Color;
|
2018-05-02 20:16:40 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn cycle(color: Color) -> Color {
|
|
|
|
match color {
|
|
|
|
Color::Green => Color::Yellow,
|
|
|
|
Color::Yellow => Color::Red,
|
|
|
|
Color::Red => Color::Green,
|
|
|
|
}
|
2018-02-23 19:44:48 +03:00
|
|
|
}
|
2018-07-05 06:37:09 +03:00
|
|
|
"#,
|
2018-06-28 08:42:34 +03:00
|
|
|
)
|
|
|
|
.file(
|
2018-07-05 06:37:09 +03:00
|
|
|
"test.js",
|
2018-06-28 08:42:34 +03:00
|
|
|
r#"
|
2018-07-05 06:37:09 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
"#,
|
2018-06-28 08:42:34 +03:00
|
|
|
)
|
2018-02-23 19:44:48 +03:00
|
|
|
.test();
|
|
|
|
}
|