Skip to content

Commit

Permalink
csv-core: fix Reader::reset not resetting output_pos
Browse files Browse the repository at this point in the history
FIxes #382, PR #383
  • Loading branch information
levkk authored Feb 12, 2025
1 parent 95a5e1a commit 066de4a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions csv-core/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ impl Reader {
self.nfa_state = NfaState::StartRecord;
self.line = 1;
self.has_read = false;
self.output_pos = 0;
}

/// Return the current line number as measured by the number of occurrences
Expand Down Expand Up @@ -2002,4 +2003,27 @@ mod tests {

assert_read_record!(rdr, &inp, out, ends, 0, 0, 0, End);
}

#[test]
fn reset_input_partial() {
use crate::ReadRecordResult::*;

let inp = b("foo,bar\nbaz");
let out = &mut [0; 1024];
let ends = &mut [0; 10];
let mut rdr = Reader::new();

assert_read_record!(rdr, &inp, out, ends, 8, 6, 2, Record);

// Try to read incomplete record.
let (result, _, _, _) = rdr.read_record(&inp[8..], out, ends);
assert_eq!(result, InputEmpty);

rdr.reset();

let inp = b("baz,raz\n");
let (result, _, _, _) = rdr.read_record(inp, out, ends);
assert_eq!(result, Record);
assert_eq!(ends[0], 3);
}
}

0 comments on commit 066de4a

Please sign in to comment.