diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2019-11-26 08:05:49 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2019-11-26 08:05:49 +0100 |
| commit | 2231a5cf6cdeb90c1cdb75d161a0063d4a385576 (patch) | |
| tree | 2bb81ea4169fd4e811304482e461e1adb1343238 /tests/test_query.rs | |
| parent | 63635360cd25e95bfa2c52c09592e19e656e3d66 (diff) | |
| download | mail-2231a5cf6cdeb90c1cdb75d161a0063d4a385576.tar.gz | |
add tests for query
Diffstat (limited to 'tests/test_query.rs')
| -rw-r--r-- | tests/test_query.rs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/test_query.rs b/tests/test_query.rs new file mode 100644 index 0000000..ad8f299 --- /dev/null +++ b/tests/test_query.rs @@ -0,0 +1,97 @@ +use std::sync::Arc; +use fixtures::{NotmuchCommand, MailBox}; + + +struct QueryFixture { + // Return a single thread with 2 messages + pub mailbox: MailBox, + pub query: notmuch::Query<'static>, +} + +impl QueryFixture { + pub fn new() -> Self{ + let mailbox = MailBox::new(); + + let (msgid, _) = mailbox.deliver(None, Some("foo".to_string()), None, None, vec![], true, None, false, false, false).unwrap(); + mailbox.deliver(None, Some("bar".to_string()), None, None, vec![], true, None, false, false, false).unwrap(); + mailbox.deliver(None, Some("baz".to_string()), None, None, vec![("In-Reply-To".to_string(), format!("<{}>", msgid))], true, None, false, false, false).unwrap(); + mailbox.deliver(None, Some("foo qux".to_string()), None, None, vec![], true, None, false, false, false).unwrap(); + mailbox.deliver(None, Some("foo quux".to_string()), None, None, vec![], true, None, false, false, false).unwrap(); + + let cmd = NotmuchCommand::new(&mailbox.path()); + cmd.run(vec!["new"]).unwrap(); + + let query = { + let database = Arc::new(notmuch::Database::open(&mailbox.path(), notmuch::DatabaseMode::ReadWrite).unwrap()); + + notmuch::Query::create(database, &"foo".to_string()).unwrap() + }; + + Self { + mailbox, + query + } + } +} + +#[test] +fn test_iter_threads() { + let q = QueryFixture::new(); + + let threads = q.query.search_threads().unwrap(); + + let mut num = 0; + for _thread in threads { + num += 1; + } + + assert_eq!(num, 3); + +} + +#[test] +fn test_iter_threads_ext() { + let q = QueryFixture::new(); + + let threads = <notmuch::Query as notmuch::QueryExt>::search_threads(q.query).unwrap(); + + let mut num = 0; + for _thread in threads { + num += 1; + } + + assert_eq!(num, 3); + +} + + +#[test] +fn test_iter_messages() { + let q = QueryFixture::new(); + + let messages = q.query.search_messages().unwrap(); + + let mut num = 0; + for _message in messages { + num += 1; + } + + assert_eq!(num, 3); + +} + +#[test] +fn test_iter_messages_ext() { + let q = QueryFixture::new(); + + let messages = <notmuch::Query as notmuch::QueryExt>::search_messages(q.query).unwrap(); + + let mut num = 0; + for _message in messages { + num += 1; + } + + assert_eq!(num, 3); + +} + |
