webidl: initial enum support

Add enum support to the WebIDL interface generator.
This commit is contained in:
Stephan Wolski
2018-07-08 22:09:00 -04:00
parent 94d939f4da
commit a981dfd507
10 changed files with 239 additions and 12 deletions

View File

@ -0,0 +1,64 @@
use super::project;
#[test]
fn top_level_enum() {
project()
.file(
"shape.webidl",
r#"
enum ShapeType { "circle", "square" };
[Constructor(ShapeType kind)]
interface Shape {
[Pure]
boolean isSquare();
[Pure]
boolean isCircle();
};
"#,
)
.file(
"shape.mjs",
r#"
export class Shape {
constructor(kind) {
this.kind = kind;
}
isSquare() {
return this.kind === 'square';
}
isCircle() {
return this.kind === 'circle';
}
}
"#,
)
.file(
"src/lib.rs",
r#"
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
pub mod shape;
use shape::{Shape, ShapeType};
#[wasm_bindgen]
pub fn test() {
let circle = Shape::new(ShapeType::Circle);
let square = Shape::new(ShapeType::Square);
assert!(circle.is_circle());
assert!(!circle.is_square());
assert!(square.is_square());
assert!(!square.is_circle());
}
"#,
)
.test();
}

View File

@ -2,3 +2,4 @@ extern crate wasm_bindgen_test_project_builder as project_builder;
use project_builder::project;
mod simple;
mod enums;