Files
benilla-octo/crates/benilla-ui/src/script/tests/gm_ticket.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

142 lines
4.7 KiB
Rust

//! The Help window's seven engine globals ([`crate::script::gm_ticket`]).
use super::common::script;
use crate::script::{GmTicketIntent, GmTicketWrite, UiScript};
/// The catalog as the app pushes it: `GMTicketCategory.dbc`'s own ids and order.
fn with_categories() -> UiScript {
let mut s = script();
s.set_gm_ticket_categories(vec![
(1, "Stuck".into()),
(2, "Behavior/Harassment".into()),
(3, "Guild".into()),
]);
s
}
/// The stock window walks it as `arg[i]`, `arg[i+1]` pairs up to `arg.n`.
#[test]
fn the_categories_come_back_as_a_flat_id_name_vararg_list() {
let s = with_categories();
let n: i64 = s
.eval("local f = function(...) return arg.n end return f(GetGMTicketCategories())")
.unwrap();
assert_eq!(n, 6, "three categories = six varargs");
let (id1, name1, id3, name3): (i64, String, i64, String) = s
.eval(
"local f = function(...) return arg[1], arg[2], arg[5], arg[6] end \
return f(GetGMTicketCategories())",
)
.unwrap();
assert_eq!((id1, name1.as_str()), (1, "Stuck"));
assert_eq!((id3, name3.as_str()), (3, "Guild"));
}
/// `HelpFrameGM_UpdateCategories` stores the id as `button.key` and as the wire `ticketType`.
#[test]
fn the_ids_are_the_dbc_ids_not_list_positions() {
let mut s = script();
// Gappy and unsorted on purpose.
s.set_gm_ticket_categories(vec![(10, "Character".into()), (4, "Item".into())]);
let (a, b): (i64, i64) = s
.eval("local f = function(...) return arg[1], arg[3] end return f(GetGMTicketCategories())")
.unwrap();
assert_eq!((a, b), (10, 4), "ids and order pass through untouched");
}
/// The bare-XML harness and a run with no client data have no catalog.
#[test]
fn an_absent_catalog_returns_nothing_rather_than_erroring() {
let s = script();
let n: i64 = s
.eval("local f = function(...) return arg.n end return f(GetGMTicketCategories())")
.unwrap();
assert_eq!(n, 0);
}
/// Two `GetGMTicket()` calls are two packets: `TicketStatus_OnUpdate` re-polls every 10 minutes.
#[test]
fn the_payload_free_verbs_queue_rather_than_latch() {
let mut s = script();
s.run("GetGMTicket() GetGMTicket() GetGMStatus() DeleteGMTicket() Stuck() Stuck() Stuck()")
.unwrap();
assert_eq!(
s.take_gm_ticket_intents(),
vec![
GmTicketIntent::Ask,
GmTicketIntent::Ask,
GmTicketIntent::AskStatus,
GmTicketIntent::Delete,
]
);
assert_eq!(s.take_stuck_casts(), 3, "Stuck is not a ticket verb");
assert!(s.take_gm_ticket_intents().is_empty());
assert_eq!(s.take_stuck_casts(), 0);
}
/// Call order is wire order: reversed, the get would answer with the ticket just deleted.
#[test]
fn the_queue_preserves_call_order_across_different_verbs() {
let mut s = script();
s.run("DeleteGMTicket() GetGMTicket()").unwrap();
assert_eq!(
s.take_gm_ticket_intents(),
vec![GmTicketIntent::Delete, GmTicketIntent::Ask],
"delete first, exactly as Lua called them"
);
// The other way round, so a fixed per-verb order cannot pass.
s.run("GetGMTicket() DeleteGMTicket()").unwrap();
assert_eq!(
s.take_gm_ticket_intents(),
vec![GmTicketIntent::Ask, GmTicketIntent::Delete]
);
s.run("NewGMTicket(1, \"a\") GetGMTicket()").unwrap();
assert!(matches!(
s.take_gm_ticket_intents().as_slice(),
[GmTicketIntent::Write(_), GmTicketIntent::Ask]
));
}
/// Same signature, different opcodes; the stock window picks one from its own `hasTicket` flag.
#[test]
fn new_and_update_are_distinguishable_and_keep_their_order() {
let mut s = script();
s.run("NewGMTicket(4, \"My sword vanished.\") UpdateGMTicket(4, \"Still gone.\")")
.unwrap();
assert_eq!(
s.take_gm_ticket_intents(),
vec![
GmTicketIntent::Write(GmTicketWrite {
category: 4,
text: "My sword vanished.".into(),
is_new: true,
}),
GmTicketIntent::Write(GmTicketWrite {
category: 4,
text: "Still gone.".into(),
is_new: false,
}),
]
);
}
/// The reference's usage string is `Usage: UpdateGMTicket(type, text)`. The binding queues any
/// text; the reference refuses an empty one before the send (`ERR_TICKET_NO_TEXT`, `0x5ef808`,
/// `0x5efae7`).
#[test]
fn an_empty_ticket_body_is_queued_not_swallowed() {
let mut s = script();
s.run("NewGMTicket(1, \"\")").unwrap();
assert_eq!(
s.take_gm_ticket_intents(),
vec![GmTicketIntent::Write(GmTicketWrite {
category: 1,
text: String::new(),
is_new: true,
})]
);
}