Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / css / tests_css_values_units_1.lucb

#==============================================================================================
#
#   tests_css_values_units_1 - the oracle dump of region r36 (CSS values and units), part 1
#
#   DESCRIPTION:
#       Ladybird has no unit tests for Length, Angle, Display and the other values of region
#       r36 (TestCSSPixels.cpp is luce-browser-render's). The test "the values and units
#       print what the reference build prints" (tests_css_values_units_2) builds the same
#       dump as the local oracle (luce-browser-tools/oracles/luce-browser-engine/
#       css_values_units/oracle.cpp, which runs the reference build's LibWeb) and compares it
#       line by line with the oracle's output (tests_css_values_units_expected). Doubles and
#       floats are printed as their bits, CSSPixels as raw values, colors as ARGB. This part
#       holds the printing helpers and the sections for lengths, the other dimensions,
#       percentages, ratios, numeric ranges, displays, system colors, sizing, edge rects,
#       sizes, length-percentages and grids; part 2 the rest.
#
#==============================================================================================

# mark: Printing ================================================================================

## Append `text`.
func tw(out: ak.StringBuilder*, text: str):
    ak.string_builder_append(out, text)

## Append a StringView.
func tv(out: ak.StringBuilder*, text: ak.StringView):
    ak.string_builder_append_string_view(out, text)

## Append a String.
func ts(out: ak.StringBuilder*, text: ak.String):
    ak.string_builder_append_string_view(out, ak.string_bytes_as_string_view(&text))

## Append a FlyString.
func tfly(out: ak.StringBuilder*, text: ak.FlyString):
    ak.string_builder_append_string_view(out, ak.fly_string_bytes_as_string_view(&text))

## Append `value` as `digits` hexadecimal digits.
func thex(out: ak.StringBuilder*, value: u64, digits: u32):
    var shift = digits * 4
    while shift > 0:
        shift -= 4
        let nibble = (u8)((value >> (u64)shift) & 15)
        ak.string_builder_append_u8(out, (u8)('0' + nibble) if nibble < 10 else (u8)('a' + nibble - 10))

## Append the bits of a double.
func td(out: ak.StringBuilder*, value: f64):
    thex(out, value.bits(), 16)

## Append the bits of a float.
func tf(out: ak.StringBuilder*, value: f32):
    thex(out, (u64)value.bits(), 8)

## Append an integer in decimal.
func tn(out: ak.StringBuilder*, value: i64):
    var buffer: u8[32]
    let text = format(buffer, f"{value}") else trap("an integer's digits")
    ak.string_builder_append(out, text)

## Append a CSSPixels' raw value.
func tpx(out: ak.StringBuilder*, value: gfx.CssPixels):
    tn(out, (i64)value.raw_value())

## Append "1" or "0".
func tb(out: ak.StringBuilder*, value: bool):
    ak.string_builder_append(out, "1" if value else "0")

## End the line.
func tl(out: ak.StringBuilder*):
    ak.string_builder_append_u8(out, '\n')

## The values every dimension is printed with: 0, 1.5, -2.25, 0.1, 100, 1e10, 1/3.
let test_css_values: f64[7] = [0.0, 1.5, -2.25, 0.1, 100.0, 1e10, 1.0 / 3.0]

# mark: Lengths =================================================================================

## The oracle's font metrics.
func test_font_metrics() -> CssLengthFontMetrics:
    let metrics = web_fonts.FontPixelMetrics(size = 16.0, x_height = 7.5, advance_of_ascii_zero = 9.25, ascent = 12.796875, descent = 0.0, line_gap = 0.0)
    return css_length_font_metrics_new(gfx.css_pixels_from_int(16), metrics, gfx.css_pixels_from_f64(18.5))

## The oracle's root font metrics.
func test_root_font_metrics() -> CssLengthFontMetrics:
    let metrics = web_fonts.FontPixelMetrics(size = 20.0, x_height = 8.0, advance_of_ascii_zero = 10.0, ascent = 15.0, descent = 0.0, line_gap = 0.0)
    return css_length_font_metrics_new(gfx.css_pixels_from_int(20), metrics, gfx.css_pixels_from_int(22))

