robson-core 0.1.0

Rust async agent orchestrator for automated development workflows
Documentation
use robson_core::utils::truncate_log;

const MAX: usize = 3000;

#[test]
fn short_ascii_unchanged() {
    let s = "hello world";
    assert_eq!(truncate_log(s, MAX), s);
}

#[test]
fn empty_string_unchanged() {
    let s = "";
    assert_eq!(truncate_log(s, MAX), s);
}

#[test]
fn exactly_max_chars_unchanged() {
    let s: String = "a".repeat(MAX);
    assert_eq!(truncate_log(&s, MAX), s);
}

#[test]
fn over_max_ascii_truncated_with_suffix() {
    let s: String = "a".repeat(MAX + 100);
    let result = truncate_log(&s, MAX);
    assert!(result.ends_with("...[truncated]"));
    let content = result.strip_suffix("...[truncated]").unwrap();
    assert_eq!(content.len(), MAX);
    assert!(content.chars().all(|c| c == 'a'));
}

#[test]
fn multibyte_utf8_truncated_at_char_boundary() {
    let s: String = "".repeat(MAX + 5);
    let result = truncate_log(&s, MAX);
    assert!(result.ends_with("...[truncated]"));
    let content = result.strip_suffix("...[truncated]").unwrap();
    assert_eq!(content.chars().count(), MAX);
    assert!(std::str::from_utf8(content.as_bytes()).is_ok());
}

#[test]
fn multibyte_utf8_under_max_unchanged() {
    let s: String = "🚀".repeat(10);
    assert_eq!(truncate_log(&s, MAX), s);
}

#[test]
fn truncation_suffix_present_only_when_cut() {
    let short = "no truncation here";
    assert!(!truncate_log(short, MAX).contains("...[truncated]"));

    let long: String = "x".repeat(MAX + 1);
    assert!(truncate_log(&long, MAX).contains("...[truncated]"));
}