-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
12 changed files
with
370 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use derive_ctor::ctor; | ||
|
||
#[derive(ctor, Debug, PartialEq)] | ||
struct MixedStruct { | ||
provided1: i16, | ||
provided2: bool, | ||
#[ctor(impl)] | ||
provided3: String, | ||
#[ctor(expr("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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use derive_ctor::ctor; | ||
|
||
#[derive(ctor, Debug, PartialEq)] | ||
struct StructExpr { | ||
provided: u32, | ||
#[ctor(expr(10))] | ||
generated: u32 | ||
} | ||
|
||
#[derive(ctor, Debug, PartialEq)] | ||
struct StructManyExpr { | ||
provided: u32, | ||
#[ctor(expr(11))] | ||
generated1: u32, | ||
#[ctor(expr(false))] | ||
generated2: bool | ||
} | ||
|
||
#[derive(ctor, Debug, PartialEq)] | ||
struct StructComplexExpr { | ||
provided: u32, | ||
#[ctor(expr(String::from("Foo")))] | ||
generated: String | ||
} | ||
|
||
#[derive(ctor, Debug, PartialEq)] | ||
struct StructReliantExpr { | ||
provided: u32, | ||
#[ctor(expr(provided.to_string()))] | ||
generated: String | ||
} | ||
|
||
#[test] | ||
fn test_struct_expr_field() { | ||
let test = StructExpr::new(100); | ||
assert_eq!(StructExpr { provided: 100, generated: 10 }, test); | ||
} | ||
|
||
#[test] | ||
fn test_struct_many_expr_fields() { | ||
let test = StructManyExpr::new(101); | ||
assert_eq!(StructManyExpr { provided: 101, generated1: 11, generated2: false }, test); | ||
} | ||
|
||
#[test] | ||
fn test_struct_complex_expr_field() { | ||
let test = StructComplexExpr::new(102); | ||
assert_eq!(StructComplexExpr { provided: 102, generated: String::from("Foo") }, test); | ||
} | ||
|
||
#[test] | ||
fn test_struct_reliant_expr_field() { | ||
let test = StructReliantExpr::new(103); | ||
assert_eq!(StructReliantExpr { provided: 103, generated: 103.to_string() }, test); | ||
} |
Oops, something went wrong.