• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Blightmud / Blightmud / 23965955605

03 Apr 2026 11:26PM UTC coverage: 74.122%. First build
23965955605

Pull #1406

github

web-flow
Merge 4d2eeb87b into abbfa3d0f
Pull Request #1406: Adds tag support to lines through lua.

474 of 608 new or added lines in 12 files covered. (77.96%)

10168 of 13718 relevant lines covered (74.12%)

672.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.89
/src/lua/blight.rs
1
use super::{constants::*, regex::Regex, ui_event::UiEvent};
2
use crate::event::{Event, QuitMethod};
3
use crate::{
4
    model::{Line, TagMask},
5
    PROJECT_NAME, VERSION,
6
};
7
use log::debug;
8
use mlua::{
9
    AnyUserData, FromLua, Function, Result as LuaResult, Table, UserData, UserDataMethods, Variadic,
10
};
11
use std::sync::mpsc::Sender;
12

13
#[derive(Clone, FromLua)]
×
14
pub struct Blight {
15
    main_writer: Sender<Event>,
16
    output_lines: Vec<Line>,
17
    ui_events: Vec<UiEvent>,
18
    pub screen_dimensions: (u16, u16),
19
    pub core_mode: bool,
20
    pub reader_mode: bool,
21
    pub _tts_enabled: bool,
22
    tag_mask: TagMask,
23
}
24

25
impl Blight {
26
    pub fn new(writer: Sender<Event>) -> Self {
279✔
27
        Self {
279✔
28
            main_writer: writer,
279✔
29
            output_lines: vec![],
279✔
30
            ui_events: vec![],
279✔
31
            screen_dimensions: (0, 0),
279✔
32
            core_mode: false,
279✔
33
            reader_mode: false,
279✔
34
            _tts_enabled: false,
279✔
35
            tag_mask: TagMask::default(),
279✔
36
        }
279✔
37
    }
279✔
38

39
    pub fn core_mode(&mut self, mode: bool) {
520✔
40
        self.core_mode = mode;
520✔
41
    }
520✔
42

43
    pub fn get_output_lines(&mut self) -> Vec<Line> {
1,559✔
44
        let return_lines = self.output_lines.clone();
1,559✔
45
        self.output_lines.clear();
1,559✔
46
        return_lines
1,559✔
47
    }
1,559✔
48

49
    pub fn get_ui_events(&mut self) -> Vec<UiEvent> {
17✔
50
        let events = self.ui_events.clone();
17✔
51
        self.ui_events.clear();
17✔
52
        events
17✔
53
    }
17✔
54
}
55

