]>
git.proxmox.com Git - rustc.git/blob - vendor/wasm-bindgen/tests/wasm/enums.rs
1 use self::inner
::ColorWithCustomValues
;
2 use wasm_bindgen
::prelude
::*;
3 use wasm_bindgen_test
::*;
5 #[wasm_bindgen(module = "tests/wasm/enums.js")]
8 fn js_c_style_enum_with_custom_values();
9 fn js_handle_optional_enums(x
: Option
<Color
>) -> Option
<Color
>;
10 fn js_expect_enum(x
: Color
, y
: Option
<Color
>);
11 fn js_expect_enum_none(x
: Option
<Color
>);
12 fn js_renamed_enum(b
: RenamedEnum
);
16 #[derive(PartialEq, Debug)]
24 use wasm_bindgen
::prelude
::*;
27 pub enum ColorWithCustomValues
{
34 #[wasm_bindgen(js_name = JsRenamedEnum)]
35 #[derive(Copy, Clone)]
36 pub enum RenamedEnum
{
42 pub fn enum_cycle(color
: Color
) -> Color
{
44 Color
::Green
=> Color
::Yellow
,
45 Color
::Yellow
=> Color
::Red
,
46 Color
::Red
=> Color
::Green
,
51 pub fn enum_with_custom_values_cycle(color
: ColorWithCustomValues
) -> ColorWithCustomValues
{
53 ColorWithCustomValues
::Green
=> ColorWithCustomValues
::Yellow
,
54 ColorWithCustomValues
::Yellow
=> ColorWithCustomValues
::Red
,
55 ColorWithCustomValues
::Red
=> ColorWithCustomValues
::Green
,
65 fn c_style_enum_with_custom_values() {
66 js_c_style_enum_with_custom_values();
70 pub fn handle_optional_enums(x
: Option
<Color
>) -> Option
<Color
> {
75 fn test_optional_enums() {
78 assert_eq
!(js_handle_optional_enums(None
), None
);
79 assert_eq
!(js_handle_optional_enums(Some(Green
)), Some(Green
));
80 assert_eq
!(js_handle_optional_enums(Some(Yellow
)), Some(Yellow
));
81 assert_eq
!(js_handle_optional_enums(Some(Red
)), Some(Red
));
85 fn test_optional_enum_values() {
88 js_expect_enum(Green
, Some(Green
));
89 js_expect_enum(Yellow
, Some(Yellow
));
90 js_expect_enum(Red
, Some(Red
));
91 js_expect_enum_none(None
);
95 fn test_renamed_enum() {
96 js_renamed_enum(RenamedEnum
::B
);