bitreq 0.3.5

Simple, minimal-dependency HTTP client
Documentation
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
// Parity tests comparing bitreq::Url with url::Url (MaxUrl)
// Ensures our implementation matches the behavior of the reference url crate
// for all public API methods that exist on both types.
//
// Note: We use "special" schemes (http, https, ws, wss, ftp) for parity testing
// because the url crate treats non-special schemes differently (as opaque paths).

mod common;

use bitreq::Url as BitreqUrl;
use common::special_url_string_strategy;
use proptest::prelude::*;
use url::Url as MaxUrl;

proptest! {
    /// Test that scheme() returns the same value for both implementations.
    #[test]
    fn scheme_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        prop_assert_eq!(
            bitreq_url.scheme(),
            max_url.scheme(),
            "scheme() mismatch for URL: {}",
            url_string
        );
    }

    /// Test that port() returns expected values for both implementations.
    ///
    /// Note: The APIs differ:
    /// - `url::Url::port()` returns `Option<u16>`, where `None` means the default port for the scheme
    /// - `bitreq::Url::port()` returns `u16`, always returning the effective port (explicit or default)
    ///
    /// This test verifies that when `url::Url::port()` returns `Some(p)`, `bitreq::Url::port()`
    /// also returns `p`, and when `url::Url::port()` returns `None`, `bitreq::Url::port()`
    /// returns the expected default port for the scheme.
    #[test]
    fn port_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        // Both implementations should agree on the effective port
        prop_assert_eq!(
            bitreq_url.port(),
            max_url.port_or_known_default().expect("special schemes should have known default ports"),
            "port() mismatch for URL: {} (bitreq: {}, url port_or_known_default: {:?})",
            url_string,
            bitreq_url.port(),
            max_url.port_or_known_default()
        );

        // When url::Url::port() returns Some, it should match bitreq::Url::port()
        if let Some(explicit_port) = max_url.port() {
            prop_assert_eq!(
                bitreq_url.port(),
                explicit_port,
                "port() mismatch for URL with explicit port: {}",
                url_string
            );
        }
    }

    /// Test that username() returns the same value for both implementations.
    #[test]
    fn username_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        prop_assert_eq!(
            bitreq_url.username(),
            max_url.username(),
            "username() mismatch for URL: {}",
            url_string
        );
    }

    /// Test that password() returns consistent values for both implementations.
    /// Note: bitreq filters out empty passwords (returns None), while url crate
    /// returns Some(""). We compare the non-empty case for parity.
    #[test]
    fn password_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        let bitreq_password = bitreq_url.password();
        let max_password = max_url.password();

        // bitreq filters out empty passwords, url crate returns Some("")
        // Compare filtered versions for parity
        let max_password_filtered = max_password.filter(|s| !s.is_empty());

        prop_assert_eq!(
            bitreq_password,
            max_password_filtered,
            "password() mismatch for URL: {}",
            url_string
        );
    }

    /// Test that path() returns the same value for both implementations.
    #[test]
    fn path_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        let bitreq_path = bitreq_url.path();
        let max_path = max_url.path();

        prop_assert_eq!(
            bitreq_path,
            max_path,
            "path() mismatch for URL: {} (bitreq: '{}', url: '{}')",
            url_string,
            bitreq_path,
            max_path
        );
    }

    /// Test that query() returns the same value for both implementations.
    #[test]
    fn query_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        prop_assert_eq!(
            bitreq_url.query(),
            max_url.query(),
            "query() mismatch for URL: {}",
            url_string
        );
    }

    /// Test that fragment() returns the same value for both implementations.
    #[test]
    fn fragment_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        prop_assert_eq!(
            bitreq_url.fragment(),
            max_url.fragment(),
            "fragment() mismatch for URL: {}",
            url_string
        );
    }

    /// Test that host (base_url vs host_str) returns the same value.
    /// bitreq::Url::base_url() corresponds to url::Url::host_str().
    #[test]
    fn host_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        prop_assert_eq!(
            Some(bitreq_url.base_url()),
            max_url.host_str(),
            "host mismatch for URL: {} (bitreq base_url: '{}', url host_str: {:?})",
            url_string,
            bitreq_url.base_url(),
            max_url.host_str()
        );
    }

    /// Test that as_str() returns equivalent URLs.
    #[test]
    fn as_str_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        // Both should produce parseable URLs that round-trip correctly
        let bitreq_str = bitreq_url.as_str();
        let max_str = max_url.as_str();

        // Re-parse to ensure both produce valid URLs
        let bitreq_reparsed = BitreqUrl::parse(bitreq_str);
        let max_reparsed = MaxUrl::parse(max_str);

        prop_assert!(
            bitreq_reparsed.is_ok(),
            "bitreq as_str() produced unparseable URL: {}",
            bitreq_str
        );
        prop_assert!(
            max_reparsed.is_ok(),
            "url crate as_str() produced unparseable URL: {}",
            max_str
        );

        // The serialized forms should be semantically equivalent
        let bitreq_reparsed = bitreq_reparsed.unwrap();
        let max_reparsed = max_reparsed.unwrap();

        prop_assert_eq!(
            bitreq_reparsed.scheme(),
            max_reparsed.scheme(),
            "Reparsed scheme mismatch"
        );
        prop_assert_eq!(
            bitreq_reparsed.port(),
            max_reparsed.port_or_known_default().expect("special schemes should have known default ports"),
            "Reparsed port mismatch"
        );
        prop_assert_eq!(
            bitreq_reparsed.path(),
            max_reparsed.path(),
            "Reparsed path mismatch"
        );
        prop_assert_eq!(
            bitreq_reparsed.query(),
            max_reparsed.query(),
            "Reparsed query mismatch"
        );
        prop_assert_eq!(
            bitreq_reparsed.fragment(),
            max_reparsed.fragment(),
            "Reparsed fragment mismatch"
        );
    }

    /// Test that path_segments() returns consistent segments for both implementations.
    /// Note: url crate's path_segments() returns None for cannot-be-a-base URLs,
    /// but our generated URLs always have authority so this shouldn't happen.
    /// Note: bitreq filters out empty segments while the url crate includes them,
    /// so we compare the filtered versions.
    #[test]
    fn path_segments_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        let bitreq_segments: Vec<&str> = bitreq_url.path_segments().collect();
        let max_segments: Option<Vec<&str>> = max_url.path_segments().map(|s| s.collect());

        // url crate should always return Some for URLs with authority
        prop_assert!(
            max_segments.is_some(),
            "url crate returned None for path_segments on URL with authority: {}",
            url_string
        );

        let max_segments = max_segments.unwrap();

        // bitreq filters out empty segments, url crate includes them
        // Compare the filtered versions for parity
        let max_segments_filtered: Vec<&str> = max_segments.into_iter().filter(|s| !s.is_empty()).collect();

        prop_assert_eq!(
            bitreq_segments,
            max_segments_filtered,
            "path_segments() mismatch for URL: {}",
            url_string
        );
    }

    /// Test that Display output matches as_str() for both implementations.
    #[test]
    fn display_parity(url_string in special_url_string_strategy()) {
        let bitreq_url = BitreqUrl::parse(&url_string).expect("bitreq should parse");
        let max_url = MaxUrl::parse(&url_string).expect("url crate should parse");

        // Both should have Display == as_str()
        prop_assert_eq!(
            format!("{}", bitreq_url),
            bitreq_url.as_str(),
            "bitreq Display doesn't match as_str()"
        );
        prop_assert_eq!(
            format!("{}", max_url),
            max_url.as_str(),
            "url crate Display doesn't match as_str()"
        );
    }
}

