flowcode-core 0.4.3-alpha

Core execution engine for FlowCode data scripting language
Documentation
use flowcode_core::logger::Logger;

#[test]
fn test_logger_new() {
    let logger = Logger::new(10);
    assert_eq!(logger.capacity, 10);
    assert!(logger.get_logs().is_empty());
}

#[test]
fn test_log_action_under_capacity() {
    let mut logger = Logger::new(3);
    logger.log_action("Log 1".to_string());
    logger.log_action("Log 2".to_string());
    assert_eq!(logger.get_logs(), vec!["Log 1", "Log 2"]);
}

#[test]
fn test_log_action_at_capacity() {
    let mut logger = Logger::new(2);
    logger.log_action("Log 1".to_string());
    logger.log_action("Log 2".to_string());
    logger.log_action("Log 3".to_string()); // This should push out "Log 1"
    assert_eq!(logger.get_logs(), vec!["Log 2", "Log 3"]);
}

#[test]
fn test_log_action_capacity_one() {
    let mut logger = Logger::new(1);
    logger.log_action("Log A".to_string());
    assert_eq!(logger.get_logs(), vec!["Log A"]);
    logger.log_action("Log B".to_string());
    assert_eq!(logger.get_logs(), vec!["Log B"]);
    logger.log_action("Log C".to_string());
    assert_eq!(logger.get_logs(), vec!["Log C"]);
}

#[test]
fn test_get_logs_empty() {
    let logger = Logger::new(5);
    assert!(logger.get_logs().is_empty());
}

#[test]
fn test_clear_logs_with_capacity() {
    let mut logger = Logger::new(3);
    logger.log_action("Log 1".to_string());
    logger.log_action("Log 2".to_string());
    logger.clear_logs();
    assert!(logger.get_logs().is_empty());
}

#[test]
fn test_logger_capacity_zero() {
    let mut logger = Logger::new(0);
    logger.log_action("Should not be logged".to_string());
    assert!(logger.get_logs().is_empty(), "Logs should be empty if capacity is 0");
}

#[test]
fn test_log_action_multiple_rotations() {
    let mut logger = Logger::new(2);
    logger.log_action("Log 1".to_string()); // [Log 1]
    logger.log_action("Log 2".to_string()); // [Log 1, Log 2]
    logger.log_action("Log 3".to_string()); // [Log 2, Log 3]
    assert_eq!(logger.get_logs(), vec!["Log 2", "Log 3"]);
    logger.log_action("Log 4".to_string()); // [Log 3, Log 4]
    assert_eq!(logger.get_logs(), vec!["Log 3", "Log 4"]);
    logger.log_action("Log 5".to_string()); // [Log 4, Log 5]
    assert_eq!(logger.get_logs(), vec!["Log 4", "Log 5"]);
}