f-office-docx 0.2.3

DOCX model and Word's layout rules.
Documentation
//! The narrowest piece of a line beside a frame that the text flows around, by compatibility
//! mode.

use f_office_units::Length;

use crate::layout::testing::{on_base, pass_with};
use crate::numbering::Numbering;

/// The left edge of the text of the first line beside a frame, in the compatibility mode `mode`,
/// when the frame leaves `piece` twips between the left margin and its left side.
fn first_edge(piece: u32, mode: u32) -> Option<Length> {
    let words = ["nnn"; 40].join(" ");
    let body = format!(
        r#"<w:p><w:pPr><w:framePr w:w="2000" w:wrap="around" w:vAnchor="text" w:hAnchor="margin" w:x="{piece}" w:y="0"/></w:pPr><w:r><w:t>q</w:t></w:r></w:p><w:p><w:r><w:t>{words}</w:t></w:r></w:p>"#
    );
    let pass = pass_with(
        &body,
        ("", Some(mode)),
        None,
        Numbering::default(),
        on_base(),
    );
    pass.lines
        .iter()
        .find(|line| line.text.text.starts_with("nnn"))
        .map(|line| line.text.left)
}

#[test]
fn leaves_a_piece_narrower_than_an_inch_beside_a_frame_empty_before_mode_15() {
    let margin = first_edge(1_500, 14);
    assert_eq!(margin, first_edge(1_440, 14));
    assert!(first_edge(1_430, 14) > margin);
    assert!(first_edge(400, 14) > margin);
}

#[test]
fn fills_a_narrow_piece_beside_a_frame_from_mode_15() {
    let margin = first_edge(1_500, 15);
    assert_eq!(margin, first_edge(1_430, 15));
    assert_eq!(margin, first_edge(400, 15));
}