mirror of
https://github.com/dlang/phobos.git
synced 2025-04-26 21:22:20 +03:00
std.uri: Add unittests for 100% code coverage. (#7220)
std.uri: Add unittests for 100% code coverage. merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
This commit is contained in:
parent
c189b61086
commit
a2af7d674d
1 changed files with 46 additions and 0 deletions
46
std/uri.d
46
std/uri.d
|
@ -172,6 +172,18 @@ private string URI_Encode(dstring str, uint unescapedSet) @safe pure
|
|||
return R[0 .. Rlen].idup;
|
||||
}
|
||||
|
||||
@safe pure unittest
|
||||
{
|
||||
import std.exception : assertThrown;
|
||||
|
||||
assert(URI_Encode("", 0) == "");
|
||||
assert(URI_Encode(URI_Decode("%F0%BF%BF%BF", 0), 0) == "%F0%BF%BF%BF");
|
||||
dstring a;
|
||||
a ~= cast(dchar) 0xFFFFFFFF;
|
||||
assertThrown(URI_Encode(a, 0));
|
||||
assert(URI_Encode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0).length == 3 * 60);
|
||||
}
|
||||
|
||||
private uint ascii2hex(dchar c) @nogc @safe pure nothrow
|
||||
{
|
||||
return (c <= '9') ? c - '0' :
|
||||
|
@ -278,6 +290,22 @@ if (isSomeChar!Char)
|
|||
return R[0 .. Rlen].idup;
|
||||
}
|
||||
|
||||
@safe pure unittest
|
||||
{
|
||||
import std.exception : assertThrown;
|
||||
|
||||
assert(URI_Decode("", 0) == "");
|
||||
assertThrown!URIException(URI_Decode("%", 0));
|
||||
assertThrown!URIException(URI_Decode("%xx", 0));
|
||||
assertThrown!URIException(URI_Decode("%FF", 0));
|
||||
assertThrown!URIException(URI_Decode("%C0", 0));
|
||||
assertThrown!URIException(URI_Decode("%C0000000", 0));
|
||||
assertThrown!URIException(URI_Decode("%C0%xx0000", 0));
|
||||
assertThrown!URIException(URI_Decode("%C0%C00000", 0));
|
||||
assertThrown!URIException(URI_Decode("%F7%BF%BF%BF", 0));
|
||||
assert(URI_Decode("%23", URI_Hash) == "%23");
|
||||
}
|
||||
|
||||
/*************************************
|
||||
* Decodes the URI string encodedURI into a UTF-8 string and returns it.
|
||||
* Escape sequences that resolve to reserved URI characters are not replaced.
|
||||
|
@ -480,6 +508,11 @@ if (isSomeChar!Char)
|
|||
assert(uriLength("issue 14924") < 0);
|
||||
}
|
||||
|
||||
@safe pure nothrow @nogc unittest
|
||||
{
|
||||
assert(uriLength("") == -1);
|
||||
assert(uriLength("https://www") == -1);
|
||||
}
|
||||
|
||||
/***************************
|
||||
* Does string s[] start with an email address?
|
||||
|
@ -496,6 +529,9 @@ if (isSomeChar!Char)
|
|||
|
||||
ptrdiff_t i;
|
||||
|
||||
if (s.length == 0)
|
||||
return -1;
|
||||
|
||||
if (!isAlpha(s[0]))
|
||||
return -1;
|
||||
|
||||
|
@ -594,3 +630,13 @@ if (isSomeChar!Char)
|
|||
assert(encoded2 == encode(decoded2).to!StringType);
|
||||
}}
|
||||
}
|
||||
|
||||
@safe pure nothrow @nogc unittest
|
||||
{
|
||||
assert(emailLength("") == -1);
|
||||
assert(emailLength("@") == -1);
|
||||
assert(emailLength("abcd") == -1);
|
||||
assert(emailLength("blah@blub") == -1);
|
||||
assert(emailLength("blah@blub.") == -1);
|
||||
assert(emailLength("blah@blub.domain") == -1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue