Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/delimited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl LineDelimiter {
}
},
};
let end_offset = record_ends.next_back().unwrap_or(start_offset);
let end_offset = record_ends.last().unwrap_or(start_offset);
if start_offset != end_offset {
self.complete.push_back(val.slice(start_offset..end_offset));
}
Expand Down Expand Up @@ -270,4 +270,38 @@ mod tests {
]
)
}

#[tokio::test]
async fn test_delimiter_quotes_stream() {
let input = vec!["x,y,z\n,\"new\nline\",\"with ", "space\""];
let input_stream =
futures_util::stream::iter(input.into_iter().map(|s| Ok(Bytes::from(s))));
let stream = newline_delimited_stream(input_stream);

let results: Vec<_> = stream.try_collect().await.unwrap();
assert_eq!(
results,
vec![
Bytes::from("x,y,z\n"),
Bytes::from(",\"new\nline\",\"with space\"")
]
)
}

#[tokio::test]
async fn test_delimiter_escape_stream() {
let input = vec!["hello\n\n\"\\ttabulated\"", "world"];
let input_stream =
futures_util::stream::iter(input.into_iter().map(|s| Ok(Bytes::from(s))));
let stream = newline_delimited_stream(input_stream);

let results: Vec<_> = stream.try_collect().await.unwrap();
assert_eq!(
results,
vec![
Bytes::from("hello\n\n"),
Bytes::from("\"\\ttabulated\"world")
]
)
}
}