1mod clients;
2pub mod constants;
3pub mod pressers;
4pub mod records;
5mod test_server;
6
7#[cfg(test)]
8mod tests {
9 use crate::pressers::HtmlPresser;
10 use crate::test_server::TestServer;
11 use serial_test::serial;
12 use std::thread;
13
14 macro_rules! aw {
15 ($e:expr) => {
16 tokio_test::block_on($e)
17 };
18 }
19
20 #[test]
21 #[serial]
22 fn press_urls() {
23 let press_urls = aw!(HtmlPresser::press_urls("https://example.com", 1, 1));
24 let url = press_urls.unwrap();
25
26 assert_eq!(url.len(), 1);
27 }
28
29 #[test]
30 #[serial]
31 fn press_curated_urls_nm() {
32 let pressed_urls = aw!(HtmlPresser::press_curated_urls(
33 "https://example.com",
34 "no_match123",
35 1,
36 1
37 ));
38 let url = pressed_urls.unwrap();
39
40 assert_eq!(url.len(), 0);
41 }
42
43 #[test]
44 #[serial]
45 fn press_curated_urls_m() {
46 thread::spawn(|| {
47 TestServer::test_anchors_server();
48 });
49 let pressed_urls = aw!(HtmlPresser::press_curated_urls(
50 "http://127.0.0.1:7878",
51 "not-example.com",
52 1,
53 1
54 ));
55 let url = pressed_urls.unwrap();
56 println!("{:?}", url);
57 assert_eq!(url.len(), 6);
58 }
59
60 #[test]
61 #[serial]
62 fn press_recs_blind() {
63 let pressed_recs = aw!(HtmlPresser::press_records_blind("https://funnyjunk.com", 2));
64 let rec = pressed_recs.unwrap();
65
66 assert_eq!(rec.len(), 2);
67 }
68
69 #[test]
70 #[serial]
71 fn press_recs_vector() {
72 let pressed_recs = aw!(HtmlPresser::press_records(vec!["https://example.com"]));
73 let rec = pressed_recs.unwrap();
74
75 assert_eq!(rec.len(), 1);
76 }
77
78 #[test]
79 #[serial]
80 fn press_recs_single() {
81 let pressed_recs = aw!(HtmlPresser::press_record("https://example.com"));
82 let rec = pressed_recs.unwrap();
83
84 assert_eq!(rec.origin, "https://example.com/");
85 }
86
87 #[test]
93 #[serial]
94 fn test_server_works() {
95 thread::spawn(|| {
96 TestServer::test_anchors_server();
97 });
98
99 let pressed_rec = aw!(HtmlPresser::press_record("http://127.0.0.1:7878"));
100 assert_eq!(pressed_rec.is_ok(), true);
101 }
102
103 #[test]
104 #[serial]
105 fn record_domain_anchors() {
106 thread::spawn(move || {
107 TestServer::test_anchors_server();
108 });
109
110 let pressed_rec = aw!(HtmlPresser::press_record("http://127.0.0.1:7878"));
111
112 let mut rec = pressed_rec.unwrap();
113 rec.origin = "https://example.com".to_string();
114 let domain_anchors = rec.domain_anchors();
115
116 assert_eq!(domain_anchors.unwrap().len(), 5);
117 }
118
119 #[test]
120 #[serial]
121 fn record_non_domain_anchors() {
122 thread::spawn(|| {
123 TestServer::test_anchors_server();
124 });
125
126 let pressed_rec_result = aw!(HtmlPresser::press_record("http://127.0.0.1:7878"));
127 let mut rec = pressed_rec_result.unwrap();
128 rec.origin = "https://example.com".to_string();
129 let domain_anchors = rec.non_domain_anchors().unwrap();
130
131 assert_eq!(domain_anchors.len(), 5);
132 }
133
134 #[test]
135 #[serial]
136 fn record_tag_text() {
137 thread::spawn(|| {
138 TestServer::test_anchors_server();
139 });
140
141 let pressed_rec_result = aw!(HtmlPresser::press_record("http://127.0.0.1:7878"));
142 let rec = pressed_rec_result.unwrap();
143 let anchors = rec.tag_text("a").unwrap();
144
145 assert_eq!(anchors.len(), 10);
146 }
147
148 #[test]
149 #[serial]
150 fn record_tag_html() {
151 thread::spawn(|| {
152 TestServer::test_anchors_server();
153 });
154
155 let pressed_rec_result = aw!(HtmlPresser::press_record("http://127.0.0.1:7878"));
156 let rec = pressed_rec_result.unwrap();
157 let anchors = rec.tag_html("a");
158
159 assert_eq!(anchors.unwrap().len(), 10);
160 }
161
162 #[test]
163 #[serial]
164 fn record_get_emails() {
165 thread::spawn(|| {
166 TestServer::test_anchors_server();
167 });
168 let pressed_rec_result = aw!(HtmlPresser::press_record("http://127.0.0.1:7878"));
169 let rec = pressed_rec_result.unwrap();
170 let emails = rec.get_emails().unwrap();
171
172 assert_eq!(emails.len(), 2);
173 }
174 #[test]
175 #[serial]
176 fn doc_test_one() {
177 thread::spawn(|| {
178 TestServer::test_anchors_server();
179 });
180 let pressed_rec_result = aw!(HtmlPresser::press_record("http://127.0.0.1:7878"));
181 let mut rec = pressed_rec_result.unwrap();
182 let emails = rec.get_emails().unwrap();
183 assert_eq!(emails.len(), 2);
184 let anchors = rec.anchors().unwrap();
185 assert_eq!(anchors.len(), 10);
186 rec.origin = "https://example.com".to_string();
187 let anchors = rec.domain_anchors().unwrap();
188 assert_eq!(anchors.len(), 5);
189 let anchors = rec.non_domain_anchors().unwrap();
190 assert_eq!(anchors.len(), 5);
191 let anchors = rec.anchors_curate("example").unwrap();
192 assert_eq!(anchors.len(), 10);
193 let d_anchors = rec.anchors_curate("not-example.com").unwrap();
194 assert_eq!(d_anchors.len(), 5);
195 let meta = rec.html_meta();
196 assert!(meta.is_some());
197 }
198}