dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / tests_dump.lucb
#==============================================================================================
#
# tests_dump - the number, point and rectangle formatting of the dumps
#
# DESCRIPTION:
# The layout and paintable dumps need layout and paint trees, which later regions build;
# these pin the pieces of their text that Dump writes itself (indentation, CSSPixels,
# Gfx::Point and Gfx::Rect formatting, the box model line) to what the donor's AK
# formatters write for the same values (checked locally against the reference build).
#
#==============================================================================================
## A CSSPixels from its raw 1/64 fixed-point value.
func dump_test_px(raw: i32) -> gfx.CssPixels:
return gfx.CssPixels(m_value = raw)
## The builder's text.
func dump_test_text(builder: ak.StringBuilder*) -> str:
let view = ak.string_builder_string_view(builder)
return (str)ak.string_view_bytes(&view)
test "Dump: indentation":
var builder = ak.string_builder_new()
dump_indent(&builder, 3)
ak.string_builder_append(&builder, "x")
dump_indent(&builder, 0)
assert(dump_test_text(&builder) == " x")
test "Dump: CSSPixels, points and rectangles as AK formats them":
let rect = gfx.CssPixelRect(m_location = gfx.CssPixelPoint(m_x = dump_test_px(8 * 64), m_y = dump_test_px(1738)),
m_size = gfx.CssPixelSize(m_width = dump_test_px(-545), m_height = dump_test_px(64 * 123456 + 57)))
var builder = ak.string_builder_new()
ak.string_builder_append(&builder, "rect: ")
dump_append_css_pixel_rect(&builder, rect)
dump_appendff(&builder, " baseline: {}", [dump_arg_css_pixels(dump_test_px(883))])
assert(dump_test_text(&builder) == "rect: [8,27.15625 -8.515625x123456.890625] baseline: 13.796875")
var line = ak.string_builder_new()
ak.string_builder_append(&line, "at ")
dump_append_css_pixel_point(&line, gfx.css_pixel_rect_location(&rect))
dump_appendff(&line, " [{}+{}+{} {} {}+{}+{}]", [dump_arg_css_pixels(dump_test_px(0)), dump_arg_css_pixels(dump_test_px(1)),
dump_arg_css_pixels(dump_test_px(-1)), dump_arg_css_pixels(dump_test_px(64 * 800)), dump_arg_css_pixels(dump_test_px(32)),
dump_arg_css_pixels(dump_test_px(0)), dump_arg_css_pixels(dump_test_px(7))])
assert(dump_test_text(&line) == "at [8,27.15625] [0+0.015625+-0.015625 800 0.5+0+0.109375]")
test "Dump: strings and the class name of a cell":
var builder = ak.string_builder_new()
let name = ak.fly_string_from_str("BlockContainer")
let identifier = ak.string_from_str("#main.wide")
dump_appendff(&builder, "{} <{}{}> ", [dump_arg_fly_string(&name), ak.arg_str("div"), dump_arg_string(&identifier)])
let text = ak.utf16_string_from_str("h\u{e9}llo")
dump_append_utf16_string(&builder, &text)
assert(dump_test_text(&builder) == "BlockContainer <div#main.wide> h\u{e9}llo")
var cell = gc.Cell(vtable = (const gc.CellVTable*)&platform_timer_vtable)
let class_name = dump_class_name(&cell)
assert((str)ak.string_view_bytes(&class_name) == "Timer")