1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: GPL-3.0-or-later
//! Generator to get all redirects
//!
//! See the [`AllRedirects`] type documentation for specifics.
use super::{Generator, SortDirection};
/// Get all pages in a given namespace
///
/// See [API documentation](https://www.mediawiki.org/wiki/API:Allredirects) for more details.
#[derive(Generator)]
#[params(generator = "allredirects", garlimit = "max")]
pub struct AllRedirects {
/// The namespace to enumerate
#[param("garnamespace")]
namespace: Option<u32>,
/// The page title to start enumerating from.
#[param("garfrom")]
from: Option<String>,
/// The page title to stop enumerating at.
#[param("garto")]
to: Option<String>,
/// The title prefix for filtering.
#[param("garprefix")]
prefix: Option<String>,
/// Sort direction
#[param("gardir")]
sort: Option<SortDirection>,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::testwp;
use std::collections::HashMap;
#[tokio::test]
async fn test_allredirects() {
let bot = testwp().await;
let gen = AllRedirects::new().namespace(0u32);
dbg!(gen.params());
assert_eq!(
gen.params(),
HashMap::from([
("generator", "allredirects".to_string()),
("garlimit", "max".to_string()),
("garnamespace", "0".to_string())
])
);
let mut pages = gen.generate(&bot);
let mut count = 0;
while let Some(page) = pages.recv().await {
page.unwrap();
count += 1;
if count == 5 {
break;
}
}
assert_eq!(count, 5);
}
}