Skip to main content

runec/
trigger_table.rs

1//! Single source of truth for RuneScript trigger metadata.
2//!
3//! Every trigger keyword (`[opnpc1,…]`, `[if_button,…]`, `[login,_]`, …)
4//! has the same shape of metadata: a byte discriminant for lookup-key
5//! dispatch, an optional preferred subject type for entity resolution,
6//! whether its subject should be validated to resolve, and whether it's a
7//! button trigger that participates in pointer-grant logic.
8//!
9//! Before this module existed, that metadata was scattered across three
10//! separate matches in `compiler.rs` (the byte table, the
11//! `is_byte_keyed_trigger` whitelist, and the `preferred_type` selector)
12//! plus a 13-arm match in `pointer_checker.rs`. Adding a trigger meant
13//! editing four places, and one of them was the bug shape that silently
14//! produced unreachable scripts.
15
16use crate::types::Type;
17use std::collections::HashMap;
18use std::sync::OnceLock;
19
20#[derive(Debug, Clone, Copy)]
21pub struct TriggerInfo {
22    pub name: &'static str,
23    pub byte: u8,
24    /// Preferred entity type for `lookup_entity_id_typed`. `None` falls
25    /// through to the flat entity-id lookup.
26    pub subject_type: Option<Type>,
27    /// True if a `[trigger,name]` script with a non-`_`, non-`_category`,
28    /// non-coord subject should resolve to a real entity. Drives the
29    /// "subject did not resolve" warning. False for triggers that:
30    ///   - have no entity subject (login, logout)
31    ///   - take coord-shaped subjects (zone, zoneexit, mapzone, mapzoneexit)
32    ///   - intentionally don't validate (ai_queue, ai_timer — preserved
33    ///     from the original `is_byte_keyed_trigger` whitelist; widening
34    ///     this would change emitted warnings)
35    pub validates_subject: bool,
36    /// True for if_button/if_button1-10/if_buttond and inv_button1-5/inv_buttond.
37    /// Used by pointer_checker to grant p_active_player on non-overlay
38    /// interfaces, mirroring ServerPointerChecker.setsPointerTrigger().
39    pub is_button: bool,
40}
41
42const TRIGGERS: &[TriggerInfo] = &[
43    // ── NPC triggers ─────────────────────────────────────────────────
44    npc("apnpc1", 3),
45    npc("apnpc2", 4),
46    npc("apnpc3", 5),
47    npc("apnpc4", 6),
48    npc("apnpc5", 7),
49    npc("apnpcu", 8),
50    npc("apnpct", 9),
51    npc("opnpc1", 10),
52    npc("opnpc2", 11),
53    npc("opnpc3", 12),
54    npc("opnpc4", 13),
55    npc("opnpc5", 14),
56    npc("opnpcu", 15),
57    npc("opnpct", 16),
58    npc("ai_apnpc1", 17),
59    npc("ai_apnpc2", 18),
60    npc("ai_apnpc3", 19),
61    npc("ai_apnpc4", 20),
62    npc("ai_apnpc5", 21),
63    npc("ai_opnpc1", 24),
64    npc("ai_opnpc2", 25),
65    npc("ai_opnpc3", 26),
66    npc("ai_opnpc4", 27),
67    npc("ai_opnpc5", 28),
68    // ── Ground obj triggers ──────────────────────────────────────────
69    obj("apobj1", 31),
70    obj("apobj2", 32),
71    obj("apobj3", 33),
72    obj("apobj4", 34),
73    obj("apobj5", 35),
74    obj("apobju", 36),
75    obj("apobjt", 37),
76    obj("opobj1", 38),
77    obj("opobj2", 39),
78    obj("opobj3", 40),
79    obj("opobj4", 41),
80    obj("opobj5", 42),
81    obj("opobju", 43),
82    obj("opobjt", 44),
83    // An npc's AI triggers name the npc (or `_category`) whatever its target:
84    // the engine keys them by the acting npc's type, and RuneScriptTS gives them
85    // SubjectMode.Type(NPC).
86    npc("ai_apobj1", 45),
87    npc("ai_apobj2", 46),
88    npc("ai_apobj3", 47),
89    npc("ai_apobj4", 48),
90    npc("ai_apobj5", 49),
91    npc("ai_opobj1", 52),
92    npc("ai_opobj2", 53),
93    npc("ai_opobj3", 54),
94    npc("ai_opobj4", 55),
95    npc("ai_opobj5", 56),
96    // ── Loc triggers ─────────────────────────────────────────────────
97    loc("aploc1", 59),
98    loc("aploc2", 60),
99    loc("aploc3", 61),
100    loc("aploc4", 62),
101    loc("aploc5", 63),
102    loc("aplocu", 64),
103    loc("aploct", 65),
104    loc("oploc1", 66),
105    loc("oploc2", 67),
106    loc("oploc3", 68),
107    loc("oploc4", 69),
108    loc("oploc5", 70),
109    loc("oplocu", 71),
110    loc("oploct", 72),
111    // An npc's AI triggers name the npc (or `_category`) whatever its target:
112    // the engine keys them by the acting npc's type, and RuneScriptTS gives them
113    // SubjectMode.Type(NPC).
114    npc("ai_aploc1", 73),
115    npc("ai_aploc2", 74),
116    npc("ai_aploc3", 75),
117    npc("ai_aploc4", 76),
118    npc("ai_aploc5", 77),
119    npc("ai_oploc1", 80),
120    npc("ai_oploc2", 81),
121    npc("ai_oploc3", 82),
122    npc("ai_oploc4", 83),
123    npc("ai_oploc5", 84),
124    // ── Player triggers (no preferred type — fall through to flat lookup) ──
125    flat("applayer1", 87),
126    flat("applayer2", 88),
127    flat("applayer3", 89),
128    flat("applayer4", 90),
129    flat("applayer5", 91),
130    flat("applayeru", 92),
131    flat("applayert", 93),
132    flat("opplayer1", 94),
133    flat("opplayer2", 95),
134    flat("opplayer3", 96),
135    flat("opplayer4", 97),
136    flat("opplayer5", 98),
137    flat("opplayeru", 99),
138    flat("opplayert", 100),
139    // Rev-647 players have ops 6-10 (the client shows eight). Bytes 182-186 and
140    // 189-193 must match the engine's ServerTriggerType ApPlayer6-10 and
141    // OpPlayer6-10, which keeps each op 7 past its ap.
142    flat("applayer6", 182),
143    flat("applayer7", 183),
144    flat("applayer8", 184),
145    flat("applayer9", 185),
146    flat("applayer10", 186),
147    flat("opplayer6", 189),
148    flat("opplayer7", 190),
149    flat("opplayer8", 191),
150    flat("opplayer9", 192),
151    flat("opplayer10", 193),
152    // Rev-647 ground targeting (APCOORDT): a component aimed at a tile,
153    // approached only and keyed by the component. Byte 194 must match the
154    // engine's ServerTriggerType ApCoordT, and 201, 7 past it, stays unused:
155    // the engine looks an op trigger up there.
156    flat("apcoordt", 194),
157    // An npc's AI triggers name the npc (or `_category`) whatever its target:
158    // the engine keys them by the acting npc's type, and RuneScriptTS gives them
159    // SubjectMode.Type(NPC).
160    npc("ai_applayer1", 101),
161    npc("ai_applayer2", 102),
162    npc("ai_applayer3", 103),
163    npc("ai_applayer4", 104),
164    npc("ai_applayer5", 105),
165    npc("ai_opplayer1", 108),
166    npc("ai_opplayer2", 109),
167    npc("ai_opplayer3", 110),
168    npc("ai_opplayer4", 111),
169    npc("ai_opplayer5", 112),
170    // ── AI queue / timer (NPC-keyed, but historically not validated) ──
171    npc_no_validate("ai_queue1", 117),
172    npc_no_validate("ai_queue2", 118),
173    npc_no_validate("ai_queue3", 119),
174    npc_no_validate("ai_queue4", 120),
175    npc_no_validate("ai_queue5", 121),
176    npc_no_validate("ai_queue6", 122),
177    npc_no_validate("ai_queue7", 123),
178    npc_no_validate("ai_queue8", 124),
179    npc_no_validate("ai_queue9", 125),
180    npc_no_validate("ai_queue10", 126),
181    npc_no_validate("ai_queue11", 127),
182    npc_no_validate("ai_queue12", 128),
183    npc_no_validate("ai_queue13", 129),
184    npc_no_validate("ai_queue14", 130),
185    npc_no_validate("ai_queue15", 131),
186    npc_no_validate("ai_queue16", 132),
187    npc_no_validate("ai_queue17", 133),
188    npc_no_validate("ai_queue18", 134),
189    npc_no_validate("ai_queue19", 135),
190    npc_no_validate("ai_queue20", 136),
191    npc_no_validate("ai_timer", 139),
192    // ── Held / inventory item triggers ───────────────────────────────
193    obj("opheld1", 140),
194    obj("opheld2", 141),
195    obj("opheld3", 142),
196    obj("opheld4", 143),
197    obj("opheld5", 144),
198    obj("opheldu", 145),
199    obj("opheldt", 146),
200    // ── Interface / button triggers ──────────────────────────────────
201    iface("if_button", 147, true),
202    iface("if_close", 148, false),
203    iface("if_button1", 149, true),
204    iface("if_button2", 150, true),
205    iface("if_button3", 151, true),
206    iface("if_button4", 152, true),
207    iface("if_button5", 153, true),
208    iface("if_buttond", 154, true),
209    // Rev-647: client merged OpHeld/InvButton into IfButton1-10. Inventory
210    // item ops 6-10 (e.g. Drop=op8) are handled in content via
211    // `[if_button6..10,inv:component]` + `p_opheld(op, inv, slot)`.
212    // Bytes 173-177 must match the engine's ServerTriggerType InvButton6-10.
213    iface("if_button6", 173, true),
214    iface("if_button7", 174, true),
215    iface("if_button8", 175, true),
216    iface("if_button9", 176, true),
217    iface("if_button10", 177, true),
218    component("inv_button1", 149),
219    component("inv_button2", 150),
220    component("inv_button3", 151),
221    component("inv_button4", 152),
222    component("inv_button5", 153),
223    component("inv_buttond", 154),
224    // ── Player lifecycle / coord / stat triggers ─────────────────────
225    flat_no_validate("login", 157),
226    flat_no_validate("logout", 158),
227    flat("tutorial", 159),
228    stat("advancestat", 160),
229    flat_no_validate("mapzone", 161),
230    flat_no_validate("mapzoneexit", 162),
231    flat_no_validate("zone", 163),
232    flat_no_validate("zoneexit", 164),
233    stat("changestat", 165),
234    // An npc's spawn and despawn name the npc, as its other AI triggers do.
235    npc("ai_spawn", 166),
236    npc("ai_despawn", 167),
237    // A player entering or leaving an area painted on the map. 168-172 stay
238    // unused: they were opheld6-10.
239    area("area", 178),
240    area("areaexit", 179),
241    // A controller's one queue script (Jagex's `[ai_conqueue,<controller>]`,
242    // the int queued with it in last_int) and its timer.
243    controller("ai_conqueue", 180),
244    controller("ai_contimer", 181),
245];
246
247// ── Constructor helpers ──────────────────────────────────────────────
248//
249// `const fn` so the static slice above stays trivially constructible.
250
251const fn npc(name: &'static str, byte: u8) -> TriggerInfo {
252    TriggerInfo {
253        name,
254        byte,
255        subject_type: Some(Type::Npc),
256        validates_subject: true,
257        is_button: false,
258    }
259}
260
261const fn npc_no_validate(name: &'static str, byte: u8) -> TriggerInfo {
262    TriggerInfo {
263        name,
264        byte,
265        subject_type: Some(Type::Npc),
266        validates_subject: false,
267        is_button: false,
268    }
269}
270
271const fn obj(name: &'static str, byte: u8) -> TriggerInfo {
272    TriggerInfo {
273        name,
274        byte,
275        subject_type: Some(Type::Obj),
276        validates_subject: true,
277        is_button: false,
278    }
279}
280
281const fn loc(name: &'static str, byte: u8) -> TriggerInfo {
282    TriggerInfo {
283        name,
284        byte,
285        subject_type: Some(Type::Loc),
286        validates_subject: true,
287        is_button: false,
288    }
289}
290
291const fn iface(name: &'static str, byte: u8, is_button: bool) -> TriggerInfo {
292    TriggerInfo {
293        name,
294        byte,
295        subject_type: Some(Type::Interface),
296        validates_subject: true,
297        is_button,
298    }
299}
300
301const fn component(name: &'static str, byte: u8) -> TriggerInfo {
302    TriggerInfo {
303        name,
304        byte,
305        subject_type: Some(Type::Component),
306        validates_subject: true,
307        is_button: true,
308    }
309}
310
311const fn controller(name: &'static str, byte: u8) -> TriggerInfo {
312    TriggerInfo {
313        name,
314        byte,
315        subject_type: Some(Type::Controller),
316        validates_subject: true,
317        is_button: false,
318    }
319}
320
321const fn area(name: &'static str, byte: u8) -> TriggerInfo {
322    TriggerInfo {
323        name,
324        byte,
325        subject_type: Some(Type::Area),
326        validates_subject: true,
327        is_button: false,
328    }
329}
330
331/// `[advancestat,stat]` / `[changestat,stat]` — subject is a player stat.
332/// Routes to `Type::Stat` so the subject resolves via the typed map instead
333/// of the flat entity-id map, where a same-named entity of another type
334/// (e.g. a `hunt` called `ranged`) would otherwise shadow the stat.
335const fn stat(name: &'static str, byte: u8) -> TriggerInfo {
336    TriggerInfo {
337        name,
338        byte,
339        subject_type: Some(Type::Stat),
340        validates_subject: true,
341        is_button: false,
342    }
343}
344
345const fn flat(name: &'static str, byte: u8) -> TriggerInfo {
346    TriggerInfo {
347        name,
348        byte,
349        subject_type: None,
350        validates_subject: true,
351        is_button: false,
352    }
353}
354
355const fn flat_no_validate(name: &'static str, byte: u8) -> TriggerInfo {
356    TriggerInfo {
357        name,
358        byte,
359        subject_type: None,
360        validates_subject: false,
361        is_button: false,
362    }
363}
364
365// ── Name-keyed triggers ─────────────────────────────────────────────
366//
367// Triggers dispatched by script name (no byte discriminant). These are
368// valid trigger keywords but don't participate in lookup-key hashing.
369
370const NAME_KEYED_TRIGGERS: &[&str] = &[
371    "proc",
372    "label",
373    "debugproc",
374    "command",
375    "clientscript",
376    "walktrigger",
377    "queue",
378    "timer",
379    "softtimer",
380    "controller_queue",
381    "npc_queue",
382];
383
384// Rev-647 extensions: valid triggers whose byte discriminants are not
385// yet standardized in the reference implementation.
386const EXTENDED_TRIGGERS: &[&str] = &["switch_window_mode"];
387
388// ── Public lookup API ────────────────────────────────────────────────
389
390fn table() -> &'static HashMap<&'static str, TriggerInfo> {
391    static TABLE: OnceLock<HashMap<&'static str, TriggerInfo>> = OnceLock::new();
392    TABLE.get_or_init(|| TRIGGERS.iter().map(|t| (t.name, *t)).collect())
393}
394
395pub fn lookup(name: &str) -> Option<TriggerInfo> {
396    table().get(name).copied()
397}
398
399pub fn names() -> impl Iterator<Item = &'static str> {
400    TRIGGERS
401        .iter()
402        .map(|trigger| trigger.name)
403        .chain(NAME_KEYED_TRIGGERS.iter().copied())
404        .chain(EXTENDED_TRIGGERS.iter().copied())
405}
406
407pub fn byte(name: &str) -> Option<u8> {
408    lookup(name).map(|t| t.byte)
409}
410
411pub fn subject_type(name: &str) -> Option<Type> {
412    lookup(name).and_then(|t| t.subject_type)
413}
414
415pub fn validates_subject(name: &str) -> bool {
416    lookup(name).map(|t| t.validates_subject).unwrap_or(false)
417}
418
419pub fn is_button(name: &str) -> bool {
420    lookup(name).map(|t| t.is_button).unwrap_or(false)
421}
422
423pub fn is_valid_trigger(name: &str) -> bool {
424    lookup(name).is_some()
425        || NAME_KEYED_TRIGGERS.contains(&name)
426        || EXTENDED_TRIGGERS.contains(&name)
427}
428
429pub fn allows_returns(name: &str) -> bool {
430    matches!(name, "proc" | "clientscript" | "command" | "logout")
431}
432
433#[cfg(test)]
434mod tests {
435    use super::*;
436
437    #[test]
438    fn no_duplicate_trigger_names() {
439        let mut seen = std::collections::HashSet::new();
440        for t in TRIGGERS {
441            assert!(seen.insert(t.name), "duplicate trigger name: {}", t.name);
442        }
443    }
444
445    #[test]
446    fn button_triggers_match_legacy_set() {
447        // Locks in pointer_checker's old hand-maintained list.
448        let expected = [
449            "if_button",
450            "if_button1",
451            "if_button2",
452            "if_button3",
453            "if_button4",
454            "if_button5",
455            "if_button6",
456            "if_button7",
457            "if_button8",
458            "if_button9",
459            "if_button10",
460            "if_buttond",
461            "inv_button1",
462            "inv_button2",
463            "inv_button3",
464            "inv_button4",
465            "inv_button5",
466            "inv_buttond",
467        ];
468        for name in expected {
469            assert!(is_button(name), "{} should be a button trigger", name);
470        }
471        // Spot-check that non-buttons aren't flagged.
472        assert!(!is_button("if_close"));
473        assert!(!is_button("opnpc1"));
474        assert!(!is_button("login"));
475    }
476
477    #[test]
478    fn known_byte_values() {
479        // Anchors against the RuneScriptTS ServerTriggerType.ts byte
480        // discriminants. If any of these change, the engine's dispatch
481        // will silently desync.
482        assert_eq!(byte("opnpc1"), Some(10));
483        assert_eq!(byte("opheld1"), Some(140));
484        assert_eq!(byte("if_button"), Some(147));
485        assert_eq!(byte("if_button1"), Some(149));
486        assert_eq!(byte("inv_button1"), Some(149));
487        assert_eq!(byte("login"), Some(157));
488        assert_eq!(byte("ai_despawn"), Some(167));
489        assert_eq!(byte("totally_unknown_trigger"), None);
490    }
491
492    #[test]
493    fn subject_type_routing() {
494        assert_eq!(subject_type("opnpc1"), Some(Type::Npc));
495        assert_eq!(subject_type("opobj1"), Some(Type::Obj));
496        assert_eq!(subject_type("oploc1"), Some(Type::Loc));
497        assert_eq!(subject_type("opheld1"), Some(Type::Obj));
498        assert_eq!(subject_type("if_button"), Some(Type::Interface));
499        assert_eq!(subject_type("inv_button1"), Some(Type::Component));
500        assert_eq!(subject_type("login"), None);
501        assert_eq!(subject_type("opplayer1"), None); // flat lookup
502        // advancestat/changestat take a stat subject. Without this routing,
503        // `[advancestat,ranged]` flat-resolves `ranged` to whatever type was
504        // registered last under that name (e.g. a hunt) instead of the stat.
505        assert_eq!(subject_type("advancestat"), Some(Type::Stat));
506        assert_eq!(subject_type("changestat"), Some(Type::Stat));
507    }
508
509    /// Every npc AI trigger's subject is the acting npc, whatever it targets
510    /// (RuneScriptTS: SubjectMode.Type(NPC); the engine keys them by npc type).
511    #[test]
512    fn npc_ai_triggers_take_an_npc_subject() {
513        let mut names: Vec<String> = Vec::new();
514        for target in ["player", "loc", "obj", "npc"] {
515            for op in ["ap", "op"] {
516                for i in 1..=5 {
517                    names.push(format!("ai_{op}{target}{i}"));
518                }
519            }
520        }
521        for i in 1..=20 {
522            names.push(format!("ai_queue{i}"));
523        }
524        names.extend(["ai_timer", "ai_spawn", "ai_despawn"].map(String::from));
525        for name in &names {
526            assert_eq!(subject_type(name), Some(Type::Npc), "{name}");
527        }
528    }
529
530    #[test]
531    fn validation_skip_list() {
532        // Triggers historically excluded from subject validation.
533        assert!(!validates_subject("login"));
534        assert!(!validates_subject("logout"));
535        assert!(!validates_subject("zone"));
536        assert!(!validates_subject("zoneexit"));
537        assert!(!validates_subject("mapzone"));
538        assert!(!validates_subject("mapzoneexit"));
539        assert!(!validates_subject("ai_queue1"));
540        assert!(!validates_subject("ai_timer"));
541        // …but the rest of the byte-keyed triggers do validate.
542        assert!(validates_subject("if_button"));
543        assert!(validates_subject("opnpc1"));
544        assert!(validates_subject("opheld1"));
545        assert!(validates_subject("tutorial"));
546    }
547
548    #[test]
549    fn is_valid_trigger_byte_keyed() {
550        assert!(is_valid_trigger("opnpc1"));
551        assert!(is_valid_trigger("opheld1"));
552        assert!(is_valid_trigger("if_button"));
553        assert!(is_valid_trigger("login"));
554        assert!(is_valid_trigger("ai_queue1"));
555        assert!(is_valid_trigger("ai_despawn"));
556    }
557
558    #[test]
559    fn is_valid_trigger_name_keyed() {
560        assert!(is_valid_trigger("proc"));
561        assert!(is_valid_trigger("label"));
562        assert!(is_valid_trigger("debugproc"));
563        assert!(is_valid_trigger("command"));
564        assert!(is_valid_trigger("clientscript"));
565        assert!(is_valid_trigger("walktrigger"));
566        assert!(is_valid_trigger("queue"));
567        assert!(is_valid_trigger("timer"));
568        assert!(is_valid_trigger("softtimer"));
569    }
570
571    #[test]
572    fn is_valid_trigger_extended() {
573        assert!(is_valid_trigger("switch_window_mode"));
574    }
575
576    #[test]
577    fn opheld_only_goes_to_five() {
578        // Rev-647 (and OSRS) have no opheld beyond 5. Inventory item ops 6-10
579        // route through if_button6-10 + the p_opheld content command instead.
580        assert!(is_valid_trigger("opheld5"));
581        assert!(!is_valid_trigger("opheld6"));
582        assert!(!is_valid_trigger("opheld7"));
583        assert!(!is_valid_trigger("opheld10"));
584    }
585
586    #[test]
587    fn if_button_extended_to_ten() {
588        // Bytes 173-177 must stay in sync with the engine's ServerTriggerType
589        // InvButton6-10.
590        assert!(is_valid_trigger("if_button6"));
591        assert!(is_valid_trigger("if_button10"));
592        assert_eq!(byte("if_button6"), Some(173));
593        assert_eq!(byte("if_button10"), Some(177));
594    }
595
596    #[test]
597    fn player_triggers_extended_to_ten() {
598        // Bytes 182-186 and 189-193 must stay in sync with the engine's
599        // ServerTriggerType ApPlayer6-10/OpPlayer6-10.
600        for op in 6..=10u8 {
601            assert_eq!(byte(&format!("applayer{op}")), Some(176 + op));
602            assert_eq!(byte(&format!("opplayer{op}")), Some(183 + op));
603        }
604        assert!(!is_valid_trigger("opplayer11"));
605    }
606
607    #[test]
608    fn ground_target_trigger() {
609        // Byte 194 must stay in sync with the engine's ServerTriggerType
610        // ApCoordT; a tile is only approached, so there is no opcoordt.
611        assert_eq!(byte("apcoordt"), Some(194));
612        assert!(TRIGGERS.iter().all(|t| t.byte != 201));
613        assert!(!is_valid_trigger("opcoordt"));
614    }
615
616    #[test]
617    fn controller_triggers() {
618        // Bytes 180-181 must stay in sync with the engine's ServerTriggerType
619        // AiConQueue/AiConTimer.
620        assert_eq!(byte("ai_conqueue"), Some(180));
621        assert_eq!(byte("ai_contimer"), Some(181));
622        assert_eq!(subject_type("ai_conqueue"), Some(Type::Controller));
623        assert_eq!(subject_type("ai_contimer"), Some(Type::Controller));
624    }
625
626    #[test]
627    fn inv_button_caps_at_five() {
628        // inv_button is the 225-era spelling with ops 1-5 (+ d). 647 content
629        // uses if_button, which extends to 6-10. Both 225 and 647 content
630        // compile here, so inv_button1-5/inv_buttond stay valid while
631        // inv_button6-10 must not exist.
632        for n in ["inv_button1", "inv_button5", "inv_buttond"] {
633            assert!(is_valid_trigger(n), "{n} should still be a trigger");
634        }
635        for n in ["inv_button6", "inv_button7", "inv_button10"] {
636            assert!(
637                !is_valid_trigger(n),
638                "{n} must not exist (inv_button caps at 5)"
639            );
640            assert_eq!(byte(n), None);
641        }
642    }
643
644    #[test]
645    fn is_valid_trigger_unknown_rejected() {
646        assert!(!is_valid_trigger("not_a_real_trigger"));
647        assert!(!is_valid_trigger(""));
648        assert!(!is_valid_trigger("procc"));
649    }
650
651    #[test]
652    fn allows_returns_matches_lib_set() {
653        assert!(allows_returns("proc"));
654        assert!(allows_returns("clientscript"));
655        assert!(allows_returns("command"));
656        assert!(allows_returns("logout"));
657        assert!(!allows_returns("label"));
658        assert!(!allows_returns("debugproc"));
659        assert!(!allows_returns("queue"));
660        assert!(!allows_returns("timer"));
661        assert!(!allows_returns("softtimer"));
662        assert!(!allows_returns("walktrigger"));
663        assert!(!allows_returns("login"));
664        assert!(!allows_returns("opnpc1"));
665    }
666
667    #[test]
668    fn name_keyed_triggers_have_no_byte() {
669        assert_eq!(byte("proc"), None);
670        assert_eq!(byte("label"), None);
671        assert_eq!(byte("command"), None);
672        assert_eq!(byte("walktrigger"), None);
673    }
674}