use static_assertions::assert_type_eq_all;
use tuco_core::Tuco;
use tuco_derive::{tuco, Tuco};
#[test]
fn associated_type_regular_struct() {
#[derive(Tuco)]
struct A {
a: i32,
b: String,
c: bool,
}
assert_type_eq_all!(<A as Tuco>::Tuple, (i32, String, bool));
let x = A::from_tuple((1, "example".to_string(), false));
assert_eq!(x.a, 1);
assert_eq!(x.b, "example".to_string());
assert_eq!(x.c, false);
}
#[test]
fn struct_with_reference() {
struct O;
#[derive(Tuco)]
struct A<'a, 'b> {
x: &'a O,
y: &'b O,
}
assert_type_eq_all!(<A as Tuco>::Tuple, (&'_ O, &'_ O));
}
#[test]
fn associated_type_nested_plain() {
struct Nested;
#[derive(Tuco)]
struct A {
nested: Nested,
}
assert_type_eq_all!(<A as Tuco>::Tuple, Nested);
}
#[test]
fn nested_derive() {
#[derive(Tuco)]
struct Nested;
#[derive(Tuco)]
struct A {
#[tuco]
nested: Nested,
}
assert_type_eq_all!(<A as Tuco>::Tuple, ());
}
#[test]
fn nested_derive_from_tuco() {
#[derive(Tuco)]
struct NestedA;
#[derive(Tuco)]
struct NestedB;
#[derive(Tuco)]
struct A {
#[tuco]
nested: NestedA,
}
#[derive(Tuco)]
struct B {
#[tuco]
nested: NestedB,
}
B::from_tuco(A { nested: NestedA });
A::from_tuco(B { nested: NestedB });
}
#[test]
fn generic_struct() {
#[derive(Tuco)]
struct Nested<T>(T);
#[derive(Tuco)]
struct A {
nested: Nested<i32>,
}
#[derive(Tuco)]
struct B {
#[tuco]
nested: Nested<f32>,
}
assert_type_eq_all!(<A as Tuco>::Tuple, Nested<i32>);
assert_type_eq_all!(<B as Tuco>::Tuple, f32);
}
#[test]
fn nested_structs() {
#[derive(Tuco)]
struct A {
nested: i32,
}
#[derive(Tuco)]
struct B {
#[tuco]
nested: A,
}
#[derive(Tuco)]
struct C {
#[tuco]
nested: B,
}
assert_type_eq_all!(<C as Tuco>::Tuple, i32);
assert_type_eq_all!(<A as Tuco>::Tuple, <B as Tuco>::Tuple, <C as Tuco>::Tuple);
}