diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-04-25 16:58:17 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-04-25 16:58:17 +0200 |
| commit | 72c2b83748a601d02c82d5bcb4220d3b238281cc (patch) | |
| tree | 38acb17db4a48fc9f340680ea5b86c6cd49d8f2a /notmuch/tests/test_query.rs | |
| parent | 51fa75397dda2c280f29760e7b525caefc03642e (diff) | |
| parent | 2231a5cf6cdeb90c1cdb75d161a0063d4a385576 (diff) | |
| download | mail-72c2b83748a601d02c82d5bcb4220d3b238281cc.tar.gz | |
Add 'notmuch/' from commit '2231a5cf6cdeb90c1cdb75d161a0063d4a385576'
git-subtree-dir: notmuch
git-subtree-mainline: 51fa75397dda2c280f29760e7b525caefc03642e
git-subtree-split: 2231a5cf6cdeb90c1cdb75d161a0063d4a385576
Diffstat (limited to 'notmuch/tests/test_query.rs')
| -rw-r--r-- | notmuch/tests/test_query.rs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/notmuch/tests/test_query.rs b/notmuch/tests/test_query.rs new file mode 100644 index 0000000..ad8f299 --- /dev/null +++ b/notmuch/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); + +} + |
