use ass_core::utils::Spans;
#[test]
fn test_span_column_functionality() {
let source = "Line 1\nLine 2 with text\nLine 3";
let spans = Spans::new(source);
let first_span = "Line 1";
if let Some(column) = spans.span_column(first_span) {
assert_eq!(column, 1); }
let second_span = "with";
if let Some(column) = spans.span_column(second_span) {
assert!(column > 1); }
let invalid_span = "not in source";
assert!(spans.span_column(invalid_span).is_none());
}
#[test]
fn test_spans_edge_cases() {
let empty_source = "";
let empty_spans = Spans::new(empty_source);
assert!(empty_spans.span_offset("anything").is_none());
assert!(empty_spans.span_column("anything").is_none());
let whitespace_source = " \n\t \r\n ";
let whitespace_spans = Spans::new(whitespace_source);
if let Some(offset) = whitespace_spans.span_offset(" ") {
assert!(offset < whitespace_source.len());
}
let unicode_source = "Hello π δΈη Ω
Ψ±ΨΨ¨Ψ§";
let unicode_spans = Spans::new(unicode_source);
if let Some(column) = unicode_spans.span_column("π") {
assert!(column > 1);
}
if let Some(column) = unicode_spans.span_column("δΈη") {
assert!(column > 1);
}
}
#[test]
fn test_spans_line_column_calculations() {
let multiline_source = "First line\nSecond line with π\n\nFourth line";
let spans = Spans::new(multiline_source);
let test_cases = vec![
("First", 1), ("Second", 1), ("with", 13), ("π", 18), ("Fourth", 1), ];
for (span_text, expected_min_column) in test_cases {
if let Some(column) = spans.span_column(span_text) {
assert!(
column >= expected_min_column,
"Column for '{span_text}' should be >= {expected_min_column}, got {column}"
);
}
}
}
#[test]
fn test_spans_with_special_characters() {
let special_source = "Line1\r\nLine2\tWith\x00Null\nLine3";
let spans = Spans::new(special_source);
if let Some(offset) = spans.span_offset("Line1") {
assert_eq!(offset, 0);
}
if let Some(offset) = spans.span_offset("Line2") {
assert!(offset > 0);
}
if let Some(column) = spans.span_column("With") {
assert!(column > 1);
}
}