diff --git a/.changeset/short-lamps-kiss.md b/.changeset/short-lamps-kiss.md new file mode 100644 index 0000000..a845151 --- /dev/null +++ b/.changeset/short-lamps-kiss.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/src/command.rs b/src/command.rs index 654ac65..7a889da 100644 --- a/src/command.rs +++ b/src/command.rs @@ -14,6 +14,32 @@ pub fn define_command(options: Command) -> Command { options } +#[cfg(test)] +mod tests { + use crate::command::{define_command, Command}; + use crate::types::CommandMeta; + + #[test] + fn test_define_command() { + let meta = CommandMeta { + name: Some("test".to_string()), + version: Some("1.0.0".to_string()), + about: Some("test case".to_string()), + styled: Some(false), + }; + let cmd = Command { + meta: meta.clone(), + options: Default::default(), + callback: None, + subcommands: None, + }; + + let defined_cmd = define_command(cmd); + + assert_eq!(defined_cmd.meta, meta); + } +} + /// Run command /// /// **NOTE**: If the given `args` is empty, it will use `process.argv` instead. diff --git a/src/types.rs b/src/types.rs index 25c354a..f283c0d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -23,7 +23,7 @@ pub struct Context { /// Command metadata #[napi(object)] -#[derive(Clone)] +#[derive(Clone, Debug, PartialEq)] pub struct CommandMeta { /// Command name /// @@ -183,7 +183,7 @@ pub struct CommandOption { pub struct Command { pub meta: CommandMeta, pub options: HashMap, - #[napi(ts_type = "(ctx: Context) => void")] + #[napi(ts_type = "(ctx: Context) => void ")] pub callback: Option, pub subcommands: Option>, }