56
impl UserData for Blight {
57
    fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
279✔
58
        methods.add_function("output", |ctx, strings: Variadic<String>| {
279✔
59
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
149✔
60
            let mut this = this_aux.borrow_mut::<Blight>()?;
149✔
61
            this.output_lines.push(Line::from(strings.join(" ")));
149✔
62
            Ok(())
149✔
63
        });
149✔
64
        methods.add_function("terminal_dimensions", |ctx, _: ()| {
279✔
65
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
2✔
66
            let this = this_aux.borrow::<Blight>()?;
2✔
67
            Ok(this.screen_dimensions)
2✔
68
        });
2✔
69
        methods.add_function("bind", |ctx, (cmd, callback): (String, mlua::Function)| {
7,202✔
70
            let bind_table: mlua::Table = ctx.named_registry_value(COMMAND_BINDING_TABLE)?;
7,202✔
71
            if cmd.to_lowercase().starts_with("alt-") {
7,202✔
72
                let (_, right) = cmd.split_at(3);
1,030✔
73
                let mut cmd = "alt".to_string();
1,030✔
74
                cmd.push_str(right);
1,030✔
75
                bind_table.set(cmd, callback)?;
1,030✔
76
            } else {
77
                bind_table.set(cmd.to_lowercase(), callback)?;
6,172✔
78
            }
79
            Ok(())
7,202✔
80
        });
7,202✔
81
        methods.add_function("unbind", |ctx, cmd: String| {
279✔
82
            let bind_table: mlua::Table = ctx.named_registry_value(COMMAND_BINDING_TABLE)?;
1✔
83
            bind_table.set(cmd, mlua::Nil)?;
1✔
84
            Ok(())
1✔
85
        });
1✔
86
        methods.add_function("ui", |ctx, cmd: String| -> mlua::Result<()> {
279✔
87
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
21✔
88
            let mut this = this_aux.borrow_mut::<Blight>()?;
21✔
89
            let event: UiEvent = UiEvent::from(cmd.as_str());
21✔
90
            if let UiEvent::Unknown(cmd) = event {
21✔
91
                this.main_writer
1✔
92
                    .send(Event::Error(format!("Invalid ui command: {cmd}")))
1✔
93
                    .unwrap();
1✔
94
            } else {
20✔
95
                this.ui_events.push(event);
20✔
96
            }
20✔
97
            Ok(())
21✔
98
        });
21✔
99
        methods.add_function("debug", |_, strings: Variadic<String>| {
279✔
100
            debug!("{}", strings.join(" "));
24✔
101
            Ok(())
24✔
102
        });
24✔
103
        methods.add_function("is_core_mode", |ctx, ()| {
7,782✔
104
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
7,782✔
105
            let this = this_aux.borrow::<Blight>()?;
7,782✔
106
            Ok(this.core_mode)
7,782✔
107
        });
7,782✔
108
        methods.add_function("is_reader_mode", |ctx, ()| {
279✔
109
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
8✔
110
            let this = this_aux.borrow::<Blight>()?;
8✔
111
            Ok(this.reader_mode)
8✔
112
        });
8✔
113
        methods.add_function("status_height", |ctx, requested: Option<u16>| {
279✔
114
            let height: u16 = if let Some(height) = requested {
5✔
115
                let height = height.clamp(0, 5);
2✔
116
                let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
2✔
117
                let this = this_aux.borrow::<Blight>()?;
2✔
118
                this.main_writer
2✔
119
                    .send(Event::StatusAreaHeight(height))
2✔
120
                    .unwrap();
2✔
121
                ctx.set_named_registry_value(STATUS_AREA_HEIGHT, height)?;
2✔
122
                height
2✔
123
            } else {
124
                ctx.named_registry_value(STATUS_AREA_HEIGHT)?
3✔
125
            };
126
            Ok(height)
5✔
127
        });
5✔
128
        methods.add_function("status_line", |ctx, (index, line): (usize, String)| {
279✔
129
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
×
130
            let this = this_aux.borrow::<Blight>()?;
×
131
            this.main_writer
×
132
                .send(Event::StatusLine(index, line))
×
133
                .unwrap();
×
134
            Ok(())
×
135
        });
×
136
        methods.add_function("version", |_, _: ()| -> LuaResult<(&str, &str)> {
287✔
137
            Ok((PROJECT_NAME, VERSION))
268✔
138
        });
268✔
139
        methods.add_function("config_dir", |_, ()| -> mlua::Result<String> {
279✔
140
            Ok(crate::CONFIG_DIR.to_string_lossy().to_string())
1✔
141
        });
1✔
142
        methods.add_function("data_dir", |_, ()| -> mlua::Result<String> {
279✔
143
            Ok(crate::DATA_DIR.to_string_lossy().to_string())
1✔
144
        });
1✔
145
        methods.add_function("on_quit", |ctx, func: Function| -> mlua::Result<()> {
279✔
146
            let table: Table = ctx.named_registry_value(BLIGHT_ON_QUIT_LISTENER_TABLE)?;
260✔
147
            table.set(table.raw_len() + 1, func)?;
260✔
148
            Ok(())
260✔
149
        });
260✔
150
        methods.add_function(
279✔
151
            "on_complete",
152
            |ctx, func: mlua::Function| -> mlua::Result<()> {
3✔
153
                let table: Table = ctx.named_registry_value(COMPLETION_CALLBACK_TABLE)?;
3✔
154
                table.set(table.raw_len() + 1, func)?;
3✔
155
                Ok(())
3✔
156
            },
3✔
157
        );
158
        methods.add_function(
279✔
159
            "on_dimensions_change",
160
            |ctx, func: Function| -> mlua::Result<()> {
258✔
161
                let table: Table =
258✔
162
                    ctx.named_registry_value(BLIGHT_ON_DIMENSIONS_CHANGE_LISTENER_TABLE)?;
258✔
163
                table.set(table.raw_len() + 1, func)?;
258✔
164
                Ok(())
258✔
165
            },
258✔
166
        );
167
        methods.add_function("quit", |ctx, ()| {
279✔
168
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
147✔
169
            let this = this_aux.borrow::<Blight>()?;
147✔
170
            this.main_writer
147✔
171
                .send(Event::Quit(QuitMethod::Script))
147✔
172
                .unwrap();
147✔
173
            Ok(())
147✔
174
        });
147✔
175
        methods.add_function("show_help", |ctx, (name, lock_scroll): (String, bool)| {
279✔
176
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
3✔
177
            let this = this_aux.borrow::<Blight>()?;
3✔
178
            this.main_writer
3✔
179
                .send(Event::ShowHelp(name, lock_scroll))
3✔
180
                .unwrap();
3✔
181
            Ok(())
3✔
182
        });
3✔
183
        methods.add_function(
279✔
184
            "show_tags",
185
            |ctx, val: Option<bool>| -> mlua::Result<bool> {
4✔
186
                if let Some(val) = val {
4✔
187
                    let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
2✔
188
                    let this = this_aux.borrow::<Blight>()?;
2✔
189
                    this.main_writer.send(Event::ShowTags(val)).unwrap();
2✔
190
                    ctx.set_named_registry_value(SHOW_TAGS, val)?;
2✔
191
                }
2✔
192
                Ok(ctx.named_registry_value(SHOW_TAGS).unwrap_or(false))
4✔
193
            },
4✔
194
        );
195
        methods.add_function("filter_tag_color", |ctx, color: Option<String>| {
279✔
NEW
196
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
×
NEW
197
            let mut this = this_aux.borrow_mut::<Blight>()?;
×
NEW
198
            this.tag_mask.color = color;
×
NEW
199
            this.main_writer
×
NEW
200
                .send(Event::SetTagMask(this.tag_mask.clone()))
×
NEW
201
                .unwrap();
×
NEW
202
            Ok(())
×
NEW
203
        });
×
204
        methods.add_function("filter_tag_key", |ctx, key: Option<String>| {
279✔
NEW
205
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
×
NEW
206
            let mut this = this_aux.borrow_mut::<Blight>()?;
×
NEW
207
            this.tag_mask.key = key;
×
NEW
208
            this.main_writer
×
NEW
209
                .send(Event::SetTagMask(this.tag_mask.clone()))
×
NEW
210
                .unwrap();
×
NEW
211
            Ok(())
×
NEW
212
        });
×
213
        methods.add_function("filter_tag_symbol", |ctx, symbol: Option<String>| {
279✔
NEW
214
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
×
NEW
215
            let mut this = this_aux.borrow_mut::<Blight>()?;
×
NEW
216
            this.tag_mask.symbol = symbol.and_then(|s| s.chars().next());
×
NEW
217
            this.main_writer
×
NEW
218
                .send(Event::SetTagMask(this.tag_mask.clone()))
×
NEW
219
                .unwrap();
×
NEW
220
            Ok(())
×
NEW
221
        });
×
222
        methods.add_function("filter_tag_reverse", |ctx, val: Option<bool>| {
279✔
223
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
4✔
224
            let mut this = this_aux.borrow_mut::<Blight>()?;
4✔
225
            if let Some(val) = val {
4✔
226
                this.tag_mask.reverse = val;
1✔
227
                this.main_writer
1✔
228
                    .send(Event::SetTagMask(this.tag_mask.clone()))
1✔
229
                    .unwrap();
1✔
230
            }
3✔
231
            Ok(this.tag_mask.reverse)
4✔
232
        });
4✔
233
        methods.add_function("filter_tag_reset", |ctx, ()| {
279✔
234
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
1✔
235
            let mut this = this_aux.borrow_mut::<Blight>()?;
1✔
236
            this.tag_mask = TagMask::default();
1✔
237
            this.main_writer
1✔
238
                .send(Event::SetTagMask(this.tag_mask.clone()))
1✔
239
                .unwrap();
1✔
240
            Ok(())
1✔
241
        });
1✔
242
        methods.add_function("find_backward", |ctx, re: Regex| {
279✔
243
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
3✔
244
            let this = this_aux.borrow::<Blight>()?;
3✔
245
            this.main_writer
3✔
246
                .send(Event::FindBackward(re.regex))
3✔
247
                .unwrap();
3✔
248
            Ok(())
3✔
249
        });
3✔
250
        methods.add_function("find_forward", |ctx, re: Regex| {
279✔
251
            let this_aux = ctx.globals().get::<AnyUserData>("blight")?;
1✔
252
            let this = this_aux.borrow::<Blight>()?;
1✔
253
            this.main_writer.send(Event::FindForward(re.regex)).unwrap();
1✔
254
            Ok(())
1✔
255
        });
1✔
256
    }
