Skip to content

Commit 5b2e639

Browse files
committed
test(ExportEnum): to/from variant
1 parent 512dc08 commit 5b2e639

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod test_as_arg;
88
mod test_async;
99
mod test_constructor;
1010
mod test_derive;
11+
mod test_export_enum;
1112
mod test_free_ub;
1213
mod test_generic_class;
1314
mod test_indexed_props;
@@ -52,6 +53,7 @@ pub extern "C" fn run_tests(
5253
status &= test_vararray_return::run_tests();
5354
status &= test_variant_call_args::run_tests();
5455
status &= test_variant_ops::run_tests();
56+
status &= test_export_enum::run_tests();
5557

5658
Variant::new(status).leak()
5759
}

test/src/test_export_enum.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use gdnative::prelude::*;
2+
3+
#[derive(Debug, PartialEq, Clone, Copy, ExportEnum)]
4+
enum Dir {
5+
Up = 1,
6+
Down = -1,
7+
}
8+
9+
pub(crate) fn run_tests() -> bool {
10+
let mut ok = true;
11+
12+
ok &= test_from_variant();
13+
ok &= test_to_variant();
14+
15+
ok
16+
}
17+
18+
crate::godot_itest!(test_from_variant {
19+
assert_eq!(Dir::from_variant(&1_i32.to_variant()), Ok(Dir::Up));
20+
assert_eq!(Dir::from_variant(&(-1_i32).to_variant()), Ok(Dir::Down));
21+
// 42 isn't mapped to any variant of `Dir`
22+
assert!(Dir::from_variant(&42_i32.to_variant()).is_err());
23+
});
24+
25+
crate::godot_itest!(test_to_variant {
26+
assert_eq!(Dir::Up.to_variant(), 1_i32.to_variant());
27+
assert_eq!(Dir::Down.to_variant(), (-1_i32).to_variant());
28+
});

0 commit comments

Comments
 (0)