| 360 | |
| 361 | #[test] |
| 362 | fn decode_malformed_json() { |
| 363 | // Setup |
| 364 | let mut decoder = JsonLinesDecoder::<TestItem>::new(); |
| 365 | |
| 366 | // Create malformed JSON (invalid syntax with missing quotes around name) |
| 367 | // The malformed part is that "name" is missing quotes - should be "name":"value" |
| 368 | let mut buffer = BytesMut::from(&b"{\"id\":1,name:\"test\"}\n"[..]); |
| 369 | |
| 370 | // Try to decode the malformed JSON |
| 371 | let result = decoder.decode(&mut buffer); |
| 372 | |
| 373 | // Expect an error for malformed JSON |
| 374 | assert!(result.is_err(), "Should return error for malformed JSON"); |
| 375 | let err = result.expect_err("should have an error for malformed JSON"); |
| 376 | |
| 377 | // The error should contain a message about invalid JSON syntax |
| 378 | // The actual error message contains "key must be a string" |
| 379 | let err_string = format!("{err:?}"); |
| 380 | assert!( |
| 381 | err_string.contains("key must be a string"), |
| 382 | "Error should indicate JSON parsing failure: {err_string}" |
| 383 | ); |
| 384 | } |
| 385 | |
| 386 | #[test] |
| 387 | fn decode_empty_buffer() { |