Files
benilla-octo/crates/benilla-ui/src/script/tests/talent.rs
T
Sam SungandClaude Opus 5.5 fd386e75ae Comments in benilla-ui: one line of fact each, no history, no record numbers (#143)
Part of #41: the comments of `benilla-ui` (the Lua UI engine, its FrameXML loader and its widgets) are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 43,140 comment lines become 15,161.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - `0x64a480` is the case-sensitive compare (a byte `repz cmpsb`), and `0x64a4c0` the case-insensitive one.
  - A frame's id sits at `+0xb0`, not `+0xb4`. `EnableKeyboard`/`IsKeyboardEnabled` are `0x776ec0`/`0x776f90`.
  - A region's unpinned edge has no fallback to its owner's rect: the owner supplies only the scale.
  - `$parent` expands to the nearest named ancestor, or "Top" when none is named (`0x76c5b0`), not simply to the parent.
  - A StatusBar fills from its internal normalised fraction, not from `GetValue()`.
  - The addresses of `StartDuel` and `StartDuelUnit` were swapped.
  - Many "untraced" notes now give the traced reference fact: the drag threshold, the per-grip sizing edges, the empty-`autoFocus` skip, and `SetTexCoordModifiesRect`'s default.
  - Stock FrameXML line citations are checked against the stock 1.12 files and corrected. `ref-` file names become the stock file names.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. A surface that exists only for the retired Era addon target says so plainly: it is not 1.12.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Nine second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the code, the stock files, vmangos and the reference.

Behaviour differences the rewrite surfaced are filed as their own issues (#131–#142), and more are being validated. The comments here state what the code does. String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 01:58:49 +07:00

221 lines
7.6 KiB
Rust

//! The talent bindings over a pushed snapshot, the learn queue, and `SetTalent`: the spell tooltip
//! with the talent lines interleaved.
use super::common::script;
use crate::script::*;
fn one_tab_state() -> TalentUiState {
TalentUiState {
tabs: vec![
TalentTabView {
name: "Fire".into(),
background: "MageFire".into(),
points_spent: 7,
},
TalentTabView {
name: "Frost".into(),
background: "MageFrost".into(),
points_spent: 0,
},
],
talents: vec![
vec![
TalentView {
name: "Improved Fireball".into(),
texture: Some("Interface\\Icons\\Spell_Fire_FlameBolt".into()),
tier: 1,
column: 1,
rank: 3,
max_rank: 5,
exceptional: false,
meets_prereq: true,
prereqs: Vec::new(),
display_spell: 11070,
next_spell: 11071,
req_lines: Vec::new(),
learnable: true,
},
TalentView {
name: "Ignite".into(),
texture: None,
tier: 2,
column: 2,
rank: 0,
max_rank: 5,
exceptional: false,
meets_prereq: true,
prereqs: vec![TalentPrereqView {
tier: 1,
column: 1,
learnable: false,
}],
display_spell: 11119,
next_spell: 0,
req_lines: vec!["Requires 5 points in Improved Fireball".into()],
learnable: false,
},
],
Vec::new(),
],
points: (2, 1),
}
}
#[test]
fn bindings_read_the_pushed_snapshot() {
let mut s = script();
s.set_talents(one_tab_state());
s.run(
r#"
assert(GetNumTalentTabs() == 2)
local name, texture, points, file = GetTalentTabInfo(1)
assert(name == "Fire" and texture == nil and points == 7 and file == "MageFire")
assert(GetTalentTabInfo(3) == nil, "out of range is nil")
assert(GetNumTalents(1) == 2 and GetNumTalents(2) == 0 and GetNumTalents(9) == 0)
local n, icon, tier, col, rank, max, exc, meets = GetTalentInfo(1, 1)
assert(n == "Improved Fireball" and tier == 1 and col == 1)
assert(rank == 3 and max == 5 and exc == 0 and meets == true)
assert(icon == "Interface\\Icons\\Spell_Fire_FlameBolt")
assert(GetTalentInfo(1, 9) == nil)
-- The prereq triplets, flat (the reference walks arg[5], arg[6], arg[7], ...).
local pt, pc, pl = GetTalentPrereqs(1, 2)
assert(pt == 1 and pc == 1 and pl == false)
assert(GetTalentPrereqs(1, 1) == nil, "no prereqs is empty")
local cp1, cp2 = UnitCharacterPoints("player")
assert(cp1 == 2 and cp2 == 1)
"#,
)
.unwrap();
assert!(s.take_errors().is_empty());
}
#[test]
fn learn_talent_queues_for_the_app_drain() {
let mut s = script();
s.set_talents(one_tab_state());
s.run("LearnTalent(1, 1); LearnTalent(1, 2)").unwrap();
assert_eq!(s.take_talent_learns(), vec![(1, 1), (1, 2)]);
assert!(s.take_talent_learns().is_empty(), "drain empties the queue");
assert!(s.take_errors().is_empty());
}
/// Stand-in values for the three talent keys, not the shipped wording: the tests check which key
/// each line reaches.
fn seed_talent_strings(s: &mut UiScript) {
s.run(
r#"
TOOLTIP_TALENT_RANK = "[RANK %d/%d]"
TOOLTIP_TALENT_NEXT_RANK = "[NEXT_RANK]"
TOOLTIP_TALENT_LEARN = "[LEARN]"
"#,
)
.unwrap();
}
/// `SetTalent`'s lines: name, `TOOLTIP_TALENT_RANK` (white), cost, gold description,
/// `TOOLTIP_TALENT_NEXT_RANK` and the next rank's gold description, green `TOOLTIP_TALENT_LEARN`.
#[test]
fn set_talent_renders_the_interleaved_tooltip() {
let mut s = script();
seed_talent_strings(&mut s);
s.set_talents(one_tab_state());
s.set_spell_tooltip(
11070,
SpellTooltipView {
name: "Improved Fireball".into(),
cast_time: Some("Instant".into()),
description: "Reduces the casting time of your Fireball spell by 0.3 sec.".into(),
..Default::default()
},
);
s.set_spell_tooltip(
11071,
SpellTooltipView {
name: "Improved Fireball".into(),
description: "Reduces the casting time of your Fireball spell by 0.4 sec.".into(),
..Default::default()
},
);
s.run(
r#"
local a = CreateFrame("Button", "TB1"); a:SetPoint("CENTER", 0, 0); a:SetWidth(10); a:SetHeight(10)
local tt = CreateFrame("GameTooltip", "TT")
tt:SetOwner(a, "ANCHOR_RIGHT")
tt:SetTalent(1, 1)
assert(tt:IsShown(), "SetTalent shows")
-- name, rank, Instant, desc, next-rank header, next desc, learn hint = 7 lines.
assert(tt:NumLines() == 7, "got " .. tt:NumLines())
assert(TTTextLeft1:GetText() == "Improved Fireball")
assert(TTTextLeft2:GetText() == "[RANK 3/5]", "got " .. TTTextLeft2:GetText())
assert(TTTextLeft3:GetText() == "Instant")
assert(TTTextLeft5:GetText() == "[NEXT_RANK]")
assert(TTTextLeft7:GetText() == "[LEARN]")
"#,
)
.unwrap();
s.resolve();
let quads = s.extract();
let green = quads.iter().any(|q| {
matches!(&q.content, QuadContent::Text { text: Some(t), color: Some(c), .. }
if t == "[LEARN]" && c[0] < 1e-6 && (c[1] - 1.0).abs() < 1e-6)
});
assert!(green, "the learn hint is green");
assert!(s.take_errors().is_empty());
}
/// A missing spell view renders the rank line alone and asks for the view once.
#[test]
fn set_talent_locked_reqs_and_the_ask_once_miss() {
let mut s = script();
seed_talent_strings(&mut s);
s.set_talents(one_tab_state());
// No spell view pushed for Ignite (11119).
s.run(
r#"
local a = CreateFrame("Button", "TB2"); a:SetPoint("CENTER", 0, 0); a:SetWidth(10); a:SetHeight(10)
local tt = CreateFrame("GameTooltip", "TT2")
tt:SetOwner(a, "ANCHOR_RIGHT")
tt:SetTalent(1, 2)
assert(tt:IsShown())
assert(TT2TextLeft1:GetText() == "[RANK 0/5]", "fallback shows the rank head")
"#,
)
.unwrap();
let asks = s.take_spell_tooltip_asks();
assert!(
asks.contains(&11119),
"the display spell was asked: {asks:?}"
);
s.set_spell_tooltip(
11119,
SpellTooltipView {
name: "Ignite".into(),
description: "Your critical strikes ignite the target.".into(),
..Default::default()
},
);
s.run(
r#"
local tt = getglobal("TT2")
tt:SetOwner(getglobal("TB2"), "ANCHOR_RIGHT")
tt:SetTalent(1, 2)
-- name, rank, req(red), desc = 4 lines; rank 0 has no next block, locked has no hint.
assert(tt:NumLines() == 4, "got " .. tt:NumLines())
assert(TT2TextLeft3:GetText() == "Requires 5 points in Improved Fireball")
"#,
)
.unwrap();
s.resolve();
let quads = s.extract();
let red = quads.iter().any(|q| {
matches!(&q.content, QuadContent::Text { text: Some(t), color: Some(c), .. }
if t.starts_with("Requires 5") && (c[0] - 1.0).abs() < 1e-6 && c[1] < 0.2)
});
assert!(red, "the requirement line is red");
assert!(s.take_errors().is_empty());
}