Debian Codegraph @

tests/resolve.rs

raw symbols SCIP
1 #![cfg(feature = "alloc")]
2
3 use fluent_urirust-analyzer cargo fluent-uri 0.4.1 crate/::{
4 resolverust-analyzer cargo fluent-uri 0.4.1 resolve/::{ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#, Resolverrust-analyzer cargo fluent-uri 0.4.1 resolve/Resolver#},
5 Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#, UriRefrust-analyzer cargo fluent-uri 0.4.1 imp/UriRef#,
6 };
7
8 trait Testrust-analyzer cargo fluent-uri 0.4.1 Test# {
9 fn passrust-analyzer cargo fluent-uri 0.4.1 Test#pass().(&self, r: &str, res: &str);
10 fn failrust-analyzer cargo fluent-uri 0.4.1 Test#fail().(&self, r: &str, err: ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#);
11 }
12
13 impl Testrust-analyzer cargo fluent-uri 0.4.1 Test# for Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<&str> {
14 #[track_caller]
15 fn passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().(&self, r: &str, expected: &str) {
16 let r = UriRefrust-analyzer cargo fluent-uri 0.4.1 imp/UriRef#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`UriRef<T>`]parse().(r).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
17 for b in [true, false] {
18 let resolver = Resolverrust-analyzer cargo fluent-uri 0.4.1 resolve/Resolver#::with_baserust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]with_base().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).allow_path_underflowrust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]allow_path_underflow().(b);
19 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolver.resolverust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]resolve().(&r).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), expected);
20 }
21 }
22
23 #[track_caller]
24 fn failrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]fail().(&self, r: &str, expected: ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#) {
25 let r = UriRefrust-analyzer cargo fluent-uri 0.4.1 imp/UriRef#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`UriRef<T>`]parse().(r).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
26 for b in [true, false] {
27 let resolver = Resolverrust-analyzer cargo fluent-uri 0.4.1 resolve/Resolver#::with_baserust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]with_base().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).allow_path_underflowrust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]allow_path_underflow().(b);
28 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolver.resolverust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]resolve().(&r).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(), expected);
29 }
30 }
31 }
32
33 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
34 fn resolverust-analyzer cargo fluent-uri 0.4.1 resolve().() {
35 // Examples from Section 5.4 of RFC 3986.
36 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("http://a/b/c/d;p?q").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
37
38 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g:h", "g:h");
39 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g", "http://a/b/c/g");
40 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("./g", "http://a/b/c/g");
41 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g/", "http://a/b/c/g/");
42 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("/g", "http://a/g");
43 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("//g", "http://g");
44 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("?y", "http://a/b/c/d;p?y");
45 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g?y", "http://a/b/c/g?y");
46 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("#s", "http://a/b/c/d;p?q#s");
47 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g#s", "http://a/b/c/g#s");
48 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g?y#s", "http://a/b/c/g?y#s");
49 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().(";x", "http://a/b/c/;x");
50 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g;x", "http://a/b/c/g;x");
51 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g;x?y#s", "http://a/b/c/g;x?y#s");
52 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("", "http://a/b/c/d;p?q");
53 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().(".", "http://a/b/c/");
54 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("./", "http://a/b/c/");
55 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("..", "http://a/b/");
56 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("../", "http://a/b/");
57 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("../g", "http://a/b/g");
58 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("../..", "http://a/");
59 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("../../", "http://a/");
60 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("../../g", "http://a/g");
61
62 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("/./g", "http://a/g");
63 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g.", "http://a/b/c/g.");
64 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().(".g", "http://a/b/c/.g");
65 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g..", "http://a/b/c/g..");
66 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("..g", "http://a/b/c/..g");
67
68 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("./../g", "http://a/b/g");
69 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("./g/.", "http://a/b/c/g/");
70 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g/./h", "http://a/b/c/g/h");
71 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g/../h", "http://a/b/c/h");
72 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g;x=1/./y", "http://a/b/c/g;x=1/y");
73 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g;x=1/../y", "http://a/b/c/y");
74
75 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g?y/./x", "http://a/b/c/g?y/./x");
76 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g?y/../x", "http://a/b/c/g?y/../x");
77 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g#s/./x", "http://a/b/c/g#s/./x");
78 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("g#s/../x", "http://a/b/c/g#s/../x");
79
80 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("http:g", "http:g");
81
82 // Non-hierarchical base URI.
83 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("foo:bar").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
84
85 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("", "foo:bar");
86 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("#baz", "foo:bar#baz");
87 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("http://example.com/", "http://example.com/");
88 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("foo:baz", "foo:baz");
89 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("bar:baz", "bar:baz");
90
91 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("foo:/").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
92 // The result would be "foo://@@" using the original algorithm.
93 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().(".//@@", "foo:/.//@@");
94
95 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("foo:/bar/baz/.%2E/").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
96 // The result would be "foo:/bar/baz" using the original algorithm.
97 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("..", "foo:/");
98
99 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("foo:/bar/..").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
100 // The result would be "foo:/bar/" using the original algorithm.
101 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().(".", "foo:/");
102
103 let base = base.normalizerust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]normalize().();
104 base.borrowrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]borrow().().passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().(".", "foo:/");
105 }
106
107 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
108 fn resolve_errorrust-analyzer cargo fluent-uri 0.4.1 resolve_error().() {
109 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("http://example.com/#title1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
110 base.failrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]fail().("foo", ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#::BaseWithFragmentrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#BaseWithFragment#);
111
112 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("foo:bar").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
113 base.failrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]fail().("baz", ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#::InvalidReferenceAgainstOpaqueBaserust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#InvalidReferenceAgainstOpaqueBase#);
114 base.failrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]fail().("?baz", ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#::InvalidReferenceAgainstOpaqueBaserust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#InvalidReferenceAgainstOpaqueBase#);
115 }
116
117 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
118 fn resolve_underflowrust-analyzer cargo fluent-uri 0.4.1 resolve_underflow().() {
119 for (base, rs) in [
120 (
121 "http://a/b/c/d;p?q",
122 ["../../../g", "../../../../g", "/../g"],
123 ),
124 ("foo:/..", ["", "?a", "#a"]),
125 ] {
126 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().(base).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
127
128 for r in rs {
129 let resolver = Resolverrust-analyzer cargo fluent-uri 0.4.1 resolve/Resolver#::with_baserust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]with_base().(base).allow_path_underflowrust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]allow_path_underflow().(true);
130 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(resolver.resolverust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]resolve().(&UriRefrust-analyzer cargo fluent-uri 0.4.1 imp/UriRef#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`UriRef<T>`]parse().(r).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
131
132 let resolver = Resolverrust-analyzer cargo fluent-uri 0.4.1 resolve/Resolver#::with_baserust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]with_base().(base).allow_path_underflowrust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]allow_path_underflow().(false);
133 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
134 resolver.resolverust-analyzer cargo fluent-uri 0.4.1 resolve/impl#[`Resolver<R>`]resolve().(&UriRefrust-analyzer cargo fluent-uri 0.4.1 imp/UriRef#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`UriRef<T>`]parse().(r).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(),
135 ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#::PathUnderflowrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#PathUnderflow#
136 );
137 }
138 }
139
140 let base = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::parserust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]parse().("foo:bar/..").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
141 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("", "foo:bar/..");
142 base.failrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]fail().("?a", ResolveErrorrust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#::InvalidReferenceAgainstOpaqueBaserust-analyzer cargo fluent-uri 0.4.1 resolve/ResolveError#InvalidReferenceAgainstOpaqueBase#);
143 base.passrust-analyzer cargo fluent-uri 0.4.1 impl#[`Uri<&str>`][Test]pass().("#a", "foo:bar/..#a");
144 }