func test_dump_lengths(out: ak.StringBuilder*):
    tw(out, "# lengths")
    tl(out)
    var viewport: gfx.CssPixelRect = ---
    gfx.css_pixel_rect_construct_int(&viewport, 0, 0, 800, 600)
    let context = CssLengthResolutionContext(viewport_rect = viewport, font_metrics = test_font_metrics(), root_font_metrics = test_root_font_metrics())
    let metrics = test_font_metrics()
    tw(out, "metrics ")
    tpx(out, metrics.font_size)
    tw(out, " ")
    tpx(out, metrics.x_height)
    tw(out, " ")
    tpx(out, metrics.cap_height)
    tw(out, " ")
    tpx(out, metrics.zero_advance)
    tw(out, " ")
    tpx(out, metrics.line_height)
    tl(out)
    for unit_index: u8 in 0..=(u8)css_data.LengthUnit.vw:
        let unit_ = (css_data.LengthUnit)unit_index
        for value in test_css_values:
            let length = css_length_new(value, unit_)
            tfly(out, css_length_unit_name(&length))
            tw(out, " ")
            td(out, value)
            tw(out, " ")
            tb(out, css_length_is_px(&length))
            tb(out, css_length_is_absolute(&length))
            tb(out, css_length_is_font_relative(&length))
            tb(out, css_length_is_viewport_relative(&length))
            tb(out, css_length_is_relative(&length))
            tb(out, css_length_is_computationally_independent(&length))
            tw(out, " ")
            ts(out, css_length_to_string(&length))
            tw(out, " ")
            ts(out, css_length_to_string(&length, css_syntax.SerializationMode.resolved_value))
            tw(out, " ")
            tpx(out, css_length_to_px_css_length_resolution_context(&length, context))
            tw(out, " ")
            td(out, css_length_to_px_without_rounding(&length, context))
            tw(out, " ")
            if let absolutized = css_length_absolutize(&length, context):
                ts(out, css_length_to_string(&absolutized))
            else:
                tw(out, "none")
            tw(out, " ")
            tb(out, css_length_eq(&length, css_length_new(value, unit_)))
            tb(out, css_length_eq(&length, css_length_make_px_f64(value)))
            tl(out)
    let em = css_length_new(12.0, css_data.LengthUnit.em)
    tw(out, "percentage_of ")
    let quarter = css_length_percentage_of(&em, css_percentage_new(25.0))
    ts(out, css_length_to_string(&quarter))
    tl(out)
    tw(out, "make_px ")
    let made = css_length_make_px_css_pixels(gfx.css_pixels_from_raw(97))
    ts(out, css_length_to_string(&made))
    tl(out)
    let auto_ = css_length_or_auto_make_auto()
    let length_or_auto = css_length_or_auto_new(css_length_new(3.0, css_data.LengthUnit.rem))
    tw(out, "length_or_auto ")
    ts(out, css_length_or_auto_to_string(&auto_))
    tw(out, " ")
    tb(out, css_length_or_auto_is_auto(&auto_))
    tb(out, css_length_or_auto_is_length(&auto_))
    tb(out, css_length_or_auto_is_font_relative(&auto_))
    tb(out, css_length_or_auto_is_computationally_independent(&auto_))
    tw(out, " ")
    ts(out, css_length_or_auto_to_string(&length_or_auto))
    tw(out, " ")
    tb(out, css_length_or_auto_is_auto(&length_or_auto))
    tb(out, css_length_or_auto_is_length(&length_or_auto))
    tb(out, css_length_or_auto_is_font_relative(&length_or_auto))
    tb(out, css_length_or_auto_is_computationally_independent(&length_or_auto))
    tw(out, " ")
    tb(out, auto_ == css_length_or_auto_make_auto())
    tb(out, auto_ == length_or_auto)
    tl(out)

# mark: The other dimensions ====================================================================

## One dimension's line: unit, value, canonical value, serializations, `<=>` and `==` against the
## reference, and the 150% of it.
func test_dimension_line(out: ak.StringBuilder*, unit_name: ak.FlyString, value: f64, canonical: f64, normal: ak.String, resolved: ak.String, cmp: i32, eq: bool, percentage_of: ak.String?):
    tfly(out, unit_name)
    tw(out, " ")
    td(out, value)
    tw(out, " ")
    td(out, canonical)
    tw(out, " ")
    ts(out, normal)
    tw(out, " ")
    ts(out, resolved)
    tw(out, " ")
    tn(out, (i64)cmp)
    tw(out, " ")
    tb(out, eq)
    if let text = percentage_of:
        tw(out, " ")
        ts(out, text)
    tl(out)

