1
use supp_macro::command;
2

            
3
// Simple debug test to see what the macro generates
4

            
5
#[derive(Debug, Clone)]
6
pub enum Argument {
7
    String(String),
8
}
9

            
10
#[derive(Debug)]
11
pub enum CmdError {
12
    Args(String),
13
}
14

            
15
impl std::fmt::Display for CmdError {
16
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17
        write!(f, "{:?}", self)
18
    }
19
}
20

            
21
impl std::error::Error for CmdError {}
22

            
23
#[derive(Debug)]
24
pub enum CmdResult {
25
    Success(String),
26
}
27

            
28
impl TryFrom<Argument> for String {
29
    type Error = CmdError;
30

            
31
    fn try_from(arg: Argument) -> Result<Self, Self::Error> {
32
        match arg {
33
            Argument::String(s) => Ok(s),
34
        }
35
    }
36
}
37

            
38
// Try the most basic case first - progressive types approach
39
command! {
40
    TestCommand {
41
    } => {
42
        Ok(Some(CmdResult::Success("test".to_string())))
43
    }
44
4
}
45

            
46
#[tokio::test]
47
3
async fn test_basic_macro() {
48
    // Test that it compiles and actually works with progressive types
49
2
    let result = TestCommand::new().run().await.unwrap();
50
2
    assert!(result.is_some());
51

            
52
3
    if let Some(CmdResult::Success(msg)) = result {
53
3
        assert_eq!(msg, "test");
54
2
    } else {
55
2
        panic!("Expected Success result");
56
2
    }
57
2
}
58

            
59
#[test]
60
2
fn test_generated_struct() {
61
    // Test that the command struct was generated
62
2
    let _cmd = TestCommand;
63
2
}