Server: domain (entities, value objects, ports), protocol (postcard wire types), application (config service, data projection), adapters (config-memory, tcp-server), bootstrap (composition root with fake data). Client: client-domain (layout engine, render tree, HAL ports), client-application (message handling, repaint commands), adapters (tcp-client, display-terminal), client-desktop (end-to-end working). ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking. Display test verified on hardware — landscape orientation, text rendering works. 60 workspace tests, all passing.
67 lines
1.8 KiB
Rust
67 lines
1.8 KiB
Rust
use std::collections::BTreeSet;
|
|
use domain::{
|
|
ContainerNode, Direction, Layout, LayoutChild, LayoutNode, LayoutValidationError, Sizing,
|
|
WidgetId,
|
|
};
|
|
|
|
fn leaf(id: WidgetId) -> LayoutChild {
|
|
LayoutChild {
|
|
sizing: Sizing::Flex(1),
|
|
node: LayoutNode::Leaf(id),
|
|
}
|
|
}
|
|
|
|
fn row(children: Vec<LayoutChild>) -> LayoutNode {
|
|
LayoutNode::Container(ContainerNode {
|
|
direction: Direction::Row,
|
|
gap: 0,
|
|
padding: 0,
|
|
children,
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn validate_returns_empty_when_all_widgets_exist() {
|
|
let layout = Layout { root: row(vec![leaf(1), leaf(2)]) };
|
|
let known = BTreeSet::from([1, 2]);
|
|
assert!(layout.validate(&known).is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn validate_reports_unknown_widget_ids() {
|
|
let layout = Layout { root: row(vec![leaf(1), leaf(99)]) };
|
|
let known = BTreeSet::from([1]);
|
|
let errors = layout.validate(&known);
|
|
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(99)]);
|
|
}
|
|
|
|
#[test]
|
|
fn validate_reports_empty_container() {
|
|
let layout = Layout { root: row(vec![]) };
|
|
let known = BTreeSet::new();
|
|
let errors = layout.validate(&known);
|
|
assert_eq!(errors, vec![LayoutValidationError::EmptyContainer]);
|
|
}
|
|
|
|
#[test]
|
|
fn validate_checks_nested_containers() {
|
|
let inner = LayoutChild {
|
|
sizing: Sizing::Flex(1),
|
|
node: row(vec![leaf(1), leaf(42)]),
|
|
};
|
|
let layout = Layout { root: row(vec![inner, leaf(2)]) };
|
|
let known = BTreeSet::from([1, 2]);
|
|
let errors = layout.validate(&known);
|
|
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(42)]);
|
|
}
|
|
|
|
#[test]
|
|
fn widget_ids_collects_all_leaf_ids() {
|
|
let inner = LayoutChild {
|
|
sizing: Sizing::Flex(1),
|
|
node: row(vec![leaf(3)]),
|
|
};
|
|
let layout = Layout { root: row(vec![leaf(1), inner, leaf(2)]) };
|
|
assert_eq!(layout.widget_ids(), BTreeSet::from([1, 2, 3]));
|
|
}
|