// Test that both implementations accept or reject the same URLs
proptest! {
    /// Test that valid URLs are accepted by both implementations.
    #[test]
    fn both_accept_valid_urls(url_string in special_url_string_strategy()) {
        let bitreq_result = BitreqUrl::parse(&url_string);
        let max_result = MaxUrl::parse(&url_string);

        prop_assert!(
            bitreq_result.is_ok(),
            "bitreq rejected valid URL: {} - {:?}",
            url_string,
            bitreq_result.err()
        );
        prop_assert!(
            max_result.is_ok(),
            "url crate rejected valid URL: {} - {:?}",
            url_string,
            max_result.err()
        );
    }
}

// Parity tests for empty and edge cases
#[cfg(test)]
mod empty_and_edge_cases {
    use super::*;

    #[test]
    fn path_empty_parity() {
        let bitreq = BitreqUrl::parse("http://example.com").unwrap();
        let max = MaxUrl::parse("http://example.com").unwrap();

        // url crate normalizes empty path to "/"
        // bitreq returns "" for empty path, which we normalize in parity tests
        let bitreq_path = bitreq.path();
        let bitreq_normalized = if bitreq_path.is_empty() { "/" } else { bitreq_path };
        assert_eq!(bitreq_normalized, max.path());
    }

    #[test]
    fn path_root_only_parity() {
        let bitreq = BitreqUrl::parse("http://example.com/").unwrap();
        let max = MaxUrl::parse("http://example.com/").unwrap();

        assert_eq!(bitreq.path(), max.path());
    }