func test_dump_units(out: ak.StringBuilder*):
    let one_fifty = css_percentage_new(150.0)
    tw(out, "# angles")
    tl(out)
    let degrees_90 = css_angle_make_degrees(90.0)
    for unit_index: u8 in 0..=(u8)css_data.AngleUnit.turn:
        for value in test_css_values:
            let angle = css_angle_new(value, (css_data.AngleUnit)unit_index)
            let percentage_of = css_angle_percentage_of(&angle, one_fifty)
            test_dimension_line(out, css_angle_unit_name(&angle), value, css_angle_to_degrees(&angle), css_angle_to_string(&angle), css_angle_to_string(&angle, css_syntax.SerializationMode.resolved_value),
                                css_angle_cmp(&angle, degrees_90), css_angle_eq(&angle, degrees_90), css_angle_to_string(&percentage_of))
    for unit_index: u8 in 0..=(u8)css_data.AngleUnit.turn:
        let angle = css_angle_new(1.25, (css_data.AngleUnit)unit_index)
        tw(out, "radians ")
        td(out, css_angle_to_radians(&angle))
        tl(out)

    tw(out, "# times")
    tl(out)
    let seconds = css_time_make_seconds(1.5)
    for unit_index: u8 in 0..=(u8)css_data.TimeUnit.s:
        for value in test_css_values:
            let time = css_time_new(value, (css_data.TimeUnit)unit_index)
            let percentage_of = css_time_percentage_of(&time, one_fifty)
            test_dimension_line(out, css_time_unit_name(&time), value, css_time_to_seconds(&time), css_time_to_string(&time), css_time_to_string(&time, css_syntax.SerializationMode.resolved_value),
                                css_time_cmp(&time, seconds), css_time_eq(&time, seconds), css_time_to_string(&percentage_of))
    for unit_index: u8 in 0..=(u8)css_data.TimeUnit.s:
        let time = css_time_new(1.25, (css_data.TimeUnit)unit_index)
        tw(out, "milliseconds ")
        td(out, css_time_to_milliseconds(&time))
        tl(out)

    tw(out, "# frequencies")
    tl(out)
    let hertz = css_frequency_make_hertz(100.0)
    for unit_index: u8 in 0..=(u8)css_data.FrequencyUnit.k_hz:
        for value in test_css_values:
            let frequency = css_frequency_new(value, (css_data.FrequencyUnit)unit_index)
            let percentage_of = css_frequency_percentage_of(&frequency, one_fifty)
            test_dimension_line(out, css_frequency_unit_name(&frequency), value, css_frequency_to_hertz(&frequency), css_frequency_to_string(&frequency), css_frequency_to_string(&frequency, css_syntax.SerializationMode.resolved_value),
                                css_frequency_cmp(&frequency, hertz), css_frequency_eq(&frequency, hertz), css_frequency_to_string(&percentage_of))

    tw(out, "# resolutions")
    tl(out)
    let dots = css_resolution_make_dots_per_pixel(2.0)
    for unit_index: u8 in 0..=(u8)css_data.ResolutionUnit.x:
        for value in test_css_values:
            let resolution = css_resolution_new(value, (css_data.ResolutionUnit)unit_index)
            test_dimension_line(out, css_resolution_unit_name(&resolution), value, css_resolution_to_dots_per_pixel(&resolution), css_resolution_to_string(&resolution), css_resolution_to_string(&resolution, css_syntax.SerializationMode.resolved_value),
                                css_resolution_cmp(&resolution, dots), css_resolution_eq(&resolution, dots), none)

    tw(out, "# flexes")
    tl(out)
    let one_fr = css_flex_make_fr(1.0)
    for value in test_css_values:
        let flex = css_flex_new(value, css_data.FlexUnit.fr)
        let percentage_of = css_flex_percentage_of(&flex, one_fifty)
        test_dimension_line(out, css_flex_unit_name(&flex), value, css_flex_to_fr(&flex), css_flex_to_string(&flex), css_flex_to_string(&flex, css_syntax.SerializationMode.resolved_value),
                            css_flex_cmp(&flex, one_fr), css_flex_eq(&flex, one_fr), css_flex_to_string(&percentage_of))

    tw(out, "# percentages")
    tl(out)
    for value in test_css_values:
        let percentage = css_percentage_new(value)
        td(out, value)
        tw(out, " ")
        td(out, css_percentage_as_fraction(&percentage))
        tw(out, " ")
        ts(out, css_percentage_to_string(&percentage))
        tw(out, " ")
        tn(out, (i64)css_percentage_cmp(&percentage, css_percentage_new(50.0)))
        tw(out, " ")
        tb(out, css_percentage_eq(&percentage, css_percentage_new(100.0)))
        tl(out)

    tw(out, "# ratios")
    tl(out)
    let ratio_values: f64[7][2] = [[16.0, 9.0], [1.0, 0.0], [0.0, 1.0], [4.0, 3.0], [1.5, 2.5], [math.infinity, 1.0], [-2.0, 4.0]]
    for pair in ratio_values:
        let ratio = css_ratio_new(pair[0], pair[1])
        ts(out, css_ratio_to_string(&ratio))
        tw(out, " ")
        td(out, css_ratio_value(&ratio))
        tw(out, " ")
        td(out, css_ratio_numerator(&ratio))
        tw(out, " ")
        td(out, css_ratio_denominator(&ratio))
        tw(out, " ")
        tb(out, css_ratio_is_degenerate(&ratio))
        tw(out, " ")
        tn(out, (i64)css_ratio_cmp(&ratio, css_ratio_new(4.0, 3.0)))
        tw(out, " ")
        tb(out, css_ratio_eq(&ratio, css_ratio_new(8.0, 6.0)))
        tl(out)
    tw(out, "default_ratio ")
    let default_ratio = css_ratio_new(2.0)
    ts(out, css_ratio_to_string(&default_ratio))
    tl(out)

    tw(out, "# numeric ranges")
    tl(out)
    let ranges: CssNumericRange[4] = [css_infinite_range, css_non_negative_range, css_infinite_integer_range, css_non_negative_integer_range]
    for range in ranges:
        td(out, range.min)
        tw(out, " ")
        td(out, range.max)
        tw(out, " ")
        tb(out, css_numeric_range_contains(&range, -1.0))
        tb(out, css_numeric_range_contains(&range, 0.0))
        tb(out, css_numeric_range_contains(&range, 3e38))
        tb(out, css_numeric_range_contains(&range, 4e9))
        tl(out)
    let bounded = CssNumericRange(min = 1.0, max = 1000.0)
    tb(out, css_numeric_range_contains(&bounded, 1.0))
    tb(out, css_numeric_range_contains(&bounded, 1000.5))
    tl(out)

