-
Notifications
You must be signed in to change notification settings - Fork 0
/
uri.rs
725 lines (637 loc) · 22.1 KB
/
uri.rs
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
#![allow(unused_comparisons)]
use nom::{ErrorKind, IResult};
use nom::{alpha, digit, hex_digit, is_alphanumeric, is_digit, is_hex_digit};
use std::fmt;
use std::str;
/// RRP is a collection of parsers for RDF data written in Rust.
/// Copyright (C) 2017 Henrik Jürges; see the LICENSE file in this repo
///
/// # A module for parsing URI's.
///
///
/// It's main purpose is to validate URI's.
/// A simple URI struct is generated as parsing output.
/// The URI struct is not very sophisticated, but contains the most important
/// parts.
///
/// This implementations shall be close to the
/// (RFC3986 ABNF)[https://tools.ietf.org/html/rfc3986#appendix-A].
///
/// Missing: pct-encoded (something implemented)
#[derive(Debug)]
struct URI<'a> {
scheme: String,
domain: Option<Domain<'a>>,
path: Path<'a>,
query: Option<&'a str>,
fragment: Option<&'a str>,
}
impl<'a> URI<'a> {
fn new(s: &str) -> Option<URI> {
if let IResult::Done(_, uri) = uri_ref(s.as_bytes()) {
Some(uri)
} else {
None
}
}
fn validate(s: &str) -> bool {
if let IResult::Done(_, _) = uri_ref(s.as_bytes()) {
true
} else {
false
}
}
}
impl<'a> fmt::Display for URI<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}{}{}{}{}",
{
if self.scheme == "" { "" } else { &self.scheme }
},
{
if let Some(ref d) = self.domain {
d.to_string()
} else {
String::from("")
}
},
self.path.to_string(),
{
if let Some(q) = self.query {
"?".to_owned() + q
} else {
String::from("")
}
},
{
if let Some(f) = self.fragment {
"#".to_owned() + f
} else {
String::from("")
}
}
)
}
}
/// The domain holds the user host and port information
#[derive(Debug, PartialEq)]
struct Domain<'a> {
user: Option<&'a str>,
host: Host<'a>,
port: &'a str,
}
impl<'a> fmt::Display for Domain<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}{}{}{}{}",
self.user.unwrap_or(""),
{
if self.user.is_some() { "@" } else { "" }
},
self.host.to_string(),
{
if self.port.len() != 0 { ":" } else { "" }
},
self.port
)
}
}
/// A path is a vector of path segments
#[derive(Debug)]
struct Path<'a>(Vec<&'a str>);
impl<'a> fmt::Display for Path<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0.join("/")) }
}
/// A host can be some IP address or literal or a registered name
#[derive(Debug, PartialEq)]
enum Host<'a> {
IPv4(&'a str),
IPvLiteral(&'a str),
Named(&'a str),
}
impl<'a> Domain<'a> {
fn new_v4(s: &[u8]) -> Host { Host::IPv4(str::from_utf8(s).unwrap()) }
fn new_lit(s: &[u8]) -> Host { Host::IPvLiteral(str::from_utf8(s).unwrap()) }
fn new_named(s: &[u8]) -> Host { Host::Named(str::from_utf8(s).unwrap()) }
fn get_user_dom(&self) -> String {
match self.user {
None => self.host.to_string(),
Some(u) => u.to_owned() + "@" + &self.host.to_string(),
}
}
}
/// The display form is the extraction from the host enum
impl<'a> fmt::Display for Host<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use uri::Host;
match self {
&Host::IPv4(a) => write!(f, "{}", a),
&Host::Named(a) => write!(f, "{}", a),
&Host::IPvLiteral(a) => write!(f, "[{}]", a),
}
}
}
///
/// # Parser for URI's
named!(uri_ref<URI>,
alt_complete!(uri | relative_ref)
);
named!(relative_ref<URI>,
do_parse!(
hier: hier_part >>
query: opt!(map_res!(query, str::from_utf8)) >>
frag: opt!(map_res!(fragment, str::from_utf8)) >>
(URI {
scheme: "".to_owned(),
domain: hier.0,
path: Path(hier.1),
query: query,
fragment: frag,
})
)
);
/// Parse a whole uri, returning a URI struct
named!(uri<URI>,
do_parse!(
scheme: scheme >>
hier: hier_part >>
query: opt!(map_res!(query, str::from_utf8)) >>
frag: opt!(map_res!(fragment, str::from_utf8)) >>
(URI {
scheme: scheme.to_owned(),
domain: hier.0,
path: Path(hier.1),
query: query,
fragment: frag,
})
)
);
/// The strict scheme parsers takes the following characters
/// alpha ( alphanumeric / + / - / . )*
named!(scheme<String>,
terminated!(
do_parse!(
fc: map_res!(alpha, str::from_utf8) >>
val: map_res!(take_while!(is_scheme), str::from_utf8) >>
(fc.to_owned() + val)
),
tag!(":")
)
);
/// parses authority path or path only parts
named!(hier_part<(Option<Domain>, Vec<&str>)>,
alt!(do_parse!(
tag!("//") >>
a: authority >>
p: map!(path_abempty, |i| {
let mut v = vec![""];
v.append(&mut i.iter().map(|x| str::from_utf8(x).unwrap()).collect());
v
}) >> (Some(a), p)) |
map!(path_absolute, |v| {
(None, v.iter().map(|x| str::from_utf8(x).unwrap()).collect() )}) |
map!(path_rootless, |v| {
(None, v.iter().map(|x| str::from_utf8(x).unwrap()).collect() )}) |
map!(path_empty, |v| {
(None, vec![""])})
)
);
/// Parse the query part of an URI
named!(query<&[u8]>,
complete!(do_parse!(
tag!("?") >>
q: take_while!(is_query) >>
(q)))
);
/// Parse the fragment of an URI
named!(fragment<&[u8]>,
complete!(do_parse!(
tag!("#") >>
q: take_while!(is_fragment) >>
(q)))
);
/// Parse the domain part which consists out of user info, host and port
named!(authority<Domain>,
do_parse!(
u: opt!(map_res!(userinfo, str::from_utf8)) >>
h: host >>
p: opt!(map_res!(port, str::from_utf8)) >>
(Domain{
user: u,
host: h,
port: p.unwrap_or("")
}))
);
/// matches an abitrary string ending with @ and shall not be incomplete
named!(userinfo<&[u8]>,
complete!(do_parse!(user: take_while!(is_userinfo) >> tag!("@") >> (user)))
);
/// only reg-names allowed at the moment
named!(host<Host>,
alt_complete!(
map!(ipv4_address, |i| Domain::new_v4(i)) |
map!(ip_literal, |i| Domain::new_lit(i)) |
map!(take_while!(is_basic), |i| Domain::new_named(i)))
);
/// Parse a port number
named!(port<&[u8]>,
complete!(do_parse!(tag!(":") >> p: take_while!(is_digit) >> (p)))
);
/// match the empty path
named!(path_empty, eof!());
/// matches zero to multiple path segments
named!(path_abempty<Vec<&[u8]>>, many0!(path_part));
/// matches a path without /
named!(path_rootless<Vec<&[u8]>>,
do_parse!(seg: segment_nz >> seg1: path_abempty >> (concat(vec![seg], seg1)))
);
/// matches a path without / or :
named!(path_noscheme<Vec<&[u8]>>,
do_parse!(seg: segment_nz_nc >> seg1: path_abempty >> (concat(vec![seg], seg1)))
);
/// matches path segments starting with /
named!(path_absolute<Vec<&[u8]>>,
do_parse!(
tag!("/") >>
seg: opt!(complete!(segment_nz_nc)) >>
seg1: path_abempty >>
(concat(vec![&b""[..], seg.unwrap_or(&b""[..])], seg1))
)
);
/// matches a / and a segment part
named!(path_part<&[u8]>, do_parse!(tag!("/") >> s: segment >> (s)));
/// an empty segment or multiple pchar's
named!(segment<&[u8]>, take_while!(is_pchar));
/// a segment of minimum one pchar
named!(segment_nz<&[u8]>, take_while1!(is_pchar));
/// a segment of minimum one pchar but without colons
named!(segment_nz_nc<&[u8]>, take_while1!(is_pchar_nc));
/// ## IP and Named parsing functions
/// Parse an ipv4 address
named!(ipv4_address<&[u8]>,
recognize!(do_parse!(
dec_octed >> tag!(".") >>
dec_octed >> tag!(".") >>
dec_octed >> tag!(".") >>
dec_octed >>
()))
);
/// recognize a one to three digits
named!(dec_octed<&[u8]>, recognize!(many_m_n!(1, 3, digit)));
/// Parse an ipv6 or a future address
named!(ip_literal<&[u8]>,
delimited!(
tag!("["),
alt!(ipv6_address | ipv_future),
tag!("]")
)
);
/// Parse an ip future address v '..' . '..'
named!(ipv_future<&[u8]>,
do_parse!(
tag!("v") >>
take_while!(is_hex_digit) >>
tag!(".") >>
take_while1!(is_future) >>
("".as_bytes()))
);
/// ipv6 parsing seems a bit complicated
/// parsing of not fully qualified ipv6 address is not working
named!(ipv6_address<&[u8]>,
alt_complete!(
recognize!(call!(ipv6_many, 6)) |
recognize!(do_parse!(tag!("::") >> call!(ipv6_many, 5) >> ())) |
recognize!(do_parse!(opt!(h16) >> tag!("::") >> call!(ipv6_many, 4) >> ())) |
recognize!(do_parse!(
opt!(call!(ipv6_prefix, 1)) >> tag!("::") >> call!(ipv6_many, 3) >> ()
)) |
recognize!(do_parse!(
opt!(call!(ipv6_prefix, 2)) >> tag!("::") >> call!(ipv6_many, 2) >> ()
)) |
recognize!(do_parse!(
opt!(call!(ipv6_prefix, 3)) >> tag!("::") >> call!(ipv6_many, 1) >> ()
)) |
recognize!(do_parse!(
opt!(call!(ipv6_prefix, 4)) >> tag!("::") >> ls32 >> ()
)) |
recognize!(do_parse!(
opt!(call!(ipv6_prefix, 5)) >> tag!("::") >> h16 >> ()
)) |
recognize!(dbg!(do_parse!(
opt!(call!(ipv6_prefix, 6)) >> tag!("::") >> ()
))))
);
/// reading one to four hex digits
named!(h16<&[u8]>, recognize!(many_m_n!(1, 4, hex_digit)));
/// matches hexdigit:
named!(ipv6_part<&[u8]>,
recognize!(do_parse!(h16 >> tag!(":") >> ()))
);
/// matches hexdigit:hixdigit or an ipv4 address
named!(ls32<&[u8]>,
alt_complete!(recognize!(tuple!(ipv6_part, h16)) | ipv4_address)
);
/// matches m times an ipv6 part and ls32
named_args!(ipv6_many(num: usize)<&[u8]>,
recognize!(do_parse!(count!(ipv6_part, num) >> ls32 >> ()))
);
/// matches 0 to n times an ipv6 part and hexdigit
named_args!(ipv6_prefix_max(max: usize)<&[u8]>,
recognize!(do_parse!(count!(ipv6_part, max) >> h16 >> ()))
);
/// may be a quick shot approach
fn ipv6_prefix(input: &[u8], max: usize) -> IResult<&[u8], &[u8]> {
let mut counter = max;
let result;
loop {
match ipv6_prefix_max(input, counter) {
IResult::Done(i, o) => {
result = IResult::Done(i, o);
break;
}
_ => {
if counter > 0 {
counter -= 1
} else {
result = IResult::Error(ErrorKind::Tag);
break;
}
}
}
}
result
}
/// Produces a function for char checking
/// ```
/// contains!(name, "str", is_digit) => fn name(c: ..) { c is in "str" ||
/// is_digit ..}
/// ```
macro_rules! contains {
($name:ident, $tkn:expr, $($fn:ident),*) => (
fn $name(chr: u8) -> bool {
$tkn.chars().any(|t| chr == (t as u8))
$(|| $fn(chr))*
}
);
}
/// helpful functions checking if some char is one of the matching elements
contains!(is_gen_delim, ":/?#[]@",);
contains!(is_sub_delim, "!&'()*+,;=",);
contains!(is_unreserved, "-_.~", is_alphanumeric);
contains!(is_scheme, "-+.", is_alphanumeric);
contains!(is_basic, "", is_unreserved, is_sub_delim, is_pct_encoded);
contains!(is_userinfo, ":", is_basic);
contains!(is_pchar_nc, "@", is_basic);
contains!(is_pchar, ":",is_pchar_nc);
contains!(is_future, ":", is_basic);
contains!(is_query, "/?", is_pchar);
contains!(is_fragment, "/?", is_pchar);
/* not correct testing of pct encoding, since %_a_F is also correct.
* may be another way of character testing is more appropriate */
contains!(is_pct_encoded, "%", is_hex_digit);
/* concatenate two vectors */
fn concat<'a>(mut s: Vec<&'a [u8]>, s1: Vec<&'a [u8]>) -> Vec<&'a [u8]> {
s.append(&mut s1.to_vec());
s
}
#[cfg(test)]
mod test {
use super::Domain;
use nom::ErrorKind;
use nom::IResult;
use std::str::from_utf8;
/// (uri, scheme, domain, port, path, query, fragment)
/// domain includes user and pass
type TestUri<'a> = (&'a str, &'a str, &'a str, &'a str, &'a str, &'a str, &'a str);
named!(test_part<&str>,
ws!(delimited!(
tag!("\""),
map_res!(take_until!("\""), from_utf8),
tag!("\""))));
named!(test_uri<TestUri>,
tuple!(test_part, test_part, test_part, test_part, test_part, test_part, test_part)
);
named!(test_uri_parser<Vec<TestUri>>,
many0!(ws!(delimited!(tag!("("), test_uri, tag!(")")))));
//#[test]
fn test_parser() {
if let IResult::Done(_, uris) = test_uri_parser(include_bytes!("../assets/uris")) {
/* test the individual high level parsing parts */
for uri in uris.iter() {
if let IResult::Done(rest, uri_s) = super::uri_ref(uri.0.as_bytes()) {
assert_eq!(rest, []);
assert_eq!(&uri_s.scheme, uri.1);
assert_eq!(uri_s.path.to_string(), uri.4);
/* test domain */
match uri_s.domain {
Some(Domain {
user: None,
host: h,
port: p,
}) => {
assert_eq!(h.to_string(), uri.2);
assert_eq!(p, uri.3);
}
Some(Domain {
user: u,
host: h,
port: p,
}) => {
let d = u.unwrap().to_owned() + "@" + &h.to_string();
assert_eq!(d, uri.2);
assert_eq!(p, uri.3);
}
None => {
assert_eq!("", uri.2);
assert_eq!("", uri.3);
}
}
match uri_s.query {
Some(s) => {
assert_eq!(s, uri.5);
}
None => {
assert_eq!("", uri.5);
}
}
match uri_s.query {
Some(s) => {
assert_eq!(s, uri.6);
}
None => {
assert_eq!("", uri.6);
}
}
} else {
println!("failed");
};
}
}
}
#[test]
fn test_invalid_schemes() {
let nuris = vec!["ft/p://ftp.is.co.za/rfc/rfc1808.txt",
"ht_tp://www.ietf.org/rfc/rfc2396.txt",
"l,dap://[2001:db8::7]/c=GB?objectClass=one"];
for uri in nuris.into_iter() {
let r = super::scheme(uri.as_bytes());
match r {
IResult::Error(_) => {}
_ => panic!("Parsing error"),
}
}
}
/// Test partial parser
/// first rule: takes a function to test, input, expected output and
/// optional function args
/// second rule: takes a fn under test, input, expected output and the
/// input left
/// third rule: takes a fn under test, input, error
macro_rules! btest {
($fn:ident, $in:expr, $out:expr $(, $args:expr)*) => ({
let ok = super::$fn($in.as_bytes() $(, $args)*);
assert_eq!(ok, IResult::Done(&b""[..], $out));
});
($fn:ident, $in:expr, $out:expr; $left:expr) => ({
let ok = super::$fn($in.as_bytes());
assert_eq!(ok, IResult::Done($left, $out));
});
($fn:ident, $in:expr;; $out:expr) => ({
let err = super::$fn($in.as_bytes());
assert_eq!(err, IResult::Error($out));
});
}
#[test]
fn test_fragment() {
btest!(fragment, "";; ErrorKind::Complete);
btest!(fragment, "#", &b""[..]);
btest!(fragment, "#header1", &b"header1"[..]);
}
#[test]
fn test_query() {
btest!(query, "";; ErrorKind::Complete);
btest!(query, "?", &b""[..]);
btest!(query, "?a=1&b=2+2&c=3&c=4&d=%65%6e%63%6F%64%65%64",
&b"a=1&b=2+2&c=3&c=4&d=%65%6e%63%6F%64%65%64"[..]);
}
#[test]
fn test_authority() {
use super::{Domain, Host};
btest!(authority, "www.ietf.org",
Domain{user: None, host: Host::Named("www.ietf.org"), port: ""});
btest!(authority, "[email protected]",
Domain{user: Some("alice"), host: Host::Named("example.com"), port: ""});
btest!(authority, "alice:[email protected]",
Domain{user: Some("alice:pass"), host: Host::Named("example.com"), port: ""});
}
#[test]
fn test_port() {
btest!(port, "";; ErrorKind::Complete);
btest!(port, ":80", &b"80"[..]);
btest!(port, ":8000", &b"8000"[..]);
}
#[test]
fn test_host() {
use super::Host;
btest!(host, "", Host::Named(""));
btest!(host, "127.0.0.1", Host::IPv4("127.0.0.1"));
btest!(host, "example.com", Host::Named("example.com"));
btest!(host, "[2001:db8::7]", Host::IPvLiteral("2001:db8::7"));
}
#[test]
fn test_user() {
btest!(userinfo, "";; ErrorKind::Complete);
btest!(userinfo, "@", &b""[..]);
btest!(userinfo, "John.Doe@", &b"John.Doe"[..]);
btest!(userinfo, "alice@", &b"alice"[..]);
btest!(userinfo, "alice:somepass@", &b"alice:somepass"[..]);
}
#[test]
fn test_dec_octed() {
btest!(dec_octed, "1", &b"1"[..]);
btest!(dec_octed, "99", &b"99"[..]);
btest!(dec_octed, "127", &b"127"[..]);
}
#[test]
fn test_h16() {
btest!(h16, "0", &b"0"[..]);
btest!(h16, "1", &b"1"[..]);
btest!(h16, "2000", &b"2000"[..]);
btest!(h16, "db8", &b"db8"[..]);
btest!(h16, "7344", &b"7344"[..]);
btest!(h16, "0db8", &b"0db8"[..]);
btest!(h16, "57ab", &b"57ab"[..]);
btest!(ipv6_part, "2001:", &b"2001:"[..]);
btest!(ipv6_part, "db8:", &b"db8:"[..]);
}
#[test]
fn test_ipv6_many_prefix() {
btest!(ipv6_many, "10:127.0.0.1", &b"10:127.0.0.1"[..], 1);
btest!(ipv6_many, "100:10:127.0.0.1", &b"100:10:127.0.0.1"[..], 2);
btest!(ipv6_many, "2001:0db8:0", &b"2001:0db8:0"[..], 1);
btest!(ipv6_many, "2001:0db8:0:0:8d3", &b"2001:0db8:0:0:8d3"[..], 3);
btest!(ipv6_prefix, "100:10", &b"100:10"[..], 1);
btest!(ipv6_prefix, "100:10", &b"100:10"[..], 3);
btest!(ipv6_prefix, "10", &b"10"[..], 0);
}
#[test]
fn test_ip_literal() {
btest!(ip_literal, "[2001:db8::7]", &b"2001:db8::7"[..]);
}
#[test]
fn test_ipv6() {
btest!(ipv6_address, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
&b"2001:0db8:85a3:08d3:1319:8a2e:0370:7344"[..]);
btest!(ipv6_address, "::ffff:ffff:ffff:ffff:ffff:127.0.0.1",
&b"::ffff:ffff:ffff:ffff:ffff:127.0.0.1"[..]);
btest!(ipv6_address, "ffff::ffff:ffff:ffff:ffff:127.0.0.1",
&b"ffff::ffff:ffff:ffff:ffff:127.0.0.1"[..]);
btest!(ipv6_address, "::ffff:ffff:ffff:ffff:127.0.0.1",
&b"::ffff:ffff:ffff:ffff:127.0.0.1"[..]);
btest!(ipv6_address, "::ffff:ffff:ffff:127.0.0.1",
&b"::ffff:ffff:ffff:127.0.0.1"[..]);
btest!(ipv6_address, "ffff:ffff::ffff:ffff:ffff:127.0.0.1",
&b"ffff:ffff::ffff:ffff:ffff:127.0.0.1"[..]);
btest!(ipv6_address, "2001:0db8:0:0:8d3::", &b"2001:0db8:0:0:8d3::"[..]);
}
#[test]
fn test_ipv4() {
btest!(ipv4_address, "127.0.0.1", &b"127.0.0.1"[..]);
}
#[test]
fn test_path_empty() {
btest!(path_empty, "", &b""[..]);
btest!(path_empty, "00";; ErrorKind::Eof);
}
#[test]
fn test_path_abempty() {
btest!(path_abempty, "", vec![]);
btest!(path_abempty, "/11", vec![&b"11"[..]]);
btest!(path_abempty, "xx", vec![]; &b"xx"[..]);
}
#[test]
fn test_path_rootless() {
btest!(path_rootless, "some/", vec![&b"some"[..], &b""[..]]);
btest!(path_rootless, "some/more/and/more",
vec![&b"some"[..], &b"more"[..], &b"and"[..], &b"more"[..]]);
btest!(path_rootless, "/";; ErrorKind::TakeWhile1);
}
#[test]
fn test_path_noscheme() {
btest!(path_noscheme, "some/", vec![&b"some"[..], &b""[..]]);
btest!(path_noscheme, "some/more/and/more",
vec![&b"some"[..], &b"more"[..], &b"and"[..], &b"more"[..]]);
btest!(path_noscheme, ":";; ErrorKind::TakeWhile1);
}
#[test]
fn test_path_absolute() {
btest!(path_absolute, "/", vec![&b""[..], &b""[..]]);
btest!(path_absolute, "/some/", vec![&b""[..], &b"some"[..], &b""[..]]);
btest!(path_absolute, "/some/more/and/more",
vec![&b""[..], &b"some"[..], &b"more"[..], &b"and"[..], &b"more"[..]]);
btest!(path_absolute, ":";; ErrorKind::Tag);
}
}