Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions picojson/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,4 @@ ureq = { version = "2.0", optional = true }
zip = { version = "0.6", optional = true }

[dev-dependencies]
test-log = "0.2.18"
paste = "1.0"

[dependencies]
log = "0.4.27"
9 changes: 7 additions & 2 deletions picojson/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ fn generate_conformance_tests() -> Result<(), Box<dyn std::error::Error>> {

let generated_code = format!(
r#"// Generated by build.rs - DO NOT EDIT
#![allow(non_snake_case)] // Keep test names discoverable and matching original JSON test suite

#[cfg(feature = "remote-tests")]
#[allow(clippy::non_snake_case)] // Keep test names discoverable and matching original JSON test suite
mod conformance_generated {{
use picojson::{{Event, ParseError, PullParser, SliceParser}};

Expand Down Expand Up @@ -129,6 +130,7 @@ mod conformance_generated {{
Ok(())
}

#[cfg(feature = "remote-tests")]
fn sanitize_test_name(
filename: &str,
test_name_counts: &mut std::collections::HashMap<String, u32>,
Expand Down Expand Up @@ -156,23 +158,26 @@ fn sanitize_test_name(
*count += 1;

if *count > 1 {
format!("{}_{}", result, count)
format!("{result}_{count}")
} else {
result
}
}

// Configuration from Cargo.toml metadata
#[cfg(feature = "remote-tests")]
fn get_jsontest_suite_url() -> String {
std::env::var("CARGO_PKG_METADATA_CONFORMANCE_TESTS_JSONTEST_SUITE_URL")
.unwrap_or_else(|_| "https://github.com/nst/JSONTestSuite/archive/{commit}.zip".to_string())
}

#[cfg(feature = "remote-tests")]
fn get_jsontest_suite_commit() -> String {
std::env::var("CARGO_PKG_METADATA_CONFORMANCE_TESTS_JSONTEST_SUITE_COMMIT")
.unwrap_or_else(|_| "1ef36fa01286573e846ac449e8683f8833c5b26a".to_string())
}

#[cfg(feature = "json-checker-tests")]
fn get_json_checker_url() -> String {
std::env::var("CARGO_PKG_METADATA_CONFORMANCE_TESTS_JSON_CHECKER_URL")
.unwrap_or_else(|_| "https://www.json.org/JSON_checker/test.zip".to_string())
Expand Down
2 changes: 1 addition & 1 deletion picojson/src/chunk_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'a> ChunkReader<'a> {
}
}

impl<'a> Reader for ChunkReader<'a> {
impl Reader for ChunkReader<'_> {
type Error = ();

fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions picojson/src/json_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ impl core::fmt::Display for JsonNumber<'_, '_> {
JsonNumber::Copied { raw, parsed } => (raw, parsed),
};
match parsed {
NumberResult::Integer(val) => write!(f, "{}", val),
NumberResult::Integer(val) => write!(f, "{val}"),
#[cfg(feature = "float")]
NumberResult::Float(val) => write!(f, "{}", val),
NumberResult::Float(val) => write!(f, "{val}"),
#[cfg(all(not(feature = "float"), feature = "float-truncate"))]
NumberResult::FloatTruncated(val) => write!(f, "{}", val),
// For overflow, disabled, or skipped cases, show the exact raw string
Expand Down
1 change: 1 addition & 0 deletions picojson/src/number_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub fn parse_number_with_delimiter_logic<T: NumberExtractor>(
/// 2. Convert to UTF-8 string
/// 3. Parse using shared number parsing logic
/// 4. Create JsonNumber::Borrowed event
///
/// All position logic is handled by the calling parser.
pub fn parse_number_event<T: NumberExtractor>(
extractor: &T,
Expand Down
6 changes: 3 additions & 3 deletions picojson/src/parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl From<UnexpectedState> for ParseError {
impl core::fmt::Display for ParseError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ParseError::TokenizerError(e) => write!(f, "{}", e),
ParseError::InvalidUtf8(e) => write!(f, "Invalid UTF-8: {}", e),
_ => write!(f, "{:?}", self),
ParseError::TokenizerError(e) => write!(f, "{e}"),
ParseError::InvalidUtf8(e) => write!(f, "Invalid UTF-8: {e}"),
_ => write!(f, "{self:?}"),
}
}
}
Expand Down
37 changes: 8 additions & 29 deletions picojson/src/stream_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,52 +1630,31 @@ mod tests {
// JSON: ["hello\\"] = 10 bytes total, should work with ~7 byte buffer
let json_stream = br#"["hello\\"]"#;

println!("Testing escape sequence with buffer size: {}", buffer_size);
println!(
"JSON input: {:?}",
core::str::from_utf8(json_stream).unwrap()
);
let mut buffer = vec![0u8; buffer_size];
let mut parser = StreamParser::new(SliceReader::new(json_stream), &mut buffer);

// Array start
match parser.next_event()? {
Event::StartArray => println!(" ✅ StartArray OK"),
other => panic!("Expected StartArray, got: {:?}", other),
}
assert!(matches!(parser.next_event()?, Event::StartArray));

// String with escape
match parser.next_event()? {
Event::String(s) => {
println!(" ✅ String OK: '{}'", s.as_str());
assert_eq!(s.as_str(), "hello\\");
}
other => panic!("Expected String, got: {:?}", other),
}
assert!(matches!(parser.next_event()?, Event::String(s) if s.as_str() == "hello\\"));

// Array end
match parser.next_event()? {
Event::EndArray => println!(" ✅ EndArray OK"),
other => panic!("Expected EndArray, got: {:?}", other),
}
assert!(matches!(parser.next_event()?, Event::EndArray));

// End document
match parser.next_event()? {
Event::EndDocument => println!(" ✅ EndDocument OK"),
other => panic!("Expected EndDocument, got: {:?}", other),
}
assert!(matches!(parser.next_event()?, Event::EndDocument));

println!(" 🎉 SUCCESS with buffer size: {}", buffer_size);
Ok(())
}

#[test]
fn test_minimal_buffer_simple_escape_1() {
// Buffer size 4 - clearly not enough
match test_simple_escape_with_buffer_size(4) {
Ok(()) => panic!("Expected failure with 4-byte buffer, but succeeded!"),
Err(e) => println!("Expected failure with 4-byte buffer: {:?}", e),
}
assert!(matches!(
test_simple_escape_with_buffer_size(4),
Err(crate::ParseError::ScratchBufferFull)
));
}

#[test]
Expand Down
48 changes: 0 additions & 48 deletions picojson/tests/debug_root_numbers.rs

This file was deleted.

31 changes: 0 additions & 31 deletions picojson/tests/debug_stress_case.rs

This file was deleted.

Loading