chore(checkpoint): save current v0 build state

This commit is contained in:
slhx agent
2026-05-10 20:51:22 +02:00
parent e0484f8eb6
commit c4e02db5f8
25 changed files with 4095 additions and 508 deletions
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "slhx-test"
version.workspace = true
edition.workspace = true
[dependencies]
slhx-core = { path = "../slhx-core" }
+88
View File
@@ -0,0 +1,88 @@
use slhx_core::{Atom, BuildFingerprint, Effect, EffectBatch, Form, IntoEffect, KeyedSlot, ResourceId, ResourceRef, Slot};
pub fn run<I, F, R>(handler: F, input: I) -> EffectInspector
where
F: FnOnce(I) -> R,
R: IntoEffect,
{
inspect(handler(input))
}
pub fn inspect(effect: impl IntoEffect) -> EffectInspector {
EffectInspector {
batch: effect.into_batch(BuildFingerprint(0)),
}
}
#[derive(Clone, Debug)]
pub struct EffectInspector {
batch: EffectBatch,
}
impl EffectInspector {
pub fn batch(&self) -> &EffectBatch {
&self.batch
}
pub fn ops(&self) -> &[Effect] {
&self.batch.ops
}
pub fn contains(&self, op: &Effect) -> bool {
self.batch.ops.contains(op)
}
pub fn has_resource(&self, resource: ResourceId) -> bool {
self.batch
.ops
.iter()
.any(|op| op_targets_resource(op, resource))
}
pub fn has_ref(&self, target: &ResourceRef) -> bool {
self.batch.ops.iter().any(|op| op_targets_ref(op, target))
}
pub fn has_slot<T>(&self, slot: Slot<T>) -> bool {
self.has_resource(slot.id())
}
pub fn has_keyed_slot<K, T>(&self, slot: KeyedSlot<K, T>) -> bool
where
K: ToString,
{
self.has_resource(slot.id())
}
pub fn has_atom<T>(&self, atom: Atom<T>) -> bool {
self.has_resource(atom.id())
}
pub fn has_form<T>(&self, form: Form<T>) -> bool {
self.has_resource(form.id())
}
}
fn op_targets_resource(op: &Effect, resource: ResourceId) -> bool {
match op {
Effect::Put { target, .. }
| Effect::Insert { target, .. }
| Effect::Prepend { target, .. }
| Effect::Remove { target, .. }
| Effect::Move { target, .. }
| Effect::Focus { target } => target.resource == resource,
Effect::Navigate { .. } | Effect::Emit { .. } => false,
}
}
fn op_targets_ref(op: &Effect, wanted: &ResourceRef) -> bool {
match op {
Effect::Put { target, .. }
| Effect::Insert { target, .. }
| Effect::Prepend { target, .. }
| Effect::Remove { target, .. }
| Effect::Move { target, .. }
| Effect::Focus { target } => target == wanted,
Effect::Navigate { .. } | Effect::Emit { .. } => false,
}
}
+28
View File
@@ -0,0 +1,28 @@
use slhx_core::{Atom, Effect, KeyedSlot, Payload, ResourceRef, Slot};
#[test]
fn inspects_tuple_effects() {
let count = Slot::<u32>::new(1);
let user = Atom::<String>::new(2);
let inspected = slhx_test::run(
|value| (count.text(value), user.set("alice")),
42,
);
assert!(inspected.has_slot(count));
assert!(inspected.has_atom(user));
assert!(inspected.contains(&Effect::Put {
target: ResourceRef::unscoped(count.id()),
payload: Payload::text(42),
}));
}
#[test]
fn finds_keyed_slot_targets() {
let rows = KeyedSlot::<u32, String>::new(9);
let inspected = slhx_test::inspect(rows.append(7, "row"));
assert!(inspected.has_keyed_slot(rows));
assert_eq!(inspected.ops().len(), 1);
}