Files
benilla-octo/crates/benilla-ui/src/script/tests/end_to_end.rs
T
SamandClaude Fable 5 2ad0043523 benilla: initial public release
A from-scratch World of Warcraft 1.12.1 client in Rust + Bevy.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 14:27:01 +07:00

79 lines
3.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! End-to-end: build a two-frame anchored tree with textures, extract in ZKey order.
use super::common::script;
use crate::layout::Rect;
use crate::script::*;
#[test]
fn end_to_end_two_frame_tree_extracts_in_zkey_order() {
let mut s = script();
s.set_screen_size(800.0, 600.0);
s.run(
r#"
-- A parent frame with a background texture, and a child frame (lower in insertion order,
-- same strata/level) with a texture and a fontstring. ~30 lines of ordinary FrameXML Lua.
local parent = CreateFrame("Frame", "Root")
parent:SetPoint("TOPLEFT", 0, 0) -- anchored to the screen root
parent:SetSize(400, 300)
local pbg = parent:CreateTexture(nil, "BACKGROUND")
pbg:SetTexture("Interface\\Parent.blp")
local child = CreateFrame("Frame", "Leaf", parent)
child:SetPoint("TOPLEFT", parent, "TOPLEFT", 10, -10)
child:SetSize(100, 50)
local cbg = child:CreateTexture(nil, "ARTWORK")
cbg:SetTexture("Interface\\Child.blp")
local ctext = child:CreateFontString(nil, "OVERLAY")
ctext:SetText("Hello")
ctext:SetVertexColor(1, 0, 0, 1)
"#,
)
.unwrap();
s.resolve();
let quads = s.extract();
// The renderable content, in painter order: parent's bg, child's bg, child's text — parent frame
// draws before child (earlier insertion, same strata/level), each frame's regions grouped behind
// it (order.rs ZKey).
let content: Vec<String> = quads
.iter()
.filter_map(|q| match &q.content {
QuadContent::Texture { path: Some(p), .. } => Some(format!("tex:{p}")),
QuadContent::Text { text: Some(t), .. } => Some(format!("txt:{t}")),
_ => None,
})
.collect();
assert_eq!(
content,
vec![
"tex:Interface\\Parent.blp",
"tex:Interface\\Child.blp",
"txt:Hello",
]
);
// Region rects are their owner frame's resolved rect (v1). Parent → Rect(300,0,600,400);
// child (TOPLEFT+10,-10 of parent, 100×50) → Rect(540,10,590,110).
let child_text = quads
.iter()
.find(|q| matches!(&q.content, QuadContent::Text { text: Some(t), .. } if t == "Hello"))
.unwrap();
assert_eq!(child_text.rect, Some(Rect::new(540.0, 10.0, 590.0, 110.0)));
// The fontstring got a red vertex color via SetVertexColor(1,0,0,1).
assert!(
matches!(&child_text.content, QuadContent::Text { color: Some(c), .. } if *c == [1.0, 0.0, 0.0, 1.0])
);
let parent_bg = quads
.iter()
.find(|q| matches!(&q.content, QuadContent::Texture { path: Some(p), .. } if p.ends_with("Parent.blp")))
.unwrap();
assert_eq!(parent_bg.rect, Some(Rect::new(300.0, 0.0, 600.0, 400.0)));
// ZKey order is ascending and strictly increasing across the emitted list.
let zs: Vec<u64> = quads.iter().map(|q| q.z).collect();
let mut sorted = zs.clone();
sorted.sort_unstable();
assert_eq!(zs, sorted, "extract must already be in ZKey order");
}