# mark: Displays ================================================================================

func test_display_flags(out: ak.StringBuilder*, display: const CssDisplay*):
    tb(out, css_display_is_none(display))
    tb(out, css_display_is_contents(display))
    tb(out, css_display_is_internal(display))
    tb(out, css_display_is_outside_and_inside(display))
    tw(out, " ")
    tb(out, css_display_is_table_column(display))
    tb(out, css_display_is_table_row_group(display))
    tb(out, css_display_is_table_header_group(display))
    tb(out, css_display_is_table_footer_group(display))
    tb(out, css_display_is_table_row(display))
    tb(out, css_display_is_table_cell(display))
    tb(out, css_display_is_table_column_group(display))
    tb(out, css_display_is_table_caption(display))
    tb(out, css_display_is_internal_table(display))
    tw(out, " ")
    tb(out, css_display_is_block_outside(display))
    tb(out, css_display_is_inline_outside(display))
    tb(out, css_display_is_inline_block(display))
    tb(out, css_display_is_list_item(display))
    tw(out, " ")
    tb(out, css_display_is_flow_inside(display))
    tb(out, css_display_is_flow_root_inside(display))
    tb(out, css_display_is_table_inside(display))
    tb(out, css_display_is_flex_inside(display))
    tb(out, css_display_is_grid_inside(display))
    tb(out, css_display_is_ruby_inside(display))
    tb(out, css_display_is_math_inside(display))
    if css_display_is_outside_and_inside(display):
        tw(out, " ")
        tv(out, css_data.to_string_display_outside(css_display_outside(display)))
        tw(out, "/")
        tv(out, css_data.to_string_display_inside(css_display_inside(display)))
    if css_display_is_internal(display):
        tw(out, " ")
        tv(out, css_data.to_string_display_internal(css_display_internal(display)))

## A display's keyword or "none".
func test_display_keyword(out: ak.StringBuilder*, display: const CssDisplay*):
    if let keyword = css_display_to_keyword(display):
        tv(out, css_data.string_from_keyword(keyword))
    else:
        tw(out, "none")

