Skip to content

Commit

Permalink
Add tests for ClipboardContext and NopClipboardContext
Browse files Browse the repository at this point in the history
copypasta doesn't seem to have unit tests, so I accidentally made
changes with the PR: alacritty#57

I want to make sure any changes are checked by running test codes.
That's why I want to add test codes.
  • Loading branch information
yykamei committed Oct 18, 2023
1 parent 54699fb commit 278ae41
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/nop_clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ impl ClipboardProvider for NopClipboardContext {
Ok(())
}
}

#[cfg(test)]
mod tests {
use crate::common::ClipboardProvider;
use crate::nop_clipboard::NopClipboardContext;

#[test]
fn it_does_nothing() {
let mut ctx = NopClipboardContext::new().unwrap();
let msg = "Hello, world!";
ctx.set_contents(msg.to_owned()).unwrap();

assert_eq!(ctx.get_contents().unwrap(), "");
}
}
10 changes: 10 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use copypasta::{ClipboardContext, ClipboardProvider};

#[test]
fn it_works() {
let mut ctx = ClipboardContext::new().unwrap();
let msg = "Hello, world!";

ctx.set_contents(msg.to_owned()).unwrap();
assert_eq!(ctx.get_contents().unwrap(), "Hello, world!");
}

0 comments on commit 278ae41

Please sign in to comment.