Current section

Files

Jump to
gleam_stdlib gen test gleam@uri_test.erl
Raw

gen/test/gleam@uri_test.erl

-module(gleam@uri_test).
-compile(no_auto_import).
-export([full_parse_test/0, parse_only_path_test/0, parse_only_host_test/0, colon_uri_test/0, parse_scheme_test/0, parse_https_scheme_test/0, parse_file_scheme_test/0, parse_ftp_scheme_test/0, parse_sftp_scheme_test/0, parse_tftp_scheme_test/0, parse_ldap_scheme_test/0, parse_ldap_2_scheme_test/0, parse_bad_uris_test/0, parse_downcases_scheme/0, parse_empty_fragments_test/0, parse_empty_queries_test/0, full_uri_to_string_test/0, path_only_uri_to_string_test/0, scheme_to_string_test/0, host_to_string_test/0, port_to_string_test/0, parse_query_string_test/0, parse_empty_query_string_test/0, parse_query_string_with_empty_test/0, error_parsing_query_test/0, query_to_string_test/0, empty_query_to_string_test/0, percent_encode_test/0, percent_encode_consistency_test/0, percent_decode_test/0, percent_decode_consistency_test/0, parse_segments_test/0, origin1_test/0, origin2_test/0, origin3_test/0, origin4_test/0, origin5_test/0, origin6_test/0, origin7_test/0, merge1_test/0, merge2_test/0, merge3_test/0, merge4_test/0, merge5_test/0, merge6_test/0, merge7_test/0, merge8_test/0, merge9_test/0, merge10_test/0, merge11_test/0, merge12_test/0, merge13_test/0, merge14_test/0, merge15_test/0]).
-spec full_parse_test() -> nil.
full_parse_test() ->
Parsed = gleam@uri:parse(
<<"https://weebl:bob@example.com:1234/path?query=true#fragment"/utf8>>
),
gleam@should:equal(erlang:element(2, Parsed), {some, <<"https"/utf8>>}),
gleam@should:equal(erlang:element(3, Parsed), {some, <<"weebl:bob"/utf8>>}),
gleam@should:equal(
erlang:element(4, Parsed),
{some, <<"example.com"/utf8>>}
),
gleam@should:equal(erlang:element(5, Parsed), {some, 1234}),
gleam@should:equal(erlang:element(6, Parsed), <<"/path"/utf8>>),
gleam@should:equal(erlang:element(7, Parsed), {some, <<"query=true"/utf8>>}),
gleam@should:equal(erlang:element(8, Parsed), {some, <<"fragment"/utf8>>}).
-spec parse_only_path_test() -> nil.
parse_only_path_test() ->
Parsed = gleam@uri:parse(<<""/utf8>>),
gleam@should:equal(erlang:element(2, Parsed), none),
gleam@should:equal(erlang:element(3, Parsed), none),
gleam@should:equal(erlang:element(4, Parsed), none),
gleam@should:equal(erlang:element(5, Parsed), none),
gleam@should:equal(erlang:element(6, Parsed), <<""/utf8>>),
gleam@should:equal(erlang:element(7, Parsed), none),
gleam@should:equal(erlang:element(8, Parsed), none).
-spec parse_only_host_test() -> nil.
parse_only_host_test() ->
Parsed = gleam@uri:parse(<<"//"/utf8>>),
gleam@should:equal(erlang:element(2, Parsed), none),
gleam@should:equal(erlang:element(3, Parsed), none),
gleam@should:equal(erlang:element(4, Parsed), {some, <<""/utf8>>}),
gleam@should:equal(erlang:element(5, Parsed), none),
gleam@should:equal(erlang:element(6, Parsed), <<""/utf8>>),
gleam@should:equal(erlang:element(7, Parsed), none),
gleam@should:equal(erlang:element(8, Parsed), none).
-spec colon_uri_test() -> nil.
colon_uri_test() ->
Parsed = gleam@uri:parse(<<"::"/utf8>>),
gleam@should:equal(erlang:element(2, Parsed), none),
gleam@should:equal(erlang:element(3, Parsed), none),
gleam@should:equal(erlang:element(4, Parsed), none),
gleam@should:equal(erlang:element(5, Parsed), none),
gleam@should:equal(erlang:element(6, Parsed), <<"::"/utf8>>),
gleam@should:equal(erlang:element(7, Parsed), none),
gleam@should:equal(erlang:element(8, Parsed), none).
-spec parse_scheme_test() -> nil.
parse_scheme_test() ->
_pipe = gleam@uri:parse(
<<"http://one.com/path/to/something?one=two&two=one#fragment"/utf8>>
),
gleam@should:equal(
_pipe,
{uri,
{some, <<"http"/utf8>>},
none,
{some, <<"one.com"/utf8>>},
{some, 80},
<<"/path/to/something"/utf8>>,
{some, <<"one=two&two=one"/utf8>>},
{some, <<"fragment"/utf8>>}}
).
-spec parse_https_scheme_test() -> nil.
parse_https_scheme_test() ->
_pipe = gleam@uri:parse(<<"https://foo.com"/utf8>>),
gleam@should:equal(
_pipe,
{uri,
{some, <<"https"/utf8>>},
none,
{some, <<"foo.com"/utf8>>},
{some, 443},
<<""/utf8>>,
none,
none}
).
-spec parse_file_scheme_test() -> nil.
parse_file_scheme_test() ->
_pipe = gleam@uri:parse(<<"file:///one/two/three"/utf8>>),
gleam@should:equal(
_pipe,
{uri,
{some, <<"file"/utf8>>},
none,
{some, <<""/utf8>>},
none,
<<"/one/two/three"/utf8>>,
none,
none}
).
-spec parse_ftp_scheme_test() -> nil.
parse_ftp_scheme_test() ->
_pipe = <<"ftp://user001:password@private.ftp-server.example.com/my_directory/my_file.txt"/utf8>>,
_pipe@1 = gleam@uri:parse(_pipe),
gleam@should:equal(
_pipe@1,
{uri,
{some, <<"ftp"/utf8>>},
{some, <<"user001:password"/utf8>>},
{some, <<"private.ftp-server.example.com"/utf8>>},
{some, 21},
<<"/my_directory/my_file.txt"/utf8>>,
none,
none}
).
-spec parse_sftp_scheme_test() -> nil.
parse_sftp_scheme_test() ->
_pipe = <<"sftp://user001:password@private.ftp-server.example.com/my_directory/my_file.txt"/utf8>>,
_pipe@1 = gleam@uri:parse(_pipe),
gleam@should:equal(
_pipe@1,
{uri,
{some, <<"sftp"/utf8>>},
{some, <<"user001:password"/utf8>>},
{some, <<"private.ftp-server.example.com"/utf8>>},
{some, 22},
<<"/my_directory/my_file.txt"/utf8>>,
none,
none}
).
-spec parse_tftp_scheme_test() -> nil.
parse_tftp_scheme_test() ->
_pipe = <<"tftp://user001:password@private.ftp-server.example.com/my_directory/my_file.txt"/utf8>>,
_pipe@1 = gleam@uri:parse(_pipe),
gleam@should:equal(
_pipe@1,
{uri,
{some, <<"tftp"/utf8>>},
{some, <<"user001:password"/utf8>>},
{some, <<"private.ftp-server.example.com"/utf8>>},
{some, 69},
<<"/my_directory/my_file.txt"/utf8>>,
none,
none}
).
-spec parse_ldap_scheme_test() -> nil.
parse_ldap_scheme_test() ->
_pipe = <<"ldap:///dc=example,dc=com??sub?(givenName=John)"/utf8>>,
_pipe@1 = gleam@uri:parse(_pipe),
gleam@should:equal(
_pipe@1,
{uri,
{some, <<"ldap"/utf8>>},
none,
{some, <<""/utf8>>},
{some, 389},
<<"/dc=example,dc=com"/utf8>>,
{some, <<"?sub?(givenName=John)"/utf8>>},
none}
).
-spec parse_ldap_2_scheme_test() -> nil.
parse_ldap_2_scheme_test() ->
_pipe = <<"ldap://ldap.example.com/cn=John%20Doe,dc=foo,dc=com"/utf8>>,
_pipe@1 = gleam@uri:parse(_pipe),
gleam@should:equal(
_pipe@1,
{uri,
{some, <<"ldap"/utf8>>},
none,
{some, <<"ldap.example.com"/utf8>>},
{some, 389},
<<"/cn=John%20Doe,dc=foo,dc=com"/utf8>>,
none,
none}
).
-spec parse_bad_uris_test() -> binary().
parse_bad_uris_test() ->
gleam@uri:parse(<<""/utf8>>),
gleam@uri:parse(<<"https:??@?F?@#>F//23/"/utf8>>),
<<":https"/utf8>> = case erlang:element(
6,
gleam@uri:parse(<<":https"/utf8>>)
) of
<<":https"/utf8>> -> <<":https"/utf8>>;
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_bad_uris_test"/utf8>>,
line => 167})
end,
<<"https"/utf8>> = case erlang:element(6, gleam@uri:parse(<<"https"/utf8>>)) of
<<"https"/utf8>> -> <<"https"/utf8>>;
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_bad_uris_test"/utf8>>,
line => 168})
end.
-spec parse_downcases_scheme() -> gleam@option:option(binary()).
parse_downcases_scheme() ->
Uri = gleam@uri:parse(<<"HTTPS://EXAMPLE.COM"/utf8>>),
{some, <<"https"/utf8>>} = case erlang:element(2, Uri) of
{some, <<"https"/utf8>>} -> {some, <<"https"/utf8>>};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_downcases_scheme"/utf8>>,
line => 173})
end,
{some, <<"EXAMPLE.COM"/utf8>>} = case erlang:element(4, Uri) of
{some, <<"EXAMPLE.COM"/utf8>>} -> {some, <<"EXAMPLE.COM"/utf8>>};
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_downcases_scheme"/utf8>>,
line => 174})
end.
-spec parse_empty_fragments_test() -> gleam@option:option(binary()).
parse_empty_fragments_test() ->
{some, <<""/utf8>>} = case erlang:element(
8,
gleam@uri:parse(<<"http://example.com#"/utf8>>)
) of
{some, <<""/utf8>>} -> {some, <<""/utf8>>};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_empty_fragments_test"/utf8>>,
line => 178})
end,
{some, <<""/utf8>>} = case erlang:element(
8,
gleam@uri:parse(<<"http://example.com/#"/utf8>>)
) of
{some, <<""/utf8>>} -> {some, <<""/utf8>>};
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_empty_fragments_test"/utf8>>,
line => 179})
end,
{some, <<""/utf8>>} = case erlang:element(
8,
gleam@uri:parse(<<"http://example.com/test#"/utf8>>)
) of
{some, <<""/utf8>>} -> {some, <<""/utf8>>};
_try@2 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@2,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_empty_fragments_test"/utf8>>,
line => 180})
end.
-spec parse_empty_queries_test() -> gleam@option:option(binary()).
parse_empty_queries_test() ->
{some, <<""/utf8>>} = case erlang:element(
7,
gleam@uri:parse(<<"http://example.com?"/utf8>>)
) of
{some, <<""/utf8>>} -> {some, <<""/utf8>>};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_empty_queries_test"/utf8>>,
line => 184})
end,
{some, <<""/utf8>>} = case erlang:element(
7,
gleam@uri:parse(<<"http://example.com/?"/utf8>>)
) of
{some, <<""/utf8>>} -> {some, <<""/utf8>>};
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_empty_queries_test"/utf8>>,
line => 185})
end,
{some, <<""/utf8>>} = case erlang:element(
7,
gleam@uri:parse(<<"http://example.com/test?"/utf8>>)
) of
{some, <<""/utf8>>} -> {some, <<""/utf8>>};
_try@2 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@2,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_empty_queries_test"/utf8>>,
line => 186})
end.
-spec full_uri_to_string_test() -> nil.
full_uri_to_string_test() ->
Test_uri = {uri,
{some, <<"https"/utf8>>},
{some, <<"weebl:bob"/utf8>>},
{some, <<"example.com"/utf8>>},
{some, 1234},
<<"/path"/utf8>>,
{some, <<"query=true"/utf8>>},
{some, <<"fragment"/utf8>>}},
gleam@should:equal(
gleam@uri:to_string(Test_uri),
<<"https://weebl:bob@example.com:1234/path?query=true#fragment"/utf8>>
).
-spec path_only_uri_to_string_test() -> nil.
path_only_uri_to_string_test() ->
_pipe = {uri, none, none, none, none, <<"/"/utf8>>, none, none},
_pipe@1 = gleam@uri:to_string(_pipe),
gleam@should:equal(_pipe@1, <<"/"/utf8>>),
_pipe@2 = {uri, none, none, none, none, <<"/teapot"/utf8>>, none, none},
_pipe@3 = gleam@uri:to_string(_pipe@2),
gleam@should:equal(_pipe@3, <<"/teapot"/utf8>>),
_pipe@4 = {uri,
none,
{some, <<"user"/utf8>>},
none,
none,
<<"/teapot"/utf8>>,
none,
none},
_pipe@5 = gleam@uri:to_string(_pipe@4),
gleam@should:equal(_pipe@5, <<"/teapot"/utf8>>),
_pipe@6 = {uri, none, none, none, none, <<""/utf8>>, none, none},
_pipe@7 = gleam@uri:to_string(_pipe@6),
gleam@should:equal(_pipe@7, <<""/utf8>>).
-spec scheme_to_string_test() -> nil.
scheme_to_string_test() ->
_pipe = {uri,
{some, <<"ftp"/utf8>>},
none,
none,
none,
<<"thing.txt"/utf8>>,
none,
none},
_pipe@1 = gleam@uri:to_string(_pipe),
gleam@should:equal(_pipe@1, <<"ftp:thing.txt"/utf8>>),
_pipe@2 = {uri,
{some, <<"ftp"/utf8>>},
none,
none,
none,
<<""/utf8>>,
none,
none},
_pipe@3 = gleam@uri:to_string(_pipe@2),
gleam@should:equal(_pipe@3, <<"ftp:"/utf8>>),
_pipe@4 = {uri,
{some, <<"ftp"/utf8>>},
{some, <<"ignored"/utf8>>},
none,
none,
<<""/utf8>>,
none,
none},
_pipe@5 = gleam@uri:to_string(_pipe@4),
gleam@should:equal(_pipe@5, <<"ftp:"/utf8>>),
_pipe@6 = {uri,
{some, <<"https"/utf8>>},
none,
none,
none,
<<"/one/two"/utf8>>,
none,
none},
_pipe@7 = gleam@uri:to_string(_pipe@6),
gleam@should:equal(_pipe@7, <<"https:/one/two"/utf8>>),
_pipe@8 = {uri,
none,
none,
none,
none,
<<"noslash"/utf8>>,
none,
{some, <<"frag"/utf8>>}},
_pipe@9 = gleam@uri:to_string(_pipe@8),
gleam@should:equal(_pipe@9, <<"noslash#frag"/utf8>>).
-spec host_to_string_test() -> nil.
host_to_string_test() ->
_pipe = {uri,
{some, <<"ftp"/utf8>>},
none,
{some, <<"example.com"/utf8>>},
none,
<<""/utf8>>,
none,
none},
_pipe@1 = gleam@uri:to_string(_pipe),
gleam@should:equal(_pipe@1, <<"ftp://example.com/"/utf8>>),
_pipe@2 = {uri,
none,
none,
{some, <<"example.com"/utf8>>},
none,
<<""/utf8>>,
none,
none},
_pipe@3 = gleam@uri:to_string(_pipe@2),
gleam@should:equal(_pipe@3, <<"//example.com/"/utf8>>),
_pipe@4 = {uri,
none,
none,
{some, <<"example.com"/utf8>>},
none,
<<"/slash"/utf8>>,
none,
none},
_pipe@5 = gleam@uri:to_string(_pipe@4),
gleam@should:equal(_pipe@5, <<"//example.com/slash"/utf8>>),
_pipe@6 = {uri,
none,
none,
{some, <<"example.com"/utf8>>},
none,
<<"noslash"/utf8>>,
none,
none},
_pipe@7 = gleam@uri:to_string(_pipe@6),
gleam@should:equal(_pipe@7, <<"//example.com/noslash"/utf8>>),
_pipe@8 = {uri,
none,
none,
{some, <<""/utf8>>},
none,
<<""/utf8>>,
none,
none},
_pipe@9 = gleam@uri:to_string(_pipe@8),
gleam@should:equal(_pipe@9, <<"//"/utf8>>),
_pipe@10 = {uri,
none,
none,
{some, <<"example.com"/utf8>>},
none,
<<"noslash"/utf8>>,
none,
{some, <<"ok"/utf8>>}},
_pipe@11 = gleam@uri:to_string(_pipe@10),
gleam@should:equal(_pipe@11, <<"//example.com/noslash#ok"/utf8>>),
_pipe@12 = {uri,
none,
none,
{some, <<""/utf8>>},
none,
<<""/utf8>>,
none,
{some, <<"ok"/utf8>>}},
_pipe@13 = gleam@uri:to_string(_pipe@12),
gleam@should:equal(_pipe@13, <<"//#ok"/utf8>>).
-spec port_to_string_test() -> nil.
port_to_string_test() ->
_pipe = {uri,
{some, <<"ftp"/utf8>>},
none,
{some, <<"example.com"/utf8>>},
{some, 80},
<<""/utf8>>,
none,
none},
_pipe@1 = gleam@uri:to_string(_pipe),
gleam@should:equal(_pipe@1, <<"ftp://example.com:80/"/utf8>>),
_pipe@2 = {uri,
none,
none,
{some, <<"example.com"/utf8>>},
{some, 40},
<<""/utf8>>,
none,
none},
_pipe@3 = gleam@uri:to_string(_pipe@2),
gleam@should:equal(_pipe@3, <<"//example.com:40/"/utf8>>),
_pipe@4 = {uri,
none,
none,
{some, <<"example.com"/utf8>>},
{some, 80},
<<"/slash"/utf8>>,
none,
none},
_pipe@5 = gleam@uri:to_string(_pipe@4),
gleam@should:equal(_pipe@5, <<"//example.com:80/slash"/utf8>>),
_pipe@6 = {uri,
none,
none,
{some, <<"example.com"/utf8>>},
{some, 81},
<<"noslash"/utf8>>,
none,
none},
_pipe@7 = gleam@uri:to_string(_pipe@6),
gleam@should:equal(_pipe@7, <<"//example.com:81/noslash"/utf8>>),
_pipe@8 = {uri,
none,
none,
none,
{some, 81},
<<"noslash"/utf8>>,
none,
none},
_pipe@9 = gleam@uri:to_string(_pipe@8),
gleam@should:equal(_pipe@9, <<"noslash"/utf8>>).
-spec parse_query_string_test() -> nil.
parse_query_string_test() ->
{ok, Parsed@1} = case gleam@uri:parse_query(
<<"weebl+bob=1&city=%C3%B6rebro"/utf8>>
) of
{ok, Parsed} -> {ok, Parsed};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_query_string_test"/utf8>>,
line => 299})
end,
gleam@should:equal(
Parsed@1,
[{<<"weebl bob"/utf8>>, <<"1"/utf8>>},
{<<"city"/utf8>>, <<"örebro"/utf8>>}]
),
{ok, Parsed@3} = case gleam@uri:parse_query(<<"a[]=1&a[]=2"/utf8>>) of
{ok, Parsed@2} -> {ok, Parsed@2};
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_query_string_test"/utf8>>,
line => 303})
end,
_pipe = Parsed@3,
gleam@should:equal(
_pipe,
[{<<"a[]"/utf8>>, <<"1"/utf8>>}, {<<"a[]"/utf8>>, <<"2"/utf8>>}]
).
-spec parse_empty_query_string_test() -> nil.
parse_empty_query_string_test() ->
{ok, Parsed@1} = case gleam@uri:parse_query(<<""/utf8>>) of
{ok, Parsed} -> {ok, Parsed};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleam/uri_test"/utf8>>,
function => <<"parse_empty_query_string_test"/utf8>>,
line => 310})
end,
gleam@should:equal(Parsed@1, []).
-spec parse_query_string_with_empty_test() -> nil.
parse_query_string_with_empty_test() ->
_pipe = gleam@uri:parse_query(<<"present"/utf8>>),
gleam@should:equal(_pipe, {ok, [{<<"present"/utf8>>, <<""/utf8>>}]}).
-spec error_parsing_query_test() -> nil.
error_parsing_query_test() ->
gleam@should:equal(gleam@uri:parse_query(<<"%C2"/utf8>>), {error, nil}).
-spec query_to_string_test() -> nil.
query_to_string_test() ->
Query_string = gleam@uri:query_to_string(
[{<<"weebl bob"/utf8>>, <<"1"/utf8>>},
{<<"city"/utf8>>, <<"örebro"/utf8>>}]
),
gleam@should:equal(Query_string, <<"weebl%20bob=1&city=%C3%B6rebro"/utf8>>).
-spec empty_query_to_string_test() -> nil.
empty_query_to_string_test() ->
Query_string = gleam@uri:query_to_string([]),
gleam@should:equal(Query_string, <<""/utf8>>).
-spec percent_encode_test() -> list(nil).
percent_encode_test() ->
_pipe = [{<<" "/utf8>>, <<"%20"/utf8>>},
{<<","/utf8>>, <<"%2C"/utf8>>},
{<<";"/utf8>>, <<"%3B"/utf8>>},
{<<":"/utf8>>, <<"%3A"/utf8>>},
{<<"!"/utf8>>, <<"!"/utf8>>},
{<<"?"/utf8>>, <<"%3F"/utf8>>},
{<<"'"/utf8>>, <<"'"/utf8>>},
{<<"("/utf8>>, <<"("/utf8>>},
{<<")"/utf8>>, <<")"/utf8>>},
{<<"["/utf8>>, <<"%5B"/utf8>>},
{<<"@"/utf8>>, <<"%40"/utf8>>},
{<<"/"/utf8>>, <<"%2F"/utf8>>},
{<<"\\"/utf8>>, <<"%5C"/utf8>>},
{<<"&"/utf8>>, <<"%26"/utf8>>},
{<<"#"/utf8>>, <<"%23"/utf8>>},
{<<"="/utf8>>, <<"%3D"/utf8>>},
{<<"~"/utf8>>, <<"~"/utf8>>},
{<<"ñ"/utf8>>, <<"%C3%B1"/utf8>>},
{<<"-"/utf8>>, <<"-"/utf8>>},
{<<"_"/utf8>>, <<"_"/utf8>>},
{<<"."/utf8>>, <<"."/utf8>>},
{<<"*"/utf8>>, <<"*"/utf8>>},
{<<"100% great"/utf8>>, <<"100%25%20great"/utf8>>}],
gleam@list:map(
_pipe,
fun(T) ->
{A, B} = T,
_pipe@1 = gleam@uri:percent_encode(A),
gleam@should:equal(_pipe@1, B)
end
).
-spec percent_encode_consistency_test() -> nil.
percent_encode_consistency_test() ->
K = <<"weebl bob[]"/utf8>>,
V = <<"ñaña (,:*~)"/utf8>>,
Query_string = gleam@uri:query_to_string([{K, V}]),
Encoded_key = gleam@uri:percent_encode(K),
Encoded_value = gleam@uri:percent_encode(V),
Manual_query_string = gleam@string:concat(
[Encoded_key, <<"="/utf8>>, Encoded_value]
),
gleam@should:equal(Query_string, Manual_query_string).
-spec percent_decode_test() -> list(nil).
percent_decode_test() ->
_pipe = [{<<" "/utf8>>, <<"%20"/utf8>>},
{<<","/utf8>>, <<"%2C"/utf8>>},
{<<";"/utf8>>, <<"%3B"/utf8>>},
{<<":"/utf8>>, <<"%3A"/utf8>>},
{<<"!"/utf8>>, <<"!"/utf8>>},
{<<"?"/utf8>>, <<"%3F"/utf8>>},
{<<"'"/utf8>>, <<"'"/utf8>>},
{<<"("/utf8>>, <<"("/utf8>>},
{<<")"/utf8>>, <<")"/utf8>>},
{<<"["/utf8>>, <<"%5B"/utf8>>},
{<<"@"/utf8>>, <<"%40"/utf8>>},
{<<"/"/utf8>>, <<"%2F"/utf8>>},
{<<"\\"/utf8>>, <<"%5C"/utf8>>},
{<<"&"/utf8>>, <<"%26"/utf8>>},
{<<"#"/utf8>>, <<"%23"/utf8>>},
{<<"="/utf8>>, <<"%3D"/utf8>>},
{<<"~"/utf8>>, <<"~"/utf8>>},
{<<"ñ"/utf8>>, <<"%C3%B1"/utf8>>},
{<<"-"/utf8>>, <<"-"/utf8>>},
{<<"_"/utf8>>, <<"_"/utf8>>},
{<<"."/utf8>>, <<"."/utf8>>},
{<<"*"/utf8>>, <<"*"/utf8>>},
{<<"100% great"/utf8>>, <<"100%25%20great"/utf8>>}],
gleam@list:map(
_pipe,
fun(T) ->
{A, B} = T,
_pipe@1 = gleam@uri:percent_decode(B),
gleam@should:equal(_pipe@1, {ok, A})
end
).
-spec percent_decode_consistency_test() -> nil.
percent_decode_consistency_test() ->
K = <<"weebl%20bob[]"/utf8>>,
V = <<"%C3%B6rebro"/utf8>>,
Query = gleam@string:concat([K, <<"="/utf8>>, V]),
{ok, Parsed@1} = case gleam@uri:parse_query(Query) of
{ok, Parsed} -> {ok, Parsed};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleam/uri_test"/utf8>>,
function => <<"percent_decode_consistency_test"/utf8>>,
line => 396})
end,
{ok, Decoded_key@1} = case gleam@uri:percent_decode(K) of
{ok, Decoded_key} -> {ok, Decoded_key};
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"gleam/uri_test"/utf8>>,
function => <<"percent_decode_consistency_test"/utf8>>,
line => 398})
end,
{ok, Decoded_value@1} = case gleam@uri:percent_decode(V) of
{ok, Decoded_value} -> {ok, Decoded_value};
_try@2 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@2,
module => <<"gleam/uri_test"/utf8>>,
function => <<"percent_decode_consistency_test"/utf8>>,
line => 399})
end,
gleam@should:equal(Parsed@1, [{Decoded_key@1, Decoded_value@1}]).
-spec parse_segments_test() -> nil.
parse_segments_test() ->
gleam@should:equal(gleam@uri:path_segments(<<"/"/utf8>>), []),
gleam@should:equal(
gleam@uri:path_segments(<<"/weebl/bob"/utf8>>),
[<<"weebl"/utf8>>, <<"bob"/utf8>>]
),
gleam@should:equal(gleam@uri:path_segments(<<"////"/utf8>>), []),
gleam@should:equal(
gleam@uri:path_segments(<<"/weebl//bob"/utf8>>),
[<<"weebl"/utf8>>, <<"bob"/utf8>>]
),
gleam@should:equal(gleam@uri:path_segments(<<"/."/utf8>>), []),
gleam@should:equal(
gleam@uri:path_segments(<<"/.weebl"/utf8>>),
[<<".weebl"/utf8>>]
),
gleam@should:equal(
gleam@uri:path_segments(<<"/../bob"/utf8>>),
[<<"bob"/utf8>>]
),
gleam@should:equal(
gleam@uri:path_segments(<<"../bob"/utf8>>),
[<<"bob"/utf8>>]
),
gleam@should:equal(
gleam@uri:path_segments(<<"/weebl/../bob"/utf8>>),
[<<"bob"/utf8>>]
).
-spec origin1_test() -> nil.
origin1_test() ->
Parsed = gleam@uri:parse(<<"http://example.test/path?weebl#bob"/utf8>>),
_pipe = gleam@uri:origin(Parsed),
gleam@should:equal(_pipe, {ok, <<"http://example.test/"/utf8>>}).
-spec origin2_test() -> nil.
origin2_test() ->
Parsed = gleam@uri:parse(<<"http://example.test:8080"/utf8>>),
_pipe = gleam@uri:origin(Parsed),
gleam@should:equal(_pipe, {ok, <<"http://example.test:8080/"/utf8>>}).
-spec origin3_test() -> nil.
origin3_test() ->
Parsed = gleam@uri:parse(<<"https://example.test"/utf8>>),
_pipe = gleam@uri:origin(Parsed),
gleam@should:equal(_pipe, {ok, <<"https://example.test/"/utf8>>}).
-spec origin4_test() -> nil.
origin4_test() ->
Parsed = gleam@uri:parse(<<"http:///path"/utf8>>),
_pipe = gleam@uri:origin(Parsed),
gleam@should:equal(_pipe, {ok, <<"http://"/utf8>>}).
-spec origin5_test() -> nil.
origin5_test() ->
Parsed = gleam@uri:parse(<<"http://"/utf8>>),
_pipe = gleam@uri:origin(Parsed),
gleam@should:equal(_pipe, {ok, <<"http://"/utf8>>}).
-spec origin6_test() -> nil.
origin6_test() ->
Parsed = gleam@uri:parse(<<"/path"/utf8>>),
_pipe = gleam@uri:origin(Parsed),
gleam@should:equal(_pipe, {error, nil}).
-spec origin7_test() -> nil.
origin7_test() ->
Parsed = gleam@uri:parse(<<"file:///dev/null"/utf8>>),
_pipe = gleam@uri:origin(Parsed),
gleam@should:equal(_pipe, {error, nil}).
-spec merge1_test() -> nil.
merge1_test() ->
A = gleam@uri:parse(<<"/relative"/utf8>>),
B = gleam@uri:parse(<<""/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(_pipe, {error, nil}).
-spec merge2_test() -> nil.
merge2_test() ->
A = gleam@uri:parse(<<"http://google.com/weebl"/utf8>>),
B = gleam@uri:parse(<<"http://example.com/baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/baz"/utf8>>)}
).
-spec merge3_test() -> nil.
merge3_test() ->
A = gleam@uri:parse(<<"http://google.com/weebl"/utf8>>),
B = gleam@uri:parse(<<"http://example.com/.././bob/../../baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/baz"/utf8>>)}
).
-spec merge4_test() -> nil.
merge4_test() ->
A = gleam@uri:parse(<<"http://google.com/weebl"/utf8>>),
B = gleam@uri:parse(<<"//example.com/baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/baz"/utf8>>)}
).
-spec merge5_test() -> nil.
merge5_test() ->
A = gleam@uri:parse(<<"http://google.com/weebl"/utf8>>),
B = gleam@uri:parse(<<"//example.com/.././bob/../../../baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/baz"/utf8>>)}
).
-spec merge6_test() -> nil.
merge6_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/bob"/utf8>>),
B = gleam@uri:parse(<<"/baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/baz"/utf8>>)}
).
-spec merge7_test() -> nil.
merge7_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/bob"/utf8>>),
B = gleam@uri:parse(<<"baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/weebl/baz"/utf8>>)}
).
-spec merge8_test() -> nil.
merge8_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/"/utf8>>),
B = gleam@uri:parse(<<"baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/weebl/baz"/utf8>>)}
).
-spec merge9_test() -> nil.
merge9_test() ->
A = gleam@uri:parse(<<"http://example.com"/utf8>>),
B = gleam@uri:parse(<<"baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/baz"/utf8>>)}
).
-spec merge10_test() -> nil.
merge10_test() ->
A = gleam@uri:parse(<<"http://example.com"/utf8>>),
B = gleam@uri:parse(<<"/.././bob/../../../baz"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/baz"/utf8>>)}
).
-spec merge11_test() -> nil.
merge11_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/bob"/utf8>>),
B = gleam@uri:parse(<<""/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/weebl/bob"/utf8>>)}
).
-spec merge12_test() -> nil.
merge12_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/bob"/utf8>>),
B = gleam@uri:parse(<<"#fragment"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/weebl/bob#fragment"/utf8>>)}
).
-spec merge13_test() -> nil.
merge13_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/bob"/utf8>>),
B = gleam@uri:parse(<<"?query"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/weebl/bob?query"/utf8>>)}
).
-spec merge14_test() -> nil.
merge14_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/bob?query1"/utf8>>),
B = gleam@uri:parse(<<"?query2"/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/weebl/bob?query2"/utf8>>)}
).
-spec merge15_test() -> nil.
merge15_test() ->
A = gleam@uri:parse(<<"http://example.com/weebl/bob?query"/utf8>>),
B = gleam@uri:parse(<<""/utf8>>),
_pipe = gleam@uri:merge(A, B),
gleam@should:equal(
_pipe,
{ok, gleam@uri:parse(<<"http://example.com/weebl/bob?query"/utf8>>)}
).