Skip to content

Commit

Permalink
add a test for derive(Export)
Browse files Browse the repository at this point in the history
  • Loading branch information
patataofcourse committed Aug 3, 2023
1 parent e27adb5 commit 5054830
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion itest/rust/src/property_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub enum TestEnum {

#[derive(GodotClass)]
pub struct DeriveProperty {
#[export]
#[var]
pub foo: TestEnum,
}

Expand All @@ -315,3 +315,54 @@ fn derive_property() {
class.set_foo(TestEnum::C as i64);
assert_eq!(class.foo, TestEnum::C);
}

#[derive(GodotClass)]
#[class( base = Object)]
pub struct DeriveExport {
#[export]
pub foo: TestEnum,

#[base]
pub base: Base<Object>,
}

#[godot_api]
impl DeriveExport {}

#[godot_api]
impl ObjectVirtual for DeriveExport {
fn init(base: godot::obj::Base<Self::Base>) -> Self {
Self {
foo: TestEnum::B,
base,
}
}
}

#[itest]
fn derive_export() {
let class: Gd<DeriveExport> = Gd::new_default();

let property = class
.bind()
.get_property_list()
.iter_shared()
.find(|c| c.get_or_nil("name") == "foo".to_variant())
.unwrap();
assert_eq!(
property.get_or_nil("class_name"),
"DeriveExport".to_variant()
);
assert_eq!(
property.get_or_nil("type"),
(VariantType::Int as i32).to_variant()
);
assert_eq!(
property.get_or_nil("hint"),
(PropertyHint::PROPERTY_HINT_ENUM.ord()).to_variant()
);
assert_eq!(
property.get_or_nil("hint_string"),
"A:0,B:1,C:2".to_variant()
);
}

0 comments on commit 5054830

Please sign in to comment.