dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / css / style_values / tests_style_values_1.lucb
#==============================================================================================
#
# tests_style_values_1 - region r34's style values print what the reference build prints
#
# DESCRIPTION:
# Builds the values of tests_style_values_1_values and prints, as the local oracle
# (luce-browser-tools/oracles/luce-browser-engine/style_values_1/oracle.cpp) does, each
# value's serialization in both modes, its flags and computational independence, its colors
# in a light and a dark context, its absolutization in a context with and without a color
# scheme (and whether that answered the value itself), the full equality matrix, the
# tokenization, the free helpers and statics, and the geometry of gradient angles and radial
# sizes; then compares the dump line by line with tests_style_values_1_expected. Colors are
# ARGB, CSSPixels raw values, floats bits. The printing helpers (tw, tv, ts, ...) are
# tests_css_values_units_1's.
#
#==============================================================================================
# mark: Contexts ================================================================================
## The oracle's length resolution context: an 800x600 viewport and its font metrics.
func test_style_length_context() -> CssLengthResolutionContext:
var viewport: gfx.CssPixelRect = ---
gfx.css_pixel_rect_construct_int(&viewport, 0, 0, 800, 600)
return CssLengthResolutionContext(viewport_rect = viewport, font_metrics = test_font_metrics(), root_font_metrics = test_root_font_metrics())
## Append a color as ARGB, or "none".
func test_color(out: ak.StringBuilder*, color: gfx.Color?):
if let c = color:
thex(out, (u64)gfx.color_value(&c), 8)
else:
tw(out, "none")
## Whether a position has an edge without an offset (EdgeStyleValue::is_computationally_independent needs one).
func test_position_lacks_offset(position: CssPositionStyleValue*) -> bool:
return position.m_properties.edge_x.m_properties.offset == none or position.m_properties.edge_y.m_properties.offset == none
## The values whose is_computationally_independent() verifies or needs a missing edge offset.
func test_independence_verifies(value: CssStyleValue*) -> bool:
if css_style_value_is_edge(value):
return css_style_value_as_edge(value).m_properties.offset == none
if css_style_value_is_position(value):
return test_position_lacks_offset(css_style_value_as_position(value))
if css_style_value_is_conic_gradient(value):
return test_position_lacks_offset(css_style_value_as_conic_gradient(value).m_properties.position)
if css_style_value_is_radial_gradient(value):
return test_position_lacks_offset(css_style_value_as_radial_gradient(value).m_properties.position)
if css_style_value_is_tuple(value):
for member in ak.vector_span_const(&css_style_value_as_tuple(value).m_tuple):
if member == none:
return true
return false
return css_style_value_is_guaranteed_invalid(value) or css_style_value_is_pending_substitution(value) or css_style_value_is_unicode_range(value) or css_style_value_is_unresolved(value)
## The values whose absolutized() needs an element.
func test_absolutize_needs_element(value: CssStyleValue*) -> bool:
if css_style_value_is_tree_counting_function(value):
return true
if css_style_value_is_random_value_sharing(value):
return css_style_value_as_random_value_sharing(value).m_fixed_value == none
return false
## The type's snake-case name, as ENUMERATE_CSS_STYLE_VALUE_TYPES spells it.
func test_type_name(type_: CssStyleValueType) -> str:
match type_:
.anchor: return "anchor"
.anchor_size: return "anchor_size"
.angle: return "angle"
.background_size: return "background_size"
.basic_shape: return "basic_shape"
.border_image_slice: return "border_image_slice"
.border_radius: return "border_radius"
.border_radius_rect: return "border_radius_rect"
.calculated: return "calculated"
.color_interpolation_method: return "color_interpolation_method"
.color_scheme: return "color_scheme"
.color: return "color"
.conic_gradient: return "conic_gradient"
.content: return "content"
.cursor: return "cursor"
.custom_ident: return "custom_ident"
.display: return "display"
.edge: return "edge"
.flex: return "flex"
.frequency: return "frequency"
.function: return "function"
.guaranteed_invalid: return "guaranteed_invalid"
.image: return "image"
.image_set: return "image_set"
.integer: return "integer"
.keyword: return "keyword"
.length: return "length"
.linear_gradient: return "linear_gradient"
.number: return "number"
.opacity_value: return "opacity_value"
.open_type_tagged: return "open_type_tagged"
.pending_substitution: return "pending_substitution"
.percentage: return "percentage"
.position: return "position"
.radial_gradient: return "radial_gradient"
.radial_size: return "radial_size"
.random_value_sharing: return "random_value_sharing"
.ratio: return "ratio"
.rect: return "rect"
.repeat_style: return "repeat_style"
.resolution: return "resolution"
.scrollbar_color: return "scrollbar_color"
.scrollbar_gutter: return "scrollbar_gutter"
.shadow: return "shadow"
.shorthand: return "shorthand"
.string: return "string"
.superellipse: return "superellipse"
.text_indent: return "text_indent"
.text_underline_position: return "text_underline_position"
.time: return "time"
.tree_counting_function: return "tree_counting_function"
.tuple: return "tuple"
.unicode_range: return "unicode_range"
.unresolved: return "unresolved"
.url: return "url"
.value_list: return "value_list"
_: return "?"
# mark: Sections ================================================================================
## The `# values` section.
func test_dump_style_values(out: ak.StringBuilder*, values: const ak.Vector[TestStyleValue]*):
let context = CssComputationContext(length_resolution_context = test_style_length_context())
let dark_context = CssComputationContext(length_resolution_context = test_style_length_context(), color_scheme = CssPreferredColorScheme.dark)
let light = CssColorResolutionContext(color_scheme = CssPreferredColorScheme.light, current_color = gfx.color_new_u8_u8_u8(10, 20, 30), accent_color = none, document = none, calculation_resolution_context = CssCalculationResolutionContext(length_resolution_context = test_style_length_context()))
let dark = CssColorResolutionContext(color_scheme = CssPreferredColorScheme.dark, current_color = gfx.color_new_u8_u8_u8_u8(40, 50, 60, 70), accent_color = gfx.color_new_u8_u8_u8(200, 100, 50), document = none, calculation_resolution_context = CssCalculationResolutionContext(length_resolution_context = test_style_length_context()))
tw(out, "# values\n")
for i in 0..<ak.vector_size(values):
let entry = ak.vector_at_const(values, i)
let value = entry.value
tn(out, (i64)i)
tw(out, " ")
tw(out, entry.label)
tw(out, " ")
tw(out, test_type_name(css_style_value_type(value)))
tw(out, "\n N ")
ts(out, css_style_value_to_string(value, css_syntax.SerializationMode.normal))
tw(out, "\n R ")
ts(out, css_style_value_to_string(value, css_syntax.SerializationMode.resolved_value))
tw(out, "\n flags ")
tb(out, css_style_value_is_abstract_image(value))
tb(out, css_style_value_is_dimension(value))
tb(out, css_style_value_is_color_function(value))
tb(out, css_style_value_has_color(value))
tb(out, css_style_value_has_auto(value))
tb(out, css_style_value_is_css_wide_keyword(value))
tb(out, css_style_value_is_inherit(value))
tb(out, css_style_value_is_initial(value))
tb(out, css_style_value_is_unset(value))
tb(out, css_style_value_is_revert(value))
tb(out, css_style_value_is_revert_layer(value))
tw(out, " ")
tv(out, css_data.string_from_keyword(css_style_value_to_keyword(value)))
tw(out, " ")
if test_independence_verifies(value):
tw(out, "-")
else:
tb(out, css_style_value_is_computationally_independent(value))
tw(out, "\n colors ")
test_color(out, css_style_value_to_color(value, light))
tw(out, " ")
test_color(out, css_style_value_to_color(value, dark))
if test_absolutize_needs_element(value):
tw(out, "\n abs -\n")
continue
let absolutized = css_style_value_absolutized(value, context)
let dark_absolutized = css_style_value_absolutized(value, dark_context)
tw(out, "\n abs ")
tb(out, absolutized == value)
tw(out, " ")
ts(out, css_style_value_to_string(absolutized, css_syntax.SerializationMode.normal))
tw(out, " ; ")
ts(out, css_style_value_to_string(absolutized, css_syntax.SerializationMode.resolved_value))
tw(out, " ; ")
tb(out, dark_absolutized == value)
tw(out, " ")
ts(out, css_style_value_to_string(dark_absolutized, css_syntax.SerializationMode.normal))
tl(out)
## A radial size of one length-percentage.
func test_radial_size_of(value: CssStyleValue*) -> CssRadialSizeStyleValue*:
var components = ak.Vector[CssRadialSizeStyleValueComponent]()
ak.vector_append_t(&components, CssRadialSizeStyleValueComponent.css_style_value(value))
return css_radial_size_style_value_create(components)
## A shorthand of margin-like longhands.
func test_shorthand(shorthand: css_data.PropertyId, longhands: const css_data.PropertyId[], values: const (CssStyleValue*)[]) -> CssStyleValue*:
var sub_properties = ak.Vector[css_data.PropertyId]()
for longhand in longhands:
ak.vector_append_t(&sub_properties, longhand)
var vector = ak.Vector[CssStyleValue*]()
for value in values:
ak.vector_append_t(&vector, value)
return css_shorthand_style_value_create(shorthand, sub_properties, vector).css_style_value()
## An image-set() of one option.
func test_image_set_one() -> CssStyleValue*:
var options = ak.Vector[CssImageSetStyleValueOption]()
ak.vector_append_t(&options, CssImageSetStyleValueOption(image = tsv_image("a.png").css_abstract_image_style_value(), resolution = css_resolution_style_value_create(css_resolution_new(1.0, css_data.ResolutionUnit.x)).css_style_value(), type_ = ak.string_from_str("image/png")))
return css_image_set_style_value_create(options).css_style_value()
## A linear-gradient() of one stop.
func test_linear_one(direction: CssLinearGradientStyleValueGradientDirection, type_: CssLinearGradientStyleValueGradientType) -> CssLinearGradientStyleValue*:
return css_linear_gradient_style_value_create(direction, tsv_stops([tsv_stop(tsv_rgb(1.0, 1.0, 1.0))]), type_, CssGradientRepeating.no, none)
## The `# equals` section.
func test_dump_equals(out: ak.StringBuilder*, values: const ak.Vector[TestStyleValue]*):
let px = css_data.LengthUnit.px
let em = css_data.LengthUnit.em
tw(out, "# equals\n")
for i in 0..<ak.vector_size(values):
tn(out, (i64)i)
tw(out, " ")
for j in 0..<ak.vector_size(values):
tb(out, css_style_value_equals(ak.vector_at_const(values, i).value, ak.vector_at_const(values, j).value))
tl(out)
# Equal values built separately.
tw(out, "separately ")
tb(out, css_style_value_equals(tsv_rgb(1.0, 2.0, 3.0), tsv_rgb(1.0, 2.0, 3.0)))
tb(out, css_style_value_equals(tsv_len(2.0, em), tsv_len(2.0, em)))
tb(out, css_style_value_equals(tsv_list([tsv_num(1.0), tsv_num(2.0)], CssStyleValueListSeparator.space).css_style_value(), tsv_list([tsv_num(1.0), tsv_num(2.0)], CssStyleValueListSeparator.space).css_style_value()))
tb(out, css_style_value_equals(tsv_list([tsv_num(1.0), tsv_num(2.0)], CssStyleValueListSeparator.space).css_style_value(), tsv_list([tsv_num(1.0), tsv_num(2.0)], CssStyleValueListSeparator.comma).css_style_value()))
tb(out, css_style_value_equals(test_radial_size_of(tsv_pct(1.0)).css_style_value(), test_radial_size_of(tsv_pct(1.0)).css_style_value()))
tb(out, css_style_value_equals(tsv_extent(css_data.RadialExtent.closest_corner).css_style_value(), tsv_extent(css_data.RadialExtent.closest_corner).css_style_value()))
tb(out, css_style_value_equals(test_linear_one(.css_side_or_corner(CssSideOrCorner.right), CssLinearGradientStyleValueGradientType.standard).css_style_value(), test_linear_one(.css_side_or_corner(CssSideOrCorner.right), CssLinearGradientStyleValueGradientType.standard).css_style_value()))
tb(out, css_style_value_equals(test_shorthand(css_data.PropertyId.margin, [css_data.PropertyId.margin_top, css_data.PropertyId.margin_right], [tsv_len(1.0, px), tsv_len(2.0, px)]), test_shorthand(css_data.PropertyId.margin, [css_data.PropertyId.margin_top, css_data.PropertyId.margin_right], [tsv_len(1.0, px), tsv_len(2.0, px)])))
tb(out, css_style_value_equals(test_shorthand(css_data.PropertyId.margin, [css_data.PropertyId.margin_top], [tsv_len(1.0, px)]), test_shorthand(css_data.PropertyId.padding, [css_data.PropertyId.margin_top], [tsv_len(1.0, px)])))
tb(out, css_style_value_equals(test_image_set_one(), test_image_set_one()))
tl(out)
## The `# tokenize` section.
func test_dump_tokenize(out: ak.StringBuilder*, values: const ak.Vector[TestStyleValue]*):
tw(out, "# tokenize\n")
for i in 0..<ak.vector_size(values):
let value = ak.vector_at_const(values, i).value
if not (css_style_value_is_unresolved(value) or css_style_value_is_guaranteed_invalid(value) or css_style_value_is_pending_substitution(value) or css_style_value_is_keyword(value) or css_style_value_is_number(value) or css_style_value_is_integer(value) or css_style_value_is_dimension(value) or css_style_value_is_string(value) or css_style_value_is_custom_ident(value) or css_style_value_is_ratio(value) or css_style_value_is_value_list(value) or css_style_value_is_color(value) or css_style_value_is_edge(value)):
continue
tn(out, (i64)i)
tw(out, " ")
let tokens = css_style_value_tokenize(value)
for j in 0..<ak.vector_size(&tokens):
if j != 0:
tw(out, " | ")
ts(out, css_syntax.component_value_to_debug_string(ak.vector_at_const(&tokens, j)))
tl(out)