279✔
257
}
258

259
#[cfg(test)]
260
mod test_blight {
261
    use std::sync::mpsc::{channel, Receiver, Sender};
262

263
    use mlua::{AnyUserData, Lua};
264

265
    use crate::event::{Event, QuitMethod};
266
    use crate::lua::UiEvent;
267

268
    use super::Blight;
269
    use crate::lua::constants::{
270
        BLIGHT_ON_DIMENSIONS_CHANGE_LISTENER_TABLE, BLIGHT_ON_QUIT_LISTENER_TABLE,
271
        COMMAND_BINDING_TABLE, COMPLETION_CALLBACK_TABLE, SHOW_TAGS, STATUS_AREA_HEIGHT,
272
    };
273
    use crate::{PROJECT_NAME, VERSION};
274

275
    fn get_lua_state() -> (Lua, Receiver<Event>) {
16✔
276
        let (writer, reader): (Sender<Event>, Receiver<Event>) = channel();
16✔
277
        let regex = crate::lua::regex::RegexLib {};
16✔
278
        let blight = Blight::new(writer);
16✔
279
        let lua = Lua::new();
16✔
280
        lua.globals().set("regex", regex).unwrap();
16✔
281
        lua.globals().set("blight", blight).unwrap();
16✔
282
        lua.set_named_registry_value(BLIGHT_ON_QUIT_LISTENER_TABLE, lua.create_table().unwrap())
16✔
283
            .unwrap();
16✔
284
        lua.set_named_registry_value(
16✔
285
            BLIGHT_ON_DIMENSIONS_CHANGE_LISTENER_TABLE,
16✔
286
            lua.create_table().unwrap(),
16✔
287
        )
288
        .unwrap();
16✔
289
        lua.set_named_registry_value(COMPLETION_CALLBACK_TABLE, lua.create_table().unwrap())
16✔
290
            .unwrap();
16✔
291
        lua.set_named_registry_value(COMMAND_BINDING_TABLE, lua.create_table().unwrap())
16✔
292
            .unwrap();
16✔
293
        lua.set_named_registry_value(STATUS_AREA_HEIGHT, 1u16)
16✔
294
            .unwrap();
16✔
295
        lua.set_named_registry_value(SHOW_TAGS, false).unwrap();
16✔
296
        (lua, reader)
16✔
297
    }
16✔
298

299
    #[test]
300
    fn test_config_dir() {
1✔
301
        let (lua, _reader) = get_lua_state();
1✔
302
        assert!(lua
1✔
303
            .load("return blight.config_dir()")
1✔
304
            .call::<String>(())
1✔
305
            .unwrap()
1✔
306
            .ends_with(".run/test/config"));
1✔
307
    }
1✔
308

309
    #[test]
310
    fn test_data_dir() {
1✔
311
        let (lua, _reader) = get_lua_state();
1✔
312
        assert!(lua
1✔
313
            .load("return blight.data_dir()")
1✔
314
            .call::<String>(())
1✔
315
            .unwrap()
1✔
316
            .ends_with(".run/test/data"));
1✔
317
    }
1✔
318

319
    #[test]
320
    fn test_version() {
1✔
321
        let (lua, _reader) = get_lua_state();
1✔
322
        assert_eq!(
1✔
323
            lua.load("return blight.version()")
1✔
324
                .call::<(String, String)>(())
1✔
325
                .unwrap(),
1✔
326
            (PROJECT_NAME.to_string(), VERSION.to_string())
1✔
327
        );
328
    }
1✔
329

330
    #[test]
331
    fn confirm_on_quite_register() {
1✔
332
        let (lua, _reader) = get_lua_state();
1✔
333
        let table: mlua::Table = lua
1✔
334
            .named_registry_value(BLIGHT_ON_QUIT_LISTENER_TABLE)
1✔
335
            .unwrap();
1✔
336
        assert_eq!(table.raw_len(), 0);
1✔
337
        lua.load("blight.on_quit(function () end)").exec().unwrap();
1✔
338
        let table: mlua::Table = lua
1✔
339
            .named_registry_value(BLIGHT_ON_QUIT_LISTENER_TABLE)
1✔
340
            .unwrap();
1✔
341
        assert_eq!(table.raw_len(), 1);
1✔
342
    }
1✔
343

344
    #[test]
345
    fn on_complete() {
1✔
346
        let (lua, _reader) = get_lua_state();
1✔
347
        let table: mlua::Table = lua.named_registry_value(COMPLETION_CALLBACK_TABLE).unwrap();
1✔
348
        assert_eq!(table.raw_len(), 0);
1✔
349
        lua.load("blight.on_complete(function () end)")
1✔
350
            .exec()
1✔
351
            .unwrap();
1✔
352
        let table: mlua::Table = lua.named_registry_value(COMPLETION_CALLBACK_TABLE).unwrap();
1✔
353
        assert_eq!(table.raw_len(), 1);
1✔
354
    }
1✔
355

356
    #[test]
357
    fn on_quit_function() {
1✔
358
        let (lua, _reader) = get_lua_state();
1✔
359
        lua.load("blight.on_quit(function () blight.output(\"on_quit\") end)")
1✔
360
            .exec()
1✔
361
            .unwrap();
1✔
362
        let table: mlua::Table = lua
1✔
363
            .named_registry_value(BLIGHT_ON_QUIT_LISTENER_TABLE)
1✔
364
            .unwrap();
1✔
365
        for pair in table.pairs::<mlua::Value, mlua::Function>() {
1✔
366
            let (_, cb) = pair.unwrap();
1✔
367
            cb.call::<()>(()).unwrap();
1✔
368
        }
1✔
369
        let blight_aux = lua.globals().get::<AnyUserData>("blight").unwrap();
1✔
370
        let mut blight = blight_aux.borrow_mut::<Blight>().unwrap();
1✔
371
        let lines = blight.get_output_lines();
1✔
372
        let mut it = lines.iter();
1✔
373
        assert_eq!(it.next().unwrap(), &crate::model::Line::from("on_quit"));
1✔
374
    }
1✔
375

376
    #[test]
377
    fn quit() {
1✔
378
        let (lua, reader) = get_lua_state();
1✔
379
        lua.load("blight.quit()").exec().unwrap();
1✔
380
        assert_eq!(reader.recv(), Ok(Event::Quit(QuitMethod::Script)));
1✔
381
    }
1✔
382

383
    #[test]
384
    fn find() {
1✔
385
        let (lua, reader) = get_lua_state();
1✔
386
        let re = crate::model::Regex::new("test", None).unwrap();
1✔
387
        lua.load(r#"blight.find_forward(regex.new("test"))"#)
1✔
388
            .exec()
1✔
389
            .unwrap();
1✔
390
        assert_eq!(reader.recv(), Ok(Event::FindForward(re.clone())));
1✔
391
        lua.load(r#"blight.find_backward(regex.new("test"))"#)
1✔
392
            .exec()
1✔
393
            .unwrap();
1✔
394
        assert_eq!(reader.recv(), Ok(Event::FindBackward(re)));
1✔
395
    }
1✔
396

397
    #[test]
398
    fn show_help() {
1✔
399
        let (lua, reader) = get_lua_state();
1✔
400
        lua.load("blight.show_help(\"test1\", false)")
1✔
401
            .exec()
1✔
402
            .unwrap();
1✔
403
        assert_eq!(
1✔
404
            reader.recv(),
1✔
405
            Ok(Event::ShowHelp("test1".to_string(), false))
1✔
406
        );
407
        lua.load("blight.show_help(\"test2\", true)")
1✔
408
            .exec()
1✔
409
            .unwrap();
1✔
410
        assert_eq!(
1✔
411
            reader.recv(),
1✔
412
            Ok(Event::ShowHelp("test2".to_string(), true))
1✔
413
        );
414
    }
1✔
415

416
    #[test]
417
    fn confirm_ui_events() {
1✔
418
        let (lua, _) = get_lua_state();
1✔
419
        lua.load("blight.ui(\"step_left\")").exec().unwrap();
1✔
420
        lua.load("blight.ui(\"step_right\")").exec().unwrap();
1✔
421
        lua.load("blight.ui(\"scroll_up\")").exec().unwrap();
1✔
422
        lua.load("blight.ui(\"scroll_down\")").exec().unwrap();
1✔
423

424
        let mut blight: Blight = lua.globals().get("blight").unwrap();
1✔
425
        assert_eq!(
1✔
426
            blight.get_ui_events(),
1✔
427
            vec![
1✔
428
                UiEvent::StepLeft,
1✔
429
                UiEvent::StepRight,
1✔
430
                UiEvent::ScrollUp,
1✔
431
                UiEvent::ScrollDown
1✔
432
            ]
433
        );
434
    }
1✔
435

436
    #[test]
437
    fn test_bad_ui_event() {
1✔
438
        let (lua, reader) = get_lua_state();
1✔
439
        lua.load("blight.ui(\"schplort\")").exec().unwrap();
1✔
440
        assert_eq!(
1✔
441
            reader.recv(),
1✔
442
            Ok(Event::Error("Invalid ui command: schplort".to_string()))
1✔
443
        );
444
    }
1✔
445

446
    #[test]
447
    fn test_command_bindings() {
1✔
448
        let (lua, _) = get_lua_state();
1✔
449
        lua.load("blight.bind(\"f1\", function () end)")
1✔
450
            .exec()
1✔
451
            .unwrap();
1✔
452
        let bindings: mlua::Table = lua.named_registry_value(COMMAND_BINDING_TABLE).unwrap();
1✔
453
        assert!(bindings.get::<mlua::Function>("f1").is_ok());
1✔
454
        lua.load("blight.unbind(\"f1\")").exec().unwrap();
1✔
455
        assert!(bindings.get::<mlua::Function>("f1").is_err());
1✔
456
    }
1✔
457

458
    #[test]
459
    fn test_command_bindings_alt_with_capitalized_letter() {
1✔
460
        let (lua, _) = get_lua_state();
1✔
461
        lua.load("blight.bind(\"Alt-H\", function () end)")
1✔
462
            .exec()
1✔
463
            .unwrap();
1✔
464
        let bindings: mlua::Table = lua.named_registry_value(COMMAND_BINDING_TABLE).unwrap();
1✔
465
        assert!(bindings.get::<mlua::Function>("alt-H").is_ok());
1✔
466
        assert!(bindings.get::<mlua::Function>("alt-h").is_err());
1✔
467
    }
1✔
468

469
    #[test]
470
    fn test_show_tags() {
1✔
471
        let (lua, reader) = get_lua_state();
1✔
472

473
        // Default is false
474
        let val = lua
1✔
475
            .load("return blight.show_tags()")
1✔
476
            .call::<bool>(())
1✔
477
            .unwrap();
1✔
478
        assert!(!val);
1✔
479

480
        // Set to true
481
        let val = lua
1✔
482
            .load("return blight.show_tags(true)")
1✔
483
            .call::<bool>(())
1✔
484
            .unwrap();
1✔
485
        assert!(val);
1✔
486
        assert_eq!(reader.recv(), Ok(Event::ShowTags(true)));
1✔
487

488
        // Getter reflects update
489
        let val = lua
1✔
490
            .load("return blight.show_tags()")
1✔
491
            .call::<bool>(())
1✔
492
            .unwrap();
1✔
493
        assert!(val);
1✔
494

495
        // Set back to false
496
        lua.load("blight.show_tags(false)").exec().unwrap();
1✔
497
        assert_eq!(reader.recv(), Ok(Event::ShowTags(false)));
1✔
498
    }
1✔
499

500
    #[test]
501
    fn test_filter_tag_reverse() {
1✔
502
        let (lua, reader) = get_lua_state();
1✔
503

504
        // Default is false
505
        let val = lua
1✔
506
            .load("return blight.filter_tag_reverse()")
1✔
507
            .call::<bool>(())
1✔
508
            .unwrap();
1✔
509
        assert!(!val);
1✔
510

511
        // Set to true
512
        let val = lua
1✔
513
            .load("return blight.filter_tag_reverse(true)")
1✔
514
            .call::<bool>(())
1✔
515
            .unwrap();
1✔
516
        assert!(val);
1✔
517
        // Discard the SetTagMask event
518
        let _ = reader.recv();
1✔
519

520
        // Getter reflects update
521
        let val = lua
1✔
522
            .load("return blight.filter_tag_reverse()")
1✔
523
            .call::<bool>(())
1✔
524
            .unwrap();
1✔
525
        assert!(val);
1✔
526

527
        // Reset clears reverse too
528
        lua.load("blight.filter_tag_reset()").exec().unwrap();
1✔
529
        let _ = reader.recv();
1✔
530
        let val = lua
1✔
531
            .load("return blight.filter_tag_reverse()")
1✔
532
            .call::<bool>(())
1✔
533
            .unwrap();
1✔
534
        assert!(!val);
1✔
535
    }
1✔
536

537
    #[test]
538
    fn test_status_height() {
1✔
539
        let (lua, _reader) = get_lua_state();
1✔
540
        let height = lua
1✔
541
            .load("return blight.status_height()")
1✔
542
            .call::<u16>(())
1✔
543
            .unwrap();
1✔
544
        assert_eq!(height, 1);
1✔
545
        let height = lua
1✔
546
            .load("return blight.status_height(3)")
1✔
547
            .call::<u16>(())
1✔
548
            .unwrap();
1✔
549
        assert_eq!(height, 3);
1✔
550
        let height = lua
1✔
551
            .load("return blight.status_height()")
1✔
552
            .call::<u16>(())
1✔
553
            .unwrap();
1✔
554
        assert_eq!(height, 3);
1✔
555
        let height = lua
1✔
556
            .load("return blight.status_height(1)")
1✔
557
            .call::<u16>(())
1✔
558
            .unwrap();
1✔
559
        assert_eq!(height, 1);
1✔
560
        let height = lua
1✔
561
            .load("return blight.status_height()")
1✔
562
            .call::<u16>(())
1✔
563
            .unwrap();
1✔
564
        assert_eq!(height, 1);
1✔
565
    }
1✔
566
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc