use azul_css::props::layout::LayoutDisplay;
fn check_display(display: LayoutDisplay, expected: LayoutDisplay) -> bool {
display == expected
}
#[test]
fn test_whitespace_detection_empty_string() {
let text = "";
assert!(text.chars().all(|c| c.is_whitespace()));
}
#[test]
fn test_whitespace_detection_spaces() {
let text = " \t\n ";
assert!(text.chars().all(|c| c.is_whitespace()));
}
#[test]
fn test_whitespace_detection_with_content() {
let text = " hello ";
assert!(!text.chars().all(|c| c.is_whitespace()));
}
#[test]
fn test_whitespace_detection_unicode_spaces() {
let text = "\u{00A0}\u{2003}\u{2009}"; assert!(text.chars().all(|c| c.is_whitespace()));
}
#[test]
fn test_display_type_table() {
let display = LayoutDisplay::Table;
assert!(check_display(display, LayoutDisplay::Table));
assert!(!check_display(display, LayoutDisplay::Block));
}
#[test]
fn test_display_type_table_row() {
let display = LayoutDisplay::TableRow;
assert!(check_display(display, LayoutDisplay::TableRow));
assert!(!check_display(display, LayoutDisplay::Table));
}
#[test]
fn test_display_type_table_cell() {
let display = LayoutDisplay::TableCell;
assert!(check_display(display, LayoutDisplay::TableCell));
assert!(!check_display(display, LayoutDisplay::TableRow));
}
#[test]
fn test_display_type_row_groups() {
let thead = LayoutDisplay::TableHeaderGroup;
let tbody = LayoutDisplay::TableRowGroup;
let tfoot = LayoutDisplay::TableFooterGroup;
assert!(check_display(thead, LayoutDisplay::TableHeaderGroup));
assert!(check_display(tbody, LayoutDisplay::TableRowGroup));
assert!(check_display(tfoot, LayoutDisplay::TableFooterGroup));
}
#[test]
fn test_table_structural_elements() {
let structural = vec![
LayoutDisplay::Table,
LayoutDisplay::TableRowGroup,
LayoutDisplay::TableHeaderGroup,
LayoutDisplay::TableFooterGroup,
LayoutDisplay::TableRow,
];
for display in structural {
assert!(matches!(
display,
LayoutDisplay::Table
| LayoutDisplay::TableRowGroup
| LayoutDisplay::TableHeaderGroup
| LayoutDisplay::TableFooterGroup
| LayoutDisplay::TableRow
));
}
}
#[test]
fn test_non_structural_elements() {
let non_structural = vec![
LayoutDisplay::Block,
LayoutDisplay::Inline,
LayoutDisplay::InlineBlock,
LayoutDisplay::TableCell,
LayoutDisplay::None,
];
for display in non_structural {
assert!(!matches!(
display,
LayoutDisplay::Table
| LayoutDisplay::TableRowGroup
| LayoutDisplay::TableHeaderGroup
| LayoutDisplay::TableFooterGroup
| LayoutDisplay::TableRow
));
}
}
#[test]
fn test_stage2_cell_wrapping_needed() {
let parent = LayoutDisplay::TableRow;
let child = LayoutDisplay::Block;
assert!(parent == LayoutDisplay::TableRow);
assert!(child != LayoutDisplay::TableCell);
}
#[test]
fn test_stage2_cell_wrapping_not_needed() {
let parent = LayoutDisplay::TableRow;
let child = LayoutDisplay::TableCell;
assert!(parent == LayoutDisplay::TableRow);
assert!(child == LayoutDisplay::TableCell);
}
#[test]
fn test_stage2_row_wrapping_needed() {
let parent = LayoutDisplay::Table;
let child = LayoutDisplay::TableCell;
assert!(parent == LayoutDisplay::Table);
assert!(child == LayoutDisplay::TableCell);
}
#[test]
fn test_stage2_row_wrapping_not_needed() {
let parent = LayoutDisplay::Table;
let child = LayoutDisplay::TableRow;
assert!(parent == LayoutDisplay::Table);
assert!(child == LayoutDisplay::TableRow);
}
#[test]
fn test_stage3_cell_needs_row_parent() {
let parent = LayoutDisplay::Block;
let child = LayoutDisplay::TableCell;
assert!(child == LayoutDisplay::TableCell);
assert!(parent != LayoutDisplay::TableRow);
assert!(parent != LayoutDisplay::TableRowGroup);
}
#[test]
fn test_stage3_row_needs_table_parent() {
let parent = LayoutDisplay::Block;
let child = LayoutDisplay::TableRow;
assert!(child == LayoutDisplay::TableRow);
assert!(parent != LayoutDisplay::Table);
assert!(parent != LayoutDisplay::TableRowGroup);
}
#[test]
fn test_stage3_rowgroup_needs_table_parent() {
let parent = LayoutDisplay::Block;
let child = LayoutDisplay::TableRowGroup;
assert!(matches!(
child,
LayoutDisplay::TableRowGroup
| LayoutDisplay::TableHeaderGroup
| LayoutDisplay::TableFooterGroup
));
assert!(parent != LayoutDisplay::Table);
}
#[test]
fn test_stage3_cell_in_row_no_wrapper() {
let parent = LayoutDisplay::TableRow;
let child = LayoutDisplay::TableCell;
assert!(child == LayoutDisplay::TableCell);
assert!(parent == LayoutDisplay::TableRow);
}
#[test]
fn test_stage3_cell_in_rowgroup_no_wrapper() {
let parent = LayoutDisplay::TableRowGroup;
let child = LayoutDisplay::TableCell;
assert!(child == LayoutDisplay::TableCell);
assert!(matches!(
parent,
LayoutDisplay::TableRowGroup
| LayoutDisplay::TableHeaderGroup
| LayoutDisplay::TableFooterGroup
));
}
#[test]
fn test_stage3_row_in_table_no_wrapper() {
let parent = LayoutDisplay::Table;
let child = LayoutDisplay::TableRow;
assert!(child == LayoutDisplay::TableRow);
assert!(parent == LayoutDisplay::Table);
}
#[test]
fn test_stage3_row_in_rowgroup_no_wrapper() {
let parent = LayoutDisplay::TableRowGroup;
let child = LayoutDisplay::TableRow;
assert!(child == LayoutDisplay::TableRow);
assert!(matches!(
parent,
LayoutDisplay::TableRowGroup
| LayoutDisplay::TableHeaderGroup
| LayoutDisplay::TableFooterGroup
));
}
#[test]
fn test_stage3_rowgroup_in_table_no_wrapper() {
let parent = LayoutDisplay::Table;
let child = LayoutDisplay::TableRowGroup;
assert!(matches!(
child,
LayoutDisplay::TableRowGroup
| LayoutDisplay::TableHeaderGroup
| LayoutDisplay::TableFooterGroup
));
assert!(parent == LayoutDisplay::Table);
}
#[test]
fn test_complex_scenario_cell_in_block() {
let parent = LayoutDisplay::Block;
let child = LayoutDisplay::TableCell;
assert!(child == LayoutDisplay::TableCell);
assert!(parent != LayoutDisplay::TableRow);
let anonymous_row = LayoutDisplay::TableRow;
assert!(anonymous_row == LayoutDisplay::TableRow);
assert!(parent != LayoutDisplay::Table);
}
#[test]
fn test_complex_scenario_mixed_children() {
let parent = LayoutDisplay::Table;
let child1 = LayoutDisplay::TableRow;
let child2 = LayoutDisplay::TableCell;
let child3 = LayoutDisplay::TableCell;
let child4 = LayoutDisplay::TableRow;
assert!(child1 == LayoutDisplay::TableRow);
assert!(child2 == LayoutDisplay::TableCell);
assert!(child3 == LayoutDisplay::TableCell);
assert!(child4 == LayoutDisplay::TableRow);
}
#[test]
fn test_edge_case_nested_tables() {
let outer_table = LayoutDisplay::Table;
let row = LayoutDisplay::TableRow;
let cell = LayoutDisplay::TableCell;
let inner_table = LayoutDisplay::Table;
assert!(outer_table == LayoutDisplay::Table);
assert!(row == LayoutDisplay::TableRow);
assert!(cell == LayoutDisplay::TableCell);
assert!(inner_table == LayoutDisplay::Table);
}
#[test]
fn test_edge_case_empty_table() {
let display = LayoutDisplay::Table;
assert!(display == LayoutDisplay::Table);
}
#[test]
fn test_edge_case_table_with_only_whitespace() {
let _parent = LayoutDisplay::Table;
let whitespace1 = " ";
let whitespace2 = "\n\t";
assert!(whitespace1.chars().all(|c| c.is_whitespace()));
assert!(whitespace2.chars().all(|c| c.is_whitespace()));
}
#[test]
fn test_all_stages_integration() {
let parent = LayoutDisplay::Block;
let whitespace = " ";
let child = LayoutDisplay::TableCell;
assert!(whitespace.chars().all(|c| c.is_whitespace()));
assert!(child == LayoutDisplay::TableCell);
assert!(parent != LayoutDisplay::TableRow);
let anon_row = LayoutDisplay::TableRow;
assert!(anon_row == LayoutDisplay::TableRow);
assert!(parent != LayoutDisplay::Table);
}
#[test]
fn test_caption_not_wrapped() {
let parent = LayoutDisplay::Table;
let caption = LayoutDisplay::TableCaption;
assert!(parent == LayoutDisplay::Table);
assert!(caption == LayoutDisplay::TableCaption);
}
#[test]
fn test_column_group_not_wrapped() {
let parent = LayoutDisplay::Table;
let colgroup = LayoutDisplay::TableColumnGroup;
assert!(parent == LayoutDisplay::Table);
assert!(colgroup == LayoutDisplay::TableColumnGroup);
}
#[test]
fn test_column_not_wrapped() {
let parent = LayoutDisplay::TableColumnGroup;
let col = LayoutDisplay::TableColumn;
assert!(parent == LayoutDisplay::TableColumnGroup);
assert!(col == LayoutDisplay::TableColumn);
}