52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use client_domain::{FontMetrics, FontSize, wrap_lines};
|
||
|
||
fn metrics() -> FontMetrics {
|
||
FontMetrics {
|
||
small: (6, 10),
|
||
large: (10, 20),
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn text_that_fits_returns_single_line() {
|
||
// "hello" = 5 chars × 6px = 30px, available = 100px
|
||
let lines = wrap_lines("hello", 100, FontSize::Small, &metrics());
|
||
assert_eq!(lines, vec!["hello"]);
|
||
}
|
||
|
||
#[test]
|
||
fn text_wraps_at_word_boundary() {
|
||
// "hello world" = 11 chars × 6px = 66px, available = 40px
|
||
// "hello" = 30px fits, "world" = 30px fits on next line
|
||
let lines = wrap_lines("hello world", 40, FontSize::Small, &metrics());
|
||
assert_eq!(lines, vec!["hello", "world"]);
|
||
}
|
||
|
||
#[test]
|
||
fn long_word_breaks_by_character() {
|
||
// "abcdefghij" = 10 chars × 6px = 60px, available = 36px (6 chars)
|
||
let lines = wrap_lines("abcdefghij", 36, FontSize::Small, &metrics());
|
||
assert_eq!(lines, vec!["abcdef", "ghij"]);
|
||
}
|
||
|
||
#[test]
|
||
fn empty_text_returns_empty() {
|
||
let lines = wrap_lines("", 100, FontSize::Small, &metrics());
|
||
assert_eq!(lines, Vec::<&str>::new());
|
||
}
|
||
|
||
#[test]
|
||
fn multiple_words_wrap_across_lines() {
|
||
// available = 42px (7 chars)
|
||
// "one two three" → "one two" (7 chars = 42px), "three" (5 chars = 30px)
|
||
let lines = wrap_lines("one two three", 42, FontSize::Small, &metrics());
|
||
assert_eq!(lines, vec!["one two", "three"]);
|
||
}
|
||
|
||
#[test]
|
||
fn uses_large_font_metrics() {
|
||
// "hi" = 2 chars × 10px = 20px, available = 15px (1 char)
|
||
let lines = wrap_lines("hi", 15, FontSize::Large, &metrics());
|
||
assert_eq!(lines, vec!["h", "i"]);
|
||
}
|