    #[test]
    fn path_segments_empty_parity() {
        let bitreq = BitreqUrl::parse("http://example.com").unwrap();
        let max = MaxUrl::parse("http://example.com").unwrap();

        let bitreq_segments: Vec<&str> = bitreq.path_segments().collect();
        let max_segments: Vec<&str> =
            max.path_segments().unwrap().filter(|s| !s.is_empty()).collect();

        // Both should return empty after filtering empty segments
        assert_eq!(bitreq_segments, max_segments);
    }

    #[test]
    fn path_segments_root_only_parity() {
        let bitreq = BitreqUrl::parse("http://example.com/").unwrap();
        let max = MaxUrl::parse("http://example.com/").unwrap();

        let bitreq_segments: Vec<&str> = bitreq.path_segments().collect();
        let max_segments: Vec<&str> =
            max.path_segments().unwrap().filter(|s| !s.is_empty()).collect();

        assert_eq!(bitreq_segments, max_segments);
    }

    #[test]
    fn path_segments_consecutive_slashes_parity() {
        let bitreq = BitreqUrl::parse("http://example.com//foo//bar//").unwrap();
        let max = MaxUrl::parse("http://example.com//foo//bar//").unwrap();

        let bitreq_segments: Vec<&str> = bitreq.path_segments().collect();
        let max_segments: Vec<&str> =
            max.path_segments().unwrap().filter(|s| !s.is_empty()).collect();

        assert_eq!(bitreq_segments, max_segments);
        assert_eq!(bitreq_segments, vec!["foo", "bar"]);
    }

    #[test]
    fn query_empty_parity() {
        // No query at all
        let bitreq = BitreqUrl::parse("http://example.com").unwrap();
        let max = MaxUrl::parse("http://example.com").unwrap();

        assert_eq!(bitreq.query(), max.query());
        assert_eq!(bitreq.query(), None);
    }

    #[test]
    fn query_empty_string_parity() {
        // Query with just "?" - url crate returns Some("")
        let bitreq = BitreqUrl::parse("http://example.com?").unwrap();
        let max = MaxUrl::parse("http://example.com?").unwrap();

        assert_eq!(bitreq.query(), max.query());
        assert_eq!(bitreq.query(), Some(""));
    }

    #[test]
    fn query_pairs_empty_parity() {
        // No query
        let bitreq = BitreqUrl::parse("http://example.com").unwrap();
        let max = MaxUrl::parse("http://example.com").unwrap();

        let bitreq_pairs: Vec<_> = bitreq.query_pairs().collect();
        let max_pairs: Vec<_> = max.query_pairs().into_iter().collect();

        assert!(bitreq_pairs.is_empty());
        assert!(max_pairs.is_empty());
    }

    #[test]
    fn query_pairs_empty_key_filtered_parity() {
        // Query with empty key "?=value" - bitreq filters these out
        let bitreq = BitreqUrl::parse("http://example.com?=value&foo=bar").unwrap();
        let max = MaxUrl::parse("http://example.com?=value&foo=bar").unwrap();

        let bitreq_pairs: Vec<(String, String)> = bitreq.query_pairs().collect();
        // url crate returns Cow<str> pairs, filter out empty keys for parity
        let max_pairs: Vec<(String, String)> = max
            .query_pairs()
            .filter(|(k, _)| !k.is_empty())
            .map(|(k, v)| (k.into_owned(), v.into_owned()))
            .collect();

        assert_eq!(bitreq_pairs, max_pairs);
        assert_eq!(bitreq_pairs, vec![("foo".to_string(), "bar".to_string())]);
    }

