edit icon indicating copy to clipboard operation
edit copied to clipboard

Added test in clipboard.rs

Open nalbasgeorgios opened this issue 5 months ago • 3 comments

I added a test case in clipboard.rs to make sure it reads and writes data correctly.

nalbasgeorgios avatar Jun 26 '25 14:06 nalbasgeorgios

@microsoft-github-policy-service agree

nalbasgeorgios avatar Jun 26 '25 14:06 nalbasgeorgios

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Test placement

The mod tests block is declared inside the impl Clipboard scope, which will result in a syntax error. Test modules should be defined at the crate or file root, outside of impl blocks.


   ///Tests if writing to clipboard and 
   ///reading from it returns the correct data.

   #[cfg(test)]
   mod tests {
     use super::*;

     #[test]
     fn test_write_and_read() {
         let mut clipboard = Clipboard::default();
         let data = b"Hello, world!".to_vec();
         clipboard.write(data.clone());
         assert_eq!(clipboard.read(), &data[..]);
         assert!(clipboard.wants_host_sync());
    }
}
Insufficient coverage

The new test only verifies basic write/read behavior and wants_host_sync. Consider adding tests for write_was_line_copy and is_line_copy, edge cases like empty data, and potential error conditions.

#[test]
fn test_write_and_read() {
    let mut clipboard = Clipboard::default();
    let data = b"Hello, world!".to_vec();
    clipboard.write(data.clone());
    assert_eq!(clipboard.read(), &data[..]);
    assert!(clipboard.wants_host_sync());

rohanbalkondekar avatar Jun 26 '25 15:06 rohanbalkondekar

Sorry, my mistake for the code not compiling. I'll try to fix it. Thank you for reviewing my code.

nalbasgeorgios avatar Jun 26 '25 16:06 nalbasgeorgios

But this code in general doesn't need unit tests, because it's so trivial. People often forget to consider that even test code needs to be maintained, just like any other code. It's not a good trade-off.

lhecker avatar Jun 30 '25 12:06 lhecker