Merge pull request #10440 from dotCooCoo/fix/test-tolerances-text-color

Tests: tighten loose bounds in color and text tests
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-01 06:50:03 -08:00
commit dd144f7cab
4 files changed
+32 -27

No files matched your search

+3 -1
View File
@@ -685,7 +685,9 @@ mod tests {
let mid = f.split_line(0, 0, 0.5).unwrap();
assert_eq!((mid, &f.lines[0]), (3, &vec![0, 3, 1, 2]));
let p = f.points[3];
assert!(p.at.y.abs() < 1e-9 && p.at.x > 0.0 && p.at.x < 100.0 && (p.opacity - 0.75).abs() < 1e-6, "on the curve, half way: {p:?}");
// The Catmull-Rom segment from (0, 0) to (100, 0), with (200, 0) after it, is at x = 43.75
// half way, not at the straight line's 50.
assert!(p.at.y.abs() < 1e-9 && (p.at.x - 43.75).abs() < 1e-9 && (p.opacity - 0.75).abs() < 1e-6, "on the curve, half way: {p:?}");
assert!(f.remove_point(1));
assert_eq!(f.lines, vec![vec![0, 2, 1]]);
assert!(f.add_line(vec![0, 9]).is_err() && f.add_line(vec![0]).is_err());
+1 -1
View File
@@ -1379,7 +1379,7 @@ fn diamond_pixels_follow_the_squares() {
g.geom = Some(diamond_at(Point::new(2.5, 2.5), 2.5, 1.0));
let px: Vec<[u8; 4]> = g.pixels(b, b, 5, 5, false, &Color::to_rgb).collect();
// White at the center, black in the corners, and the same on each side of it.
assert!(px[2 * 5 + 2][0] > 200 && px[0][0] < 10 && px[24][0] < 10, "{px:?}");
assert_eq!((px[2 * 5 + 2], px[0], px[24]), ([255, 255, 255, 255], [0, 0, 0, 255], [0, 0, 0, 255]), "{px:?}");
assert_eq!(px[2 * 5 + 1], px[2 * 5 + 3]);
assert_eq!(px[5 + 2], px[3 * 5 + 2]);
assert_eq!(px[2 * 5 + 1], px[5 + 2]);
+1 -1
View File
@@ -104,7 +104,7 @@ fn ruby_is_half_the_base_size_by_default_and_size_follows_the_span() {
whole.ruby[0].size_percent = 100.0;
let half = ruby_ink(&layout(db(), &half));
let whole = ruby_ink(&layout(db(), &whole));
assert!(half.height() < whole.height() * 0.75, "{} vs {}", half.height(), whole.height());
assert!((half.height() / whole.height() - 0.5).abs() < 1e-6, "{} vs {}", half.height(), whole.height());
}
#[test]
+27 -24
View File
@@ -562,8 +562,13 @@ fn caret_up_down_keeps_column() {
let (top, _) = caret_position(&l, b);
let down = caret_vertical(&l, b, 1, top.x);
assert_eq!(l.line_of(down), 3);
// The caret lands on the stop of line 3 nearest the column, not on a neighbor.
let (t2, _) = caret_position(&l, down);
assert!((t2.x - top.x).abs() < 12.0, "{} vs {}", t2.x, top.x);
let nearest = (l.lines[3].start..=l.lines[3].end)
.filter(|&i| COPY.is_char_boundary(i) && l.line_of(i) == 3)
.map(|i| (caret_position(&l, i).0.x - top.x).abs())
.fold(f64::INFINITY, f64::min);
assert!(((t2.x - top.x).abs() - nearest).abs() < 1e-6, "{} vs {} (nearest stop {nearest} away)", t2.x, top.x);
let up = caret_vertical(&l, down, -1, top.x);
assert_eq!(up, b);
assert_eq!(caret_vertical(&l, b, -10, top.x), 0);
@@ -1267,34 +1272,32 @@ fn hyphenation_zone_breaks_before_the_word_with_the_single_line_composer() {
assert_eq!(line_texts(&every, &layout(db(), &every)), without);
}
/// The default Hyphenation options keep the line breaks of hyphenated text: the copy twice over
/// at three widths, ragged and justified, with either composer. The constant is an FNV-1a hash of
/// each line's end and whether it ends with a hyphen. It changed once since: justified lines
/// follow the default Justification options (word spacing up to 133%, where the composer used
/// to stretch spaces to 150%), and the every-line composer no longer gives up on loose lines.
/// With the default Hyphenation options, ragged and justified, with either composer: "The
/// language" in a frame that holds "The lan-" breaks as "The lan-" and "guage", only the first
/// line ends with a hyphen. The 6-letter "garden" (longer than the default 5 letters) breaks the
/// same way, as "The gar-" and "den".
#[test]
fn default_hyphenation_options_keep_the_line_breaks() {
let mut hash: u64 = 0xcbf2_9ce4_8422_2325;
let mut mix = |v: u64| {
for b in v.to_le_bytes() {
hash = (hash ^ u64::from(b)).wrapping_mul(0x0100_0000_01b3);
}
let ends_with_hyphen = |l: &TextLayout| -> Vec<bool> {
l.lines.iter().map(|li| li.glyph_end > li.glyph_start && l.glyphs.get(li.glyph_end - 1).is_some_and(|g| g.len == 0)).collect()
};
for width in [150.0, 190.0, 240.0] {
for justify in [Justify::Left, Justify::JustifyLeft] {
for composer in [Composer::SingleLine, Composer::EveryLine] {
let mut t = area(&COPY.repeat(2), style(12.0), Rect::new(0.0, 0.0, width, 4000.0), justify);
t.para.hyphenate = true;
t.para.composer = composer;
let l = layout(db(), &t);
for li in &l.lines {
let hyphenated = li.glyph_end > li.glyph_start && l.glyphs.get(li.glyph_end - 1).is_some_and(|g| g.len == 0);
mix(li.end as u64 * 2 + u64::from(hyphenated));
}
}
for justify in [Justify::Left, Justify::JustifyLeft] {
for composer in [Composer::SingleLine, Composer::EveryLine] {
let mut t = the_language("language", composer);
t.para.justify = justify;
let l = layout(db(), &t);
assert_eq!(line_texts(&t, &l), ["The lan", "guage"], "{justify:?} {composer:?}");
assert_eq!(ends_with_hyphen(&l), [true, false], "{justify:?} {composer:?}");
let w = natural_width("The gar-", 12.0).max(natural_width("garden", 12.0)) + 1.0;
assert!(w < natural_width("The garden", 12.0));
let mut t = area("The garden", style(12.0), Rect::new(0.0, 0.0, w, 400.0), justify);
t.para.hyphenate = true;
t.para.composer = composer;
let l = layout(db(), &t);
assert_eq!(line_texts(&t, &l), ["The gar", "den"], "{justify:?} {composer:?}");
assert_eq!(ends_with_hyphen(&l), [true, false], "{justify:?} {composer:?}");
}
}
assert_eq!(hash, 4_188_642_633_634_327_633);
}
/// The longest run of consecutive lines of `l` that end with a hyphen.