func test_dump_displays(out: ak.StringBuilder*):
    tw(out, "# displays")
    tl(out)
    let keywords: str[29] = ["none", "contents", "block", "inline", "flow", "flow-root", "inline-block", "run-in", "list-item", "flex", "inline-flex", "grid", "inline-grid", "ruby", "table", "inline-table", "math",
                             "table-row-group", "table-header-group", "table-footer-group", "table-row", "table-cell", "table-column-group", "table-column", "table-caption", "ruby-base", "ruby-text", "ruby-base-container", "ruby-text-container"]
    for keyword_name in keywords:
        let keyword = css_data.keyword_from_string(ak.sv(keyword_name)) else trap("a display keyword")
        let display = css_display_from_keyword(keyword)
        tw(out, keyword_name)
        tw(out, " ")
        ts(out, css_display_to_string(&display))
        tw(out, " ")
        test_display_keyword(out, &display)
        tw(out, " ")
        test_display_flags(out, &display)
        tl(out)
    for short_index: i32 in 0..=(i32)CssDisplayShort.math:
        let display = css_display_from_short((CssDisplayShort)short_index)
        tw(out, "short ")
        tn(out, (i64)short_index)
        tw(out, " ")
        ts(out, css_display_to_string(&display))
        tw(out, " ")
        test_display_flags(out, &display)
        tl(out)
    var default_display: CssDisplay
    let custom: CssDisplay[5] = [
        css_display_new_list_item(css_data.DisplayOutside.inline, css_data.DisplayInside.flow, CssDisplayListItem.yes),
        css_display_new(css_data.DisplayOutside.run_in, css_data.DisplayInside.table),
        css_display_new_list_item(css_data.DisplayOutside.block, css_data.DisplayInside.flow_root, CssDisplayListItem.yes),
        css_display_new_list_item(css_data.DisplayOutside.inline, css_data.DisplayInside.grid, CssDisplayListItem.yes),
        default_display,
    ]
    for display in custom:
        tw(out, "custom ")
        ts(out, css_display_to_string(&display))
        tw(out, " ")
        test_display_keyword(out, &display)
        tw(out, " ")
        test_display_flags(out, &display)
        tw(out, " ")
        tb(out, css_display_eq(&display, css_display_from_short(CssDisplayShort.inline_list_item)))
        tl(out)

# mark: System colors ===========================================================================

func test_dump_system_colors(out: ak.StringBuilder*):
    tw(out, "# system colors")
    tl(out)
    let functions: (func(CssPreferredColorScheme) -> gfx.Color)[19] = [
        css_system_color_accent_color, css_system_color_accent_color_text, css_system_color_active_text, css_system_color_button_border, css_system_color_button_face, css_system_color_button_text,
        css_system_color_canvas, css_system_color_canvas_text, css_system_color_field, css_system_color_field_text, css_system_color_gray_text, css_system_color_highlight, css_system_color_highlight_text,
        css_system_color_link_text, css_system_color_mark, css_system_color_mark_text, css_system_color_selected_item, css_system_color_selected_item_text, css_system_color_visited_text,
    ]
    for function in functions:
        thex(out, (u64)function(CssPreferredColorScheme.light).m_value, 8)
        tw(out, " ")
        thex(out, (u64)function(CssPreferredColorScheme.dark).m_value, 8)
        tw(out, " ")
        thex(out, (u64)function(CssPreferredColorScheme.auto).m_value, 8)
        tl(out)

# mark: Sizing, edge rects, sizes, length-percentages ===========================================

## An optional CSSPixels' raw value or "-".
func test_optional_px(out: ak.StringBuilder*, value: gfx.CssPixels?):
    if let pixels = value:
        tpx(out, pixels)
    else:
        tw(out, "-")

## `CSSPixelFraction(numerator, denominator)`.
func test_fraction(numerator: gfx.CssPixels, denominator: gfx.CssPixels) -> gfx.CssPixelFraction:
    var fraction: gfx.CssPixelFraction = ---
    gfx.css_pixel_fraction_construct_css_pixels(&fraction, numerator, denominator)
    return fraction

## `CSSPixelSize(width, height)` of integers.
func test_size(width: i64, height: i64) -> gfx.CssPixelSize:
    var size: gfx.CssPixelSize = ---
    gfx.css_pixel_size_construct_int(&size, width, height)
    return size