    #[test]
    fn query_pairs_normal_parity() {
        let bitreq = BitreqUrl::parse("http://example.com?foo=bar&baz=qux").unwrap();
        let max = MaxUrl::parse("http://example.com?foo=bar&baz=qux").unwrap();

        let bitreq_pairs: Vec<(String, String)> = bitreq.query_pairs().collect();
        let max_pairs: Vec<(String, String)> =
            max.query_pairs().map(|(k, v)| (k.into_owned(), v.into_owned())).collect();

        assert_eq!(bitreq_pairs, max_pairs);
        assert_eq!(
            bitreq_pairs,
            vec![("foo".to_string(), "bar".to_string()), ("baz".to_string(), "qux".to_string())]
        );
    }

    #[test]
    fn username_parity() {
        // Normal username
        let bitreq = BitreqUrl::parse("http://user@example.com").unwrap();
        let max = MaxUrl::parse("http://user@example.com").unwrap();
        assert_eq!(bitreq.username(), max.username());

        // No username
        let bitreq = BitreqUrl::parse("http://example.com").unwrap();
        let max = MaxUrl::parse("http://example.com").unwrap();
        assert_eq!(bitreq.username(), max.username());
        assert_eq!(bitreq.username(), "");
    }

    #[test]
    fn password_empty_parity() {
        // Normal password
        let bitreq = BitreqUrl::parse("http://user:pass@example.com").unwrap();
        let max = MaxUrl::parse("http://user:pass@example.com").unwrap();
        assert_eq!(bitreq.password(), max.password());

        // No password
        let bitreq = BitreqUrl::parse("http://user@example.com").unwrap();
        let max = MaxUrl::parse("http://user@example.com").unwrap();
        assert_eq!(bitreq.password(), max.password());
        assert_eq!(bitreq.password(), None);

        // Empty password - both return None (url crate also filters empty password)
        let bitreq = BitreqUrl::parse("http://user:@example.com").unwrap();
        let max = MaxUrl::parse("http://user:@example.com").unwrap();
        assert_eq!(bitreq.password(), None);
        assert_eq!(bitreq.password(), max.password());
    }
}

// Parity tests for percent-encoded URLs
#[cfg(test)]
mod percent_encoding_parity {
    use super::*;

    #[test]
    fn username_with_percent_encoded_chars() {
        // %40 encodes '@'
        let bitreq = BitreqUrl::parse("http://user%40name@example.com").unwrap();
        let max = MaxUrl::parse("http://user%40name@example.com").unwrap();

        // Both should return raw percent-encoded username
        assert_eq!(bitreq.username(), max.username());
        assert_eq!(bitreq.username(), "user%40name");
    }

    #[test]
    fn password_with_percent_encoded_chars() {
        // %40 encodes '@', %3A encodes ':'
        let bitreq = BitreqUrl::parse("http://user:pass%40word@example.com").unwrap();
        let max = MaxUrl::parse("http://user:pass%40word@example.com").unwrap();

        // Both should return raw percent-encoded password
        assert_eq!(bitreq.password(), max.password());
        assert_eq!(bitreq.password(), Some("pass%40word"));
    }

    #[test]
    fn path_with_percent_encoded_chars() {
        // %2F encodes '/', %20 encodes space
        let bitreq = BitreqUrl::parse("http://example.com/path%2Fwith%20spaces").unwrap();
        let max = MaxUrl::parse("http://example.com/path%2Fwith%20spaces").unwrap();

        // Both should return raw percent-encoded path
        assert_eq!(bitreq.path(), max.path());
        assert_eq!(bitreq.path(), "/path%2Fwith%20spaces");
    }

