From 8fd07321ceea09ce550643985af3695b6775f15b Mon Sep 17 00:00:00 2001
From: ImaMapleTree <59880284+ImaMapleTree@users.noreply.github.com>
Date: Wed, 29 May 2024 08:01:49 +0900
Subject: [PATCH 1/3] split tests across multiple files
---
tests/struct_base.rs | 42 +++++
tests/struct_field_all.rs | 19 +++
tests/struct_field_default.rs | 29 ++++
tests/struct_field_impl.rs | 29 ++++
tests/struct_field_specific_ctor.rs | 60 +++++++
tests/struct_field_value.rs | 55 +++++++
tests/struct_method_config.rs | 58 +++++++
tests/struct_mixed_method_field.rs | 15 ++
tests/test.rs | 232 ----------------------------
9 files changed, 307 insertions(+), 232 deletions(-)
create mode 100644 tests/struct_base.rs
create mode 100644 tests/struct_field_all.rs
create mode 100644 tests/struct_field_default.rs
create mode 100644 tests/struct_field_impl.rs
create mode 100644 tests/struct_field_specific_ctor.rs
create mode 100644 tests/struct_field_value.rs
create mode 100644 tests/struct_method_config.rs
create mode 100644 tests/struct_mixed_method_field.rs
delete mode 100644 tests/test.rs
diff --git a/tests/struct_base.rs b/tests/struct_base.rs
new file mode 100644
index 0000000..1e04ad9
--- /dev/null
+++ b/tests/struct_base.rs
@@ -0,0 +1,42 @@
+use derive_ctor::ctor;
+
+#[derive(ctor, Debug, PartialEq)]
+pub struct Unit;
+
+#[test]
+fn test_unit_struct() {
+ let unit = Unit::new();
+ assert_eq!(Unit, unit);
+}
+
+#[derive(ctor, Debug, PartialEq)]
+pub struct Empty {}
+
+#[test]
+fn test_empty_struct_no_config() {
+ let empty = Empty::new();
+ assert_eq!(Empty { }, empty)
+}
+
+#[derive(ctor, Debug, PartialEq)]
+pub struct OneFieldStruct {
+ value: u32
+}
+
+#[test]
+fn test_struct_with_field() {
+ let ofs = OneFieldStruct::new(300);
+ assert_eq!(OneFieldStruct { value: 300 }, ofs)
+}
+
+#[derive(ctor, Debug, PartialEq)]
+pub struct ManyFieldStruct {
+ value1: u32,
+ value2: bool
+}
+
+#[test]
+fn test_struct_with_many_fields() {
+ let mfs = ManyFieldStruct::new(400, true);
+ assert_eq!(ManyFieldStruct { value1: 400, value2: true }, mfs);
+}
\ No newline at end of file
diff --git a/tests/struct_field_all.rs b/tests/struct_field_all.rs
new file mode 100644
index 0000000..67999ff
--- /dev/null
+++ b/tests/struct_field_all.rs
@@ -0,0 +1,19 @@
+use derive_ctor::ctor;
+
+#[derive(ctor, Debug, PartialEq)]
+struct MixedStruct {
+ provided1: i16,
+ provided2: bool,
+ #[ctor(impl)]
+ provided3: String,
+ #[ctor(value("Foo"))]
+ generated1: &'static str,
+ #[ctor(default)]
+ generated2: u32
+}
+
+#[test]
+fn test_struct_with_multiple_generated_fields() {
+ let multi = MixedStruct::new(41, false, "Test");
+ assert_eq!(MixedStruct { provided1: 41, provided2: false, provided3: String::from("Test"), generated1: "Foo", generated2: Default::default() }, multi)
+}
\ No newline at end of file
diff --git a/tests/struct_field_default.rs b/tests/struct_field_default.rs
new file mode 100644
index 0000000..abf5bcf
--- /dev/null
+++ b/tests/struct_field_default.rs
@@ -0,0 +1,29 @@
+use derive_ctor::ctor;
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructDefault {
+ provided: String,
+ #[ctor(default)]
+ generated: u32
+}
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructManyDefault {
+ provided: String,
+ #[ctor(default)]
+ generated1: u32,
+ #[ctor(default)]
+ generated2: String
+}
+
+#[test]
+fn test_struct_with_default_field() {
+ let test = StructDefault::new(String::from("ABC"));
+ assert_eq!(StructDefault { provided: String::from("ABC"), generated: Default::default() }, test);
+}
+
+#[test]
+fn test_struct_with_multiple_default_fields() {
+ let test = StructManyDefault::new(String::from("ABC"));
+ assert_eq!(StructManyDefault { provided: String::from("ABC"), generated1: Default::default(), generated2: Default::default() }, test);
+}
\ No newline at end of file
diff --git a/tests/struct_field_impl.rs b/tests/struct_field_impl.rs
new file mode 100644
index 0000000..b298dc0
--- /dev/null
+++ b/tests/struct_field_impl.rs
@@ -0,0 +1,29 @@
+use derive_ctor::ctor;
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructImpl {
+ #[ctor(impl)]
+ provided: String,
+ other: bool
+}
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructManyImpl {
+ provided: bool,
+ #[ctor(impl)]
+ one: String,
+ #[ctor(impl)]
+ two: String
+}
+
+#[test]
+fn test_struct_with_impl_value() {
+ let test = StructImpl::new("Foo", false);
+ assert_eq!(StructImpl { provided: String::from("Foo"), other: false }, test);
+}
+
+#[test]
+fn test_struct_with_many_impl() {
+ let test = StructManyImpl::new(false, "One", "Two");
+ assert_eq!(StructManyImpl { provided: false, one: String::from("One"), two: String::from("Two") }, test)
+}
\ No newline at end of file
diff --git a/tests/struct_field_specific_ctor.rs b/tests/struct_field_specific_ctor.rs
new file mode 100644
index 0000000..f1093f2
--- /dev/null
+++ b/tests/struct_field_specific_ctor.rs
@@ -0,0 +1,60 @@
+use derive_ctor::ctor;
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(new, new2)]
+struct TargetedGenerationStruct {
+ arg1: u32,
+ #[ctor(default = [0])]
+ arg2: u32
+}
+
+#[test]
+fn test_struct_with_targeted_generation() {
+ let targeted = TargetedGenerationStruct::new(100);
+ assert_eq!(TargetedGenerationStruct { arg1: 100, arg2: Default::default() }, targeted);
+ let targeted2 = TargetedGenerationStruct::new2(50, 41);
+ assert_eq!(TargetedGenerationStruct { arg1: 50, arg2: 41 }, targeted2);
+}
+
+fn test_method_2() -> String {
+ String::from("FooBar")
+}
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(new, new2)]
+struct TargetedGenerationStruct2 {
+ #[ctor(value(test_method_2()) = [1])]
+ arg1: String,
+ #[ctor(value(33) = 0)]
+ arg2: u32
+}
+
+#[test]
+fn test_struct_with_multiple_targeted_generations() {
+ let tgs1 = TargetedGenerationStruct2::new(String::from("one"));
+ assert_eq!(TargetedGenerationStruct2 { arg1: String::from("one"), arg2: 33 }, tgs1);
+
+ let tgs2 = TargetedGenerationStruct2::new2(95);
+ assert_eq!(TargetedGenerationStruct2 { arg1: String::from("FooBar"), arg2: 95}, tgs2);
+}
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(m1, m2, m3)]
+struct TestStructWithFieldWithMultipleTargets {
+ #[ctor(impl)]
+ arg1: String,
+ #[ctor(value(5) = [0, 1])]
+ arg2: u32
+}
+
+#[test]
+fn test_struct_multiple_targeted_generations_single_field() {
+ let tswfwmt1 = TestStructWithFieldWithMultipleTargets::m1("One");
+ assert_eq!(TestStructWithFieldWithMultipleTargets { arg1: String::from("One"), arg2: 5 }, tswfwmt1);
+
+ let tswfwmt1 = TestStructWithFieldWithMultipleTargets::m2("Two");
+ assert_eq!(TestStructWithFieldWithMultipleTargets { arg1: String::from("Two"), arg2: 5 }, tswfwmt1);
+
+ let tswfwmt1 = TestStructWithFieldWithMultipleTargets::m3("Three", 77);
+ assert_eq!(TestStructWithFieldWithMultipleTargets { arg1: String::from("Three"), arg2: 77 }, tswfwmt1);
+}
\ No newline at end of file
diff --git a/tests/struct_field_value.rs b/tests/struct_field_value.rs
new file mode 100644
index 0000000..632fdb3
--- /dev/null
+++ b/tests/struct_field_value.rs
@@ -0,0 +1,55 @@
+use derive_ctor::ctor;
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructValue {
+ provided: u32,
+ #[ctor(value(10))]
+ generated: u32
+}
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructManyValue {
+ provided: u32,
+ #[ctor(value(11))]
+ generated1: u32,
+ #[ctor(value(false))]
+ generated2: bool
+}
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructComplexValue {
+ provided: u32,
+ #[ctor(value(String::from("Foo")))]
+ generated: String
+}
+
+#[derive(ctor, Debug, PartialEq)]
+struct StructReliantValue {
+ provided: u32,
+ #[ctor(value(provided.to_string()))]
+ generated: String
+}
+
+#[test]
+fn test_struct_value_field() {
+ let test = StructValue::new(100);
+ assert_eq!(StructValue { provided: 100, generated: 10 }, test);
+}
+
+#[test]
+fn test_struct_many_value_fields() {
+ let test = StructManyValue::new(101);
+ assert_eq!(StructManyValue { provided: 101, generated1: 11, generated2: false }, test);
+}
+
+#[test]
+fn test_struct_complex_value_field() {
+ let test = StructComplexValue::new(102);
+ assert_eq!(StructComplexValue { provided: 102, generated: String::from("Foo") }, test);
+}
+
+#[test]
+fn test_struct_reliant_value_field() {
+ let test = StructReliantValue::new(103);
+ assert_eq!(StructReliantValue { provided: 103, generated: 103.to_string() }, test);
+}
\ No newline at end of file
diff --git a/tests/struct_method_config.rs b/tests/struct_method_config.rs
new file mode 100644
index 0000000..c431145
--- /dev/null
+++ b/tests/struct_method_config.rs
@@ -0,0 +1,58 @@
+use derive_ctor::ctor;
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(init)]
+struct Empty2 {}
+
+#[test]
+fn test_empty_struct_config_name() {
+ let empty = Empty2::init();
+ assert_eq!(Empty2 { }, empty)
+}
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(pub(crate) new)]
+struct VisibilityStruct {}
+
+#[test]
+fn test_method_visibility() {
+ let visibility = VisibilityStruct::new();
+ assert_eq!(VisibilityStruct {}, visibility)
+}
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(m1, m2)]
+struct ManyMethodStruct {}
+
+#[test]
+fn test_empty_struct_many_methods() {
+ let many1 = ManyMethodStruct::m1();
+ assert_eq!(ManyMethodStruct {}, many1);
+ let many2 = ManyMethodStruct::m2();
+ assert_eq!(ManyMethodStruct {}, many2);
+}
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(pub m1, pub(crate) m2, m3)]
+struct ManyVisibleMethodStruct {}
+
+#[test]
+fn test_empty_struct_many_methods_with_visibility() {
+ let m1 = ManyVisibleMethodStruct::m1();
+ assert_eq!(ManyVisibleMethodStruct {}, m1);
+ let m2 = ManyVisibleMethodStruct::m2();
+ assert_eq!(ManyVisibleMethodStruct {}, m2);
+ let m3 = ManyVisibleMethodStruct::m3();
+ assert_eq!(ManyVisibleMethodStruct {}, m3);
+}
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(init)]
+struct FieldStructCustomCtor {
+ value: u32
+}
+
+#[test]
+fn test_field_struct_with_custom_ctor_name() {
+ let field_struct = FieldStructCustomCtor::init(15);
+ assert_eq!(FieldStructCustomCtor { value: 15 }, field_struct);
+}
\ No newline at end of file
diff --git a/tests/struct_mixed_method_field.rs b/tests/struct_mixed_method_field.rs
new file mode 100644
index 0000000..669bcf3
--- /dev/null
+++ b/tests/struct_mixed_method_field.rs
@@ -0,0 +1,15 @@
+use derive_ctor::ctor;
+
+#[derive(ctor, Debug, PartialEq)]
+#[ctor(a)]
+struct MixedCtorFieldStruct {
+ provided: u32,
+ #[ctor(default)]
+ generated: bool
+}
+
+#[test]
+fn test_struct_with_custom_ctor_and_generated_field() {
+ let test = MixedCtorFieldStruct::a(100);
+ assert_eq!(MixedCtorFieldStruct { provided: 100, generated: false }, test)
+}
\ No newline at end of file
diff --git a/tests/test.rs b/tests/test.rs
deleted file mode 100644
index f14c8aa..0000000
--- a/tests/test.rs
+++ /dev/null
@@ -1,232 +0,0 @@
-#[macro_use]
-extern crate derive_ctor;
-
-#[derive(ctor, Debug, PartialEq)]
-pub struct Empty {}
-
-#[test]
-fn test_empty_struct_no_config() {
- let empty = Empty::new();
- assert_eq!(Empty { }, empty)
-}
-
-#[derive(ctor, Debug, PartialEq)]
-#[ctor(init)]
-pub struct Empty2 {}
-
-#[test]
-fn test_empty_struct_config_name() {
- let empty = Empty2::init();
- assert_eq!(Empty2 { }, empty)
-}
-
-#[derive(ctor, Debug, PartialEq)]
-pub struct Unit;
-
-#[test]
-fn test_unit_struct() {
- let unit = Unit::new();
- assert_eq!(Unit, unit);
-}
-
-#[derive(ctor, Debug, PartialEq)]
-#[ctor(pub(crate) new)]
-pub struct VisibilityStruct {}
-
-#[test]
-fn test_method_visibility() {
- let visibility = VisibilityStruct::new();
- assert_eq!(VisibilityStruct {}, visibility)
-}
-
-#[derive(ctor, Debug, PartialEq)]
-#[ctor(m1, m2)]
-pub struct ManyMethodStruct {}
-
-#[test]
-fn test_empty_struct_many_methods() {
- let many1 = ManyMethodStruct::m1();
- assert_eq!(ManyMethodStruct {}, many1);
- let many2 = ManyMethodStruct::m2();
- assert_eq!(ManyMethodStruct {}, many2);
-}
-
-#[derive(ctor, Debug, PartialEq)]
-#[ctor(pub m1, pub(crate) m2, m3)]
-pub struct ManyVisibleMethodStruct {}
-
-#[test]
-fn test_empty_struct_many_methods_with_visibility() {
- let m1 = ManyVisibleMethodStruct::m1();
- assert_eq!(ManyVisibleMethodStruct {}, m1);
- let m2 = ManyVisibleMethodStruct::m2();
- assert_eq!(ManyVisibleMethodStruct {}, m2);
- let m3 = ManyVisibleMethodStruct::m3();
- assert_eq!(ManyVisibleMethodStruct {}, m3);
-}
-
-#[derive(ctor, Debug, PartialEq)]
-pub struct OneFieldStruct {
- value: u32
-}
-
-#[test]
-fn test_struct_with_field() {
- let ofs = OneFieldStruct::new(300);
- assert_eq!(OneFieldStruct { value: 300 }, ofs)
-}
-
-#[derive(ctor, Debug, PartialEq)]
-pub struct ManyFieldStruct {
- value1: u32,
- value2: bool
-}
-
-#[test]
-fn test_struct_with_many_fields() {
- let mfs = ManyFieldStruct::new(400, true);
- assert_eq!(ManyFieldStruct { value1: 400, value2: true }, mfs);
-}
-
-#[derive(ctor, Debug, PartialEq)]
-#[ctor(init)]
-pub struct FieldStructCustomCtor {
- value: u32
-}
-
-#[test]
-fn test_field_struct_with_custom_ctor_name() {
- let field_struct = FieldStructCustomCtor::init(15);
- assert_eq!(FieldStructCustomCtor { value: 15 }, field_struct);
-}
-
-#[derive(ctor, Debug, PartialEq)]
-pub struct DefaultValueStruct {
- provided: String,
- #[ctor(default)]
- generated: u32
-}
-
-#[test]
-fn test_struct_with_default_field() {
- let test = DefaultValueStruct::new(String::from("ABC"));
- assert_eq!(DefaultValueStruct { provided: String::from("ABC"), generated: Default::default() }, test);
-}
-
-#[derive(ctor, Debug, PartialEq)]
-pub struct ValueValueStruct {
- provided: u32,
- #[ctor(value(10))]
- generated: u32
-}
-
-#[test]
-fn test_struct_with_value_field() {
- let test = ValueValueStruct::new(100);
- assert_eq!(ValueValueStruct { provided: 100, generated: 10 }, test);
-}
-
-fn generation_method() -> Option