Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / css / tests_css_values_units_3.lucb

#==============================================================================================
#
#   tests_css_values_units_3 - focused tests of region r36 (CSS values and units)
#
#   DESCRIPTION:
#       What the oracle dump (tests_css_values_units_1, _2) does not print: counter style
#       definitions made into counter styles, Clip, ColumnCount, Filter, the numeric ranges'
#       exact values, PropertyNameAndID's cached name and the embedded style sheets' ends.
#       Expected values follow from the C++ (each test says where).
#
#==============================================================================================

test "a counter style definition makes a counter style with the C++ defaults (CounterStyle.cpp:61)":
    with memory.heap:
        let algorithm = CssCounterStyleAlgorithm.css_generic_counter_style_algorithm(CssGenericCounterStyleAlgorithm(type_ = css_data.CounterStyleSystem.alphabetic, symbol_list = test_symbols(["x", "y"])))
        let definition = css_counter_style_definition_create(ak.fly_string_from_str("letters"), .css_counter_style_algorithm(algorithm), none, none, ak.fly_string_from_str(") "), .empty, none, none)
        assert(ak.fly_string_eq_string_view(&definition.m_name, ak.sv("letters")))
        let scope = (const CssStyleScope*)&(new u8[memory.size_of(CssStyleScope)] else trap("out of memory"))[0]
        let style = css_counter_style_from_counter_style_definition(&definition, scope)
        # The negative sign defaults to "-", the prefix to "", the pad to 0 and "", the fallback to decimal; an
        # empty range resolves `auto` for the algorithm (alphabetic: 1 to infinity).
        assert(ak.fly_string_eq_string_view(&style.m_negative_sign.prefix, ak.sv("-")))
        assert(ak.fly_string_eq_string_view(&style.m_prefix, ak.sv("")))
        assert(ak.fly_string_eq_string_view(&style.m_suffix, ak.sv(") ")))
        assert(style.m_pad.minimum_length == 0)
        let fallback = style.m_fallback else trap("a fallback")
        assert(ak.fly_string_eq_string_view(&fallback, ak.sv("decimal")))
        assert(ak.vector_size(&style.m_range) == 1 and ak.vector_at_const(&style.m_range, 0).start == 1)
        let three = css_generate_a_counter_representation(style, scope, 3)
        assert(ak.string_eq_string_view(&three, ak.sv("xx")))

        # An explicit range is kept (CounterStyle.cpp:68).
        var ranges = ak.Vector[CssCounterStyleRangeEntry]()
        ak.vector_append_t(&ranges, CssCounterStyleRangeEntry(start = 2, end = 5))
        var ranged = definition
        ranged.m_range = .vector_css_counter_style_range_entry(ranges)
        let ranged_style = css_counter_style_from_counter_style_definition(&ranged, scope)
        assert(ak.vector_at_const(&ranged_style.m_range, 0).end == 5)
        assert(css_counter_style_equals(ranged_style, ranged_style) and not css_counter_style_equals(ranged_style, style))

test "Clip, ColumnCount and Filter (Clip.cpp, ColumnCount.h, Filter.h)":
    let clip = css_clip_make_auto()
    assert(css_clip_is_auto(&clip) and not css_clip_is_rect(&clip))
    let rect = css_clip_to_rect(&clip)
    assert(css_length_or_auto_is_auto(&rect.top_edge) and css_length_or_auto_is_auto(&rect.left_edge))
    var rect_clip: CssClip = ---
    css_clip_construct_css_edge_rect(&rect_clip, rect)
    assert(css_clip_is_rect(&rect_clip))

    let auto_count = css_column_count_make_auto()
    assert(css_column_count_is_auto(&auto_count) and auto_count.m_value == none)
    let three = css_column_count_make_integer(3)
    assert(not css_column_count_is_auto(&three) and css_column_count_value(&three) == 3)

    let none_filter = css_filter_make_none()
    assert(css_filter_is_none(&none_filter) and not css_filter_has_filters(&none_filter))

test "the numeric ranges are NumericLimits<float> and NumericLimits<i32> (NumericRange.h:22-26)":
    let float_max = (f64)f32.bits(0x7f7fffff)
    assert(css_infinite_range.min == -float_max and css_infinite_range.max == float_max)
    assert(css_non_negative_range.min == 0.0 and css_non_negative_range.max == float_max)
    assert(css_infinite_integer_range.min == -2147483648.0 and css_infinite_integer_range.max == 2147483647.0)
    assert(css_non_negative_integer_range.min == 0.0 and css_non_negative_integer_range.max == 2147483647.0)

test "PropertyNameAndID::name caches the name of a property made from its ID (PropertyNameAndID.h:38)":
    with memory.heap:
        let property = css_property_name_and_id_from_id(css_data.PropertyId.background_color)
        assert(property.m_name == none)
        let name = css_property_name_and_id_name(&property)
        assert(ak.fly_string_eq_string_view(&name, ak.sv("background-color")))
        assert(property.m_name != none)

test "the embedded style sheets are Default.css and QuirksMode.css (embed_as_string.py)":
    assert(css_default_stylesheet_source.length == 90248)
    let default_bytes = css_default_stylesheet_source.bytes
    assert((str)default_bytes[..<45] == "/* Default user-agent stylesheet for LibWeb\n ")
    assert((str)default_bytes[default_bytes.length - 2..] == "}\n")
    # A CSS escape keeps its backslash: `symbols: \25BE;` of the disclosure-open counter style.
    var found = false
    for i in 0..<default_bytes.length - 14:
        if (str)default_bytes[i..<i + 14] == "symbols: \\25BE":
            found = true
    assert(found)
    assert(css_quirks_mode_stylesheet_source.length == 1083)