    #[test]
    fn path_segments_with_percent_encoded_chars() {
        // Segments should be raw (percent-encoded)
        let bitreq = BitreqUrl::parse("http://example.com/seg%2F1/seg%202").unwrap();
        let max = MaxUrl::parse("http://example.com/seg%2F1/seg%202").unwrap();

        let bitreq_segments: Vec<&str> = bitreq.path_segments().collect();
        let max_segments: Vec<&str> =
            max.path_segments().unwrap().filter(|s| !s.is_empty()).collect();

        // Both return raw segments
        assert_eq!(bitreq_segments, max_segments);
        assert_eq!(bitreq_segments, vec!["seg%2F1", "seg%202"]);
    }

    #[test]
    fn query_with_percent_encoded_chars() {
        // Query string should be raw
        let bitreq = BitreqUrl::parse("http://example.com?key%3D1=value%26more").unwrap();
        let max = MaxUrl::parse("http://example.com?key%3D1=value%26more").unwrap();

        // Both should return raw query string
        assert_eq!(bitreq.query(), max.query());
        assert_eq!(bitreq.query(), Some("key%3D1=value%26more"));
    }

    #[test]
    fn query_pairs_with_percent_encoded_chars() {
        // url::Url::query_pairs() decodes percent-encoded chars
        // bitreq::Url::query_pairs() should match this behavior
        let bitreq = BitreqUrl::parse("http://example.com?key%3D1=value%26more").unwrap();
        let max = MaxUrl::parse("http://example.com?key%3D1=value%26more").unwrap();

        let bitreq_pairs: Vec<(String, String)> = bitreq.query_pairs().collect();
        let max_pairs: Vec<(String, String)> =
            max.query_pairs().map(|(k, v)| (k.into_owned(), v.into_owned())).collect();

        // Both should decode percent-encoded chars
        assert_eq!(bitreq_pairs, max_pairs);
        // key%3D1 -> "key=1", value%26more -> "value&more"
        assert_eq!(bitreq_pairs, vec![("key=1".to_string(), "value&more".to_string())]);
    }

    #[test]
    fn query_pairs_with_plus_as_space() {
        // In form-urlencoded (query strings), '+' represents space
        let bitreq = BitreqUrl::parse("http://example.com?hello+world=foo+bar").unwrap();
        let max = MaxUrl::parse("http://example.com?hello+world=foo+bar").unwrap();

        let bitreq_pairs: Vec<(String, String)> = bitreq.query_pairs().collect();
        let max_pairs: Vec<(String, String)> =
            max.query_pairs().map(|(k, v)| (k.into_owned(), v.into_owned())).collect();

        // Both should decode '+' as space
        assert_eq!(bitreq_pairs, max_pairs);
        assert_eq!(bitreq_pairs, vec![("hello world".to_string(), "foo bar".to_string())]);
    }

    #[test]
    fn query_pairs_with_utf8_percent_encoded() {
        // UTF-8 encoded character: ó = %C3%B3
        let bitreq = BitreqUrl::parse("http://example.com?name=%C3%B3").unwrap();
        let max = MaxUrl::parse("http://example.com?name=%C3%B3").unwrap();

        let bitreq_pairs: Vec<(String, String)> = bitreq.query_pairs().collect();
        let max_pairs: Vec<(String, String)> =
            max.query_pairs().map(|(k, v)| (k.into_owned(), v.into_owned())).collect();

        // Both should decode UTF-8 sequences
        assert_eq!(bitreq_pairs, max_pairs);
        assert_eq!(bitreq_pairs, vec![("name".to_string(), "ó".to_string())]);
    }

    #[test]
    fn query_pairs_mixed_encoding() {
        // Mix of encoded and unencoded characters
        let bitreq = BitreqUrl::parse("http://example.com?a=1&b=%32&c=three").unwrap();
        let max = MaxUrl::parse("http://example.com?a=1&b=%32&c=three").unwrap();

        let bitreq_pairs: Vec<(String, String)> = bitreq.query_pairs().collect();
        let max_pairs: Vec<(String, String)> =
            max.query_pairs().map(|(k, v)| (k.into_owned(), v.into_owned())).collect();

        assert_eq!(bitreq_pairs, max_pairs);
        // %32 decodes to '2'
        assert_eq!(
            bitreq_pairs,
            vec![
                ("a".to_string(), "1".to_string()),
                ("b".to_string(), "2".to_string()),
                ("c".to_string(), "three".to_string()),
            ]
        );
    }
}