use eggsact::text::{escape_text, text_fingerprint, text_hash, text_transform, unescape_text};
#[test]
fn test_text_hash_md5() {
let result = text_hash("hello", &["md5".to_string()], "hex");
assert!(!result.hashes.is_empty());
let hash = result.hashes.get("md5").unwrap();
assert_eq!(hash.len(), 32);
}
#[test]
fn test_text_hash_sha1() {
let result = text_hash("hello", &["sha1".to_string()], "hex");
let hash = result.hashes.get("sha1").unwrap();
assert_eq!(hash.len(), 40);
}
#[test]
fn test_text_hash_sha256() {
let result = text_hash("hello", &["sha256".to_string()], "hex");
let hash = result.hashes.get("sha256").unwrap();
assert_eq!(hash.len(), 64);
}
#[test]
fn test_text_hash_crc32() {
let result = text_hash("hello", &["crc32".to_string()], "hex");
let hash = result.hashes.get("crc32").unwrap();
assert_eq!(hash.len(), 8);
}
#[test]
fn test_text_hash_multiple() {
let result = text_hash(
"hello",
&["md5".to_string(), "sha1".to_string(), "sha256".to_string()],
"hex",
);
assert!(result.hashes.contains_key("md5"));
assert!(result.hashes.contains_key("sha1"));
assert!(result.hashes.contains_key("sha256"));
}
#[test]
fn test_text_hash_empty() {
let result = text_hash("", &["md5".to_string()], "hex");
let hash = result.hashes.get("md5").unwrap();
assert_eq!(hash.len(), 32);
}
#[test]
fn test_text_hash_base64() {
let result = text_hash("hello", &["md5".to_string()], "base64");
let hash = result.hashes.get("md5").unwrap();
assert!(!hash.is_empty());
}
#[test]
fn test_text_fingerprint_basic() {
let result = text_fingerprint("hello world", "none", "lf", false, false);
assert!(!result.sha256.is_empty());
}
#[test]
fn test_text_fingerprint_same_input() {
let a = text_fingerprint("hello", "none", "lf", false, false);
let b = text_fingerprint("hello", "none", "lf", false, false);
assert_eq!(a.sha256, b.sha256);
}
#[test]
fn test_text_fingerprint_different_input() {
let a = text_fingerprint("hello", "none", "lf", false, false);
let b = text_fingerprint("world", "none", "lf", false, false);
assert_ne!(a.sha256, b.sha256);
}
#[test]
fn test_text_fingerprint_casefold() {
let a = text_fingerprint("Hello", "none", "lf", false, false);
let b = text_fingerprint("hello", "none", "lf", false, false);
assert_ne!(a.sha256, b.sha256);
let c = text_fingerprint("Hello", "none", "lf", false, true);
let d = text_fingerprint("hello", "none", "lf", false, true);
assert_eq!(c.sha256, d.sha256);
}
#[test]
fn test_text_fingerprint_trim_newline() {
let a = text_fingerprint("hello\n", "none", "lf", true, false);
let b = text_fingerprint("hello", "none", "lf", true, false);
assert_eq!(a.sha256, b.sha256);
}
#[test]
fn test_text_transform_uppercase() {
let result = text_transform("hello", &["upper".to_string()]);
assert_eq!(result.text, "HELLO");
}
#[test]
fn test_text_transform_lowercase() {
let result = text_transform("HELLO", &["lower".to_string()]);
assert_eq!(result.text, "hello");
}
#[test]
fn test_text_transform_title_case() {
let result = text_transform("hello world", &["title_case".to_string()]);
assert!(result.text.contains("H"));
assert!(result.text.contains("W"));
}
#[test]
fn test_text_transform_chained() {
let result = text_transform("hello", &["upper".to_string(), "trim".to_string()]);
assert_eq!(result.text, "HELLO");
}
#[test]
fn test_text_transform_no_operations() {
let result = text_transform("hello", &[]);
assert_eq!(result.text, "hello");
}
#[test]
fn test_text_transform_trim() {
let result = text_transform(" hello ", &["trim".to_string()]);
assert_eq!(result.text, "hello");
}
#[test]
fn test_text_transform_casefold() {
let result = text_transform("Hello World", &["casefold".to_string()]);
assert_eq!(result.text, "hello world");
}
#[test]
fn test_text_transform_normalize_nfc() {
let result = text_transform("caf\u{00e9}", &["normalize_nfc".to_string()]);
assert!(!result.text.is_empty());
}
#[test]
fn test_text_transform_strip_all_final_newlines() {
let result = text_transform("hello\n\n", &["strip_final_newline".to_string()]);
assert_eq!(result.text, "hello");
let result = text_transform(
"hello\n\n",
&[
"strip_final_newline".to_string(),
"ensure_final_newline".to_string(),
],
);
assert_eq!(result.text, "hello\n");
}
#[test]
fn test_escape_text_python_string() {
let result = escape_text("hello\nworld", "python_string").unwrap();
assert!(result.escaped.contains("\\n"));
}
#[test]
fn test_escape_text_python_string_quotes() {
let result = escape_text("it's a test", "python_string").unwrap();
assert!(result.escaped.contains("\\'"));
}
#[test]
fn test_escape_text_json() {
let result = escape_text("hello\nworld", "json_string");
match result {
Ok(r) => {
let _ = r;
}
Err(e) => {
let _ = e;
} }
}
#[test]
fn test_escape_text_backslash() {
let result = escape_text("path\\to\\file", "python_string").unwrap();
assert!(!result.escaped.is_empty());
}
#[test]
fn test_escape_text_result_struct() {
let result = escape_text("hello", "python_string").unwrap();
assert_eq!(result.mode, "python_string");
}
#[test]
fn test_unescape_text_python_string_newline() {
let result = unescape_text("'\\n'", "python_string");
assert!(result.changed);
assert_eq!(result.unescaped, "\n");
}
#[test]
fn test_unescape_text_python_string_tab() {
let result = unescape_text("'\\t'", "python_string");
assert!(result.changed);
assert_eq!(result.unescaped, "\t");
}
#[test]
fn test_unescape_text_python_string_backslash() {
let result = unescape_text("'\\\\'", "python_string");
assert!(result.changed);
assert_eq!(result.unescaped, "\\");
}
#[test]
fn test_unescape_text_python_string_quote() {
let result = unescape_text("'\\''", "python_string");
assert!(result.changed);
assert_eq!(result.unescaped, "'");
}
#[test]
fn test_unescape_text_json_newline() {
let result = unescape_text("\"\\n\"", "json_string");
assert!(result.changed);
assert_eq!(result.unescaped, "\n");
}
#[test]
fn test_unescape_text_json_tab() {
let result = unescape_text("\"\\t\"", "json_string");
assert!(result.changed);
assert_eq!(result.unescaped, "\t");
}
#[test]
fn test_unescape_text_no_escape() {
let result = unescape_text("hello", "python_string");
assert_eq!(result.unescaped, "hello");
}
#[test]
fn test_remove_zero_width_reports_character_index() {
let result = text_transform("é\u{200B}x", &["remove_zero_width".to_string()]);
assert_eq!(result.text, "éx");
assert_eq!(result.removed[0].index, 1);
}
#[test]
fn test_unescape_unicode_escape_does_not_decode_synthesized_escape() {
let result = unescape_text(r"\u005cU0001F600", "unicode_escape");
assert_eq!(result.unescaped, r"\U0001F600");
}
#[test]
fn test_unescape_python_double_backslash_before_n() {
let result = unescape_text("'\\n'", "python_string");
assert_eq!(result.unescaped, "\n"); }
#[test]
fn test_unescape_python_simple_backslash_n() {
let result = unescape_text("'\\n'", "python_string");
assert_eq!(result.unescaped, "\n");
}
#[test]
fn test_unescape_python_backslash_quote() {
let result = unescape_text("'\\''", "python_string");
assert_eq!(result.unescaped, "'");
}
#[test]
fn test_unescape_python_backslash_backslash() {
let result = unescape_text("'\\\\'", "python_string");
assert_eq!(result.unescaped, "\\");
}