diff options
| author | main <main@swarm.moe> | 2026-03-19 10:17:07 -0400 |
|---|---|---|
| committer | main <main@swarm.moe> | 2026-03-19 10:17:07 -0400 |
| commit | 08a1139eaa7a4862ab8c0e5fb5fc6845fc711208 (patch) | |
| tree | ded498d30e1d84c17b3e6dbf80594b5b62faa804 /crates/libmcp-testkit/src/lib.rs | |
| download | libmcp-08a1139eaa7a4862ab8c0e5fb5fc6845fc711208.zip | |
Initial libmcp 1.0.0
Diffstat (limited to 'crates/libmcp-testkit/src/lib.rs')
| -rw-r--r-- | crates/libmcp-testkit/src/lib.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/libmcp-testkit/src/lib.rs b/crates/libmcp-testkit/src/lib.rs new file mode 100644 index 0000000..9f33643 --- /dev/null +++ b/crates/libmcp-testkit/src/lib.rs @@ -0,0 +1,32 @@ +//! Shared test helpers for `libmcp` consumers. + +use serde::de::DeserializeOwned; +use std::{ + fs::File, + io::{self, BufRead, BufReader}, + path::Path, +}; + +/// Reads an append-only JSONL file into typed records. +pub fn read_json_lines<T>(path: &Path) -> io::Result<Vec<T>> +where + T: DeserializeOwned, +{ + let file = File::open(path)?; + let reader = BufReader::new(file); + let mut records = Vec::new(); + for line in reader.lines() { + let line = line?; + if line.trim().is_empty() { + continue; + } + let parsed = serde_json::from_str::<T>(line.as_str()).map_err(|error| { + io::Error::new( + io::ErrorKind::InvalidData, + format!("invalid JSONL test record: {error}"), + ) + })?; + records.push(parsed); + } + Ok(records) +} |