1mod cargo_commands;
7mod error;
8mod lua_exports;
9
10pub use cargo_commands::CargoCommands;
11pub use error::Error;
12
13#[mlua::lua_module]
15fn cargo_nvim(lua: &mlua::Lua) -> mlua::Result<mlua::Table> {
16 lua_exports::register_commands(lua)
17}
18
19#[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 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 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}