feat(macros): enhance Integrable derive with validation and versioning improvements
This commit is contained in:
@@ -6,20 +6,48 @@ struct TestEntity {
|
||||
value: i32,
|
||||
}
|
||||
|
||||
#[derive(arbiter_macros::Hashable, arbiter_macros::Integrable)]
|
||||
#[integrable(kind = "other_entity")]
|
||||
struct OtherEntity {
|
||||
label: String,
|
||||
count: u64,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_version_is_one() {
|
||||
assert_eq!(<TestEntity as Integrable>::VERSION, 1, "default version must be 1");
|
||||
fn kind_is_set_correctly() {
|
||||
assert_eq!(<TestEntity as Integrable>::KIND, "test_entity");
|
||||
assert_eq!(<OtherEntity as Integrable>::KIND, "other_entity");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_is_positive() {
|
||||
const {
|
||||
assert!(<TestEntity as Integrable>::VERSION > 0);
|
||||
assert!(<OtherEntity as Integrable>::VERSION > 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_field_layouts_produce_different_versions() {
|
||||
assert_ne!(
|
||||
<TestEntity as Integrable>::VERSION,
|
||||
<OtherEntity as Integrable>::VERSION,
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(arbiter_macros::Hashable, arbiter_macros::Integrable)]
|
||||
#[integrable(kind = "versioned_entity", version = 3)]
|
||||
struct VersionedEntity {
|
||||
data: String,
|
||||
#[integrable(kind = "generic_entity")]
|
||||
struct GenericEntity<T> {
|
||||
inner: T,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_version_attribute() {
|
||||
assert_eq!(<VersionedEntity as Integrable>::VERSION, 3);
|
||||
assert_eq!(<VersionedEntity as Integrable>::KIND, "versioned_entity");
|
||||
fn generic_struct_derives_integrable() {
|
||||
assert_eq!(
|
||||
<GenericEntity<TestEntity> as Integrable>::KIND,
|
||||
"generic_entity"
|
||||
);
|
||||
const {
|
||||
assert!(<GenericEntity<TestEntity> as Integrable>::VERSION > 0);
|
||||
}
|
||||
}
|
||||
|
||||
5
server/crates/arbiter-macros/tests/integrable_errors.rs
Normal file
5
server/crates/arbiter-macros/tests/integrable_errors.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#[test]
|
||||
fn integrable_compile_fail() {
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/integrable/*.rs");
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#[derive(arbiter_macros::Hashable, arbiter_macros::Integrable)]
|
||||
#[integrable(kind = "entity_a")]
|
||||
#[integrable(kind = "entity_b")]
|
||||
struct DuplicateAttr {
|
||||
value: i32,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: duplicate #[integrable] attribute
|
||||
--> tests/ui/integrable/duplicate_attr.rs:3:1
|
||||
|
|
||||
3 | #[integrable(kind = "entity_b")]
|
||||
| ^
|
||||
@@ -0,0 +1,7 @@
|
||||
#[derive(arbiter_macros::Hashable, arbiter_macros::Integrable)]
|
||||
#[integrable(kind = "")]
|
||||
struct EmptyKind {
|
||||
value: i32,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: kind must not be empty
|
||||
--> tests/ui/integrable/empty_kind.rs:2:21
|
||||
|
|
||||
2 | #[integrable(kind = "")]
|
||||
| ^^
|
||||
@@ -0,0 +1,8 @@
|
||||
#[derive(arbiter_macros::Integrable)]
|
||||
#[integrable(kind = "my_enum")]
|
||||
enum MyEnum {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: #[derive(Integrable)] is only supported on structs
|
||||
--> tests/ui/integrable/enum_not_supported.rs:3:6
|
||||
|
|
||||
3 | enum MyEnum {
|
||||
| ^^^^^^
|
||||
@@ -0,0 +1,7 @@
|
||||
#[derive(arbiter_macros::Hashable, arbiter_macros::Integrable)]
|
||||
#[integrable(kind = "bad kind!")]
|
||||
struct InvalidKind {
|
||||
value: i32,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: kind must be a valid schema name: start with a letter, contain only [a-zA-Z0-9_]
|
||||
--> tests/ui/integrable/invalid_kind.rs:2:21
|
||||
|
|
||||
2 | #[integrable(kind = "bad kind!")]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,6 @@
|
||||
#[derive(arbiter_macros::Hashable, arbiter_macros::Integrable)]
|
||||
struct MissingAttr {
|
||||
value: i32,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: #[integrable(kind = "...")] is required
|
||||
--> tests/ui/integrable/missing_attr.rs:2:8
|
||||
|
|
||||
2 | struct MissingAttr {
|
||||
| ^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user