use crate::*;
#[test]
fn gap() {
assert_xml!(
r#"
<div style="display: flex; width: 100px; gap: 10px;">
<div style="height: 10px; flex: 1" expect_width="45"></div>
<div style="height: 10px; flex: 1" expect_width="45" expect_left="55"></div>
</div>
"#
)
}
#[test]
fn column_gap_in_flex_row_box() {
assert_xml!(
r#"
<div style="display: flex; flex-direction: row; width: 100px; height: 100px; column-gap: 10px;">
<div style="width: 20px; height: 20px;" expect_left="0"></div>
<div style="width: 20px; height: 20px;" expect_left="30"></div>
</div>
"#
)
}
#[test]
fn column_gap_with_percentage_in_flex_row_box() {
assert_xml!(
r#"
<div style="display: flex; flex-direction: row; width: 200px; height: 100px; column-gap: 10%; align-items: flex-start">
<div style="width: 20px; height: 20px;" expect_left="0"></div>
<div style="width: 20px; height: 20px;" expect_left="40"></div>
</div>
"#
)
}
#[test]
fn column_gap_in_flex_column_box() {
assert_xml!(
r#"
<div style="display: flex; flex-direction: column; width: 100px; height: 20px; column-gap: 10px; flex-wrap: wrap;">
<div style="width: 20px; height: 20px;" expect_left="0"></div>
<div style="width: 20px; height: 20px;" expect_left="55"></div>
</div>
"#
)
}
#[test]
fn column_gap_in_flex_column_box_with_align_content_flex_start() {
assert_xml!(
r#"
<div style="display: flex; flex-direction: column; width: 100px; height: 20px; column-gap: 10px; flex-wrap: wrap; align-content: flex-start">
<div style="width: 20px; height: 20px;" expect_left="0"></div>
<div style="width: 20px; height: 20px;" expect_left="30"></div>
</div>
"#
)
}
#[test]
fn column_gap_with_percentage_in_flex_column_box_with_align_content_flex_start() {
assert_xml!(
r#"
<div style="display: flex; flex-direction: column; width: 100px; height: 20px; column-gap: 10%; flex-wrap: wrap; align-content: flex-start">
<div style="width: 20px; height: 20px; flex-shrink: 0" expect_left="0"></div>
<div style="width: 20px; height: 20px; flex-shrink: 0" expect_left="30"></div>
</div>
"#
)
}
#[test]
fn row_gap_in_flex_row_box() {
assert_xml!(
r#"
<div style="display: flex; flex-direction:row; width: 100px; height: 100px; row-gap: 10px; flex-wrap: wrap;">
<div style="height: 10px; width: 50px;" expect_left="0" expect_top="0"></div>
<div style="height: 10px; width: 50px;" expect_left="50" expect_top="0"></div>
<div style="height: 10px; width: 50px;" expect_left="0" expect_top="55"></div>
<div style="height: 10px; width: 50px;" expect_left="50" expect_top="55"></div>
</div>
"#
)
}
#[test]
fn row_gap_in_flex_row_box_with_align_content_flex_start() {
assert_xml!(
r#"
<div style="display: flex; flex-direction:row; width: 100px; height: 100px; row-gap: 10px; flex-wrap: wrap; align-content: flex-start;">
<div style="height: 10px; width: 50px;" expect_left="0"></div>
<div style="height: 10px; width: 50px;" expect_left="50"></div>
<div style="height: 10px; width: 50px;" expect_left="0" expect_top="20"></div>
<div style="height: 10px; width: 50px;" expect_left="50" expect_top="20"></div>
</div>
"#
)
}
#[test]
fn row_gap_with_percentage_in_flex_row_box_with_align_content_flex_start() {
assert_xml!(
r#"
<div style="display: flex; flex-direction:row; width: 100px; height: 100px; row-gap: 10%; flex-wrap: wrap; align-content: flex-start;">
<div style="height: 10px; width: 50px;" expect_left="0"></div>
<div style="height: 10px; width: 50px;" expect_left="50"></div>
<div style="height: 10px; width: 50px;" expect_left="0" expect_top="20"></div>
<div style="height: 10px; width: 50px;" expect_left="50" expect_top="20"></div>
</div>
"#
)
}
#[test]
fn row_gap_in_flex_column_box() {
assert_xml!(
r#"
<div style="display: flex; flex-direction: column; width: 100px; height: 100px; row-gap: 10px;">
<div style="width: 100px; height: 30px;"></div>
<div style="width: 100px; height: 30px;"expect_top="40"></div>
</div>
"#
)
}
#[test]
fn row_gap_with_percentage_in_flex_column_box() {
assert_xml!(
r#"
<div style="display: flex; flex-direction: column; width: 100px; height: 100px; row-gap: 10%;">
<div style="width: 100px; height: 30px;"></div>
<div style="width: 100px; height: 30px;"expect_top="40"></div>
</div>
"#
)
}
#[test]
fn flex_item_with_gap_should_shrink_to_fit() {
assert_xml!(
r#"
<div style="display: flex; width: 100px; height: 50px; flex-direction: column; gap: 10px;" expect_height="50">
<div style="height: 30px;" expect_top="0" expect_height="20"></div>
<div style="height: 30px;" expect_top="30" expect_height="20"></div>
</div>
"#
)
}
#[test]
fn gap_with_flex_grow_sum_below_one_should_not_double_subtract_gap() {
assert_xml!(
r#"
<div style="display: flex; width: 200px; gap: 20px;">
<div style="width: 50px; height: 20px; flex-grow: 0.2;" expect_width="66" expect_left="0"></div>
<div style="width: 50px; height: 20px; flex-grow: 0.2;" expect_width="66" expect_left="86"></div>
</div>
"#
)
}
#[test]
fn gap_with_flex_shrink_sum_below_one_should_not_double_subtract_gap() {
assert_xml!(
r#"
<div style="display: flex; width: 200px; gap: 20px;">
<div style="width: 150px; height: 20px; flex-shrink: 0.2;" expect_width="126" expect_left="0"></div>
<div style="width: 150px; height: 20px; flex-shrink: 0.2;" expect_width="126" expect_left="146"></div>
</div>
"#
)
}
#[test]
fn nested_flex_gap_with_space_between_should_keep_text_unwrapped() {
assert_xml!(
r#"
<div style="display: block; width: 300px; padding: 30px;">
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: center;">
<div style="display: flex; flex-direction: row; align-items: center; gap: 30px;" expect_width="124" expect_left="0">
<div style="height: 30px; width: 30px;" expect_width="30" expect_left="0"></div>
<text-slot len="4" expect_width="64" expect_left="60" expect_height="16"></text-slot>
</div>
<div style="display: flex; flex-direction: row;" expect_left="236">
<text-slot len="4" expect_width="64" expect_height="16"></text-slot>
</div>
</div>
</div>
"#,
true
)
}