func test_dump_sizing(out: ak.StringBuilder*):
    tw(out, "# sizing")
    tl(out)
    let widths: (gfx.CssPixels?)[3] = [none, gfx.css_pixels_from_int(100), gfx.css_pixels_from_f64(37.5)]
    let heights: (gfx.CssPixels?)[3] = [none, gfx.css_pixels_from_int(50), gfx.css_pixels_from_int(0)]
    let naturals: CssSizeWithAspectRatio[7] = [
        CssSizeWithAspectRatio(width = none, height = none, aspect_ratio = none),
        CssSizeWithAspectRatio(width = gfx.css_pixels_from_int(300), height = gfx.css_pixels_from_int(150), aspect_ratio = test_fraction(gfx.css_pixels_from_int(300), gfx.css_pixels_from_int(150))),
        CssSizeWithAspectRatio(width = gfx.css_pixels_from_int(300), height = none, aspect_ratio = none),
        CssSizeWithAspectRatio(width = none, height = gfx.css_pixels_from_int(80), aspect_ratio = none),
        CssSizeWithAspectRatio(width = none, height = none, aspect_ratio = test_fraction(gfx.css_pixels_from_int(16), gfx.css_pixels_from_int(9))),
        CssSizeWithAspectRatio(width = none, height = none, aspect_ratio = test_fraction(gfx.css_pixels_from_int(1), gfx.css_pixels_from_int(3))),
        CssSizeWithAspectRatio(width = none, height = none, aspect_ratio = test_fraction(gfx.css_pixels_max(), gfx.css_pixels_from_int(1))),
    ]
    let defaults: gfx.CssPixelSize[2] = [test_size(300, 150), test_size(0, 150)]
    for width in widths:
        for height in heights:
            for natural in naturals:
                for default_size in defaults:
                    let size = css_run_default_sizing_algorithm(width, height, natural, default_size)
                    test_optional_px(out, width)
                    tw(out, " ")
                    test_optional_px(out, height)
                    tw(out, " ")
                    test_optional_px(out, natural.width)
                    tw(out, " ")
                    test_optional_px(out, natural.height)
                    tw(out, " ")
                    tb(out, css_size_with_aspect_ratio_has_aspect_ratio(&natural))
                    tw(out, " ")
                    tpx(out, gfx.css_pixel_size_width(&default_size))
                    tw(out, "x")
                    tpx(out, gfx.css_pixel_size_height(&default_size))
                    tw(out, " -> ")
                    tpx(out, gfx.css_pixel_size_width(&size))
                    tw(out, "x")
                    tpx(out, gfx.css_pixel_size_height(&size))
                    tl(out)

## A LengthOrAuto of a length.
func test_length_or_auto(value: f64, unit_: css_data.LengthUnit) -> CssLengthOrAuto:
    return css_length_or_auto_new(css_length_new(value, unit_))

