Files
marathon/crates/macros/tests/basic_macro_test.rs
Sienna Meridian Satterwhite b03b71c1d9 feat(rendering): Vendor Bevy rendering crates (Phase 1 complete)
Closes #6, #7, #8, #9, #10
Refs #2, #122

Vendored bevy_render, bevy_core_pipeline, and bevy_pbr from Bevy v0.17.2
(commit 566358363126dd69f6e457e47f306c68f8041d2a) into libmarathon.

- ~51K LOC vendored to crates/libmarathon/src/render/
- Merged bevy_render_macros into crates/macros/
- Fixed 773→0 compilation errors
- Updated dependencies (encase 0.10→0.11, added 4 new deps)
- Removed bevy_render/pbr/core_pipeline from app Cargo features

All builds passing, macOS smoke test successful.

Signed-off-by: Sienna Meridian Satterwhite <sienna@r3t.io>
2026-02-07 18:22:13 +00:00

99 lines
2.8 KiB
Rust

/// Basic tests for the Synced attribute macro
use bevy::prelude::*;
use libmarathon::networking::{
ClockComparison,
ComponentMergeDecision,
SyncComponent,
};
// Test 1: Basic struct with LWW strategy compiles
// Note: No need to manually derive rkyv traits - synced attribute adds them automatically!
#[sync_macros::synced(version = 1, strategy = "LastWriteWins")]
#[derive(Component, Reflect, Clone, Debug, PartialEq)]
#[reflect(Component)]
struct Health(f32);
#[test]
fn test_health_compiles() {
let health = Health(100.0);
assert_eq!(health.0, 100.0);
}
#[test]
fn test_health_serialization() {
let health = Health(100.0);
let bytes = health.serialize_sync().unwrap();
let deserialized = Health::deserialize_sync(&bytes).unwrap();
assert_eq!(health, deserialized);
}
#[test]
fn test_health_lww_merge_remote_newer() {
let mut local = Health(50.0);
let remote = Health(100.0);
let decision = local.merge(remote, ClockComparison::RemoteNewer);
assert_eq!(decision, ComponentMergeDecision::TookRemote);
assert_eq!(local.0, 100.0);
}
#[test]
fn test_health_lww_merge_local_newer() {
let mut local = Health(50.0);
let remote = Health(100.0);
let decision = local.merge(remote, ClockComparison::LocalNewer);
assert_eq!(decision, ComponentMergeDecision::KeptLocal);
assert_eq!(local.0, 50.0); // Local value kept
}
#[test]
fn test_health_lww_merge_concurrent() {
let mut local = Health(50.0);
let remote = Health(100.0);
let decision = local.merge(remote, ClockComparison::Concurrent);
// With concurrent, we use hash tiebreaker
// Either TookRemote or KeptLocal depending on hash
assert!(
decision == ComponentMergeDecision::TookRemote ||
decision == ComponentMergeDecision::KeptLocal
);
}
// Test 2: Struct with multiple fields
// rkyv traits are automatically added by the synced attribute!
#[sync_macros::synced(version = 1, strategy = "LastWriteWins")]
#[derive(Component, Reflect, Clone, Debug, PartialEq)]
#[reflect(Component)]
struct Position {
x: f32,
y: f32,
}
#[test]
fn test_position_compiles() {
let pos = Position { x: 10.0, y: 20.0 };
assert_eq!(pos.x, 10.0);
assert_eq!(pos.y, 20.0);
}
#[test]
fn test_position_serialization() {
let pos = Position { x: 10.0, y: 20.0 };
let bytes = pos.serialize_sync().unwrap();
let deserialized = Position::deserialize_sync(&bytes).unwrap();
assert_eq!(pos, deserialized);
}
#[test]
fn test_position_merge() {
let mut local = Position { x: 10.0, y: 20.0 };
let remote = Position { x: 30.0, y: 40.0 };
let decision = local.merge(remote, ClockComparison::RemoteNewer);
assert_eq!(decision, ComponentMergeDecision::TookRemote);
assert_eq!(local.x, 30.0);
assert_eq!(local.y, 40.0);
}