use kaolin::{
Kaolin, fit, fixed, grow, sizing,
style::{FlexStyle, TextStyle, layout::Layout},
};
mod common;
use common::*;
#[test]
#[should_panic(expected = "Negative")]
fn negative_fixed_width() {
let kaolin = Kaolin::new((800, 600), measure_text);
kaolin.draw(|k| {
k.with(
FlexStyle::new().sizing(sizing!(fixed!(-100.0), fixed!(50.0))),
|k| k,
)
});
}
#[test]
#[should_panic(expected = "Negative")]
fn negative_fixed_height() {
let kaolin = Kaolin::new((800, 600), measure_text);
kaolin.draw(|k| {
k.with(
FlexStyle::new().sizing(sizing!(fixed!(100.0), fixed!(-50.0))),
|k| k,
)
});
}
#[test]
#[should_panic(expected = "Negative")]
fn negative_growth_factor() {
let kaolin = Kaolin::new((800, 600), measure_text);
kaolin.draw(|k| k.with(FlexStyle::new().sizing(sizing!(grow!(-1.0))), |k| k));
}
#[test]
fn very_large_fixed_sizes() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw(|k| {
k.with(
FlexStyle::new().sizing(sizing!(fixed!(1_000_000.0), fixed!(1_000_000.0))),
|k| k,
)
});
assert_size!(commands.next(), (1_000_000.0, 1_000_000.0));
}
#[test]
fn very_small_positive_sizes() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw(|k| {
k.with(
FlexStyle::new().sizing(sizing!(fixed!(0.001), fixed!(0.001))),
|k| k,
)
});
assert_size!(commands.next(), (0.001, 0.001));
}
#[test]
#[should_panic(expected = "Negative")]
fn invalid_fit_constraints() {
let kaolin = Kaolin::new((800, 600), measure_text);
kaolin.draw(|k| {
k.with(
FlexStyle::new().sizing(sizing!(fit!(-10.0, 100.0))), |k| k,
)
});
}
#[test]
fn conflicting_sizing_requirements() {
let kaolin = Kaolin::new((100, 100), measure_text); let mut commands = kaolin.draw(|k| {
k.with(FlexStyle::new().sizing(sizing!(fixed!(200.0))), |k| k) .with(FlexStyle::new().sizing(sizing!(fixed!(200.0))), |k| k) });
assert_size!(commands.next(), (200.0, 200.0)); assert_size!(commands.next(), (200.0, 200.0)); }
#[test]
fn malformed_text_input() {
let kaolin = Kaolin::new((800, 600), measure_text);
let commands = kaolin.draw(|k| {
k.with(FlexStyle::new()
.sizing(sizing!(grow!()))
.layout(
Layout::new()
.direction(kaolin::style::layout::Direction::TopToBottom)
), |k| {
k.text("", TextStyle::new()) .text("Normal text", TextStyle::new())
.text("Text\nwith\nnewlines", TextStyle::new()) .text("Very long text that exceeds normal expectations for a single text element and might cause issues", TextStyle::new())
})
});
let mut commands = commands.skip(1);
assert_text_content!(commands.next(), "Normal text");
assert_text_content!(commands.next(), "Text");
assert_text_content!(commands.next(), "with");
assert_text_content!(commands.next(), "newlines");
assert_text_content!(
commands.next(),
"Very long text that exceeds normal expectations for a single text element and"
);
assert_text_content!(commands.next(), "might cause issues");
}
#[test]
fn layout_calculation_edge_cases() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw(|k| {
k.with(
FlexStyle::new()
.sizing(sizing!(fixed!(800.0), fixed!(600.0)))
.layout(Layout::new().gap(f64::MAX)), |k| {
k.text("First", TextStyle::new())
.text("Second", TextStyle::new())
},
)
});
assert_size!(commands.next(), (800.0, 600.0)); }