use proptest::prelude::*;
use crate::platform::PlatformTextSystem;
use crate::{FontId, FontRun, NoopTextSystem};
fn non_empty_text_strategy() -> impl Strategy<Value = String> {
"[\\x20-\\x7E]{1,200}"
}
fn font_size_strategy() -> impl Strategy<Value = f32> {
1.0f32..=200.0
}
proptest! {
#![proptest_config(ProptestConfig::with_cases(100))]
#[test]
fn text_layout_produces_valid_metrics(
text in non_empty_text_strategy(),
font_size_val in font_size_strategy(),
) {
let text_system = NoopTextSystem;
let font_size = crate::px(font_size_val);
let runs = vec![FontRun {
len: text.len(),
font_id: FontId(0),
}];
let layout = text_system.layout_line(&text, font_size, &runs);
prop_assert!(
layout.width.0 >= 0.0,
"layout width must be non-negative, got {}",
layout.width.0
);
prop_assert!(
layout.ascent.0.is_finite(),
"layout ascent must be finite, got {}",
layout.ascent.0
);
prop_assert!(
layout.descent.0.is_finite(),
"layout descent must be finite, got {}",
layout.descent.0
);
prop_assert_eq!(
layout.len,
text.len(),
"layout len must equal input text byte length"
);
}
}