Skip to content

Commit 92c73b8

Browse files
authored
Merge pull request #888 from godot-rust/qol/clippy-chores
Get rid of placeholder names like "foo"
2 parents b950177 + 90f4d5d commit 92c73b8

File tree

4 files changed

+54
-43
lines changed

4 files changed

+54
-43
lines changed

itest/rust/src/builtin_tests/containers/dictionary_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ fn dictionary_macro() {
7777
let empty = dict!();
7878
assert!(empty.is_empty());
7979

80-
let foo = "foo";
80+
let key = "num";
8181
let dict_complex = dict! {
82-
foo: 10,
83-
"bar": true,
82+
key: 10,
83+
"bool": true,
8484
(1 + 2): Variant::nil(),
8585
};
86-
assert_eq!(dict_complex.get("foo"), Some(10.to_variant()));
87-
assert_eq!(dict_complex.get("bar"), Some(true.to_variant()));
86+
assert_eq!(dict_complex.get("num"), Some(10.to_variant()));
87+
assert_eq!(dict_complex.get("bool"), Some(true.to_variant()));
8888
assert_eq!(dict_complex.get(3), Some(Variant::nil()));
8989
}
9090

itest/rust/src/builtin_tests/convert_test.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ fn error_maintains_value() {
9090

9191
// Manual implementation of `GodotConvert` and related traits to ensure conversion works.
9292
#[derive(PartialEq, Debug)]
93-
struct Foo {
93+
struct ConvertedStruct {
9494
a: i32,
9595
b: f32,
9696
}
9797

98-
impl Foo {
98+
impl ConvertedStruct {
9999
const MISSING_KEY_A: &'static str = "missing `a` key";
100100
const MISSING_KEY_B: &'static str = "missing `b` key";
101101
const TOO_MANY_KEYS: &'static str = "too many keys provided";
102102
}
103103

104-
impl GodotConvert for Foo {
104+
impl GodotConvert for ConvertedStruct {
105105
type Via = Dictionary;
106106
}
107107

108-
impl ToGodot for Foo {
108+
impl ToGodot for ConvertedStruct {
109109
fn to_godot(&self) -> Self::Via {
110110
dict! {
111111
"a": self.a,
@@ -114,7 +114,7 @@ impl ToGodot for Foo {
114114
}
115115
}
116116

117-
impl FromGodot for Foo {
117+
impl FromGodot for ConvertedStruct {
118118
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
119119
let a = match via.get("a") {
120120
Some(a) => a,
@@ -139,20 +139,20 @@ impl FromGodot for Foo {
139139

140140
#[itest]
141141
fn custom_convert_roundtrip() {
142-
let foo = Foo { a: 10, b: 12.34 };
142+
let m = ConvertedStruct { a: 10, b: 12.34 };
143143

144-
let as_dict = foo.to_godot();
145-
assert_eq!(as_dict.get("a"), Some(foo.a.to_variant()));
146-
assert_eq!(as_dict.get("b"), Some(foo.b.to_variant()));
144+
let as_dict = m.to_godot();
145+
assert_eq!(as_dict.get("a"), Some(m.a.to_variant()));
146+
assert_eq!(as_dict.get("b"), Some(m.b.to_variant()));
147147

148-
let foo2 = as_dict.to_variant().to::<Foo>();
149-
assert_eq!(foo, foo2, "from_variant");
148+
let n = as_dict.to_variant().to::<ConvertedStruct>();
149+
assert_eq!(m, n, "from_variant");
150150

151-
let foo3 = Foo::from_godot(as_dict);
152-
assert_eq!(foo, foo3, "from_godot");
151+
let o = ConvertedStruct::from_godot(as_dict);
152+
assert_eq!(m, o, "from_godot");
153153
}
154154

155-
// Ensure all failure states for the `FromGodot` conversion of `Foo` are propagated through the `try_to`
155+
// Ensure all failure states for the `FromGodot` conversion of `ManuallyConverted` are propagated through the `try_to`
156156
// method of `Variant` as they should be.
157157
#[itest]
158158
fn custom_convert_error_from_variant() {
@@ -161,20 +161,26 @@ fn custom_convert_error_from_variant() {
161161
};
162162
let err = missing_a
163163
.to_variant()
164-
.try_to::<Foo>()
164+
.try_to::<ConvertedStruct>()
165165
.expect_err("should be missing key `a`");
166166

167-
assert_eq!(err.cause().unwrap().to_string(), Foo::MISSING_KEY_A);
167+
assert_eq!(
168+
err.cause().unwrap().to_string(),
169+
ConvertedStruct::MISSING_KEY_A
170+
);
168171

169172
let missing_b = dict! {
170173
"a": 58,
171174
};
172175
let err = missing_b
173176
.to_variant()
174-
.try_to::<Foo>()
177+
.try_to::<ConvertedStruct>()
175178
.expect_err("should be missing key `b`");
176179

177-
assert_eq!(err.cause().unwrap().to_string(), Foo::MISSING_KEY_B);
180+
assert_eq!(
181+
err.cause().unwrap().to_string(),
182+
ConvertedStruct::MISSING_KEY_B
183+
);
178184

179185
let too_many_keys = dict! {
180186
"a": 12,
@@ -183,18 +189,21 @@ fn custom_convert_error_from_variant() {
183189
};
184190
let err = too_many_keys
185191
.to_variant()
186-
.try_to::<Foo>()
192+
.try_to::<ConvertedStruct>()
187193
.expect_err("should have too many keys");
188194

189-
assert_eq!(err.cause().unwrap().to_string(), Foo::TOO_MANY_KEYS);
195+
assert_eq!(
196+
err.cause().unwrap().to_string(),
197+
ConvertedStruct::TOO_MANY_KEYS
198+
);
190199

191200
let wrong_type_a = dict! {
192201
"a": "hello",
193202
"b": 28.41,
194203
};
195204
let err = wrong_type_a
196205
.to_variant()
197-
.try_to::<Foo>()
206+
.try_to::<ConvertedStruct>()
198207
.expect_err("should have wrongly typed key `a`");
199208

200209
assert!(err.cause().is_none());
@@ -209,7 +218,7 @@ fn custom_convert_error_from_variant() {
209218
};
210219
let err = wrong_type_b
211220
.to_variant()
212-
.try_to::<Foo>()
221+
.try_to::<ConvertedStruct>()
213222
.expect_err("should have wrongly typed key `b`");
214223

215224
assert!(err.cause().is_none());
@@ -224,7 +233,7 @@ fn custom_convert_error_from_variant() {
224233
};
225234
let err = too_big_value
226235
.to_variant()
227-
.try_to::<Foo>()
236+
.try_to::<ConvertedStruct>()
228237
.expect_err("should have too big value for field `a`");
229238

230239
assert!(err.cause().is_none());

itest/rust/src/object_tests/property_test.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -317,21 +317,23 @@ pub enum TestEnum {
317317
#[class(no_init)]
318318
pub struct DeriveProperty {
319319
#[var]
320-
pub foo: TestEnum,
320+
pub my_enum: TestEnum,
321321
}
322322

323323
#[itest]
324324
fn derive_property() {
325-
let mut class = DeriveProperty { foo: TestEnum::B };
326-
assert_eq!(class.get_foo(), TestEnum::B as i64);
327-
class.set_foo(TestEnum::C as i64);
328-
assert_eq!(class.foo, TestEnum::C);
325+
let mut class = DeriveProperty {
326+
my_enum: TestEnum::B,
327+
};
328+
assert_eq!(class.get_my_enum(), TestEnum::B as i64);
329+
class.set_my_enum(TestEnum::C as i64);
330+
assert_eq!(class.my_enum, TestEnum::C);
329331
}
330332

331333
#[derive(GodotClass)]
332334
pub struct DeriveExport {
333335
#[export]
334-
pub foo: TestEnum,
336+
pub my_enum: TestEnum,
335337

336338
// Tests also qualified base path (type inference of Base<T> without #[hint]).
337339
pub base: godot::obj::Base<RefCounted>,
@@ -341,7 +343,7 @@ pub struct DeriveExport {
341343
impl IRefCounted for DeriveExport {
342344
fn init(base: godot::obj::Base<Self::Base>) -> Self {
343345
Self {
344-
foo: TestEnum::B,
346+
my_enum: TestEnum::B,
345347
base,
346348
}
347349
}
@@ -354,7 +356,7 @@ fn derive_export() {
354356
let property = class
355357
.get_property_list()
356358
.iter_shared()
357-
.find(|c| c.get_or_nil("name") == "foo".to_variant())
359+
.find(|c| c.get_or_nil("name") == "my_enum".to_variant())
358360
.unwrap();
359361
// `class_name` should be empty for non-Object variants.
360362
check_property(&property, "class_name", "");
@@ -377,10 +379,10 @@ pub struct RenamedCustomResource {}
377379
pub struct ExportResource {
378380
#[export]
379381
#[var(usage_flags=[DEFAULT, EDITOR_INSTANTIATE_OBJECT])]
380-
pub foo: Option<Gd<CustomResource>>,
382+
pub my_resource: Option<Gd<CustomResource>>,
381383

382384
#[export]
383-
pub bar: Option<Gd<RenamedCustomResource>>,
385+
pub renamed_resource: Option<Gd<RenamedCustomResource>>,
384386
}
385387

386388
#[itest]
@@ -390,7 +392,7 @@ fn export_resource() {
390392
let property = class
391393
.get_property_list()
392394
.iter_shared()
393-
.find(|c| c.get_or_nil("name") == "foo".to_variant())
395+
.find(|c| c.get_or_nil("name") == "my_resource".to_variant())
394396
.unwrap();
395397
check_property(&property, "class_name", "CustomResource");
396398
check_property(&property, "type", VariantType::OBJECT.ord());
@@ -405,7 +407,7 @@ fn export_resource() {
405407
let property = class
406408
.get_property_list()
407409
.iter_shared()
408-
.find(|c| c.get_or_nil("name") == "bar".to_variant())
410+
.find(|c| c.get_or_nil("name") == "renamed_resource".to_variant())
409411
.unwrap();
410412
check_property(&property, "class_name", "NewNameCustomResource");
411413
check_property(&property, "type", VariantType::OBJECT.ord());

itest/rust/src/object_tests/virtual_methods_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct FormatLoaderTest {
188188

189189
impl FormatLoaderTest {
190190
fn resource_type() -> GString {
191-
GString::from("foo")
191+
GString::from("some_resource_type")
192192
}
193193
}
194194

@@ -599,7 +599,7 @@ fn test_notifications() {
599599
fn test_get_called() {
600600
let obj = GetTest::new_gd();
601601
assert!(!obj.bind().get_called.get());
602-
assert!(obj.get("foo".into()).is_nil());
602+
assert!(obj.get("inexistent".into()).is_nil());
603603
assert!(obj.bind().get_called.get());
604604

605605
let obj = GetTest::new_gd();
@@ -626,7 +626,7 @@ fn test_get_returns_correct() {
626626
fn test_set_called() {
627627
let mut obj = SetTest::new_gd();
628628
assert!(!obj.bind().set_called);
629-
obj.set("foo".into(), Variant::nil());
629+
obj.set("inexistent_property".into(), Variant::nil());
630630
assert!(obj.bind().set_called);
631631

632632
let mut obj = SetTest::new_gd();

0 commit comments

Comments
 (0)