zlsrs 0.1.6

Rust 标准库扩展工具集,提供更便捷的使用方式
Documentation
use super::super::*;

#[test]
fn test_basic_error() {
    let resp: Result<()> = Err("test error".into());
    assert!(resp.is_err());
    assert_eq!(resp.err().unwrap().to_string(), "test error");
}

#[test]
fn test_try_catch() {
    // 测试正常情况
    let resp = try_catch(|| Ok(()));
    assert!(resp.is_ok());

    // 测试返回错误的情况
    let resp = try_catch(|| Err("test error".into()));
    assert!(resp.is_err());
    assert_eq!(resp.err().unwrap().to_string(), "test error");

    // 测试 panic 的情况
    let resp = try_catch(|| {
        panic!("test panic");
        #[allow(unreachable_code)]
        Ok(())
    });
    assert!(resp.is_err());
    assert_eq!(resp.err().unwrap().to_string(), "test panic");
}