forked from rustwasm/wasm-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rustwasm#433 from Slowki/feat/basic-enum-support
WebIDL Enum Support
- Loading branch information
Showing
10 changed files
with
228 additions
and
10 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
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
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
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
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,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).unwrap(); | ||
let square = Shape::new(ShapeType::Square).unwrap(); | ||
assert!(circle.is_circle()); | ||
assert!(!circle.is_square()); | ||
assert!(square.is_square()); | ||
assert!(!square.is_circle()); | ||
} | ||
"#, | ||
) | ||
.test(); | ||
} |
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