cargo_nvim/
lib.rs

1// src/lib.rs
2//! Neovim plugin for Cargo command integration
3//! This module provides a bridge between Neovim and Cargo commands
4//! allowing users to run Cargo commands directly from Neovim.
5
6mod cargo_commands;
7mod error;
8mod lua_exports;
9
10pub use cargo_commands::CargoCommands;
11pub use error::Error;
12
13/// Main module registration for Neovim
14#[mlua::lua_module]
15fn cargo_nvim(lua: &mlua::Lua) -> mlua::Result<mlua::Table> {
16    lua_exports::register_commands(lua)
17}
18
19/// test module for Neovim
20#[cfg(test)]
21mod tests {
22    use super::*;
23    use mlua::Lua;
24
25    #[test]
26    fn test_module_registration() {
27        let lua = Lua::new();
28        let result = cargo_nvim(&lua);
29        assert!(result.is_ok());
30    }
31
32    #[test]
33    fn test_exported_commands() {
34        let lua = Lua::new();
35        let table = cargo_nvim(&lua).unwrap();
36
37        // Fix: Remove unnecessary generic parameter and use correct type
38        assert!(table.get::<mlua::Function>("build").is_ok());
39        assert!(table.get::<mlua::Function>("test").is_ok());
40        assert!(table.get::<mlua::Function>("check").is_ok());
41    }
42
43    #[test]
44    fn test_command_error_handling() {
45        let lua = Lua::new();
46        let table = cargo_nvim(&lua).unwrap();
47
48        // Fix: Remove unnecessary generic parameter and use correct type
49        let build_fn = table.get::<mlua::Function>("build").unwrap();
50        let result: mlua::Result<String> = build_fn.call(vec!["--invalid-flag"]);
51
52        assert!(result.is_err());
53    }
54}