Files
k-frame/crates/domain/tests/value_tests.rs
Gabriel Kaszewski 26ebfad3a2 add SPA config UI, wire media/rss adapters, event-driven layout push
- React SPA: dashboard, data sources CRUD, widgets CRUD, layout builder,
  presets. TanStack Router + Query, shadcn/ui, Vite proxy to :3000
- wire media + rss adapters into polling loop, remove xtb source type
- media adapter: read username/password from headers, proper subsonic auth
- event handler: subscribe to LayoutChanged, push screen update to clients
- fix clippy warnings across workspace (Default impls, collapsible ifs,
  redundant closures, is_none_or, unused imports)
2026-06-19 00:12:42 +02:00

71 lines
1.9 KiB
Rust

use domain::Value;
use std::collections::BTreeMap;
#[test]
fn estimated_size_of_string_is_its_byte_length() {
let v = Value::String("hello".into());
assert_eq!(v.estimated_size(), 5);
}
#[test]
fn estimated_size_of_number_is_8_bytes() {
assert_eq!(Value::Number(3.14).estimated_size(), 8);
}
#[test]
fn estimated_size_of_null_and_bool_is_1() {
assert_eq!(Value::Null.estimated_size(), 1);
assert_eq!(Value::Bool(true).estimated_size(), 1);
}
#[test]
fn estimated_size_of_nested_structure_sums_recursively() {
let v = Value::Object(BTreeMap::from([
("key".into(), Value::String("value".into())),
("num".into(), Value::Number(1.0)),
]));
assert_eq!(v.estimated_size(), 19);
}
#[test]
fn estimated_size_of_array_sums_elements() {
let v = Value::Array(vec![Value::String("abc".into()), Value::Number(1.0)]);
assert_eq!(v.estimated_size(), 11);
}
#[test]
fn get_path_returns_none_for_missing_key() {
let data = Value::Object(BTreeMap::from([("main".into(), Value::Number(1.0))]));
assert_eq!(data.get_path("$.missing"), None);
}
#[test]
fn get_path_returns_none_when_traversing_non_object() {
let data = Value::Object(BTreeMap::from([("temp".into(), Value::Number(5.4))]));
assert_eq!(data.get_path("$.temp.nested"), None);
}
#[test]
fn get_path_accesses_array_by_index() {
let data = Value::Object(BTreeMap::from([(
"items".into(),
Value::Array(vec![
Value::String("first".into()),
Value::String("second".into()),
]),
)]));
assert_eq!(
data.get_path("$.items[1]"),
Some(&Value::String("second".into()))
);
}
#[test]
fn get_path_traverses_nested_object() {
let data = Value::Object(BTreeMap::from([(
"main".into(),
Value::Object(BTreeMap::from([("temp".into(), Value::Number(5.4))])),
)]));
assert_eq!(data.get_path("$.main.temp"), Some(&Value::Number(5.4)));
}