diff --git a/test_util/src/lsp.rs b/test_util/src/lsp.rs index 87602e3fe0..6cc4576d8a 100644 --- a/test_util/src/lsp.rs +++ b/test_util/src/lsp.rs @@ -337,8 +337,20 @@ mod tests { #[test] fn test_read_message() { - let msg = b"content-length: 11\r\n\r\nhello world"; - let mut reader = std::io::Cursor::new(msg); - assert_eq!(read_message(&mut reader).unwrap(), b"hello world"); + let msg1 = b"content-length: 11\r\n\r\nhello world"; + let mut reader1 = std::io::Cursor::new(msg1); + assert_eq!(read_message(&mut reader1).unwrap(), b"hello world"); + + let msg2 = b"content-length: 5\r\n\r\nhello world"; + let mut reader2 = std::io::Cursor::new(msg2); + assert_eq!(read_message(&mut reader2).unwrap(), b"hello"); + } + + #[test] + #[should_panic(expected = "failed to fill whole buffer")] + fn test_invalid_read_message() { + let msg1 = b"content-length: 12\r\n\r\nhello world"; + let mut reader1 = std::io::Cursor::new(msg1); + read_message(&mut reader1).unwrap(); } }