func test_dump_boxes(out: ak.StringBuilder*):
    tw(out, "# edge rects")
    tl(out)
    let rects: CssEdgeRect[3] = [
        CssEdgeRect(top_edge = css_length_or_auto_make_auto(), right_edge = css_length_or_auto_make_auto(), bottom_edge = css_length_or_auto_make_auto(), left_edge = css_length_or_auto_make_auto()),
        CssEdgeRect(top_edge = test_length_or_auto(5.0, css_data.LengthUnit.px), right_edge = test_length_or_auto(1.0, css_data.LengthUnit.in_), bottom_edge = test_length_or_auto(2.0, css_data.LengthUnit.cm), left_edge = test_length_or_auto(3.0, css_data.LengthUnit.pt)),
        CssEdgeRect(top_edge = test_length_or_auto(-5.5, css_data.LengthUnit.px), right_edge = css_length_or_auto_make_auto(), bottom_edge = test_length_or_auto(10.0, css_data.LengthUnit.mm), left_edge = css_length_or_auto_make_auto()),
    ]
    var border_box: gfx.CssPixelRect = ---
    gfx.css_pixel_rect_construct_css_pixels(&border_box, gfx.css_pixels_from_int(10), gfx.css_pixels_from_f64(20.25), gfx.css_pixels_from_int(300), gfx.css_pixels_from_int(150))
    for rect in rects:
        let resolved = css_edge_rect_resolved(&rect, border_box)
        tpx(out, gfx.css_pixel_rect_left(&resolved))
        tw(out, " ")
        tpx(out, gfx.css_pixel_rect_top(&resolved))
        tw(out, " ")
        tpx(out, gfx.css_pixel_rect_width(&resolved))
        tw(out, " ")
        tpx(out, gfx.css_pixel_rect_height(&resolved))
        tw(out, " ")
        tb(out, rect == rects[0])
        tl(out)

    tw(out, "# sizes")
    tl(out)
    let sizes: CssSize[12] = [
        css_size_make_auto(), css_size_make_px(gfx.css_pixels_from_f64(12.5)), css_size_make_length(css_length_new(2.0, css_data.LengthUnit.em)), css_size_make_percentage(css_percentage_new(40.0)),
        css_size_make_min_content(), css_size_make_max_content(), css_size_make_fit_content(), css_size_make_fit_content_css_length_percentage(css_length_percentage_new_css_percentage(css_percentage_new(30.0))),
        css_size_make_fit_content_css_length_percentage(css_length_percentage_new_css_length(css_length_new(4.0, css_data.LengthUnit.px))), css_size_make_none(),
        css_size_make_length_percentage(css_length_percentage_new_css_length(css_length_new(7.0, css_data.LengthUnit.vh))), css_size_make_length_percentage(css_length_percentage_new_css_percentage(css_percentage_new(8.0))),
    ]
    let fit_content_30 = css_size_make_fit_content_css_length_percentage(css_length_percentage_new_css_percentage(css_percentage_new(30.0)))
    for size in sizes:
        ts(out, css_size_to_string(&size, css_syntax.SerializationMode.normal))
        tw(out, " ")
        tn(out, (i64)css_size_type(&size))
        tw(out, " ")
        tb(out, css_size_is_auto(&size))
        tb(out, css_size_is_calculated(&size))
        tb(out, css_size_is_length(&size))
        tb(out, css_size_is_percentage(&size))
        tb(out, css_size_is_min_content(&size))
        tb(out, css_size_is_max_content(&size))
        tb(out, css_size_is_fit_content(&size))
        tb(out, css_size_is_none(&size))
        tw(out, " ")
        tb(out, css_size_is_intrinsic_sizing_constraint(&size))
        tb(out, css_size_is_length_percentage(&size))
        tb(out, css_size_contains_percentage(&size))
        tw(out, " ")
        tb(out, css_size_eq(&size, sizes[1]))
        tb(out, css_size_eq(&size, fit_content_30))
        tl(out)

    tw(out, "# length percentages")
    tl(out)
    let length_percentages: CssLengthPercentage[3] = [
        css_length_percentage_new_css_length(css_length_new(3.0, css_data.LengthUnit.px)), css_length_percentage_new_css_percentage(css_percentage_new(12.5)),
        css_length_percentage_new_css_length(css_length_new(0.0, css_data.LengthUnit.em)),
    ]
    for length_percentage in length_percentages:
        let or_auto = css_length_percentage_or_auto_new(length_percentage)
        ts(out, css_percentage_or_to_string(&length_percentage.percentage_or, css_syntax.SerializationMode.normal))
        tw(out, " ")
        tb(out, css_length_percentage_is_length(&length_percentage))
        tb(out, css_percentage_or_is_percentage(&length_percentage.percentage_or))
        tb(out, css_percentage_or_is_calculated(&length_percentage.percentage_or))
        tb(out, css_percentage_or_contains_percentage(&length_percentage.percentage_or))
        tw(out, " ")
        ts(out, css_length_percentage_or_auto_to_string(&or_auto, css_syntax.SerializationMode.normal))
        tw(out, " ")
        tb(out, css_length_percentage_or_auto_is_auto(&or_auto))
        tb(out, css_length_percentage_or_auto_is_length(&or_auto))
        tb(out, css_length_percentage_or_auto_is_percentage(&or_auto))
        tb(out, css_length_percentage_or_auto_is_calculated(&or_auto))
        tb(out, css_length_percentage_or_auto_contains_percentage(&or_auto))
        tw(out, " ")
        tb(out, css_percentage_or_eq(&length_percentage.percentage_or, length_percentages[0].percentage_or))
        tb(out, css_eq_css_percentage_or_t(length_percentage.percentage_or, css_length_new(3.0, css_data.LengthUnit.px)))
        tb(out, css_eq_css_percentage_or_css_percentage(length_percentage.percentage_or, css_percentage_new(12.5)))
        tb(out, css_length_percentage_or_auto_eq(&or_auto, css_length_percentage_or_auto_make_auto()))
        tl(out)
    let auto_ = css_length_percentage_or_auto_make_auto()
    tw(out, "auto ")
    ts(out, css_length_percentage_or_auto_to_string(&auto_, css_syntax.SerializationMode.normal))
    tw(out, " ")
    tb(out, css_length_percentage_or_auto_is_auto(&auto_))
    tb(out, css_length_percentage_or_auto_is_length(&auto_))
    tb(out, css_length_percentage_or_auto_is_percentage(&auto_))
    tb(out, css_length_percentage_or_auto_contains_percentage(&auto_))
    tw(out, " ")
    tb(out, css_length_percentage_or_auto_eq(&auto_, css_length_percentage_or_auto_make_auto()))
    tl(out)

    var box: CssLengthBox = ---
    css_length_box_construct(&box)
    var other: CssLengthBox = ---
    css_length_box_construct_css_length_percentage_or_auto(&other, css_length_percentage_or_auto_new(css_length_percentage_new_css_length(css_length_new(1.0, css_data.LengthUnit.px))),
                                                           css_length_percentage_or_auto_new(css_length_percentage_new_css_percentage(css_percentage_new(2.0))), css_length_percentage_or_auto_make_auto(),
                                                           css_length_percentage_or_auto_new(css_length_percentage_new_css_length(css_length_new(4.0, css_data.LengthUnit.em))))
    var empty_box: CssLengthBox = ---
    css_length_box_construct(&empty_box)
    tw(out, "box ")
    ts(out, css_length_percentage_or_auto_to_string(css_length_box_top(&box), css_syntax.SerializationMode.normal))
    tw(out, " ")
    ts(out, css_length_percentage_or_auto_to_string(css_length_box_top(&other), css_syntax.SerializationMode.normal))
    tw(out, " ")
    ts(out, css_length_percentage_or_auto_to_string(css_length_box_right(&other), css_syntax.SerializationMode.normal))
    tw(out, " ")
    ts(out, css_length_percentage_or_auto_to_string(css_length_box_bottom(&other), css_syntax.SerializationMode.normal))
    tw(out, " ")
    ts(out, css_length_percentage_or_auto_to_string(css_length_box_left(&other), css_syntax.SerializationMode.normal))
    tw(out, " ")
    tb(out, css_length_box_eq(&box, empty_box))
    tb(out, css_length_box_eq(&box, other))
    tl(out)

