dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / css / tests_css_values_units_2.lucb
#==============================================================================================
#
# tests_css_values_units_2 - the oracle dump of region r36 (CSS values and units), part 2
#
# DESCRIPTION:
# The sections for counter styles, color interpolation (its internal steps), the color
# function descriptors, value types, property and descriptor names, URLs and the
# embedded style sheets, and the test that compares the whole dump with the oracle's
# output (tests_css_values_units_expected). Part 1 has the helpers and the other
# sections. Values reaching other regions' stubs (style values, layout nodes, style
# scopes' registered counter styles) are left out, as in the oracle.
#
#==============================================================================================
# mark: Counter styles ==========================================================================
## FlyStrings of `texts`.
func test_symbols(texts: const str[]) -> ak.Vector[ak.FlyString]:
var result = ak.Vector[ak.FlyString]()
for text in texts:
ak.vector_append_t(&result, ak.fly_string_from_str(text))
return result
## An additive tuple.
func test_tuple(weight: i32, symbol: str) -> CssAdditiveCounterStyleAlgorithmAdditiveTuple:
return CssAdditiveCounterStyleAlgorithmAdditiveTuple(weight = weight, symbol = ak.fly_string_from_str(symbol))
## The counter values the algorithms are printed with.
let test_counter_values: i64[34] = [0, 1, 2, 3, 9, 10, 11, 15, 19, 20, 21, 99, 100, 101, 110, 999, 1000, 1001, 1010, 1100, 9999, 10000, 10001, 11111, 12345, 20000, 100000, 1000000, 10000000, 99999999, 100000000, 100010001, 123456789, 1234567890123]
## A one-entry infinite range.
func test_infinite_range() -> ak.Vector[CssCounterStyleRangeEntry]:
var range = ak.Vector[CssCounterStyleRangeEntry]()
ak.vector_append_t(&range, CssCounterStyleRangeEntry(start = -2147483648, end = 2147483647))
return range
func test_dump_counter_styles(out: ak.StringBuilder*):
tw(out, "# counter styles")
tl(out)
let negative = CssCounterStyleNegativeSign(prefix = ak.fly_string_from_str("-"), suffix = ak.fly_string_from_str(""))
let no_pad = CssCounterStylePad(minimum_length = 0, symbol = ak.fly_string_from_str(""))
var algorithms = ak.Vector[CssCounterStyleAlgorithm]()
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_generic_counter_style_algorithm(CssGenericCounterStyleAlgorithm(type_ = css_data.CounterStyleSystem.cyclic, symbol_list = test_symbols(["a", "b", "c"]))))
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_generic_counter_style_algorithm(CssGenericCounterStyleAlgorithm(type_ = css_data.CounterStyleSystem.numeric, symbol_list = test_symbols(["0", "1", "2"]))))
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_generic_counter_style_algorithm(CssGenericCounterStyleAlgorithm(type_ = css_data.CounterStyleSystem.alphabetic, symbol_list = test_symbols(["a", "b", "c"]))))
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_generic_counter_style_algorithm(CssGenericCounterStyleAlgorithm(type_ = css_data.CounterStyleSystem.symbolic, symbol_list = test_symbols(["*", "\u{2020}"]))))
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_fixed_counter_style_algorithm(CssFixedCounterStyleAlgorithm(first_symbol = 3, symbol_list = test_symbols(["x", "y", "z"]))))
var roman = ak.Vector[CssAdditiveCounterStyleAlgorithmAdditiveTuple]()
for tuple in [test_tuple(1000, "M"), test_tuple(900, "CM"), test_tuple(500, "D"), test_tuple(400, "CD"), test_tuple(100, "C"), test_tuple(90, "XC"), test_tuple(50, "L"), test_tuple(40, "XL"), test_tuple(10, "X"), test_tuple(9, "IX"), test_tuple(5, "V"), test_tuple(4, "IV"), test_tuple(1, "I")]:
ak.vector_append_t(&roman, tuple)
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_additive_counter_style_algorithm(CssAdditiveCounterStyleAlgorithm(symbol_list = roman)))
var five_zero = ak.Vector[CssAdditiveCounterStyleAlgorithmAdditiveTuple]()
ak.vector_append_t(&five_zero, test_tuple(5, "five"))
ak.vector_append_t(&five_zero, test_tuple(0, "zero"))
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_additive_counter_style_algorithm(CssAdditiveCounterStyleAlgorithm(symbol_list = five_zero)))
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_ethiopic_numeric_counter_style_algorithm(CssEthiopicNumericCounterStyleAlgorithm()))
for type_index: u8 in 0..=(u8)CssExtendedCjkCounterStyleAlgorithmType.korean_hanja_formal:
ak.vector_append_t(&algorithms, CssCounterStyleAlgorithm.css_extended_cjk_counter_style_algorithm(CssExtendedCjkCounterStyleAlgorithm(type_ = (CssExtendedCjkCounterStyleAlgorithmType)type_index)))
for index in 0..<ak.vector_size(&algorithms):
let style = css_counter_style_create(ak.fly_string_from_str("test"), *ak.vector_at_const(&algorithms, index), negative, ak.fly_string_from_str(""), ak.fly_string_from_str(". "), test_infinite_range(), ak.fly_string_from_str("decimal"), no_pad)
tw(out, "algorithm ")
tn(out, (i64)index)
tw(out, " ")
tb(out, css_counter_style_uses_a_negative_sign(style))
tw(out, ":")
# Symbolic and additive representations grow with the value: those algorithms stop early.
let maximum: i64 = 110 if index == 3 else (2000 if index == 5 or index == 6 else 9223372036854775807)
for value in test_counter_values:
if value <= maximum:
tw(out, " ")
if let representation = css_counter_style_generate_an_initial_representation_for_the_counter_value(style, value):
ts(out, representation)
else:
tw(out, "(fallback)")
tl(out)
tw(out, "auto ranges")
tl(out)
for index in 0..<7:
let range = css_auto_range_resolve(*ak.vector_at_const(&algorithms, (usize)index))
tn(out, index)
tw(out, " ")
tn(out, (i64)ak.vector_size(&range))
tw(out, " ")
tn(out, (i64)ak.vector_at_const(&range, 0).start)
tw(out, " ")
tn(out, (i64)ak.vector_at_const(&range, 0).end)
tl(out)
let decimal = css_counter_style_decimal()
let disc = css_counter_style_disc()
# No registered counter style is looked up on these paths (no fallback is needed): any scope will do.
let scope = (const CssStyleScope*)&(new u8[memory.size_of(CssStyleScope)] else trap("out of memory"))[0]
tw(out, "decimal ")
tfly(out, css_counter_style_name(decimal))
tw(out, " ")
tfly(out, css_counter_style_prefix(decimal))
tw(out, "|")
tfly(out, css_counter_style_suffix(decimal))
tw(out, " ")
tb(out, css_counter_style_fallback(decimal) != none)
tw(out, ":")
for value: i32 in -12..=12:
tw(out, " ")
ts(out, css_generate_a_counter_representation(decimal, scope, value))
tl(out)
tw(out, "disc ")
tfly(out, css_counter_style_name(disc))
tw(out, " ")
tfly(out, css_counter_style_fallback(disc) else trap("a fallback"))
tw(out, ":")
for value: i32 in -3..=3:
tw(out, " ")
ts(out, css_generate_a_counter_representation(disc, scope, value))
tl(out)
tw(out, "equals ")
tb(out, css_counter_style_equals(decimal, decimal))
tb(out, css_counter_style_equals(decimal, disc))
tb(out, css_counter_style_decimal() == decimal)
tl(out)
let padded = css_counter_style_create(ak.fly_string_from_str("padded"), .css_generic_counter_style_algorithm(CssGenericCounterStyleAlgorithm(type_ = css_data.CounterStyleSystem.numeric, symbol_list = test_symbols(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]))),
CssCounterStyleNegativeSign(prefix = ak.fly_string_from_str("(-"), suffix = ak.fly_string_from_str(")")), ak.fly_string_from_str(""), ak.fly_string_from_str(""), test_infinite_range(), ak.fly_string_from_str("decimal"),
CssCounterStylePad(minimum_length = 5, symbol = ak.fly_string_from_str("0")))
tw(out, "padded:")
for value in [-12345, -123, -1, 0, 7, 42, 123456, -2147483648, 2147483647]:
tw(out, " ")
ts(out, css_generate_a_counter_representation(padded, scope, (i32)value))
tl(out)
let additive = css_counter_style_create(ak.fly_string_from_str("roman"), *ak.vector_at_const(&algorithms, 5), CssCounterStyleNegativeSign(prefix = ak.fly_string_from_str("-"), suffix = ak.fly_string_from_str("")), ak.fly_string_from_str(""), ak.fly_string_from_str(""),
test_infinite_range(), ak.fly_string_from_str("decimal"), CssCounterStylePad(minimum_length = 3, symbol = ak.fly_string_from_str("_")))
tw(out, "roman:")
for value in [-14, 1, 4, 9, 14, 40, 90, 400, 1994, 3999]:
tw(out, " ")
ts(out, css_generate_a_counter_representation(additive, scope, (i32)value))
tl(out)
# mark: Color interpolation =====================================================================
## Append a color's four components (bits).
func test_components(out: ak.StringBuilder*, c: gfx.ColorComponents):
tf(out, gfx.color_components_at_const(&c, 0))
tw(out, " ")
tf(out, gfx.color_components_at_const(&c, 1))
tw(out, " ")
tf(out, gfx.color_components_at_const(&c, 2))
tw(out, " ")
tf(out, gfx.color_components_alpha(&c))
## Append the four missing flags.
func test_missing(out: ak.StringBuilder*, m: CssMissingComponents):
tb(out, m.components[0])
tb(out, m.components[1])
tb(out, m.components[2])
tb(out, m.alpha)
## Append the three categories.
func test_categories(out: ak.StringBuilder*, c: CssComponentCategories):
tn(out, (i64)c.components[0])
tn(out, (i64)c.components[1])
tn(out, (i64)c.components[2])
func test_dump_color_interpolation(out: ak.StringBuilder*):
tw(out, "# color interpolation")
tl(out)
let hue_pairs: f32[8][2] = [[10.0, 350.0], [350.0, 10.0], [0.0, 180.0], [180.0, 0.0], [90.0, 90.0], [30.0, 200.0], [200.0, 30.0], [0.0, 0.0]]
for method: u8 in 0..=(u8)css_data.HueInterpolationMethod.decreasing:
tw(out, "fixup_hue ")
tn(out, (i64)method)
tw(out, ":")
for pair in hue_pairs:
var hue1 = pair[0]
var hue2 = pair[1]
css_fixup_hue(&hue1, &hue2, (css_data.HueInterpolationMethod)method)
tw(out, " ")
tf(out, hue1)
tw(out, ",")
tf(out, hue2)
tl(out)
tw(out, "interpolate ")
tf(out, css_interpolate_color_component(0.25, 0.75, 0.3))
tw(out, " ")
tf(out, css_interpolate_color_component(1.0, -1.0, 1.5))
tl(out)
let colors: gfx.ColorComponents[4] = [gfx.color_components_new(1.0, 0.5, 0.25, 1.0), gfx.color_components_new(0.0, 0.0, 0.0, 0.5), gfx.color_components_new(0.2, 0.4, 0.6, 0.8), gfx.color_components_new(1.0, 1.0, 1.0, 1.0)]
for color in colors:
for space: u8 in 0..=(u8)css_data.RectangularColorSpace.xyz_d65:
tw(out, "rectangular ")
tn(out, (i64)space)
tw(out, " ")
test_components(out, css_srgb_to_rectangular_color_space(color, (css_data.RectangularColorSpace)space))
tl(out)
for space: u8 in 0..=(u8)css_data.PolarColorSpace.oklch:
tw(out, "polar ")
tn(out, (i64)space)
tw(out, " ")
test_components(out, css_srgb_to_polar_color_space(color, (css_data.PolarColorSpace)space))
tl(out)
for type_index: i32 in 0..=(i32)CssColorStyleValueColorType.xyzd65:
tw(out, "native ")
tn(out, (i64)type_index)
tw(out, " ")
test_components(out, css_native_components_to_srgb(color, (CssColorStyleValueColorType)type_index))
tl(out)
for polar in [false, true]:
let premultiplied = css_premultiply_color_components(color, polar, 2)
let interpolated = css_interpolate_premultiplied_components(premultiplied, css_premultiply_color_components(colors[2], polar, 2), 0.25)
tw(out, "premultiply ")
tb(out, polar)
tw(out, " ")
test_components(out, premultiplied)
tw(out, " ")
test_components(out, interpolated)
tw(out, " ")
test_components(out, css_unpremultiply_color_components(interpolated, 0.4, polar, 2))
tl(out)
for space: u8 in 0..=(u8)css_data.RectangularColorSpace.xyz_d65:
tw(out, "categories rectangular ")
tn(out, (i64)space)
tw(out, " ")
test_categories(out, css_categories_for_rectangular_space((css_data.RectangularColorSpace)space))
tl(out)
for space: u8 in 0..=(u8)css_data.PolarColorSpace.oklch:
tw(out, "categories polar ")
tn(out, (i64)space)
tw(out, " ")
test_categories(out, css_categories_for_polar_space((css_data.PolarColorSpace)space))
tw(out, " ")
tn(out, (i64)css_hue_index_for_color_space((css_data.PolarColorSpace)space))
tl(out)
for type_index: i32 in 0..=(i32)CssColorStyleValueColorType.xyzd65:
let color_type = (CssColorStyleValueColorType)type_index
tw(out, "color type ")
tn(out, (i64)type_index)
tw(out, " ")
test_categories(out, css_categories_for_color_type(color_type))
tw(out, " ")
for space: u8 in 0..=(u8)css_data.RectangularColorSpace.xyz_d65:
tb(out, css_color_type_matches_rectangular_space(color_type, (css_data.RectangularColorSpace)space))
tw(out, " ")
for space: u8 in 0..=(u8)css_data.PolarColorSpace.oklch:
tb(out, css_color_type_matches_polar_space(color_type, (css_data.PolarColorSpace)space))
tl(out)
var default_categories: CssComponentCategories = ---
css_component_categories_init_fields(&default_categories)
let category_sets: CssComponentCategories[6] = [
css_component_categories_new(CssComponentCategory.red, CssComponentCategory.green, CssComponentCategory.blue),
css_component_categories_new(CssComponentCategory.lightness, CssComponentCategory.opponent_a, CssComponentCategory.opponent_b),
css_component_categories_new(CssComponentCategory.hue, CssComponentCategory.colorfulness, CssComponentCategory.lightness),
css_component_categories_new(CssComponentCategory.hue, CssComponentCategory.not_analogous, CssComponentCategory.not_analogous),
css_component_categories_new(CssComponentCategory.lightness, CssComponentCategory.colorfulness, CssComponentCategory.hue),
default_categories,
]
for bits: u8 in 0..<16:
let source = css_missing_components_new((bits & 1) != 0, (bits & 2) != 0, (bits & 4) != 0, (bits & 8) != 0)
tw(out, "carry ")
test_missing(out, source)
tw(out, ":")
for from_ in category_sets:
for to in category_sets:
tw(out, " ")
test_missing(out, css_carry_forward_missing_components(source, from_, to))
tl(out)
var marked = source
css_mark_powerless_for_zero_alpha(false, 0.0, &marked)
var unmarked = source
css_mark_powerless_for_zero_alpha(true, 0.0, &unmarked)
var opaque_ = source
css_mark_powerless_for_zero_alpha(false, 0.5, &opaque_)
var state = css_interpolation_space_state_new()
state.from_missing = source
state.to_missing = css_missing_components_new((bits & 8) != 0, (bits & 1) != 0, true, (bits & 2) != 0)
state.from_components = colors[2]
state.to_components = colors[0]
let both_alpha_missing = css_reinsert_carried_forward_values(&state)
tw(out, "powerless ")
test_missing(out, marked)
tw(out, " ")
test_missing(out, unmarked)
tw(out, " ")
test_missing(out, opaque_)
tw(out, " ")
test_missing(out, css_result_missing_components(state))
tw(out, " ")
tb(out, both_alpha_missing)
tw(out, " ")
test_components(out, state.from_components)
tw(out, " ")
test_components(out, state.to_components)
tl(out)
var polar_state = css_interpolation_space_state_new()
polar_state.is_polar = true
polar_state.hue_index = 2
polar_state.hue_interpolation_method = css_data.HueInterpolationMethod.longer
polar_state.from_components = gfx.color_components_new(50.0, 20.0, 30.0, 1.0)
polar_state.to_components = gfx.color_components_new(60.0, 25.0, 100.0, 1.0)
css_fixup_hues_if_required(&polar_state)
tw(out, "fixup_hues ")
test_components(out, polar_state.from_components)
tw(out, " ")
test_components(out, polar_state.to_components)
tw(out, " ")
test_categories(out, polar_state.polar_target_categories)
tl(out)
# mark: Descriptors, value types, names =========================================================
## An optional double's bits or "-".
func test_optional_double(out: ak.StringBuilder*, value: f64?):
if let number = value:
td(out, number)
else:
tw(out, "-")
func test_dump_descriptors(out: ak.StringBuilder*):
tw(out, "# color function descriptors")
tl(out)
for type_index: i32 in 0..=(i32)CssColorStyleValueColorType.xyzd65:
let descriptor = css_color_function_descriptor_for((CssColorStyleValueColorType)type_index)
tv(out, descriptor.function_name)
tw(out, " ")
tn(out, (i64)descriptor.serialization_behavior)
tw(out, " ")
tn(out, (i64)descriptor.absolutizes_to_rgb)
for channel in descriptor.channels:
tw(out, " ")
tn(out, (i64)channel.kind)
tw(out, ",")
tf(out, channel.percent_reference)
tw(out, ",")
test_optional_double(out, channel.serialize_clamp_min)
tw(out, ",")
test_optional_double(out, channel.serialize_clamp_max)
tl(out)
for name in ["srgb", "xyz", "xyz-d50", "xyz-d65", "rgb", "hsl", "lab", "display-p3", "a98-rgb", "rec2020", "prophoto-rgb", "srgb-linear", "display-p3-linear", "SRGB", "oklch", ""]:
tw(out, "color function ")
tw(out, name)
tw(out, " ")
if let color_type = css_color_type_from_color_function_name(ak.sv(name)):
tn(out, (i64)color_type)
else:
tw(out, "none")
tl(out)
tw(out, "# value types")
tl(out)
let value_type_names: str[48] = ["anchor", "anchor-size", "angle", "ANGLE", "angle-percentage", "background-position", "basic-shape", "color", "corner-shape", "counter", "counter-style", "custom-ident", "dashed-ident",
"easing-function", "filter-value-list", "fit-content", "flex", "font-style", "font-variant-alternates", "font-variant-east-asian", "font-variant-ligatures", "font-variant-numeric",
"frequency", "frequency-percentage", "image", "integer", "length", "Length-Percentage", "number", "opacity-value", "opentype-tag", "paint", "percentage", "position", "ratio", "rect",
"resolution", "scroll-function", "string", "time", "time-percentage", "transform-function", "transform-list", "url", "view-function", "view-timeline-inset", "bogus", ""]
for name in value_type_names:
tw(out, "value type ")
tw(out, name)
tw(out, " ")
if let value_type = css_value_type_from_string(ak.sv(name)):
tn(out, (i64)value_type)
tw(out, " ")
tv(out, css_value_type_to_string(value_type))
else:
tw(out, "none")
tl(out)
for type_index: u8 in 0..=(u8)CssValueType.view_timeline_inset:
tw(out, "value type name ")
tn(out, (i64)type_index)
tw(out, " ")
tv(out, css_value_type_to_string((CssValueType)type_index))
tl(out)
tw(out, "# property names")
tl(out)
for name in ["color", "COLOR", "background-color", "--foo", "--", "-webkit-appearance", "word-wrap", "float", "bogus", ""]:
tw(out, "property ")
tw(out, name)
tw(out, " ")
tb(out, css_is_a_valid_css_property(ak.sv(name)))
tw(out, " ")
if let property = css_property_name_and_id_from_name(ak.fly_string_from_str(name)):
tn(out, (i64)css_property_name_and_id_id(&property))
tw(out, " ")
tfly(out, css_property_name_and_id_name(&property))
tw(out, " ")
ts(out, css_property_name_and_id_to_string(&property))
tw(out, " ")
tb(out, css_property_name_and_id_is_custom_property(&property))
else:
tw(out, "none")
tl(out)
let from_id = css_property_name_and_id_from_id(css_data.PropertyId.margin_top)
tw(out, "property from_id ")
tfly(out, css_property_name_and_id_name(&from_id))
tw(out, " ")
ts(out, css_property_name_and_id_to_string(&from_id))
tw(out, " ")
tb(out, css_property_name_and_id_is_custom_property(&from_id))
tl(out)
for at_rule in [css_data.AtRuleId.font_face, css_data.AtRuleId.counter_style, css_data.AtRuleId.property, css_data.AtRuleId.page]:
for name in ["font-family", "src", "system", "symbols", "syntax", "inherits", "initial-value", "size", "margin", "--x", "font-display", "bogus"]:
tw(out, "descriptor ")
tn(out, (i64)at_rule)
tw(out, " ")
tw(out, name)
tw(out, " ")
if let descriptor = css_descriptor_name_and_id_from_name(at_rule, ak.fly_string_from_str(name)):
tn(out, (i64)css_descriptor_name_and_id_id(&descriptor))
tw(out, " ")
tfly(out, css_descriptor_name_and_id_name(&descriptor))
tw(out, " ")
tn(out, (i64)css_descriptor_name_and_id_hash(&descriptor))
tw(out, " ")
var same_as_src = false
if let src = css_descriptor_name_and_id_from_name(at_rule, ak.fly_string_from_str("src")):
same_as_src = css_descriptor_name_and_id_eq(&descriptor, src)
tb(out, same_as_src)
else:
tw(out, "none")
tl(out)
let descriptor_from_id = css_descriptor_name_and_id_from_id(css_data.DescriptorId.font_family)
tw(out, "descriptor from_id ")
tfly(out, css_descriptor_name_and_id_name(&descriptor_from_id))
tw(out, " ")
tn(out, (i64)css_descriptor_name_and_id_hash(&descriptor_from_id))
tl(out)
# mark: URLs and style sheets ===================================================================
## `URL(url, type, modifiers)` as a value.
func test_url(url: str, type_: CssUrlType, modifiers: ak.Vector[CssRequestUrlModifier]) -> CssUrl:
var result: CssUrl = ---
css_url_construct(&result, ak.string_from_str(url), type_, modifiers)
return result
func test_dump_urls(out: ak.StringBuilder*):
tw(out, "# urls")
tl(out)
var modifiers = ak.Vector[CssRequestUrlModifier]()
ak.vector_append_t(&modifiers, css_request_url_modifier_create_cross_origin(css_data.CrossOriginModifierValue.use_credentials))
ak.vector_append_t(&modifiers, css_request_url_modifier_create_integrity(ak.fly_string_from_str("sha384-\"x\"")))
ak.vector_append_t(&modifiers, css_request_url_modifier_create_referrer_policy(css_data.ReferrerPolicyModifierValue.strict_origin_when_cross_origin))
ak.vector_append_t(&modifiers, css_request_url_modifier_create_cross_origin(css_data.CrossOriginModifierValue.anonymous))
let first = *ak.vector_at_const(&modifiers, 0)
for modifier in ak.vector_span_const(&modifiers):
ts(out, css_request_url_modifier_to_string(&modifier))
tw(out, " ")
tn(out, (i64)css_request_url_modifier_type(&modifier))
tw(out, " ")
tb(out, css_request_url_modifier_eq(&modifier, first))
tb(out, css_request_url_modifier_eq(&modifier, css_request_url_modifier_create_integrity(ak.fly_string_from_str("sha384-\"x\""))))
tl(out)
let no_modifiers = ak.Vector[CssRequestUrlModifier]()
let plain = test_url("image.png", CssUrlType.url, no_modifiers)
let src = test_url("a \"b\"\\c.png", CssUrlType.src, modifiers)
ts(out, css_url_to_string(&plain))
tw(out, " ")
ts(out, css_url_to_string(&src))
tw(out, " ")
tb(out, css_url_eq(&plain, test_url("image.png", CssUrlType.url, no_modifiers)))
tb(out, css_url_eq(&plain, src))
tb(out, css_url_eq(&src, test_url("a \"b\"\\c.png", CssUrlType.src, modifiers)))
tb(out, css_url_eq(&src, test_url("a \"b\"\\c.png", CssUrlType.url, modifiers)))
tl(out)
func test_dump_style_sheets(out: ak.StringBuilder*):
tw(out, "# style sheets")
tl(out)
for sheet in [css_default_stylesheet_source, css_quirks_mode_stylesheet_source]:
var sheet_hash: u32 = 2166136261
for byte in sheet.bytes:
sheet_hash = (sheet_hash ^ (u32)byte) *% 16777619
tn(out, (i64)sheet.length)
tw(out, " ")
thex(out, (u64)sheet_hash, 8)
tl(out)
# mark: The test ================================================================================
test "the values and units print what the reference build prints":
with memory.heap:
var out = ak.string_builder_new()
test_dump_lengths(&out)
test_dump_units(&out)
test_dump_displays(&out)
test_dump_system_colors(&out)
test_dump_sizing(&out)
test_dump_boxes(&out)
test_dump_grids(&out)
test_dump_counter_styles(&out)
test_dump_color_interpolation(&out)
test_dump_descriptors(&out)
test_dump_urls(&out)
test_dump_style_sheets(&out)
let actual_view = ak.string_builder_string_view(&out)
let actual = (str)ak.string_view_bytes(&actual_view)
let expected = test_css_values_units_expected
var actual_lines = test_split_lines(actual)
var expected_lines = test_split_lines(expected)
var line: usize = 1
var mismatches: usize = 0
while true:
let actual_line = actual_lines.next()
let expected_line = expected_lines.next()
if actual_line == none and expected_line == none:
break
let actual_text = actual_line else "(end)"
let expected_text = expected_line else "(end)"
if actual_text != expected_text and not test_lines_match_within_libm_ulps(actual_text, expected_text):
if mismatches < 20:
print(f"line {line}:\n expected: {expected_text}\n actual: {actual_text}")
mismatches += 1
line += 1
assert(mismatches == 0, "the dump differs from the oracle's")
## How many units in the last place a color component may differ from the oracle's bits. The
## oracle ran on macOS, and ColorInterpolation's conversions call the C library's cbrt, pow, atan2,
## sin and cos, whose last bits differ between C libraries (and arm64 fuses multiply-adds), so only
## macOS compares exactly, as luce-browser-render's gfx color tests do.
let test_libm_ulps: u64 = 0 if os.macos else 64
## Whether two dump lines are equal word by word, where words that are 8 hex digits (f32 bits) on
## both sides may differ by at most test_libm_ulps.
func test_lines_match_within_libm_ulps(actual: str, expected: str) -> bool:
var actual_words = test_split_words(actual)
var expected_words = test_split_words(expected)
while true:
let actual_word = actual_words.next()
let expected_word = expected_words.next()
if actual_word == none and expected_word == none:
return true
let a = actual_word else return false
let e = expected_word else return false
if a == e:
continue
let a_bits = test_parse_f32_bits(a) else return false
let e_bits = test_parse_f32_bits(e) else return false
let distance = a_bits - e_bits if a_bits >= e_bits else e_bits - a_bits
if distance > test_libm_ulps:
return false
## The value of an 8-digit lowercase hex word (the dump's f32 bits), or none for any other word.
func test_parse_f32_bits(word: str) -> u64?:
if word.length != 8:
return none
var value: u64 = 0
for c in word.bytes:
if c >= '0' and c <= '9':
value = value * 16 + (u64)(c - '0')
elif c >= 'a' and c <= 'f':
value = value * 16 + (u64)(c - 'a' + 10)
else:
return none
return value
## The words of a line, split at spaces.
struct TestWords:
var text: str
var position: usize
func next() -> str?:
while self.position < self.text.length and self.text.bytes[self.position] == ' ':
self.position += 1
if self.position >= self.text.length:
return none
var end = self.position
while end < self.text.length and self.text.bytes[end] != ' ':
end += 1
let result = (str)self.text.bytes[self.position..<end]
self.position = end
return result
## The words of `line`.
func test_split_words(line: str) -> TestWords:
return TestWords(text = line, position = 0)
## The lines of a text, without their line feeds.
struct TestLines:
var text: str
var position: usize
func next() -> str?:
if self.position >= self.text.length:
return none
var end = self.position
while end < self.text.length and self.text.bytes[end] != '\n':
end += 1
let result = (str)self.text.bytes[self.position..<end]
self.position = end + 1
return result
## The lines of `text`.
func test_split_lines(text: str) -> TestLines:
return TestLines(text = text, position = 0)