# mark: Grids ===================================================================================

func test_dump_grids(out: ak.StringBuilder*):
    tw(out, "# grids")
    tl(out)
    var names = CssGridLineNames(m_names = ak.Vector[CssGridLineName]())
    css_grid_line_names_append(&names, ak.fly_string_from_str("a"))
    css_grid_line_names_append(&names, ak.fly_string_from_str("b-c"))
    var more = CssGridLineNames(m_names = ak.Vector[CssGridLineName]())
    css_grid_line_names_append(&more, ak.fly_string_from_str("d"))
    var list = css_grid_track_size_list_make_none()
    tw(out, "none ")
    ts(out, css_grid_track_size_list_to_string(&list, css_syntax.SerializationMode.normal))
    tw(out, " ")
    tb(out, css_grid_track_size_list_is_empty(&list))
    tw(out, " ")
    let empty_tracks = css_grid_track_size_list_track_list(&list)
    tn(out, (i64)ak.vector_size(&empty_tracks))
    tl(out)
    # `GridLineNames { names }`: a copy.
    css_grid_track_size_list_append_css_grid_line_names(&list, CssGridLineNames(m_names = ak.vector_clone(&names.m_names)))
    tw(out, "one ")
    ts(out, css_grid_track_size_list_to_string(&list, css_syntax.SerializationMode.normal))
    tw(out, " ")
    tn(out, (i64)ak.vector_size(&list.m_list))
    tl(out)
    css_grid_track_size_list_append_css_grid_line_names(&list, CssGridLineNames(m_names = ak.vector_clone(&more.m_names)))
    tw(out, "merged ")
    ts(out, css_grid_track_size_list_to_string(&list, css_syntax.SerializationMode.normal))
    tw(out, " ")
    tn(out, (i64)ak.vector_size(&list.m_list))
    tw(out, " ")
    let tracks = css_grid_track_size_list_track_list(&list)
    tn(out, (i64)ak.vector_size(&tracks))
    tw(out, " ")
    ts(out, css_grid_line_names_to_string(&names))
    tw(out, " ")
    tb(out, css_grid_line_names_is_empty(&names))
    tw(out, " ")
    let no_names = CssGridLineNames(m_names = ak.Vector[CssGridLineName]())
    tb(out, css_grid_line_names_is_empty(&no_names))
    tl(out)
    var other = css_grid_track_size_list_make_none()
    css_grid_track_size_list_append_css_grid_line_names(&other, CssGridLineNames(m_names = ak.vector_clone(&names.m_names)))
    let none_list = css_grid_track_size_list_make_none()
    tw(out, "equal ")
    tb(out, css_grid_track_size_list_eq(&list, other))
    tb(out, css_grid_track_size_list_eq(&none_list, css_grid_track_size_list_make_none()))
    tb(out, css_grid_line_names_eq(&names, names))
    tb(out, css_grid_line_names_eq(&names, more))
    tl(out)
    var areas: CssGridTemplateAreas
    tw(out, "areas ")
    tb(out, css_grid_template_areas_is_empty(&areas))
    tl(out)