net: Add missing public imports, move tests
This commit is contained in:
parent
484cb13317
commit
20c7e47ff7
@ -7,13 +7,14 @@ os:
|
|||||||
language: d
|
language: d
|
||||||
|
|
||||||
d:
|
d:
|
||||||
|
- dmd-2.085.0
|
||||||
- dmd-2.084.1
|
- dmd-2.084.1
|
||||||
- dmd-2.083.1
|
- dmd-2.083.1
|
||||||
- dmd-2.082.1
|
- dmd-2.082.1
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- LATEST=2.084.1
|
- LATEST=2.085.0
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
- ARCH=x86_64
|
- ARCH=x86_64
|
||||||
@ -29,11 +30,6 @@ matrix:
|
|||||||
d: dmd-$LATEST
|
d: dmd-$LATEST
|
||||||
env: DDOC=true
|
env: DDOC=true
|
||||||
os: linux
|
os: linux
|
||||||
allow_failures:
|
|
||||||
- name: D-Scanner
|
|
||||||
d: dmd-$LATEST
|
|
||||||
env: DSCANNER=0.7.0
|
|
||||||
os: linux
|
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
|
@ -174,8 +174,9 @@ parameter is used)
|
|||||||
|
|
||||||
| DMD | GCC |
|
| DMD | GCC |
|
||||||
|:-------:|:---------------:|
|
|:-------:|:---------------:|
|
||||||
| 2.084.1 | gdc-8 (2.081.2) |
|
| 2.085.0 | gdc-8 (2.081.2) |
|
||||||
| 2.083.1 | gdc-7 (2.081.2) |
|
| 2.084.1 | gdc-7 (2.081.2) |
|
||||||
|
| 2.083.1 | |
|
||||||
| 2.082.1 | |
|
| 2.082.1 | |
|
||||||
|
|
||||||
### Release management
|
### Release management
|
||||||
|
@ -3,6 +3,12 @@ os: Visual Studio 2015
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
|
- DC: dmd
|
||||||
|
DVersion: 2.085.0
|
||||||
|
arch: x64
|
||||||
|
- DC: dmd
|
||||||
|
DVersion: 2.085.0
|
||||||
|
arch: x86
|
||||||
- DC: dmd
|
- DC: dmd
|
||||||
DVersion: 2.084.1
|
DVersion: 2.084.1
|
||||||
arch: x64
|
arch: x64
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
/**
|
/**
|
||||||
* Non-cryptographic, lookup hash functions.
|
* Non-cryptographic, lookup hash functions.
|
||||||
*
|
*
|
||||||
* Copyright: Eugene Wissner 2018.
|
* Copyright: Eugene Wissner 2018-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
@ -16,7 +16,6 @@ module tanya.hash.lookup;
|
|||||||
|
|
||||||
import tanya.meta.trait;
|
import tanya.meta.trait;
|
||||||
import tanya.range.primitive;
|
import tanya.range.primitive;
|
||||||
version (unittest) import tanya.test.stub;
|
|
||||||
|
|
||||||
private struct Hasher
|
private struct Hasher
|
||||||
{
|
{
|
||||||
@ -316,501 +315,6 @@ size_t hash(T)(auto ref T key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
version (unittest)
|
|
||||||
{
|
|
||||||
enum string r10(string x) = x ~ x ~ x ~ x ~ x ~ x ~ x ~ x ~ x ~ x;
|
|
||||||
enum string r100(string x) = r10!x ~ r10!x ~ r10!x ~ r10!x ~ r10!x
|
|
||||||
~ r10!x ~ r10!x ~ r10!x ~ r10!x ~ r10!x;
|
|
||||||
enum string r500(string x) = r100!x ~ r100!x ~ r100!x ~ r100!x ~ r100!x;
|
|
||||||
|
|
||||||
private static struct HashRange
|
|
||||||
{
|
|
||||||
string fo = "fo";
|
|
||||||
|
|
||||||
@property ubyte front() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.fo[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
void popFront() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
this.fo = this.fo[1 .. $];
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool empty() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.fo.length == 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static struct ToHashRange
|
|
||||||
{
|
|
||||||
bool empty_;
|
|
||||||
|
|
||||||
@property Hashable front() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return Hashable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void popFront() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
this.empty_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool empty() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.empty_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that work for any hash size
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(hash(null) == 0);
|
|
||||||
assert(hash(Hashable()) == 0U);
|
|
||||||
assert(hash('a') == 'a');
|
|
||||||
}
|
|
||||||
|
|
||||||
static if (size_t.sizeof == 4) @nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(hash(HashRange()) == 0x6222e842U);
|
|
||||||
assert(hash(ToHashRange()) == 3371162643U);
|
|
||||||
}
|
|
||||||
static if (size_t.sizeof == 8) @nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(hash(HashRange()) == 0x08985907b541d342UL);
|
|
||||||
assert(hash(ToHashRange()) == 2072958611659694473);
|
|
||||||
}
|
|
||||||
|
|
||||||
static if (size_t.sizeof == 4) @nogc nothrow pure @system unittest
|
|
||||||
{
|
|
||||||
assert(hash(cast(void*) 0x6e6f6863) == 0x6e6f6863);
|
|
||||||
}
|
|
||||||
static if (size_t.sizeof == 8) @nogc nothrow pure @system unittest
|
|
||||||
{
|
|
||||||
assert(hash(cast(void*) 0x77206f676e6f6863) == 0x77206f676e6f6863);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These are official FNV-1a test vectors and they are in the public domain.
|
|
||||||
*/
|
|
||||||
// FNV-1a 32 bit test vectors
|
|
||||||
static if (size_t.sizeof == 4) @nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(hash("") == 0x811c9dc5U);
|
|
||||||
assert(hash("a") == 0xe40c292cU);
|
|
||||||
assert(hash("b") == 0xe70c2de5U);
|
|
||||||
assert(hash("c") == 0xe60c2c52U);
|
|
||||||
assert(hash("d") == 0xe10c2473U);
|
|
||||||
assert(hash("e") == 0xe00c22e0U);
|
|
||||||
assert(hash("f") == 0xe30c2799U);
|
|
||||||
assert(hash("fo") == 0x6222e842U);
|
|
||||||
assert(hash("foo") == 0xa9f37ed7U);
|
|
||||||
assert(hash("foob") == 0x3f5076efU);
|
|
||||||
assert(hash("fooba") == 0x39aaa18aU);
|
|
||||||
assert(hash("foobar") == 0xbf9cf968U);
|
|
||||||
assert(hash("\0") == 0x050c5d1fU);
|
|
||||||
assert(hash("a\0") == 0x2b24d044U);
|
|
||||||
assert(hash("b\0") == 0x9d2c3f7fU);
|
|
||||||
assert(hash("c\0") == 0x7729c516U);
|
|
||||||
assert(hash("d\0") == 0xb91d6109U);
|
|
||||||
assert(hash("e\0") == 0x931ae6a0U);
|
|
||||||
assert(hash("f\0") == 0x052255dbU);
|
|
||||||
assert(hash("fo\0") == 0xbef39fe6U);
|
|
||||||
assert(hash("foo\0") == 0x6150ac75U);
|
|
||||||
assert(hash("foob\0") == 0x9aab3a3dU);
|
|
||||||
assert(hash("fooba\0") == 0x519c4c3eU);
|
|
||||||
assert(hash("foobar\0") == 0x0c1c9eb8U);
|
|
||||||
assert(hash("ch") == 0x5f299f4eU);
|
|
||||||
assert(hash("cho") == 0xef8580f3U);
|
|
||||||
assert(hash("chon") == 0xac297727U);
|
|
||||||
assert(hash("chong") == 0x4546b9c0U);
|
|
||||||
assert(hash("chongo") == 0xbd564e7dU);
|
|
||||||
assert(hash("chongo ") == 0x6bdd5c67U);
|
|
||||||
assert(hash("chongo w") == 0xdd77ed30U);
|
|
||||||
assert(hash("chongo wa") == 0xf4ca9683U);
|
|
||||||
assert(hash("chongo was") == 0x4aeb9bd0U);
|
|
||||||
assert(hash("chongo was ") == 0xe0e67ad0U);
|
|
||||||
assert(hash("chongo was h") == 0xc2d32fa8U);
|
|
||||||
assert(hash("chongo was he") == 0x7f743fb7U);
|
|
||||||
assert(hash("chongo was her") == 0x6900631fU);
|
|
||||||
assert(hash("chongo was here") == 0xc59c990eU);
|
|
||||||
assert(hash("chongo was here!") == 0x448524fdU);
|
|
||||||
assert(hash("chongo was here!\n") == 0xd49930d5U);
|
|
||||||
assert(hash("ch\0") == 0x1c85c7caU);
|
|
||||||
assert(hash("cho\0") == 0x0229fe89U);
|
|
||||||
assert(hash("chon\0") == 0x2c469265U);
|
|
||||||
assert(hash("chong\0") == 0xce566940U);
|
|
||||||
assert(hash("chongo\0") == 0x8bdd8ec7U);
|
|
||||||
assert(hash("chongo \0") == 0x34787625U);
|
|
||||||
assert(hash("chongo w\0") == 0xd3ca6290U);
|
|
||||||
assert(hash("chongo wa\0") == 0xddeaf039U);
|
|
||||||
assert(hash("chongo was\0") == 0xc0e64870U);
|
|
||||||
assert(hash("chongo was \0") == 0xdad35570U);
|
|
||||||
assert(hash("chongo was h\0") == 0x5a740578U);
|
|
||||||
assert(hash("chongo was he\0") == 0x5b004d15U);
|
|
||||||
assert(hash("chongo was her\0") == 0x6a9c09cdU);
|
|
||||||
assert(hash("chongo was here\0") == 0x2384f10aU);
|
|
||||||
assert(hash("chongo was here!\0") == 0xda993a47U);
|
|
||||||
assert(hash("chongo was here!\n\0") == 0x8227df4fU);
|
|
||||||
assert(hash("cu") == 0x4c298165U);
|
|
||||||
assert(hash("cur") == 0xfc563735U);
|
|
||||||
assert(hash("curd") == 0x8cb91483U);
|
|
||||||
assert(hash("curds") == 0x775bf5d0U);
|
|
||||||
assert(hash("curds ") == 0xd5c428d0U);
|
|
||||||
assert(hash("curds a") == 0x34cc0ea3U);
|
|
||||||
assert(hash("curds an") == 0xea3b4cb7U);
|
|
||||||
assert(hash("curds and") == 0x8e59f029U);
|
|
||||||
assert(hash("curds and ") == 0x2094de2bU);
|
|
||||||
assert(hash("curds and w") == 0xa65a0ad4U);
|
|
||||||
assert(hash("curds and wh") == 0x9bbee5f4U);
|
|
||||||
assert(hash("curds and whe") == 0xbe836343U);
|
|
||||||
assert(hash("curds and whey") == 0x22d5344eU);
|
|
||||||
assert(hash("curds and whey\n") == 0x19a1470cU);
|
|
||||||
assert(hash("cu\0") == 0x4a56b1ffU);
|
|
||||||
assert(hash("cur\0") == 0x70b8e86fU);
|
|
||||||
assert(hash("curd\0") == 0x0a5b4a39U);
|
|
||||||
assert(hash("curds\0") == 0xb5c3f670U);
|
|
||||||
assert(hash("curds \0") == 0x53cc3f70U);
|
|
||||||
assert(hash("curds a\0") == 0xc03b0a99U);
|
|
||||||
assert(hash("curds an\0") == 0x7259c415U);
|
|
||||||
assert(hash("curds and\0") == 0x4095108bU);
|
|
||||||
assert(hash("curds and \0") == 0x7559bdb1U);
|
|
||||||
assert(hash("curds and w\0") == 0xb3bf0bbcU);
|
|
||||||
assert(hash("curds and wh\0") == 0x2183ff1cU);
|
|
||||||
assert(hash("curds and whe\0") == 0x2bd54279U);
|
|
||||||
assert(hash("curds and whey\0") == 0x23a156caU);
|
|
||||||
assert(hash("curds and whey\n\0") == 0x64e2d7e4U);
|
|
||||||
assert(hash("hi") == 0x683af69aU);
|
|
||||||
assert(hash("hi\0") == 0xaed2346eU);
|
|
||||||
assert(hash("hello") == 0x4f9f2cabU);
|
|
||||||
assert(hash("hello\0") == 0x02935131U);
|
|
||||||
assert(hash("\xff\x00\x00\x01") == 0xc48fb86dU);
|
|
||||||
assert(hash("\x01\x00\x00\xff") == 0x2269f369U);
|
|
||||||
assert(hash("\xff\x00\x00\x02") == 0xc18fb3b4U);
|
|
||||||
assert(hash("\x02\x00\x00\xff") == 0x50ef1236U);
|
|
||||||
assert(hash("\xff\x00\x00\x03") == 0xc28fb547U);
|
|
||||||
assert(hash("\x03\x00\x00\xff") == 0x96c3bf47U);
|
|
||||||
assert(hash("\xff\x00\x00\x04") == 0xbf8fb08eU);
|
|
||||||
assert(hash("\x04\x00\x00\xff") == 0xf3e4d49cU);
|
|
||||||
assert(hash("\x40\x51\x4e\x44") == 0x32179058U);
|
|
||||||
assert(hash("\x44\x4e\x51\x40") == 0x280bfee6U);
|
|
||||||
assert(hash("\x40\x51\x4e\x4a") == 0x30178d32U);
|
|
||||||
assert(hash("\x4a\x4e\x51\x40") == 0x21addaf8U);
|
|
||||||
assert(hash("\x40\x51\x4e\x54") == 0x4217a988U);
|
|
||||||
assert(hash("\x54\x4e\x51\x40") == 0x772633d6U);
|
|
||||||
assert(hash("127.0.0.1") == 0x08a3d11eU);
|
|
||||||
assert(hash("127.0.0.1\0") == 0xb7e2323aU);
|
|
||||||
assert(hash("127.0.0.2") == 0x07a3cf8bU);
|
|
||||||
assert(hash("127.0.0.2\0") == 0x91dfb7d1U);
|
|
||||||
assert(hash("127.0.0.3") == 0x06a3cdf8U);
|
|
||||||
assert(hash("127.0.0.3\0") == 0x6bdd3d68U);
|
|
||||||
assert(hash("64.81.78.68") == 0x1d5636a7U);
|
|
||||||
assert(hash("64.81.78.68\0") == 0xd5b808e5U);
|
|
||||||
assert(hash("64.81.78.74") == 0x1353e852U);
|
|
||||||
assert(hash("64.81.78.74\0") == 0xbf16b916U);
|
|
||||||
assert(hash("64.81.78.84") == 0xa55b89edU);
|
|
||||||
assert(hash("64.81.78.84\0") == 0x3c1a2017U);
|
|
||||||
assert(hash("feedface") == 0x0588b13cU);
|
|
||||||
assert(hash("feedface\0") == 0xf22f0174U);
|
|
||||||
assert(hash("feedfacedaffdeed") == 0xe83641e1U);
|
|
||||||
assert(hash("feedfacedaffdeed\0") == 0x6e69b533U);
|
|
||||||
assert(hash("feedfacedeadbeef") == 0xf1760448U);
|
|
||||||
assert(hash("feedfacedeadbeef\0") == 0x64c8bd58U);
|
|
||||||
assert(hash("line 1\nline 2\nline 3") == 0x97b4ea23U);
|
|
||||||
assert(hash("chongo <Landon Curt Noll> /\\../\\") == 0x9a4e92e6U);
|
|
||||||
assert(hash("chongo <Landon Curt Noll> /\\../\\\0") == 0xcfb14012U);
|
|
||||||
assert(hash("chongo (Landon Curt Noll) /\\../\\") == 0xf01b2511U);
|
|
||||||
assert(hash("chongo (Landon Curt Noll) /\\../\\\0") == 0x0bbb59c3U);
|
|
||||||
assert(hash("http://antwrp.gsfc.nasa.gov/apod/astropix.html") == 0xce524afaU);
|
|
||||||
assert(hash("http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash") == 0xdd16ef45U);
|
|
||||||
assert(hash("http://epod.usra.edu/") == 0x60648bb3U);
|
|
||||||
assert(hash("http://exoplanet.eu/") == 0x7fa4bcfcU);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/cam3/") == 0x5053ae17U);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/cams/HMcam/") == 0xc9302890U);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/deformation.html") == 0x956ded32U);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/images.html") == 0x9136db84U);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/maps.html") == 0xdf9d3323U);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/volcanowatch/current_issue.html") == 0x32bb6cd0U);
|
|
||||||
assert(hash("http://neo.jpl.nasa.gov/risk/") == 0xc8f8385bU);
|
|
||||||
assert(hash("http://norvig.com/21-days.html") == 0xeb08bfbaU);
|
|
||||||
assert(hash("http://primes.utm.edu/curios/home.php") == 0x62cc8e3dU);
|
|
||||||
assert(hash("http://slashdot.org/") == 0xc3e20f5cU);
|
|
||||||
assert(hash("http://tux.wr.usgs.gov/Maps/155.25-19.5.html") == 0x39e97f17U);
|
|
||||||
assert(hash("http://volcano.wr.usgs.gov/kilaueastatus.php") == 0x7837b203U);
|
|
||||||
assert(hash("http://www.avo.alaska.edu/activity/Redoubt.php") == 0x319e877bU);
|
|
||||||
assert(hash("http://www.dilbert.com/fast/") == 0xd3e63f89U);
|
|
||||||
assert(hash("http://www.fourmilab.ch/gravitation/orbits/") == 0x29b50b38U);
|
|
||||||
assert(hash("http://www.fpoa.net/") == 0x5ed678b8U);
|
|
||||||
assert(hash("http://www.ioccc.org/index.html") == 0xb0d5b793U);
|
|
||||||
assert(hash("http://www.isthe.com/cgi-bin/number.cgi") == 0x52450be5U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/bio.html") == 0xfa72d767U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/index.html") == 0x95066709U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/src/calc/lucas-calc") == 0x7f52e123U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/astro/venus2004.html") == 0x76966481U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/astro/vita.html") == 0x063258b0U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/comp/c/expert.html") == 0x2ded6e8aU);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/comp/calc/index.html") == 0xb07d7c52U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/comp/fnv/index.html") == 0xd0c71b71U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/number/howhigh.html") == 0xf684f1bdU);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/number/number.html") == 0x868ecfa8U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html") == 0xf794f684U);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest") == 0xd19701c3U);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/corpspeak.cgi") == 0x346e171eU);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/haiku.cgi") == 0x91f8f676U);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/rand-none.cgi") == 0x0bf58848U);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/randdist.cgi") == 0x6317b6d1U);
|
|
||||||
assert(hash("http://www.lavarnd.org/index.html") == 0xafad4c54U);
|
|
||||||
assert(hash("http://www.lavarnd.org/what/nist-test.html") == 0x0f25681eU);
|
|
||||||
assert(hash("http://www.macosxhints.com/") == 0x91b18d49U);
|
|
||||||
assert(hash("http://www.mellis.com/") == 0x7d61c12eU);
|
|
||||||
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm") == 0x5147d25cU);
|
|
||||||
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm") == 0x9a8b6805U);
|
|
||||||
assert(hash("http://www.paulnoll.com/") == 0x4cd2a447U);
|
|
||||||
assert(hash("http://www.pepysdiary.com/") == 0x1e549b14U);
|
|
||||||
assert(hash("http://www.sciencenews.org/index/home/activity/view") == 0x2fe1b574U);
|
|
||||||
assert(hash("http://www.skyandtelescope.com/") == 0xcf0cd31eU);
|
|
||||||
assert(hash("http://www.sput.nl/~rob/sirius.html") == 0x6c471669U);
|
|
||||||
assert(hash("http://www.systemexperts.com/") == 0x0e5eef1eU);
|
|
||||||
assert(hash("http://www.tq-international.com/phpBB3/index.php") == 0x2bed3602U);
|
|
||||||
assert(hash("http://www.travelquesttours.com/index.htm") == 0xb26249e0U);
|
|
||||||
assert(hash("http://www.wunderground.com/global/stations/89606.html") == 0x2c9b86a4U);
|
|
||||||
assert(hash(r10!"21701") == 0xe415e2bbU);
|
|
||||||
assert(hash(r10!"M21701") == 0x18a98d1dU);
|
|
||||||
assert(hash(r10!"2^21701-1") == 0xb7df8b7bU);
|
|
||||||
assert(hash(r10!"\x54\xc5") == 0x241e9075U);
|
|
||||||
assert(hash(r10!"\xc5\x54") == 0x063f70ddU);
|
|
||||||
assert(hash(r10!"23209") == 0x0295aed9U);
|
|
||||||
assert(hash(r10!"M23209") == 0x56a7f781U);
|
|
||||||
assert(hash(r10!"2^23209-1") == 0x253bc645U);
|
|
||||||
assert(hash(r10!"\x5a\xa9") == 0x46610921U);
|
|
||||||
assert(hash(r10!"\xa9\x5a") == 0x7c1577f9U);
|
|
||||||
assert(hash(r10!"391581216093") == 0x512b2851U);
|
|
||||||
assert(hash(r10!"391581*2^216093-1") == 0x76823999U);
|
|
||||||
assert(hash(r10!"\x05\xf9\x9d\x03\x4c\x81") == 0xc0586935U);
|
|
||||||
assert(hash(r10!"FEDCBA9876543210") == 0xf3415c85U);
|
|
||||||
assert(hash(r10!"\xfe\xdc\xba\x98\x76\x54\x32\x10") == 0x0ae4ff65U);
|
|
||||||
assert(hash(r10!"EFCDAB8967452301") == 0x58b79725U);
|
|
||||||
assert(hash(r10!"\xef\xcd\xab\x89\x67\x45\x23\x01") == 0xdea43aa5U);
|
|
||||||
assert(hash(r10!"0123456789ABCDEF") == 0x2bb3be35U);
|
|
||||||
assert(hash(r10!"\x01\x23\x45\x67\x89\xab\xcd\xef") == 0xea777a45U);
|
|
||||||
assert(hash(r10!"1032547698BADCFE") == 0x8f21c305U);
|
|
||||||
assert(hash(r10!"\x10\x32\x54\x76\x98\xba\xdc\xfe") == 0x5c9d0865U);
|
|
||||||
assert(hash(r500!"\x00") == 0xfa823dd5U);
|
|
||||||
assert(hash(r500!"\x07") == 0x21a27271U);
|
|
||||||
assert(hash(r500!"~") == 0x83c5c6d5U);
|
|
||||||
assert(hash(r500!"\x7f") == 0x813b0881U);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FNV-1a 64 bit test vectors
|
|
||||||
static if (size_t.sizeof == 8) @nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(hash("") == 0xcbf29ce484222325UL);
|
|
||||||
assert(hash("a") == 0xaf63dc4c8601ec8cUL);
|
|
||||||
assert(hash("b") == 0xaf63df4c8601f1a5UL);
|
|
||||||
assert(hash("c") == 0xaf63de4c8601eff2UL);
|
|
||||||
assert(hash("d") == 0xaf63d94c8601e773UL);
|
|
||||||
assert(hash("e") == 0xaf63d84c8601e5c0UL);
|
|
||||||
assert(hash("f") == 0xaf63db4c8601ead9UL);
|
|
||||||
assert(hash("fo") == 0x08985907b541d342UL);
|
|
||||||
assert(hash("foo") == 0xdcb27518fed9d577UL);
|
|
||||||
assert(hash("foob") == 0xdd120e790c2512afUL);
|
|
||||||
assert(hash("fooba") == 0xcac165afa2fef40aUL);
|
|
||||||
assert(hash("foobar") == 0x85944171f73967e8UL);
|
|
||||||
assert(hash("\0") == 0xaf63bd4c8601b7dfUL);
|
|
||||||
assert(hash("a\0") == 0x089be207b544f1e4UL);
|
|
||||||
assert(hash("b\0") == 0x08a61407b54d9b5fUL);
|
|
||||||
assert(hash("c\0") == 0x08a2ae07b54ab836UL);
|
|
||||||
assert(hash("d\0") == 0x0891b007b53c4869UL);
|
|
||||||
assert(hash("e\0") == 0x088e4a07b5396540UL);
|
|
||||||
assert(hash("f\0") == 0x08987c07b5420ebbUL);
|
|
||||||
assert(hash("fo\0") == 0xdcb28a18fed9f926UL);
|
|
||||||
assert(hash("foo\0") == 0xdd1270790c25b935UL);
|
|
||||||
assert(hash("foob\0") == 0xcac146afa2febf5dUL);
|
|
||||||
assert(hash("fooba\0") == 0x8593d371f738acfeUL);
|
|
||||||
assert(hash("foobar\0") == 0x34531ca7168b8f38UL);
|
|
||||||
assert(hash("ch") == 0x08a25607b54a22aeUL);
|
|
||||||
assert(hash("cho") == 0xf5faf0190cf90df3UL);
|
|
||||||
assert(hash("chon") == 0xf27397910b3221c7UL);
|
|
||||||
assert(hash("chong") == 0x2c8c2b76062f22e0UL);
|
|
||||||
assert(hash("chongo") == 0xe150688c8217b8fdUL);
|
|
||||||
assert(hash("chongo ") == 0xf35a83c10e4f1f87UL);
|
|
||||||
assert(hash("chongo w") == 0xd1edd10b507344d0UL);
|
|
||||||
assert(hash("chongo wa") == 0x2a5ee739b3ddb8c3UL);
|
|
||||||
assert(hash("chongo was") == 0xdcfb970ca1c0d310UL);
|
|
||||||
assert(hash("chongo was ") == 0x4054da76daa6da90UL);
|
|
||||||
assert(hash("chongo was h") == 0xf70a2ff589861368UL);
|
|
||||||
assert(hash("chongo was he") == 0x4c628b38aed25f17UL);
|
|
||||||
assert(hash("chongo was her") == 0x9dd1f6510f78189fUL);
|
|
||||||
assert(hash("chongo was here") == 0xa3de85bd491270ceUL);
|
|
||||||
assert(hash("chongo was here!") == 0x858e2fa32a55e61dUL);
|
|
||||||
assert(hash("chongo was here!\n") == 0x46810940eff5f915UL);
|
|
||||||
assert(hash("ch\0") == 0xf5fadd190cf8edaaUL);
|
|
||||||
assert(hash("cho\0") == 0xf273ed910b32b3e9UL);
|
|
||||||
assert(hash("chon\0") == 0x2c8c5276062f6525UL);
|
|
||||||
assert(hash("chong\0") == 0xe150b98c821842a0UL);
|
|
||||||
assert(hash("chongo\0") == 0xf35aa3c10e4f55e7UL);
|
|
||||||
assert(hash("chongo \0") == 0xd1ed680b50729265UL);
|
|
||||||
assert(hash("chongo w\0") == 0x2a5f0639b3dded70UL);
|
|
||||||
assert(hash("chongo wa\0") == 0xdcfbaa0ca1c0f359UL);
|
|
||||||
assert(hash("chongo was\0") == 0x4054ba76daa6a430UL);
|
|
||||||
assert(hash("chongo was \0") == 0xf709c7f5898562b0UL);
|
|
||||||
assert(hash("chongo was h\0") == 0x4c62e638aed2f9b8UL);
|
|
||||||
assert(hash("chongo was he\0") == 0x9dd1a8510f779415UL);
|
|
||||||
assert(hash("chongo was her\0") == 0xa3de2abd4911d62dUL);
|
|
||||||
assert(hash("chongo was here\0") == 0x858e0ea32a55ae0aUL);
|
|
||||||
assert(hash("chongo was here!\0") == 0x46810f40eff60347UL);
|
|
||||||
assert(hash("chongo was here!\n\0") == 0xc33bce57bef63eafUL);
|
|
||||||
assert(hash("cu") == 0x08a24307b54a0265UL);
|
|
||||||
assert(hash("cur") == 0xf5b9fd190cc18d15UL);
|
|
||||||
assert(hash("curd") == 0x4c968290ace35703UL);
|
|
||||||
assert(hash("curds") == 0x07174bd5c64d9350UL);
|
|
||||||
assert(hash("curds ") == 0x5a294c3ff5d18750UL);
|
|
||||||
assert(hash("curds a") == 0x05b3c1aeb308b843UL);
|
|
||||||
assert(hash("curds an") == 0xb92a48da37d0f477UL);
|
|
||||||
assert(hash("curds and") == 0x73cdddccd80ebc49UL);
|
|
||||||
assert(hash("curds and ") == 0xd58c4c13210a266bUL);
|
|
||||||
assert(hash("curds and w") == 0xe78b6081243ec194UL);
|
|
||||||
assert(hash("curds and wh") == 0xb096f77096a39f34UL);
|
|
||||||
assert(hash("curds and whe") == 0xb425c54ff807b6a3UL);
|
|
||||||
assert(hash("curds and whey") == 0x23e520e2751bb46eUL);
|
|
||||||
assert(hash("curds and whey\n") == 0x1a0b44ccfe1385ecUL);
|
|
||||||
assert(hash("cu\0") == 0xf5ba4b190cc2119fUL);
|
|
||||||
assert(hash("cur\0") == 0x4c962690ace2baafUL);
|
|
||||||
assert(hash("curd\0") == 0x0716ded5c64cda19UL);
|
|
||||||
assert(hash("curds\0") == 0x5a292c3ff5d150f0UL);
|
|
||||||
assert(hash("curds \0") == 0x05b3e0aeb308ecf0UL);
|
|
||||||
assert(hash("curds a\0") == 0xb92a5eda37d119d9UL);
|
|
||||||
assert(hash("curds an\0") == 0x73ce41ccd80f6635UL);
|
|
||||||
assert(hash("curds and\0") == 0xd58c2c132109f00bUL);
|
|
||||||
assert(hash("curds and \0") == 0xe78baf81243f47d1UL);
|
|
||||||
assert(hash("curds and w\0") == 0xb0968f7096a2ee7cUL);
|
|
||||||
assert(hash("curds and wh\0") == 0xb425a84ff807855cUL);
|
|
||||||
assert(hash("curds and whe\0") == 0x23e4e9e2751b56f9UL);
|
|
||||||
assert(hash("curds and whey\0") == 0x1a0b4eccfe1396eaUL);
|
|
||||||
assert(hash("curds and whey\n\0") == 0x54abd453bb2c9004UL);
|
|
||||||
assert(hash("hi") == 0x08ba5f07b55ec3daUL);
|
|
||||||
assert(hash("hi\0") == 0x337354193006cb6eUL);
|
|
||||||
assert(hash("hello") == 0xa430d84680aabd0bUL);
|
|
||||||
assert(hash("hello\0") == 0xa9bc8acca21f39b1UL);
|
|
||||||
assert(hash("\xff\x00\x00\x01") == 0x6961196491cc682dUL);
|
|
||||||
assert(hash("\x01\x00\x00\xff") == 0xad2bb1774799dfe9UL);
|
|
||||||
assert(hash("\xff\x00\x00\x02") == 0x6961166491cc6314UL);
|
|
||||||
assert(hash("\x02\x00\x00\xff") == 0x8d1bb3904a3b1236UL);
|
|
||||||
assert(hash("\xff\x00\x00\x03") == 0x6961176491cc64c7UL);
|
|
||||||
assert(hash("\x03\x00\x00\xff") == 0xed205d87f40434c7UL);
|
|
||||||
assert(hash("\xff\x00\x00\x04") == 0x6961146491cc5faeUL);
|
|
||||||
assert(hash("\x04\x00\x00\xff") == 0xcd3baf5e44f8ad9cUL);
|
|
||||||
assert(hash("\x40\x51\x4e\x44") == 0xe3b36596127cd6d8UL);
|
|
||||||
assert(hash("\x44\x4e\x51\x40") == 0xf77f1072c8e8a646UL);
|
|
||||||
assert(hash("\x40\x51\x4e\x4a") == 0xe3b36396127cd372UL);
|
|
||||||
assert(hash("\x4a\x4e\x51\x40") == 0x6067dce9932ad458UL);
|
|
||||||
assert(hash("\x40\x51\x4e\x54") == 0xe3b37596127cf208UL);
|
|
||||||
assert(hash("\x54\x4e\x51\x40") == 0x4b7b10fa9fe83936UL);
|
|
||||||
assert(hash("127.0.0.1") == 0xaabafe7104d914beUL);
|
|
||||||
assert(hash("127.0.0.1\0") == 0xf4d3180b3cde3edaUL);
|
|
||||||
assert(hash("127.0.0.2") == 0xaabafd7104d9130bUL);
|
|
||||||
assert(hash("127.0.0.2\0") == 0xf4cfb20b3cdb5bb1UL);
|
|
||||||
assert(hash("127.0.0.3") == 0xaabafc7104d91158UL);
|
|
||||||
assert(hash("127.0.0.3\0") == 0xf4cc4c0b3cd87888UL);
|
|
||||||
assert(hash("64.81.78.68") == 0xe729bac5d2a8d3a7UL);
|
|
||||||
assert(hash("64.81.78.68\0") == 0x74bc0524f4dfa4c5UL);
|
|
||||||
assert(hash("64.81.78.74") == 0xe72630c5d2a5b352UL);
|
|
||||||
assert(hash("64.81.78.74\0") == 0x6b983224ef8fb456UL);
|
|
||||||
assert(hash("64.81.78.84") == 0xe73042c5d2ae266dUL);
|
|
||||||
assert(hash("64.81.78.84\0") == 0x8527e324fdeb4b37UL);
|
|
||||||
assert(hash("feedface") == 0x0a83c86fee952abcUL);
|
|
||||||
assert(hash("feedface\0") == 0x7318523267779d74UL);
|
|
||||||
assert(hash("feedfacedaffdeed") == 0x3e66d3d56b8caca1UL);
|
|
||||||
assert(hash("feedfacedaffdeed\0") == 0x956694a5c0095593UL);
|
|
||||||
assert(hash("feedfacedeadbeef") == 0xcac54572bb1a6fc8UL);
|
|
||||||
assert(hash("feedfacedeadbeef\0") == 0xa7a4c9f3edebf0d8UL);
|
|
||||||
assert(hash("line 1\nline 2\nline 3") == 0x7829851fac17b143UL);
|
|
||||||
assert(hash("chongo <Landon Curt Noll> /\\../\\") == 0x2c8f4c9af81bcf06UL);
|
|
||||||
assert(hash("chongo <Landon Curt Noll> /\\../\\\0") == 0xd34e31539740c732UL);
|
|
||||||
assert(hash("chongo (Landon Curt Noll) /\\../\\") == 0x3605a2ac253d2db1UL);
|
|
||||||
assert(hash("chongo (Landon Curt Noll) /\\../\\\0") == 0x08c11b8346f4a3c3UL);
|
|
||||||
assert(hash("http://antwrp.gsfc.nasa.gov/apod/astropix.html") == 0x6be396289ce8a6daUL);
|
|
||||||
assert(hash("http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash") == 0xd9b957fb7fe794c5UL);
|
|
||||||
assert(hash("http://epod.usra.edu/") == 0x05be33da04560a93UL);
|
|
||||||
assert(hash("http://exoplanet.eu/") == 0x0957f1577ba9747cUL);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/cam3/") == 0xda2cc3acc24fba57UL);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/cams/HMcam/") == 0x74136f185b29e7f0UL);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/deformation.html") == 0xb2f2b4590edb93b2UL);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/images.html") == 0xb3608fce8b86ae04UL);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/maps.html") == 0x4a3a865079359063UL);
|
|
||||||
assert(hash("http://hvo.wr.usgs.gov/volcanowatch/current_issue.html") == 0x5b3a7ef496880a50UL);
|
|
||||||
assert(hash("http://neo.jpl.nasa.gov/risk/") == 0x48fae3163854c23bUL);
|
|
||||||
assert(hash("http://norvig.com/21-days.html") == 0x07aaa640476e0b9aUL);
|
|
||||||
assert(hash("http://primes.utm.edu/curios/home.php") == 0x2f653656383a687dUL);
|
|
||||||
assert(hash("http://slashdot.org/") == 0xa1031f8e7599d79cUL);
|
|
||||||
assert(hash("http://tux.wr.usgs.gov/Maps/155.25-19.5.html") == 0xa31908178ff92477UL);
|
|
||||||
assert(hash("http://volcano.wr.usgs.gov/kilaueastatus.php") == 0x097edf3c14c3fb83UL);
|
|
||||||
assert(hash("http://www.avo.alaska.edu/activity/Redoubt.php") == 0xb51ca83feaa0971bUL);
|
|
||||||
assert(hash("http://www.dilbert.com/fast/") == 0xdd3c0d96d784f2e9UL);
|
|
||||||
assert(hash("http://www.fourmilab.ch/gravitation/orbits/") == 0x86cd26a9ea767d78UL);
|
|
||||||
assert(hash("http://www.fpoa.net/") == 0xe6b215ff54a30c18UL);
|
|
||||||
assert(hash("http://www.ioccc.org/index.html") == 0xec5b06a1c5531093UL);
|
|
||||||
assert(hash("http://www.isthe.com/cgi-bin/number.cgi") == 0x45665a929f9ec5e5UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/bio.html") == 0x8c7609b4a9f10907UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/index.html") == 0x89aac3a491f0d729UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/src/calc/lucas-calc") == 0x32ce6b26e0f4a403UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/astro/venus2004.html") == 0x614ab44e02b53e01UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/astro/vita.html") == 0xfa6472eb6eef3290UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/comp/c/expert.html") == 0x9e5d75eb1948eb6aUL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/comp/calc/index.html") == 0xb6d12ad4a8671852UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/comp/fnv/index.html") == 0x88826f56eba07af1UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/number/howhigh.html") == 0x44535bf2645bc0fdUL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/number/number.html") == 0x169388ffc21e3728UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html") == 0xf68aac9e396d8224UL);
|
|
||||||
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest") == 0x8e87d7e7472b3883UL);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/corpspeak.cgi") == 0x295c26caa8b423deUL);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/haiku.cgi") == 0x322c814292e72176UL);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/rand-none.cgi") == 0x8a06550eb8af7268UL);
|
|
||||||
assert(hash("http://www.lavarnd.org/cgi-bin/randdist.cgi") == 0xef86d60e661bcf71UL);
|
|
||||||
assert(hash("http://www.lavarnd.org/index.html") == 0x9e5426c87f30ee54UL);
|
|
||||||
assert(hash("http://www.lavarnd.org/what/nist-test.html") == 0xf1ea8aa826fd047eUL);
|
|
||||||
assert(hash("http://www.macosxhints.com/") == 0x0babaf9a642cb769UL);
|
|
||||||
assert(hash("http://www.mellis.com/") == 0x4b3341d4068d012eUL);
|
|
||||||
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm") == 0xd15605cbc30a335cUL);
|
|
||||||
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm") == 0x5b21060aed8412e5UL);
|
|
||||||
assert(hash("http://www.paulnoll.com/") == 0x45e2cda1ce6f4227UL);
|
|
||||||
assert(hash("http://www.pepysdiary.com/") == 0x50ae3745033ad7d4UL);
|
|
||||||
assert(hash("http://www.sciencenews.org/index/home/activity/view") == 0xaa4588ced46bf414UL);
|
|
||||||
assert(hash("http://www.skyandtelescope.com/") == 0xc1b0056c4a95467eUL);
|
|
||||||
assert(hash("http://www.sput.nl/~rob/sirius.html") == 0x56576a71de8b4089UL);
|
|
||||||
assert(hash("http://www.systemexperts.com/") == 0xbf20965fa6dc927eUL);
|
|
||||||
assert(hash("http://www.tq-international.com/phpBB3/index.php") == 0x569f8383c2040882UL);
|
|
||||||
assert(hash("http://www.travelquesttours.com/index.htm") == 0xe1e772fba08feca0UL);
|
|
||||||
assert(hash("http://www.wunderground.com/global/stations/89606.html") == 0x4ced94af97138ac4UL);
|
|
||||||
assert(hash(r10!"21701") == 0xc4112ffb337a82fbUL);
|
|
||||||
assert(hash(r10!"M21701") == 0xd64a4fd41de38b7dUL);
|
|
||||||
assert(hash(r10!"2^21701-1") == 0x4cfc32329edebcbbUL);
|
|
||||||
assert(hash(r10!"\x54\xc5") == 0x0803564445050395UL);
|
|
||||||
assert(hash(r10!"\xc5\x54") == 0xaa1574ecf4642ffdUL);
|
|
||||||
assert(hash(r10!"23209") == 0x694bc4e54cc315f9UL);
|
|
||||||
assert(hash(r10!"M23209") == 0xa3d7cb273b011721UL);
|
|
||||||
assert(hash(r10!"2^23209-1") == 0x577c2f8b6115bfa5UL);
|
|
||||||
assert(hash(r10!"\x5a\xa9") == 0xb7ec8c1a769fb4c1UL);
|
|
||||||
assert(hash(r10!"\xa9\x5a") == 0x5d5cfce63359ab19UL);
|
|
||||||
assert(hash(r10!"391581216093") == 0x33b96c3cd65b5f71UL);
|
|
||||||
assert(hash(r10!"391581*2^216093-1") == 0xd845097780602bb9UL);
|
|
||||||
assert(hash(r10!"\x05\xf9\x9d\x03\x4c\x81") == 0x84d47645d02da3d5UL);
|
|
||||||
assert(hash(r10!"FEDCBA9876543210") == 0x83544f33b58773a5UL);
|
|
||||||
assert(hash(r10!"\xfe\xdc\xba\x98\x76\x54\x32\x10") == 0x9175cbb2160836c5UL);
|
|
||||||
assert(hash(r10!"EFCDAB8967452301") == 0xc71b3bc175e72bc5UL);
|
|
||||||
assert(hash(r10!"\xef\xcd\xab\x89\x67\x45\x23\x01") == 0x636806ac222ec985UL);
|
|
||||||
assert(hash(r10!"0123456789ABCDEF") == 0xb6ef0e6950f52ed5UL);
|
|
||||||
assert(hash(r10!"\x01\x23\x45\x67\x89\xab\xcd\xef") == 0xead3d8a0f3dfdaa5UL);
|
|
||||||
assert(hash(r10!"1032547698BADCFE") == 0x922908fe9a861ba5UL);
|
|
||||||
assert(hash(r10!"\x10\x32\x54\x76\x98\xba\xdc\xfe") == 0x6d4821de275fd5c5UL);
|
|
||||||
assert(hash(r500!"\x00") == 0x1fe3fce62bd816b5UL);
|
|
||||||
assert(hash(r500!"\x07") == 0xc23e9fccd6f70591UL);
|
|
||||||
assert(hash(r500!"~") == 0xc1af12bdfe16b5b5UL);
|
|
||||||
assert(hash(r500!"\x7f") == 0x39e9f18f2f85e221UL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether $(D_PARAM hasher) is hash function for $(D_PARAM T), i.e.
|
* Determines whether $(D_PARAM hasher) is hash function for $(D_PARAM T), i.e.
|
||||||
* it is callable with a value of type $(D_PARAM T) and returns a
|
* it is callable with a value of type $(D_PARAM T) and returns a
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright: Eugene Wissner 2018.
|
* Copyright: Eugene Wissner 2018-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
|
@ -107,11 +107,7 @@ struct Integer
|
|||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
this(shared Allocator allocator) @nogc nothrow pure @safe
|
this(shared Allocator allocator) @nogc nothrow pure @safe
|
||||||
in
|
in (allocator !is null)
|
||||||
{
|
|
||||||
assert(allocator !is null);
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -867,11 +863,7 @@ struct Integer
|
|||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
ref Integer opOpAssign(string op : "/")(auto ref const Integer operand)
|
ref Integer opOpAssign(string op : "/")(auto ref const Integer operand)
|
||||||
in
|
in (operand.length > 0, "Division by zero.")
|
||||||
{
|
|
||||||
assert(operand.length > 0, "Division by zero.");
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
divide(operand, this);
|
divide(operand, this);
|
||||||
return this;
|
return this;
|
||||||
@ -879,37 +871,12 @@ struct Integer
|
|||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
ref Integer opOpAssign(string op : "%")(auto ref const Integer operand)
|
ref Integer opOpAssign(string op : "%")(auto ref const Integer operand)
|
||||||
in
|
in (operand.length > 0, "Division by zero")
|
||||||
{
|
|
||||||
assert(operand.length > 0, "Division by zero.");
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
divide(operand, null, this);
|
divide(operand, null, this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
auto h1 = Integer(18);
|
|
||||||
auto h2 = Integer(4);
|
|
||||||
h1 %= h2;
|
|
||||||
assert(h1 == 2);
|
|
||||||
|
|
||||||
h1 = 8;
|
|
||||||
h1 %= h2;
|
|
||||||
assert(h1 == 0);
|
|
||||||
|
|
||||||
h1 = 7;
|
|
||||||
h1 %= h2;
|
|
||||||
assert(h1 == 3);
|
|
||||||
|
|
||||||
h1 = 56088;
|
|
||||||
h2 = 456;
|
|
||||||
h1 /= h2;
|
|
||||||
assert(h1 == 123);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
ref Integer opOpAssign(string op : ">>")(const size_t operand)
|
ref Integer opOpAssign(string op : ">>")(const size_t operand)
|
||||||
{
|
{
|
||||||
@ -1055,7 +1022,7 @@ struct Integer
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
///
|
||||||
@nogc nothrow pure @safe unittest
|
@nogc nothrow pure @safe unittest
|
||||||
{
|
{
|
||||||
auto h1 = Integer(79);
|
auto h1 = Integer(79);
|
||||||
@ -1162,11 +1129,7 @@ struct Integer
|
|||||||
/// ditto
|
/// ditto
|
||||||
Integer opBinary(string op)(const auto ref Integer operand) const
|
Integer opBinary(string op)(const auto ref Integer operand) const
|
||||||
if (op == "/" || op == "%")
|
if (op == "/" || op == "%")
|
||||||
in
|
in (operand.length > 0, "Division by zero")
|
||||||
{
|
|
||||||
assert(operand.length > 0, "Division by zero.");
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
mixin("return Integer(this, allocator) " ~ op ~ "= operand;");
|
mixin("return Integer(this, allocator) " ~ op ~ "= operand;");
|
||||||
}
|
}
|
||||||
@ -1281,11 +1244,7 @@ struct Integer
|
|||||||
if ((is(Q : typeof(null))
|
if ((is(Q : typeof(null))
|
||||||
|| (is(Q : Integer) && __traits(isRef, quotient)))
|
|| (is(Q : Integer) && __traits(isRef, quotient)))
|
||||||
&& (ARGS.length == 0 || (ARGS.length == 1 && is(ARGS[0] : Integer))))
|
&& (ARGS.length == 0 || (ARGS.length == 1 && is(ARGS[0] : Integer))))
|
||||||
in
|
in (divisor != 0, "Division by zero")
|
||||||
{
|
|
||||||
assert(divisor != 0, "Division by zero.");
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
if (compare(divisor) < 0)
|
if (compare(divisor) < 0)
|
||||||
{
|
{
|
||||||
@ -1526,46 +1485,5 @@ struct Integer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
{
|
|
||||||
Integer integer;
|
|
||||||
assert(integer.toArray().length == 0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto integer = Integer(0x03);
|
|
||||||
ubyte[1] expected = [ 0x03 ];
|
|
||||||
|
|
||||||
auto array = integer.toArray();
|
|
||||||
assert(equal(array[], expected[]));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
ubyte[63] expected = [
|
|
||||||
0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
|
||||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
|
||||||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
|
||||||
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
|
|
||||||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
|
|
||||||
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
|
|
||||||
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
|
|
||||||
0x39, 0x3a, 0x3b, 0x00, 0x61, 0x62, 0x63,
|
|
||||||
];
|
|
||||||
auto integer = Integer(Sign.positive, expected[]);
|
|
||||||
|
|
||||||
auto array = integer.toArray();
|
|
||||||
assert(equal(array[], expected[]));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
ubyte[14] expected = [
|
|
||||||
0x22, 0x33, 0x44, 0x55, 0x05, 0x06, 0x07,
|
|
||||||
0x08, 0x3a, 0x3b, 0x00, 0x61, 0x62, 0x63,
|
|
||||||
];
|
|
||||||
auto integer = Integer(Sign.positive, expected[]);
|
|
||||||
|
|
||||||
auto array = integer.toArray();
|
|
||||||
assert(equal(array[], expected[]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mixin DefaultAllocator;
|
mixin DefaultAllocator;
|
||||||
}
|
}
|
||||||
|
@ -254,21 +254,6 @@ if (isFloatingPoint!F)
|
|||||||
assert(classify(-real.infinity) == FloatingPointClass.infinite);
|
assert(classify(-real.infinity) == FloatingPointClass.infinite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static if (ieeePrecision!float == IEEEPrecision.doubleExtended)
|
|
||||||
{
|
|
||||||
assert(classify(1.68105e-10) == FloatingPointClass.normal);
|
|
||||||
assert(classify(1.68105e-4932L) == FloatingPointClass.subnormal);
|
|
||||||
|
|
||||||
// Emulate unnormals, because they aren't generated anymore since i386
|
|
||||||
FloatBits!real unnormal;
|
|
||||||
unnormal.exp = 0x123;
|
|
||||||
unnormal.mantissa = 0x1;
|
|
||||||
assert(classify(unnormal) == FloatingPointClass.subnormal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether $(D_PARAM x) is a finite number.
|
* Determines whether $(D_PARAM x) is a finite number.
|
||||||
*
|
*
|
||||||
@ -581,11 +566,7 @@ if (isFloatingPoint!F)
|
|||||||
*/
|
*/
|
||||||
H pow(I, G, H)(in auto ref I x, in auto ref G y, in auto ref H z)
|
H pow(I, G, H)(in auto ref I x, in auto ref G y, in auto ref H z)
|
||||||
if (isIntegral!I && isIntegral!G && isIntegral!H)
|
if (isIntegral!I && isIntegral!G && isIntegral!H)
|
||||||
in
|
in (z > 0, "Division by zero")
|
||||||
{
|
|
||||||
assert(z > 0, "Division by zero.");
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
G mask = G.max / 2 + 1;
|
G mask = G.max / 2 + 1;
|
||||||
H result;
|
H result;
|
||||||
@ -622,11 +603,7 @@ do
|
|||||||
/// ditto
|
/// ditto
|
||||||
I pow(I)(const auto ref I x, const auto ref I y, const auto ref I z)
|
I pow(I)(const auto ref I x, const auto ref I y, const auto ref I z)
|
||||||
if (is(I == Integer))
|
if (is(I == Integer))
|
||||||
in
|
in (z.length > 0, "Division by zero")
|
||||||
{
|
|
||||||
assert(z.length > 0, "Division by zero.");
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
auto tmp1 = Integer(x, x.allocator);
|
auto tmp1 = Integer(x, x.allocator);
|
||||||
@ -708,33 +685,3 @@ bool isPseudoprime(ulong x) @nogc nothrow pure @safe
|
|||||||
assert(15485867.isPseudoprime);
|
assert(15485867.isPseudoprime);
|
||||||
assert(!15485868.isPseudoprime);
|
assert(!15485868.isPseudoprime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(74653.isPseudoprime);
|
|
||||||
assert(74687.isPseudoprime);
|
|
||||||
assert(74699.isPseudoprime);
|
|
||||||
assert(74707.isPseudoprime);
|
|
||||||
assert(74713.isPseudoprime);
|
|
||||||
assert(74717.isPseudoprime);
|
|
||||||
assert(74719.isPseudoprime);
|
|
||||||
assert(74747.isPseudoprime);
|
|
||||||
assert(74759.isPseudoprime);
|
|
||||||
assert(74761.isPseudoprime);
|
|
||||||
assert(74771.isPseudoprime);
|
|
||||||
assert(74779.isPseudoprime);
|
|
||||||
assert(74797.isPseudoprime);
|
|
||||||
assert(74821.isPseudoprime);
|
|
||||||
assert(74827.isPseudoprime);
|
|
||||||
assert(9973.isPseudoprime);
|
|
||||||
assert(49979693.isPseudoprime);
|
|
||||||
assert(104395303.isPseudoprime);
|
|
||||||
assert(593441861.isPseudoprime);
|
|
||||||
assert(104729.isPseudoprime);
|
|
||||||
assert(15485867.isPseudoprime);
|
|
||||||
assert(49979693.isPseudoprime);
|
|
||||||
assert(104395303.isPseudoprime);
|
|
||||||
assert(593441861.isPseudoprime);
|
|
||||||
assert(899809363.isPseudoprime);
|
|
||||||
assert(982451653.isPseudoprime);
|
|
||||||
}
|
|
||||||
|
@ -324,13 +324,3 @@ else version (Windows)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static if (is(PlatformEntropySource)) @nogc @system unittest
|
|
||||||
{
|
|
||||||
import tanya.memory.smartref : unique;
|
|
||||||
|
|
||||||
auto source = defaultAllocator.unique!PlatformEntropySource();
|
|
||||||
|
|
||||||
assert(source.threshold == 32);
|
|
||||||
assert(source.strong);
|
|
||||||
}
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
/**
|
/**
|
||||||
* Network interfaces.
|
* Network interfaces.
|
||||||
*
|
*
|
||||||
* Copyright: Eugene Wissner 2018.
|
* Copyright: Eugene Wissner 2018-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
module tanya.net.iface;
|
module tanya.net.iface;
|
||||||
|
|
||||||
import tanya.algorithm.comparison;
|
|
||||||
import tanya.algorithm.mutation;
|
import tanya.algorithm.mutation;
|
||||||
import tanya.container.string;
|
import tanya.container.string;
|
||||||
import tanya.meta.trait;
|
import tanya.meta.trait;
|
||||||
@ -209,20 +208,3 @@ String indexToName(uint index) @nogc nothrow @trusted
|
|||||||
return String(findNullTerminated(buffer));
|
return String(findNullTerminated(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
version (linux)
|
|
||||||
{
|
|
||||||
assert(equal(indexToName(1)[], "lo"));
|
|
||||||
}
|
|
||||||
else version (Windows)
|
|
||||||
{
|
|
||||||
assert(equal(indexToName(1)[], "loopback_0"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(equal(indexToName(1)[], "lo0"));
|
|
||||||
}
|
|
||||||
assert(indexToName(uint.max).empty);
|
|
||||||
}
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
/**
|
/**
|
||||||
* Internet utilities.
|
* Internet utilities.
|
||||||
*
|
*
|
||||||
* Copyright: Eugene Wissner 2016-2018.
|
* Copyright: Eugene Wissner 2016-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
@ -72,11 +72,7 @@ if (L > ubyte.sizeof && L <= ulong.sizeof)
|
|||||||
*/
|
*/
|
||||||
this(T)(T value)
|
this(T)(T value)
|
||||||
if (isUnsigned!T)
|
if (isUnsigned!T)
|
||||||
in
|
in (value <= (2 ^^ (L * 8)) - 1)
|
||||||
{
|
|
||||||
assert(value <= (2 ^^ (L * 8)) - 1);
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
this.value = value & StorageType.max;
|
this.value = value & StorageType.max;
|
||||||
}
|
}
|
||||||
@ -87,11 +83,7 @@ if (L > ubyte.sizeof && L <= ulong.sizeof)
|
|||||||
* Precondition: $(D_INLINECODE length > 0).
|
* Precondition: $(D_INLINECODE length > 0).
|
||||||
*/
|
*/
|
||||||
@property ubyte back() const
|
@property ubyte back() const
|
||||||
in
|
in (this.length > 0)
|
||||||
{
|
|
||||||
assert(this.length > 0);
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
return this.value & 0xff;
|
return this.value & 0xff;
|
||||||
}
|
}
|
||||||
@ -102,11 +94,7 @@ if (L > ubyte.sizeof && L <= ulong.sizeof)
|
|||||||
* Precondition: $(D_INLINECODE length > 0).
|
* Precondition: $(D_INLINECODE length > 0).
|
||||||
*/
|
*/
|
||||||
@property ubyte front() const
|
@property ubyte front() const
|
||||||
in
|
in (this.length > 0)
|
||||||
{
|
|
||||||
assert(this.length > 0);
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
return (this.value >> ((this.length - 1) * 8)) & 0xff;
|
return (this.value >> ((this.length - 1) * 8)) & 0xff;
|
||||||
}
|
}
|
||||||
@ -117,11 +105,7 @@ if (L > ubyte.sizeof && L <= ulong.sizeof)
|
|||||||
* Precondition: $(D_INLINECODE length > 0).
|
* Precondition: $(D_INLINECODE length > 0).
|
||||||
*/
|
*/
|
||||||
void popBack()
|
void popBack()
|
||||||
in
|
in (this.length > 0)
|
||||||
{
|
|
||||||
assert(this.length > 0);
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
this.value >>= 8;
|
this.value >>= 8;
|
||||||
--this.size;
|
--this.size;
|
||||||
@ -133,11 +117,7 @@ if (L > ubyte.sizeof && L <= ulong.sizeof)
|
|||||||
* Precondition: $(D_INLINECODE length > 0).
|
* Precondition: $(D_INLINECODE length > 0).
|
||||||
*/
|
*/
|
||||||
void popFront()
|
void popFront()
|
||||||
in
|
in (this.length > 0)
|
||||||
{
|
|
||||||
assert(this.length > 0);
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
this.value &= StorageType.max >> ((StorageType.sizeof - this.length) * 8);
|
this.value &= StorageType.max >> ((StorageType.sizeof - this.length) * 8);
|
||||||
--this.size;
|
--this.size;
|
||||||
@ -189,15 +169,6 @@ if (L > ubyte.sizeof && L <= ulong.sizeof)
|
|||||||
assert(networkOrder.empty);
|
assert(networkOrder.empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static tests
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static assert(isBidirectionalRange!(NetworkOrder!4));
|
|
||||||
static assert(isBidirectionalRange!(NetworkOrder!8));
|
|
||||||
static assert(!is(NetworkOrder!9));
|
|
||||||
static assert(!is(NetworkOrder!1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the $(D_KEYWORD ubyte) input range $(D_PARAM range) to
|
* Converts the $(D_KEYWORD ubyte) input range $(D_PARAM range) to
|
||||||
* $(D_PARAM T).
|
* $(D_PARAM T).
|
||||||
|
@ -384,17 +384,6 @@ if (isForwardRange!R && is(Unqual!(ElementType!R) == char) && hasLength!R)
|
|||||||
return range.empty ? typeof(return)(result) : typeof(return)();
|
return range.empty ? typeof(return)(result) : typeof(return)();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rejects malformed addresses
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(address4("256.0.0.1").isNothing);
|
|
||||||
assert(address4(".0.0.1").isNothing);
|
|
||||||
assert(address4("0..0.1").isNothing);
|
|
||||||
assert(address4("0.0.0.").isNothing);
|
|
||||||
assert(address4("0.0.").isNothing);
|
|
||||||
assert(address4("").isNothing);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an $(D_PSYMBOL Address4) from raw bytes in network byte order.
|
* Constructs an $(D_PSYMBOL Address4) from raw bytes in network byte order.
|
||||||
*
|
*
|
||||||
@ -447,20 +436,6 @@ if (isInputRange!R && is(Unqual!(ElementType!R) == ubyte))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
assert(address4(cast(ubyte[]) []).isNothing);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assignment and comparison works
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
auto address1 = Address4.loopback();
|
|
||||||
auto address2 = Address4.any();
|
|
||||||
address1 = address2;
|
|
||||||
assert(address1 == address2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IPv6 internet address.
|
* IPv6 internet address.
|
||||||
*/
|
*/
|
||||||
@ -770,50 +745,6 @@ struct Address6
|
|||||||
assert(actual == "1:2:3:4:5:6:7:8");
|
assert(actual == "1:2:3:4:5:6:7:8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
char[18] actual;
|
|
||||||
|
|
||||||
address6("ff00:2:3:4:5:6:7:8").get.toString(arrayInserter(actual));
|
|
||||||
assert(actual[] == "ff00:2:3:4:5:6:7:8");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skips zero group in the middle
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
char[12] actual;
|
|
||||||
|
|
||||||
address6("1::4:5:6:7:8").get.toString(arrayInserter(actual));
|
|
||||||
assert(actual[] == "1::4:5:6:7:8");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Doesn't replace lonely zeroes
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
char[15] actual;
|
|
||||||
|
|
||||||
address6("0:1:0:2:3:0:4:0").get.toString(arrayInserter(actual));
|
|
||||||
assert(actual[] == "0:1:0:2:3:0:4:0");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skips zero group at the beginning
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
char[13] actual;
|
|
||||||
|
|
||||||
address6("::3:4:5:6:7:8").get.toString(arrayInserter(actual));
|
|
||||||
assert(actual[] == "::3:4:5:6:7:8");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skips zero group at the end
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
char[13] actual;
|
|
||||||
|
|
||||||
address6("1:2:3:4:5:6::").get.toString(arrayInserter(actual));
|
|
||||||
assert(actual[] == "1:2:3:4:5:6::");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeGroup(OR)(ref OR output, ref size_t i) const
|
private void writeGroup(OR)(ref OR output, ref size_t i) const
|
||||||
{
|
{
|
||||||
ubyte low = this.address[i] & 0xf;
|
ubyte low = this.address[i] & 0xf;
|
||||||
@ -1101,75 +1032,6 @@ CopyTail:
|
|||||||
return typeof(return)(result);
|
return typeof(return)(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[16] expected = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8];
|
|
||||||
auto actual = address6("1:2:3:4:5:6:7:8");
|
|
||||||
assert(actual.get.address == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[16] expected;
|
|
||||||
auto actual = address6("::");
|
|
||||||
assert(actual.get.address == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
|
|
||||||
auto actual = address6("::1");
|
|
||||||
assert(actual.get.address == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[16] expected = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
||||||
auto actual = address6("1::");
|
|
||||||
assert(actual.get.address == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rejects malformed addresses
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
assert(address6("").isNothing);
|
|
||||||
assert(address6(":").isNothing);
|
|
||||||
assert(address6(":a").isNothing);
|
|
||||||
assert(address6("a:").isNothing);
|
|
||||||
assert(address6("1:2:3:4::6:").isNothing);
|
|
||||||
assert(address6("fe80:2:3:4::6:7:8%").isNothing);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parses embedded IPv4 address
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4];
|
|
||||||
auto actual = address6("0:0:0:0:0:0:1.2.3.4");
|
|
||||||
assert(actual.get.address == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4];
|
|
||||||
auto actual = address6("::1.2.3.4");
|
|
||||||
assert(actual.get.address == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 1, 2, 3, 4];
|
|
||||||
auto actual = address6("::5:6:1.2.3.4");
|
|
||||||
assert(actual.get.address == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow @safe unittest
|
|
||||||
{
|
|
||||||
assert(address6("0:0:0:0:0:0:1.2.3.").isNothing);
|
|
||||||
assert(address6("0:0:0:0:0:0:1.2:3.4").isNothing);
|
|
||||||
assert(address6("0:0:0:0:0:0:1.2.3.4.").isNothing);
|
|
||||||
assert(address6("fe80:0:0:0:0:0:1.2.3.4%1").get.scopeID == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an $(D_PSYMBOL Address6) from raw bytes in network byte order and
|
* Constructs an $(D_PSYMBOL Address6) from raw bytes in network byte order and
|
||||||
* the scope ID.
|
* the scope ID.
|
||||||
@ -1468,12 +1330,3 @@ struct Address
|
|||||||
assert(address == Address4.loopback);
|
assert(address == Address4.loopback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can assign another address
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
Address actual = Address4.loopback;
|
|
||||||
Address expected = Address6.loopback;
|
|
||||||
actual = expected;
|
|
||||||
assert(actual == expected);
|
|
||||||
}
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
/**
|
/**
|
||||||
* Network programming.
|
* Network programming.
|
||||||
*
|
*
|
||||||
* Copyright: Eugene Wissner 2017-2018.
|
* Copyright: Eugene Wissner 2017-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
@ -14,5 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
module tanya.net;
|
module tanya.net;
|
||||||
|
|
||||||
|
public import tanya.net.iface;
|
||||||
public import tanya.net.inet;
|
public import tanya.net.inet;
|
||||||
|
public import tanya.net.ip;
|
||||||
public import tanya.net.uri;
|
public import tanya.net.uri;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
/**
|
/**
|
||||||
* URL parser.
|
* URL parser.
|
||||||
*
|
*
|
||||||
* Copyright: Eugene Wissner 2017-2018.
|
* Copyright: Eugene Wissner 2017-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
@ -18,11 +18,6 @@ import tanya.conv;
|
|||||||
import tanya.encoding.ascii;
|
import tanya.encoding.ascii;
|
||||||
import tanya.memory;
|
import tanya.memory;
|
||||||
|
|
||||||
version (unittest)
|
|
||||||
{
|
|
||||||
import tanya.test.assertion;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown if an invalid URI was specified.
|
* Thrown if an invalid URI was specified.
|
||||||
*/
|
*/
|
||||||
@ -370,90 +365,6 @@ struct URL
|
|||||||
assert(u.fragment == "fragment");
|
assert(u.fragment == "fragment");
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc pure @system unittest
|
|
||||||
{
|
|
||||||
auto u = URL("127.0.0.1");
|
|
||||||
assert(u.path == "127.0.0.1");
|
|
||||||
|
|
||||||
u = URL("http://127.0.0.1");
|
|
||||||
assert(u.scheme == "http");
|
|
||||||
assert(u.host == "127.0.0.1");
|
|
||||||
|
|
||||||
u = URL("http://127.0.0.1:9000");
|
|
||||||
assert(u.scheme == "http");
|
|
||||||
assert(u.host == "127.0.0.1");
|
|
||||||
assert(u.port == 9000);
|
|
||||||
|
|
||||||
u = URL("127.0.0.1:80");
|
|
||||||
assert(u.host == "127.0.0.1");
|
|
||||||
assert(u.port == 80);
|
|
||||||
assert(u.path is null);
|
|
||||||
|
|
||||||
u = URL("//example.net");
|
|
||||||
assert(u.host == "example.net");
|
|
||||||
assert(u.scheme is null);
|
|
||||||
|
|
||||||
u = URL("//example.net?q=before:after");
|
|
||||||
assert(u.host == "example.net");
|
|
||||||
assert(u.query == "q=before:after");
|
|
||||||
|
|
||||||
u = URL("localhost:8080");
|
|
||||||
assert(u.host == "localhost");
|
|
||||||
assert(u.port == 8080);
|
|
||||||
assert(u.path is null);
|
|
||||||
|
|
||||||
u = URL("ftp:");
|
|
||||||
assert(u.scheme == "ftp");
|
|
||||||
|
|
||||||
u = URL("file:///C:\\Users");
|
|
||||||
assert(u.scheme == "file");
|
|
||||||
assert(u.path == "C:\\Users");
|
|
||||||
|
|
||||||
u = URL("localhost:66000");
|
|
||||||
assert(u.scheme == "localhost");
|
|
||||||
assert(u.path == "66000");
|
|
||||||
|
|
||||||
u = URL("file:///home/");
|
|
||||||
assert(u.scheme == "file");
|
|
||||||
assert(u.path == "/home/");
|
|
||||||
|
|
||||||
u = URL("file:///home/?q=asdf");
|
|
||||||
assert(u.scheme == "file");
|
|
||||||
assert(u.path == "/home/");
|
|
||||||
assert(u.query == "q=asdf");
|
|
||||||
|
|
||||||
u = URL("http://secret@example.org");
|
|
||||||
assert(u.scheme == "http");
|
|
||||||
assert(u.host == "example.org");
|
|
||||||
assert(u.user == "secret");
|
|
||||||
|
|
||||||
u = URL("h_tp://:80");
|
|
||||||
assert(u.path == "h_tp://:80");
|
|
||||||
assert(u.port == 0);
|
|
||||||
|
|
||||||
u = URL("zlib:/home/user/file.gz");
|
|
||||||
assert(u.scheme == "zlib");
|
|
||||||
assert(u.path == "/home/user/file.gz");
|
|
||||||
|
|
||||||
u = URL("h_tp:asdf");
|
|
||||||
assert(u.path == "h_tp:asdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc pure @system unittest
|
|
||||||
{
|
|
||||||
assertThrown!URIException(() => URL("http://:80"));
|
|
||||||
assertThrown!URIException(() => URL(":80"));
|
|
||||||
assertThrown!URIException(() => URL("http://u1:p1@u2:p2@example.org"));
|
|
||||||
assertThrown!URIException(() => URL("http://blah.com:port"));
|
|
||||||
assertThrown!URIException(() => URL("http://blah.com:66000"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc pure @system unittest
|
|
||||||
{
|
|
||||||
auto u = URL("ftp://");
|
|
||||||
assert(u.scheme == "ftp");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to parse an URL from a string and returns the specified component
|
* Attempts to parse an URL from a string and returns the specified component
|
||||||
* of the URL or $(D_PSYMBOL URL) if no component is specified.
|
* of the URL or $(D_PSYMBOL URL) if no component is specified.
|
||||||
|
@ -19,16 +19,6 @@ import tanya.memory.lifetime;
|
|||||||
import tanya.meta.trait;
|
import tanya.meta.trait;
|
||||||
import tanya.range;
|
import tanya.range;
|
||||||
|
|
||||||
version (unittest)
|
|
||||||
{
|
|
||||||
static struct Container
|
|
||||||
{
|
|
||||||
void insertBack(const(char)[])
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private mixin template InserterCtor()
|
private mixin template InserterCtor()
|
||||||
{
|
{
|
||||||
private Container* container;
|
private Container* container;
|
||||||
@ -92,22 +82,6 @@ if (hasMember!(Container, "insertBack"))
|
|||||||
assert(container.element == 5);
|
assert(container.element == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
auto func()()
|
|
||||||
{
|
|
||||||
Container container;
|
|
||||||
return backInserter(container);
|
|
||||||
}
|
|
||||||
static assert(!is(typeof(func!())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
Container container;
|
|
||||||
static assert(isOutputRange!(typeof(backInserter(container)), string));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If $(D_PARAM container) is a container with `insertFront`-support,
|
* If $(D_PARAM container) is a container with `insertFront`-support,
|
||||||
* $(D_PSYMBOL frontInserter) returns an output range that puts the elements
|
* $(D_PSYMBOL frontInserter) returns an output range that puts the elements
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
* (D_INLINECODE dchar[])) are treated as any other normal array, they aren't
|
* (D_INLINECODE dchar[])) are treated as any other normal array, they aren't
|
||||||
* auto-decoded.
|
* auto-decoded.
|
||||||
*
|
*
|
||||||
* Copyright: Eugene Wissner 2017-2018.
|
* Copyright: Eugene Wissner 2017-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* This package contains generic functions and templates to be used with D
|
* This package contains generic functions and templates to be used with D
|
||||||
* ranges.
|
* ranges.
|
||||||
*
|
*
|
||||||
* Copyright: Eugene Wissner 2017-2018.
|
* Copyright: Eugene Wissner 2017-2019.
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||||
* Mozilla Public License, v. 2.0).
|
* Mozilla Public License, v. 2.0).
|
||||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||||
|
@ -20,19 +20,6 @@ import tanya.meta.trait;
|
|||||||
import tanya.meta.transform;
|
import tanya.meta.transform;
|
||||||
import tanya.range.array;
|
import tanya.range.array;
|
||||||
|
|
||||||
version (unittest)
|
|
||||||
{
|
|
||||||
import tanya.test.stub;
|
|
||||||
|
|
||||||
private struct AssertPostblit
|
|
||||||
{
|
|
||||||
this(this) @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the element type of the range $(D_PARAM R).
|
* Returns the element type of the range $(D_PARAM R).
|
||||||
*
|
*
|
||||||
@ -391,72 +378,6 @@ template isInputRange(R)
|
|||||||
static assert(!isInputRange!(void[]));
|
static assert(!isInputRange!(void[]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static struct Range1(T)
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
T empty() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(!isInputRange!(Range1!int));
|
|
||||||
static assert(!isInputRange!(Range1!(const bool)));
|
|
||||||
|
|
||||||
static struct Range2
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
int popFront() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(isInputRange!Range2);
|
|
||||||
|
|
||||||
static struct Range3
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
void front() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(!isInputRange!Range3);
|
|
||||||
|
|
||||||
static struct Range4
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
enum bool empty = false;
|
|
||||||
}
|
|
||||||
static assert(isInputRange!Range4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ranges with non-copyable elements can be input ranges
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
@WithLvalueElements
|
|
||||||
static struct R
|
|
||||||
{
|
|
||||||
mixin InputRangeStub!NonCopyable;
|
|
||||||
}
|
|
||||||
static assert(isInputRange!R);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ranges with const non-copyable elements can be input ranges
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
@WithLvalueElements
|
|
||||||
static struct R
|
|
||||||
{
|
|
||||||
mixin InputRangeStub!(const(NonCopyable));
|
|
||||||
}
|
|
||||||
static assert(isInputRange!R);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether $(D_PARAM R) is a forward range.
|
* Determines whether $(D_PARAM R) is a forward range.
|
||||||
*
|
*
|
||||||
@ -515,34 +436,6 @@ template isForwardRange(R)
|
|||||||
static assert(!isForwardRange!(void[]));
|
static assert(!isForwardRange!(void[]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static struct Range1
|
|
||||||
{
|
|
||||||
}
|
|
||||||
static struct Range2
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
Range1 save() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return Range1();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(!isForwardRange!Range2);
|
|
||||||
|
|
||||||
static struct Range3
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
const(typeof(this)) save() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(!isForwardRange!Range3);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether $(D_PARAM R) is a bidirectional range.
|
* Determines whether $(D_PARAM R) is a bidirectional range.
|
||||||
*
|
*
|
||||||
@ -613,37 +506,6 @@ template isBidirectionalRange(R)
|
|||||||
static assert(!isBidirectionalRange!(void[]));
|
static assert(!isBidirectionalRange!(void[]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static struct Range(T, U)
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub;
|
|
||||||
|
|
||||||
@property T front() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return T.init;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property U back() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return U.init;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(!isBidirectionalRange!(Range!(int, uint)));
|
|
||||||
static assert(!isBidirectionalRange!(Range!(int, const int)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ranges with non-copyable elements can be bidirectional ranges
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
@WithLvalueElements
|
|
||||||
static struct R
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub!NonCopyable;
|
|
||||||
}
|
|
||||||
static assert(isBidirectionalRange!R);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether $(D_PARAM R) is a random-access range.
|
* Determines whether $(D_PARAM R) is a random-access range.
|
||||||
*
|
*
|
||||||
@ -735,66 +597,6 @@ template isRandomAccessRange(R)
|
|||||||
static assert(isRandomAccessRange!B);
|
static assert(isRandomAccessRange!B);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static struct Range1
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub;
|
|
||||||
mixin RandomAccessRangeStub;
|
|
||||||
}
|
|
||||||
static assert(!isRandomAccessRange!Range1);
|
|
||||||
|
|
||||||
@Length
|
|
||||||
static struct Range2(Args...)
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub;
|
|
||||||
|
|
||||||
int opIndex(Args) @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(isRandomAccessRange!(Range2!size_t));
|
|
||||||
static assert(!isRandomAccessRange!(Range2!()));
|
|
||||||
static assert(!isRandomAccessRange!(Range2!(size_t, size_t)));
|
|
||||||
|
|
||||||
@Length
|
|
||||||
static struct Range3
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub;
|
|
||||||
|
|
||||||
int opIndex(const size_t pos1, const size_t pos2 = 0)
|
|
||||||
@nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(isRandomAccessRange!Range3);
|
|
||||||
|
|
||||||
static struct Range4
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub;
|
|
||||||
mixin RandomAccessRangeStub;
|
|
||||||
|
|
||||||
size_t opDollar() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static assert(!isRandomAccessRange!Range4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ranges with non-copyable elements can be random-access ranges
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
@WithLvalueElements @Infinite
|
|
||||||
static struct R
|
|
||||||
{
|
|
||||||
mixin RandomAccessRangeStub!NonCopyable;
|
|
||||||
}
|
|
||||||
static assert(isRandomAccessRange!R);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts $(D_PARAM e) into the $(D_PARAM range).
|
* Puts $(D_PARAM e) into the $(D_PARAM range).
|
||||||
*
|
*
|
||||||
@ -1052,27 +854,6 @@ template isInfinite(R)
|
|||||||
static assert(!isInfinite!InputRange);
|
static assert(!isInfinite!InputRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
@Infinite
|
|
||||||
static struct StaticConstRange
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
static bool empty = false;
|
|
||||||
}
|
|
||||||
static assert(!isInfinite!StaticConstRange);
|
|
||||||
|
|
||||||
@Infinite
|
|
||||||
static struct TrueRange
|
|
||||||
{
|
|
||||||
mixin InputRangeStub;
|
|
||||||
|
|
||||||
static const bool empty = true;
|
|
||||||
}
|
|
||||||
static assert(!isInfinite!TrueRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes exactly $(D_PARAM count) first elements from the input range
|
* Removes exactly $(D_PARAM count) first elements from the input range
|
||||||
* $(D_PARAM range).
|
* $(D_PARAM range).
|
||||||
@ -1295,109 +1076,6 @@ if (isBidirectionalRange!R)
|
|||||||
assert(slice.length == 0);
|
assert(slice.length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
@Infinite
|
|
||||||
static struct InfiniteRange
|
|
||||||
{
|
|
||||||
mixin ForwardRangeStub;
|
|
||||||
private int i;
|
|
||||||
|
|
||||||
void popFront() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
++this.i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void popBack() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
--this.i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property int front() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property int back() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
InfiniteRange range;
|
|
||||||
popFrontExactly(range, 2);
|
|
||||||
assert(range.front == 2);
|
|
||||||
popFrontN(range, 2);
|
|
||||||
assert(range.front == 4);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
InfiniteRange range;
|
|
||||||
popBackExactly(range, 2);
|
|
||||||
assert(range.back == -2);
|
|
||||||
popBackN(range, 2);
|
|
||||||
assert(range.back == -4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static struct Range
|
|
||||||
{
|
|
||||||
private int[5] a = [1, 2, 3, 4, 5];
|
|
||||||
private size_t begin = 0, end = 5;
|
|
||||||
|
|
||||||
Range save() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void popFront() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
++this.begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void popBack() @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
--this.end;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property int front() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.a[this.begin];
|
|
||||||
}
|
|
||||||
|
|
||||||
@property int back() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.a[this.end - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool empty() const @nogc nothrow pure @safe
|
|
||||||
{
|
|
||||||
return this.begin >= this.end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
Range range;
|
|
||||||
|
|
||||||
popFrontN(range, 3);
|
|
||||||
assert(range.front == 4);
|
|
||||||
assert(range.back == 5);
|
|
||||||
|
|
||||||
popFrontN(range, 20);
|
|
||||||
assert(range.empty);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
Range range;
|
|
||||||
|
|
||||||
popBackN(range, 3);
|
|
||||||
assert(range.front == 1);
|
|
||||||
assert(range.back == 2);
|
|
||||||
|
|
||||||
popBackN(range, 20);
|
|
||||||
assert(range.empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the front element of an input range.
|
* Moves the front element of an input range.
|
||||||
*
|
*
|
||||||
@ -1439,25 +1117,6 @@ if (isInputRange!R)
|
|||||||
assert(moveFront(a[]) == 5);
|
assert(moveFront(a[]) == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
// Returns its elements by reference.
|
|
||||||
@Infinite @WithLvalueElements
|
|
||||||
static struct R1
|
|
||||||
{
|
|
||||||
mixin InputRangeStub!AssertPostblit;
|
|
||||||
}
|
|
||||||
static assert(is(typeof(moveFront(R1()))));
|
|
||||||
|
|
||||||
// Returns elements with a postblit constructor by value. moveFront fails.
|
|
||||||
@Infinite
|
|
||||||
static struct R2
|
|
||||||
{
|
|
||||||
mixin InputRangeStub!AssertPostblit;
|
|
||||||
}
|
|
||||||
static assert(!is(typeof(moveFront(R2()))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the back element of a bidirectional range.
|
* Moves the back element of a bidirectional range.
|
||||||
*
|
*
|
||||||
@ -1499,25 +1158,6 @@ if (isBidirectionalRange!R)
|
|||||||
assert(moveBack(a[]) == 5);
|
assert(moveBack(a[]) == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
// Returns its elements by reference.
|
|
||||||
@Infinite @WithLvalueElements
|
|
||||||
static struct R1
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub!AssertPostblit;
|
|
||||||
}
|
|
||||||
static assert(is(typeof(moveBack(R1()))));
|
|
||||||
|
|
||||||
// Returns elements with a postblit constructor by value. moveBack fails.
|
|
||||||
@Infinite
|
|
||||||
static struct R2
|
|
||||||
{
|
|
||||||
mixin BidirectionalRangeStub!AssertPostblit;
|
|
||||||
}
|
|
||||||
static assert(!is(typeof(moveBack(R2()))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the element at the position $(D_PARAM n) out of the range.
|
* Moves the element at the position $(D_PARAM n) out of the range.
|
||||||
*
|
*
|
||||||
@ -1558,25 +1198,6 @@ if (isRandomAccessRange!R)
|
|||||||
assert(moveAt(a[], 1) == 5);
|
assert(moveAt(a[], 1) == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
// Returns its elements by reference.
|
|
||||||
@Infinite @WithLvalueElements
|
|
||||||
static struct R1
|
|
||||||
{
|
|
||||||
mixin RandomAccessRangeStub!AssertPostblit;
|
|
||||||
}
|
|
||||||
static assert(is(typeof(moveAt(R1(), 0))));
|
|
||||||
|
|
||||||
// Returns elements with a postblit constructor by value. moveAt fails.
|
|
||||||
@Infinite
|
|
||||||
static struct R2
|
|
||||||
{
|
|
||||||
mixin RandomAccessRangeStub!AssertPostblit;
|
|
||||||
}
|
|
||||||
static assert(!is(typeof(moveAt(R2(), 0))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether $(D_PSYMBOL R) is a range containing mobile elements,
|
* Determines whether $(D_PSYMBOL R) is a range containing mobile elements,
|
||||||
* i.e. elements that can be moved out of the range.
|
* i.e. elements that can be moved out of the range.
|
||||||
@ -1731,12 +1352,6 @@ template hasLvalueElements(R)
|
|||||||
static assert(hasLvalueElements!R2);
|
static assert(hasLvalueElements!R2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Works with non-copyable elements
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
static assert(hasLvalueElements!(NonCopyable[]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the elements of $(D_PARAM R) are assignable.
|
* Determines whether the elements of $(D_PARAM R) are assignable.
|
||||||
*
|
*
|
||||||
|
501
tests/tanya/hash/tests/lookup.d
Normal file
501
tests/tanya/hash/tests/lookup.d
Normal file
@ -0,0 +1,501 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.hash.tests.lookup;
|
||||||
|
|
||||||
|
import tanya.hash.lookup;
|
||||||
|
import tanya.test.stub;
|
||||||
|
|
||||||
|
// Tests that work for any hash size
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(hash(null) == 0);
|
||||||
|
assert(hash(Hashable()) == 0U);
|
||||||
|
assert(hash('a') == 'a');
|
||||||
|
}
|
||||||
|
|
||||||
|
static if (size_t.sizeof == 4) @nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(hash(HashRange()) == 0x6222e842U);
|
||||||
|
assert(hash(ToHashRange()) == 3371162643U);
|
||||||
|
}
|
||||||
|
|
||||||
|
static if (size_t.sizeof == 8) @nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(hash(HashRange()) == 0x08985907b541d342UL);
|
||||||
|
assert(hash(ToHashRange()) == 2072958611659694473);
|
||||||
|
}
|
||||||
|
|
||||||
|
static if (size_t.sizeof == 4) @nogc nothrow pure @system unittest
|
||||||
|
{
|
||||||
|
assert(hash(cast(void*) 0x6e6f6863) == 0x6e6f6863);
|
||||||
|
}
|
||||||
|
|
||||||
|
static if (size_t.sizeof == 8) @nogc nothrow pure @system unittest
|
||||||
|
{
|
||||||
|
assert(hash(cast(void*) 0x77206f676e6f6863) == 0x77206f676e6f6863);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are official FNV-1a test vectors and they are in the public domain.
|
||||||
|
*/
|
||||||
|
// FNV-1a 32 bit test vectors
|
||||||
|
static if (size_t.sizeof == 4) @nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(hash("") == 0x811c9dc5U);
|
||||||
|
assert(hash("a") == 0xe40c292cU);
|
||||||
|
assert(hash("b") == 0xe70c2de5U);
|
||||||
|
assert(hash("c") == 0xe60c2c52U);
|
||||||
|
assert(hash("d") == 0xe10c2473U);
|
||||||
|
assert(hash("e") == 0xe00c22e0U);
|
||||||
|
assert(hash("f") == 0xe30c2799U);
|
||||||
|
assert(hash("fo") == 0x6222e842U);
|
||||||
|
assert(hash("foo") == 0xa9f37ed7U);
|
||||||
|
assert(hash("foob") == 0x3f5076efU);
|
||||||
|
assert(hash("fooba") == 0x39aaa18aU);
|
||||||
|
assert(hash("foobar") == 0xbf9cf968U);
|
||||||
|
assert(hash("\0") == 0x050c5d1fU);
|
||||||
|
assert(hash("a\0") == 0x2b24d044U);
|
||||||
|
assert(hash("b\0") == 0x9d2c3f7fU);
|
||||||
|
assert(hash("c\0") == 0x7729c516U);
|
||||||
|
assert(hash("d\0") == 0xb91d6109U);
|
||||||
|
assert(hash("e\0") == 0x931ae6a0U);
|
||||||
|
assert(hash("f\0") == 0x052255dbU);
|
||||||
|
assert(hash("fo\0") == 0xbef39fe6U);
|
||||||
|
assert(hash("foo\0") == 0x6150ac75U);
|
||||||
|
assert(hash("foob\0") == 0x9aab3a3dU);
|
||||||
|
assert(hash("fooba\0") == 0x519c4c3eU);
|
||||||
|
assert(hash("foobar\0") == 0x0c1c9eb8U);
|
||||||
|
assert(hash("ch") == 0x5f299f4eU);
|
||||||
|
assert(hash("cho") == 0xef8580f3U);
|
||||||
|
assert(hash("chon") == 0xac297727U);
|
||||||
|
assert(hash("chong") == 0x4546b9c0U);
|
||||||
|
assert(hash("chongo") == 0xbd564e7dU);
|
||||||
|
assert(hash("chongo ") == 0x6bdd5c67U);
|
||||||
|
assert(hash("chongo w") == 0xdd77ed30U);
|
||||||
|
assert(hash("chongo wa") == 0xf4ca9683U);
|
||||||
|
assert(hash("chongo was") == 0x4aeb9bd0U);
|
||||||
|
assert(hash("chongo was ") == 0xe0e67ad0U);
|
||||||
|
assert(hash("chongo was h") == 0xc2d32fa8U);
|
||||||
|
assert(hash("chongo was he") == 0x7f743fb7U);
|
||||||
|
assert(hash("chongo was her") == 0x6900631fU);
|
||||||
|
assert(hash("chongo was here") == 0xc59c990eU);
|
||||||
|
assert(hash("chongo was here!") == 0x448524fdU);
|
||||||
|
assert(hash("chongo was here!\n") == 0xd49930d5U);
|
||||||
|
assert(hash("ch\0") == 0x1c85c7caU);
|
||||||
|
assert(hash("cho\0") == 0x0229fe89U);
|
||||||
|
assert(hash("chon\0") == 0x2c469265U);
|
||||||
|
assert(hash("chong\0") == 0xce566940U);
|
||||||
|
assert(hash("chongo\0") == 0x8bdd8ec7U);
|
||||||
|
assert(hash("chongo \0") == 0x34787625U);
|
||||||
|
assert(hash("chongo w\0") == 0xd3ca6290U);
|
||||||
|
assert(hash("chongo wa\0") == 0xddeaf039U);
|
||||||
|
assert(hash("chongo was\0") == 0xc0e64870U);
|
||||||
|
assert(hash("chongo was \0") == 0xdad35570U);
|
||||||
|
assert(hash("chongo was h\0") == 0x5a740578U);
|
||||||
|
assert(hash("chongo was he\0") == 0x5b004d15U);
|
||||||
|
assert(hash("chongo was her\0") == 0x6a9c09cdU);
|
||||||
|
assert(hash("chongo was here\0") == 0x2384f10aU);
|
||||||
|
assert(hash("chongo was here!\0") == 0xda993a47U);
|
||||||
|
assert(hash("chongo was here!\n\0") == 0x8227df4fU);
|
||||||
|
assert(hash("cu") == 0x4c298165U);
|
||||||
|
assert(hash("cur") == 0xfc563735U);
|
||||||
|
assert(hash("curd") == 0x8cb91483U);
|
||||||
|
assert(hash("curds") == 0x775bf5d0U);
|
||||||
|
assert(hash("curds ") == 0xd5c428d0U);
|
||||||
|
assert(hash("curds a") == 0x34cc0ea3U);
|
||||||
|
assert(hash("curds an") == 0xea3b4cb7U);
|
||||||
|
assert(hash("curds and") == 0x8e59f029U);
|
||||||
|
assert(hash("curds and ") == 0x2094de2bU);
|
||||||
|
assert(hash("curds and w") == 0xa65a0ad4U);
|
||||||
|
assert(hash("curds and wh") == 0x9bbee5f4U);
|
||||||
|
assert(hash("curds and whe") == 0xbe836343U);
|
||||||
|
assert(hash("curds and whey") == 0x22d5344eU);
|
||||||
|
assert(hash("curds and whey\n") == 0x19a1470cU);
|
||||||
|
assert(hash("cu\0") == 0x4a56b1ffU);
|
||||||
|
assert(hash("cur\0") == 0x70b8e86fU);
|
||||||
|
assert(hash("curd\0") == 0x0a5b4a39U);
|
||||||
|
assert(hash("curds\0") == 0xb5c3f670U);
|
||||||
|
assert(hash("curds \0") == 0x53cc3f70U);
|
||||||
|
assert(hash("curds a\0") == 0xc03b0a99U);
|
||||||
|
assert(hash("curds an\0") == 0x7259c415U);
|
||||||
|
assert(hash("curds and\0") == 0x4095108bU);
|
||||||
|
assert(hash("curds and \0") == 0x7559bdb1U);
|
||||||
|
assert(hash("curds and w\0") == 0xb3bf0bbcU);
|
||||||
|
assert(hash("curds and wh\0") == 0x2183ff1cU);
|
||||||
|
assert(hash("curds and whe\0") == 0x2bd54279U);
|
||||||
|
assert(hash("curds and whey\0") == 0x23a156caU);
|
||||||
|
assert(hash("curds and whey\n\0") == 0x64e2d7e4U);
|
||||||
|
assert(hash("hi") == 0x683af69aU);
|
||||||
|
assert(hash("hi\0") == 0xaed2346eU);
|
||||||
|
assert(hash("hello") == 0x4f9f2cabU);
|
||||||
|
assert(hash("hello\0") == 0x02935131U);
|
||||||
|
assert(hash("\xff\x00\x00\x01") == 0xc48fb86dU);
|
||||||
|
assert(hash("\x01\x00\x00\xff") == 0x2269f369U);
|
||||||
|
assert(hash("\xff\x00\x00\x02") == 0xc18fb3b4U);
|
||||||
|
assert(hash("\x02\x00\x00\xff") == 0x50ef1236U);
|
||||||
|
assert(hash("\xff\x00\x00\x03") == 0xc28fb547U);
|
||||||
|
assert(hash("\x03\x00\x00\xff") == 0x96c3bf47U);
|
||||||
|
assert(hash("\xff\x00\x00\x04") == 0xbf8fb08eU);
|
||||||
|
assert(hash("\x04\x00\x00\xff") == 0xf3e4d49cU);
|
||||||
|
assert(hash("\x40\x51\x4e\x44") == 0x32179058U);
|
||||||
|
assert(hash("\x44\x4e\x51\x40") == 0x280bfee6U);
|
||||||
|
assert(hash("\x40\x51\x4e\x4a") == 0x30178d32U);
|
||||||
|
assert(hash("\x4a\x4e\x51\x40") == 0x21addaf8U);
|
||||||
|
assert(hash("\x40\x51\x4e\x54") == 0x4217a988U);
|
||||||
|
assert(hash("\x54\x4e\x51\x40") == 0x772633d6U);
|
||||||
|
assert(hash("127.0.0.1") == 0x08a3d11eU);
|
||||||
|
assert(hash("127.0.0.1\0") == 0xb7e2323aU);
|
||||||
|
assert(hash("127.0.0.2") == 0x07a3cf8bU);
|
||||||
|
assert(hash("127.0.0.2\0") == 0x91dfb7d1U);
|
||||||
|
assert(hash("127.0.0.3") == 0x06a3cdf8U);
|
||||||
|
assert(hash("127.0.0.3\0") == 0x6bdd3d68U);
|
||||||
|
assert(hash("64.81.78.68") == 0x1d5636a7U);
|
||||||
|
assert(hash("64.81.78.68\0") == 0xd5b808e5U);
|
||||||
|
assert(hash("64.81.78.74") == 0x1353e852U);
|
||||||
|
assert(hash("64.81.78.74\0") == 0xbf16b916U);
|
||||||
|
assert(hash("64.81.78.84") == 0xa55b89edU);
|
||||||
|
assert(hash("64.81.78.84\0") == 0x3c1a2017U);
|
||||||
|
assert(hash("feedface") == 0x0588b13cU);
|
||||||
|
assert(hash("feedface\0") == 0xf22f0174U);
|
||||||
|
assert(hash("feedfacedaffdeed") == 0xe83641e1U);
|
||||||
|
assert(hash("feedfacedaffdeed\0") == 0x6e69b533U);
|
||||||
|
assert(hash("feedfacedeadbeef") == 0xf1760448U);
|
||||||
|
assert(hash("feedfacedeadbeef\0") == 0x64c8bd58U);
|
||||||
|
assert(hash("line 1\nline 2\nline 3") == 0x97b4ea23U);
|
||||||
|
assert(hash("chongo <Landon Curt Noll> /\\../\\") == 0x9a4e92e6U);
|
||||||
|
assert(hash("chongo <Landon Curt Noll> /\\../\\\0") == 0xcfb14012U);
|
||||||
|
assert(hash("chongo (Landon Curt Noll) /\\../\\") == 0xf01b2511U);
|
||||||
|
assert(hash("chongo (Landon Curt Noll) /\\../\\\0") == 0x0bbb59c3U);
|
||||||
|
assert(hash("http://antwrp.gsfc.nasa.gov/apod/astropix.html") == 0xce524afaU);
|
||||||
|
assert(hash("http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash") == 0xdd16ef45U);
|
||||||
|
assert(hash("http://epod.usra.edu/") == 0x60648bb3U);
|
||||||
|
assert(hash("http://exoplanet.eu/") == 0x7fa4bcfcU);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/cam3/") == 0x5053ae17U);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/cams/HMcam/") == 0xc9302890U);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/deformation.html") == 0x956ded32U);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/images.html") == 0x9136db84U);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/maps.html") == 0xdf9d3323U);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/volcanowatch/current_issue.html") == 0x32bb6cd0U);
|
||||||
|
assert(hash("http://neo.jpl.nasa.gov/risk/") == 0xc8f8385bU);
|
||||||
|
assert(hash("http://norvig.com/21-days.html") == 0xeb08bfbaU);
|
||||||
|
assert(hash("http://primes.utm.edu/curios/home.php") == 0x62cc8e3dU);
|
||||||
|
assert(hash("http://slashdot.org/") == 0xc3e20f5cU);
|
||||||
|
assert(hash("http://tux.wr.usgs.gov/Maps/155.25-19.5.html") == 0x39e97f17U);
|
||||||
|
assert(hash("http://volcano.wr.usgs.gov/kilaueastatus.php") == 0x7837b203U);
|
||||||
|
assert(hash("http://www.avo.alaska.edu/activity/Redoubt.php") == 0x319e877bU);
|
||||||
|
assert(hash("http://www.dilbert.com/fast/") == 0xd3e63f89U);
|
||||||
|
assert(hash("http://www.fourmilab.ch/gravitation/orbits/") == 0x29b50b38U);
|
||||||
|
assert(hash("http://www.fpoa.net/") == 0x5ed678b8U);
|
||||||
|
assert(hash("http://www.ioccc.org/index.html") == 0xb0d5b793U);
|
||||||
|
assert(hash("http://www.isthe.com/cgi-bin/number.cgi") == 0x52450be5U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/bio.html") == 0xfa72d767U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/index.html") == 0x95066709U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/src/calc/lucas-calc") == 0x7f52e123U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/astro/venus2004.html") == 0x76966481U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/astro/vita.html") == 0x063258b0U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/comp/c/expert.html") == 0x2ded6e8aU);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/comp/calc/index.html") == 0xb07d7c52U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/comp/fnv/index.html") == 0xd0c71b71U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/number/howhigh.html") == 0xf684f1bdU);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/number/number.html") == 0x868ecfa8U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html") == 0xf794f684U);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest") == 0xd19701c3U);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/corpspeak.cgi") == 0x346e171eU);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/haiku.cgi") == 0x91f8f676U);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/rand-none.cgi") == 0x0bf58848U);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/randdist.cgi") == 0x6317b6d1U);
|
||||||
|
assert(hash("http://www.lavarnd.org/index.html") == 0xafad4c54U);
|
||||||
|
assert(hash("http://www.lavarnd.org/what/nist-test.html") == 0x0f25681eU);
|
||||||
|
assert(hash("http://www.macosxhints.com/") == 0x91b18d49U);
|
||||||
|
assert(hash("http://www.mellis.com/") == 0x7d61c12eU);
|
||||||
|
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm") == 0x5147d25cU);
|
||||||
|
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm") == 0x9a8b6805U);
|
||||||
|
assert(hash("http://www.paulnoll.com/") == 0x4cd2a447U);
|
||||||
|
assert(hash("http://www.pepysdiary.com/") == 0x1e549b14U);
|
||||||
|
assert(hash("http://www.sciencenews.org/index/home/activity/view") == 0x2fe1b574U);
|
||||||
|
assert(hash("http://www.skyandtelescope.com/") == 0xcf0cd31eU);
|
||||||
|
assert(hash("http://www.sput.nl/~rob/sirius.html") == 0x6c471669U);
|
||||||
|
assert(hash("http://www.systemexperts.com/") == 0x0e5eef1eU);
|
||||||
|
assert(hash("http://www.tq-international.com/phpBB3/index.php") == 0x2bed3602U);
|
||||||
|
assert(hash("http://www.travelquesttours.com/index.htm") == 0xb26249e0U);
|
||||||
|
assert(hash("http://www.wunderground.com/global/stations/89606.html") == 0x2c9b86a4U);
|
||||||
|
assert(hash(r10!"21701") == 0xe415e2bbU);
|
||||||
|
assert(hash(r10!"M21701") == 0x18a98d1dU);
|
||||||
|
assert(hash(r10!"2^21701-1") == 0xb7df8b7bU);
|
||||||
|
assert(hash(r10!"\x54\xc5") == 0x241e9075U);
|
||||||
|
assert(hash(r10!"\xc5\x54") == 0x063f70ddU);
|
||||||
|
assert(hash(r10!"23209") == 0x0295aed9U);
|
||||||
|
assert(hash(r10!"M23209") == 0x56a7f781U);
|
||||||
|
assert(hash(r10!"2^23209-1") == 0x253bc645U);
|
||||||
|
assert(hash(r10!"\x5a\xa9") == 0x46610921U);
|
||||||
|
assert(hash(r10!"\xa9\x5a") == 0x7c1577f9U);
|
||||||
|
assert(hash(r10!"391581216093") == 0x512b2851U);
|
||||||
|
assert(hash(r10!"391581*2^216093-1") == 0x76823999U);
|
||||||
|
assert(hash(r10!"\x05\xf9\x9d\x03\x4c\x81") == 0xc0586935U);
|
||||||
|
assert(hash(r10!"FEDCBA9876543210") == 0xf3415c85U);
|
||||||
|
assert(hash(r10!"\xfe\xdc\xba\x98\x76\x54\x32\x10") == 0x0ae4ff65U);
|
||||||
|
assert(hash(r10!"EFCDAB8967452301") == 0x58b79725U);
|
||||||
|
assert(hash(r10!"\xef\xcd\xab\x89\x67\x45\x23\x01") == 0xdea43aa5U);
|
||||||
|
assert(hash(r10!"0123456789ABCDEF") == 0x2bb3be35U);
|
||||||
|
assert(hash(r10!"\x01\x23\x45\x67\x89\xab\xcd\xef") == 0xea777a45U);
|
||||||
|
assert(hash(r10!"1032547698BADCFE") == 0x8f21c305U);
|
||||||
|
assert(hash(r10!"\x10\x32\x54\x76\x98\xba\xdc\xfe") == 0x5c9d0865U);
|
||||||
|
assert(hash(r500!"\x00") == 0xfa823dd5U);
|
||||||
|
assert(hash(r500!"\x07") == 0x21a27271U);
|
||||||
|
assert(hash(r500!"~") == 0x83c5c6d5U);
|
||||||
|
assert(hash(r500!"\x7f") == 0x813b0881U);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FNV-1a 64 bit test vectors
|
||||||
|
static if (size_t.sizeof == 8) @nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(hash("") == 0xcbf29ce484222325UL);
|
||||||
|
assert(hash("a") == 0xaf63dc4c8601ec8cUL);
|
||||||
|
assert(hash("b") == 0xaf63df4c8601f1a5UL);
|
||||||
|
assert(hash("c") == 0xaf63de4c8601eff2UL);
|
||||||
|
assert(hash("d") == 0xaf63d94c8601e773UL);
|
||||||
|
assert(hash("e") == 0xaf63d84c8601e5c0UL);
|
||||||
|
assert(hash("f") == 0xaf63db4c8601ead9UL);
|
||||||
|
assert(hash("fo") == 0x08985907b541d342UL);
|
||||||
|
assert(hash("foo") == 0xdcb27518fed9d577UL);
|
||||||
|
assert(hash("foob") == 0xdd120e790c2512afUL);
|
||||||
|
assert(hash("fooba") == 0xcac165afa2fef40aUL);
|
||||||
|
assert(hash("foobar") == 0x85944171f73967e8UL);
|
||||||
|
assert(hash("\0") == 0xaf63bd4c8601b7dfUL);
|
||||||
|
assert(hash("a\0") == 0x089be207b544f1e4UL);
|
||||||
|
assert(hash("b\0") == 0x08a61407b54d9b5fUL);
|
||||||
|
assert(hash("c\0") == 0x08a2ae07b54ab836UL);
|
||||||
|
assert(hash("d\0") == 0x0891b007b53c4869UL);
|
||||||
|
assert(hash("e\0") == 0x088e4a07b5396540UL);
|
||||||
|
assert(hash("f\0") == 0x08987c07b5420ebbUL);
|
||||||
|
assert(hash("fo\0") == 0xdcb28a18fed9f926UL);
|
||||||
|
assert(hash("foo\0") == 0xdd1270790c25b935UL);
|
||||||
|
assert(hash("foob\0") == 0xcac146afa2febf5dUL);
|
||||||
|
assert(hash("fooba\0") == 0x8593d371f738acfeUL);
|
||||||
|
assert(hash("foobar\0") == 0x34531ca7168b8f38UL);
|
||||||
|
assert(hash("ch") == 0x08a25607b54a22aeUL);
|
||||||
|
assert(hash("cho") == 0xf5faf0190cf90df3UL);
|
||||||
|
assert(hash("chon") == 0xf27397910b3221c7UL);
|
||||||
|
assert(hash("chong") == 0x2c8c2b76062f22e0UL);
|
||||||
|
assert(hash("chongo") == 0xe150688c8217b8fdUL);
|
||||||
|
assert(hash("chongo ") == 0xf35a83c10e4f1f87UL);
|
||||||
|
assert(hash("chongo w") == 0xd1edd10b507344d0UL);
|
||||||
|
assert(hash("chongo wa") == 0x2a5ee739b3ddb8c3UL);
|
||||||
|
assert(hash("chongo was") == 0xdcfb970ca1c0d310UL);
|
||||||
|
assert(hash("chongo was ") == 0x4054da76daa6da90UL);
|
||||||
|
assert(hash("chongo was h") == 0xf70a2ff589861368UL);
|
||||||
|
assert(hash("chongo was he") == 0x4c628b38aed25f17UL);
|
||||||
|
assert(hash("chongo was her") == 0x9dd1f6510f78189fUL);
|
||||||
|
assert(hash("chongo was here") == 0xa3de85bd491270ceUL);
|
||||||
|
assert(hash("chongo was here!") == 0x858e2fa32a55e61dUL);
|
||||||
|
assert(hash("chongo was here!\n") == 0x46810940eff5f915UL);
|
||||||
|
assert(hash("ch\0") == 0xf5fadd190cf8edaaUL);
|
||||||
|
assert(hash("cho\0") == 0xf273ed910b32b3e9UL);
|
||||||
|
assert(hash("chon\0") == 0x2c8c5276062f6525UL);
|
||||||
|
assert(hash("chong\0") == 0xe150b98c821842a0UL);
|
||||||
|
assert(hash("chongo\0") == 0xf35aa3c10e4f55e7UL);
|
||||||
|
assert(hash("chongo \0") == 0xd1ed680b50729265UL);
|
||||||
|
assert(hash("chongo w\0") == 0x2a5f0639b3dded70UL);
|
||||||
|
assert(hash("chongo wa\0") == 0xdcfbaa0ca1c0f359UL);
|
||||||
|
assert(hash("chongo was\0") == 0x4054ba76daa6a430UL);
|
||||||
|
assert(hash("chongo was \0") == 0xf709c7f5898562b0UL);
|
||||||
|
assert(hash("chongo was h\0") == 0x4c62e638aed2f9b8UL);
|
||||||
|
assert(hash("chongo was he\0") == 0x9dd1a8510f779415UL);
|
||||||
|
assert(hash("chongo was her\0") == 0xa3de2abd4911d62dUL);
|
||||||
|
assert(hash("chongo was here\0") == 0x858e0ea32a55ae0aUL);
|
||||||
|
assert(hash("chongo was here!\0") == 0x46810f40eff60347UL);
|
||||||
|
assert(hash("chongo was here!\n\0") == 0xc33bce57bef63eafUL);
|
||||||
|
assert(hash("cu") == 0x08a24307b54a0265UL);
|
||||||
|
assert(hash("cur") == 0xf5b9fd190cc18d15UL);
|
||||||
|
assert(hash("curd") == 0x4c968290ace35703UL);
|
||||||
|
assert(hash("curds") == 0x07174bd5c64d9350UL);
|
||||||
|
assert(hash("curds ") == 0x5a294c3ff5d18750UL);
|
||||||
|
assert(hash("curds a") == 0x05b3c1aeb308b843UL);
|
||||||
|
assert(hash("curds an") == 0xb92a48da37d0f477UL);
|
||||||
|
assert(hash("curds and") == 0x73cdddccd80ebc49UL);
|
||||||
|
assert(hash("curds and ") == 0xd58c4c13210a266bUL);
|
||||||
|
assert(hash("curds and w") == 0xe78b6081243ec194UL);
|
||||||
|
assert(hash("curds and wh") == 0xb096f77096a39f34UL);
|
||||||
|
assert(hash("curds and whe") == 0xb425c54ff807b6a3UL);
|
||||||
|
assert(hash("curds and whey") == 0x23e520e2751bb46eUL);
|
||||||
|
assert(hash("curds and whey\n") == 0x1a0b44ccfe1385ecUL);
|
||||||
|
assert(hash("cu\0") == 0xf5ba4b190cc2119fUL);
|
||||||
|
assert(hash("cur\0") == 0x4c962690ace2baafUL);
|
||||||
|
assert(hash("curd\0") == 0x0716ded5c64cda19UL);
|
||||||
|
assert(hash("curds\0") == 0x5a292c3ff5d150f0UL);
|
||||||
|
assert(hash("curds \0") == 0x05b3e0aeb308ecf0UL);
|
||||||
|
assert(hash("curds a\0") == 0xb92a5eda37d119d9UL);
|
||||||
|
assert(hash("curds an\0") == 0x73ce41ccd80f6635UL);
|
||||||
|
assert(hash("curds and\0") == 0xd58c2c132109f00bUL);
|
||||||
|
assert(hash("curds and \0") == 0xe78baf81243f47d1UL);
|
||||||
|
assert(hash("curds and w\0") == 0xb0968f7096a2ee7cUL);
|
||||||
|
assert(hash("curds and wh\0") == 0xb425a84ff807855cUL);
|
||||||
|
assert(hash("curds and whe\0") == 0x23e4e9e2751b56f9UL);
|
||||||
|
assert(hash("curds and whey\0") == 0x1a0b4eccfe1396eaUL);
|
||||||
|
assert(hash("curds and whey\n\0") == 0x54abd453bb2c9004UL);
|
||||||
|
assert(hash("hi") == 0x08ba5f07b55ec3daUL);
|
||||||
|
assert(hash("hi\0") == 0x337354193006cb6eUL);
|
||||||
|
assert(hash("hello") == 0xa430d84680aabd0bUL);
|
||||||
|
assert(hash("hello\0") == 0xa9bc8acca21f39b1UL);
|
||||||
|
assert(hash("\xff\x00\x00\x01") == 0x6961196491cc682dUL);
|
||||||
|
assert(hash("\x01\x00\x00\xff") == 0xad2bb1774799dfe9UL);
|
||||||
|
assert(hash("\xff\x00\x00\x02") == 0x6961166491cc6314UL);
|
||||||
|
assert(hash("\x02\x00\x00\xff") == 0x8d1bb3904a3b1236UL);
|
||||||
|
assert(hash("\xff\x00\x00\x03") == 0x6961176491cc64c7UL);
|
||||||
|
assert(hash("\x03\x00\x00\xff") == 0xed205d87f40434c7UL);
|
||||||
|
assert(hash("\xff\x00\x00\x04") == 0x6961146491cc5faeUL);
|
||||||
|
assert(hash("\x04\x00\x00\xff") == 0xcd3baf5e44f8ad9cUL);
|
||||||
|
assert(hash("\x40\x51\x4e\x44") == 0xe3b36596127cd6d8UL);
|
||||||
|
assert(hash("\x44\x4e\x51\x40") == 0xf77f1072c8e8a646UL);
|
||||||
|
assert(hash("\x40\x51\x4e\x4a") == 0xe3b36396127cd372UL);
|
||||||
|
assert(hash("\x4a\x4e\x51\x40") == 0x6067dce9932ad458UL);
|
||||||
|
assert(hash("\x40\x51\x4e\x54") == 0xe3b37596127cf208UL);
|
||||||
|
assert(hash("\x54\x4e\x51\x40") == 0x4b7b10fa9fe83936UL);
|
||||||
|
assert(hash("127.0.0.1") == 0xaabafe7104d914beUL);
|
||||||
|
assert(hash("127.0.0.1\0") == 0xf4d3180b3cde3edaUL);
|
||||||
|
assert(hash("127.0.0.2") == 0xaabafd7104d9130bUL);
|
||||||
|
assert(hash("127.0.0.2\0") == 0xf4cfb20b3cdb5bb1UL);
|
||||||
|
assert(hash("127.0.0.3") == 0xaabafc7104d91158UL);
|
||||||
|
assert(hash("127.0.0.3\0") == 0xf4cc4c0b3cd87888UL);
|
||||||
|
assert(hash("64.81.78.68") == 0xe729bac5d2a8d3a7UL);
|
||||||
|
assert(hash("64.81.78.68\0") == 0x74bc0524f4dfa4c5UL);
|
||||||
|
assert(hash("64.81.78.74") == 0xe72630c5d2a5b352UL);
|
||||||
|
assert(hash("64.81.78.74\0") == 0x6b983224ef8fb456UL);
|
||||||
|
assert(hash("64.81.78.84") == 0xe73042c5d2ae266dUL);
|
||||||
|
assert(hash("64.81.78.84\0") == 0x8527e324fdeb4b37UL);
|
||||||
|
assert(hash("feedface") == 0x0a83c86fee952abcUL);
|
||||||
|
assert(hash("feedface\0") == 0x7318523267779d74UL);
|
||||||
|
assert(hash("feedfacedaffdeed") == 0x3e66d3d56b8caca1UL);
|
||||||
|
assert(hash("feedfacedaffdeed\0") == 0x956694a5c0095593UL);
|
||||||
|
assert(hash("feedfacedeadbeef") == 0xcac54572bb1a6fc8UL);
|
||||||
|
assert(hash("feedfacedeadbeef\0") == 0xa7a4c9f3edebf0d8UL);
|
||||||
|
assert(hash("line 1\nline 2\nline 3") == 0x7829851fac17b143UL);
|
||||||
|
assert(hash("chongo <Landon Curt Noll> /\\../\\") == 0x2c8f4c9af81bcf06UL);
|
||||||
|
assert(hash("chongo <Landon Curt Noll> /\\../\\\0") == 0xd34e31539740c732UL);
|
||||||
|
assert(hash("chongo (Landon Curt Noll) /\\../\\") == 0x3605a2ac253d2db1UL);
|
||||||
|
assert(hash("chongo (Landon Curt Noll) /\\../\\\0") == 0x08c11b8346f4a3c3UL);
|
||||||
|
assert(hash("http://antwrp.gsfc.nasa.gov/apod/astropix.html") == 0x6be396289ce8a6daUL);
|
||||||
|
assert(hash("http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash") == 0xd9b957fb7fe794c5UL);
|
||||||
|
assert(hash("http://epod.usra.edu/") == 0x05be33da04560a93UL);
|
||||||
|
assert(hash("http://exoplanet.eu/") == 0x0957f1577ba9747cUL);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/cam3/") == 0xda2cc3acc24fba57UL);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/cams/HMcam/") == 0x74136f185b29e7f0UL);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/deformation.html") == 0xb2f2b4590edb93b2UL);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/images.html") == 0xb3608fce8b86ae04UL);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/kilauea/update/maps.html") == 0x4a3a865079359063UL);
|
||||||
|
assert(hash("http://hvo.wr.usgs.gov/volcanowatch/current_issue.html") == 0x5b3a7ef496880a50UL);
|
||||||
|
assert(hash("http://neo.jpl.nasa.gov/risk/") == 0x48fae3163854c23bUL);
|
||||||
|
assert(hash("http://norvig.com/21-days.html") == 0x07aaa640476e0b9aUL);
|
||||||
|
assert(hash("http://primes.utm.edu/curios/home.php") == 0x2f653656383a687dUL);
|
||||||
|
assert(hash("http://slashdot.org/") == 0xa1031f8e7599d79cUL);
|
||||||
|
assert(hash("http://tux.wr.usgs.gov/Maps/155.25-19.5.html") == 0xa31908178ff92477UL);
|
||||||
|
assert(hash("http://volcano.wr.usgs.gov/kilaueastatus.php") == 0x097edf3c14c3fb83UL);
|
||||||
|
assert(hash("http://www.avo.alaska.edu/activity/Redoubt.php") == 0xb51ca83feaa0971bUL);
|
||||||
|
assert(hash("http://www.dilbert.com/fast/") == 0xdd3c0d96d784f2e9UL);
|
||||||
|
assert(hash("http://www.fourmilab.ch/gravitation/orbits/") == 0x86cd26a9ea767d78UL);
|
||||||
|
assert(hash("http://www.fpoa.net/") == 0xe6b215ff54a30c18UL);
|
||||||
|
assert(hash("http://www.ioccc.org/index.html") == 0xec5b06a1c5531093UL);
|
||||||
|
assert(hash("http://www.isthe.com/cgi-bin/number.cgi") == 0x45665a929f9ec5e5UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/bio.html") == 0x8c7609b4a9f10907UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/index.html") == 0x89aac3a491f0d729UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/src/calc/lucas-calc") == 0x32ce6b26e0f4a403UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/astro/venus2004.html") == 0x614ab44e02b53e01UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/astro/vita.html") == 0xfa6472eb6eef3290UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/comp/c/expert.html") == 0x9e5d75eb1948eb6aUL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/comp/calc/index.html") == 0xb6d12ad4a8671852UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/comp/fnv/index.html") == 0x88826f56eba07af1UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/number/howhigh.html") == 0x44535bf2645bc0fdUL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/number/number.html") == 0x169388ffc21e3728UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html") == 0xf68aac9e396d8224UL);
|
||||||
|
assert(hash("http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest") == 0x8e87d7e7472b3883UL);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/corpspeak.cgi") == 0x295c26caa8b423deUL);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/haiku.cgi") == 0x322c814292e72176UL);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/rand-none.cgi") == 0x8a06550eb8af7268UL);
|
||||||
|
assert(hash("http://www.lavarnd.org/cgi-bin/randdist.cgi") == 0xef86d60e661bcf71UL);
|
||||||
|
assert(hash("http://www.lavarnd.org/index.html") == 0x9e5426c87f30ee54UL);
|
||||||
|
assert(hash("http://www.lavarnd.org/what/nist-test.html") == 0xf1ea8aa826fd047eUL);
|
||||||
|
assert(hash("http://www.macosxhints.com/") == 0x0babaf9a642cb769UL);
|
||||||
|
assert(hash("http://www.mellis.com/") == 0x4b3341d4068d012eUL);
|
||||||
|
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm") == 0xd15605cbc30a335cUL);
|
||||||
|
assert(hash("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm") == 0x5b21060aed8412e5UL);
|
||||||
|
assert(hash("http://www.paulnoll.com/") == 0x45e2cda1ce6f4227UL);
|
||||||
|
assert(hash("http://www.pepysdiary.com/") == 0x50ae3745033ad7d4UL);
|
||||||
|
assert(hash("http://www.sciencenews.org/index/home/activity/view") == 0xaa4588ced46bf414UL);
|
||||||
|
assert(hash("http://www.skyandtelescope.com/") == 0xc1b0056c4a95467eUL);
|
||||||
|
assert(hash("http://www.sput.nl/~rob/sirius.html") == 0x56576a71de8b4089UL);
|
||||||
|
assert(hash("http://www.systemexperts.com/") == 0xbf20965fa6dc927eUL);
|
||||||
|
assert(hash("http://www.tq-international.com/phpBB3/index.php") == 0x569f8383c2040882UL);
|
||||||
|
assert(hash("http://www.travelquesttours.com/index.htm") == 0xe1e772fba08feca0UL);
|
||||||
|
assert(hash("http://www.wunderground.com/global/stations/89606.html") == 0x4ced94af97138ac4UL);
|
||||||
|
assert(hash(r10!"21701") == 0xc4112ffb337a82fbUL);
|
||||||
|
assert(hash(r10!"M21701") == 0xd64a4fd41de38b7dUL);
|
||||||
|
assert(hash(r10!"2^21701-1") == 0x4cfc32329edebcbbUL);
|
||||||
|
assert(hash(r10!"\x54\xc5") == 0x0803564445050395UL);
|
||||||
|
assert(hash(r10!"\xc5\x54") == 0xaa1574ecf4642ffdUL);
|
||||||
|
assert(hash(r10!"23209") == 0x694bc4e54cc315f9UL);
|
||||||
|
assert(hash(r10!"M23209") == 0xa3d7cb273b011721UL);
|
||||||
|
assert(hash(r10!"2^23209-1") == 0x577c2f8b6115bfa5UL);
|
||||||
|
assert(hash(r10!"\x5a\xa9") == 0xb7ec8c1a769fb4c1UL);
|
||||||
|
assert(hash(r10!"\xa9\x5a") == 0x5d5cfce63359ab19UL);
|
||||||
|
assert(hash(r10!"391581216093") == 0x33b96c3cd65b5f71UL);
|
||||||
|
assert(hash(r10!"391581*2^216093-1") == 0xd845097780602bb9UL);
|
||||||
|
assert(hash(r10!"\x05\xf9\x9d\x03\x4c\x81") == 0x84d47645d02da3d5UL);
|
||||||
|
assert(hash(r10!"FEDCBA9876543210") == 0x83544f33b58773a5UL);
|
||||||
|
assert(hash(r10!"\xfe\xdc\xba\x98\x76\x54\x32\x10") == 0x9175cbb2160836c5UL);
|
||||||
|
assert(hash(r10!"EFCDAB8967452301") == 0xc71b3bc175e72bc5UL);
|
||||||
|
assert(hash(r10!"\xef\xcd\xab\x89\x67\x45\x23\x01") == 0x636806ac222ec985UL);
|
||||||
|
assert(hash(r10!"0123456789ABCDEF") == 0xb6ef0e6950f52ed5UL);
|
||||||
|
assert(hash(r10!"\x01\x23\x45\x67\x89\xab\xcd\xef") == 0xead3d8a0f3dfdaa5UL);
|
||||||
|
assert(hash(r10!"1032547698BADCFE") == 0x922908fe9a861ba5UL);
|
||||||
|
assert(hash(r10!"\x10\x32\x54\x76\x98\xba\xdc\xfe") == 0x6d4821de275fd5c5UL);
|
||||||
|
assert(hash(r500!"\x00") == 0x1fe3fce62bd816b5UL);
|
||||||
|
assert(hash(r500!"\x07") == 0xc23e9fccd6f70591UL);
|
||||||
|
assert(hash(r500!"~") == 0xc1af12bdfe16b5b5UL);
|
||||||
|
assert(hash(r500!"\x7f") == 0x39e9f18f2f85e221UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum string r10(string x) = x ~ x ~ x ~ x ~ x ~ x ~ x ~ x ~ x ~ x;
|
||||||
|
private enum string r100(string x) = r10!x ~ r10!x ~ r10!x ~ r10!x ~ r10!x
|
||||||
|
~ r10!x ~ r10!x ~ r10!x ~ r10!x ~ r10!x;
|
||||||
|
private enum string r500(string x) = r100!x ~ r100!x ~ r100!x ~ r100!x ~ r100!x;
|
||||||
|
|
||||||
|
private struct HashRange
|
||||||
|
{
|
||||||
|
string fo = "fo";
|
||||||
|
|
||||||
|
@property ubyte front() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.fo[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void popFront() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
this.fo = this.fo[1 .. $];
|
||||||
|
}
|
||||||
|
|
||||||
|
@property bool empty() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.fo.length == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct ToHashRange
|
||||||
|
{
|
||||||
|
bool empty_;
|
||||||
|
|
||||||
|
@property Hashable front() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return Hashable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void popFront() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
this.empty_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property bool empty() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.empty_;
|
||||||
|
}
|
||||||
|
}
|
73
tests/tanya/math/tests/mp.d
Normal file
73
tests/tanya/math/tests/mp.d
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.math.tests.mp;
|
||||||
|
|
||||||
|
import tanya.algorithm.comparison;
|
||||||
|
import tanya.math.mp;
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
auto h1 = Integer(18);
|
||||||
|
auto h2 = Integer(4);
|
||||||
|
h1 %= h2;
|
||||||
|
assert(h1 == 2);
|
||||||
|
|
||||||
|
h1 = 8;
|
||||||
|
h1 %= h2;
|
||||||
|
assert(h1 == 0);
|
||||||
|
|
||||||
|
h1 = 7;
|
||||||
|
h1 %= h2;
|
||||||
|
assert(h1 == 3);
|
||||||
|
|
||||||
|
h1 = 56088;
|
||||||
|
h2 = 456;
|
||||||
|
h1 /= h2;
|
||||||
|
assert(h1 == 123);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
Integer integer;
|
||||||
|
assert(integer.toArray().length == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
auto integer = Integer(0x03);
|
||||||
|
ubyte[1] expected = [ 0x03 ];
|
||||||
|
|
||||||
|
auto array = integer.toArray();
|
||||||
|
assert(equal(array[], expected[]));
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[63] expected = [
|
||||||
|
0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||||
|
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
||||||
|
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
||||||
|
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
|
||||||
|
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
|
||||||
|
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
|
||||||
|
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
|
||||||
|
0x39, 0x3a, 0x3b, 0x00, 0x61, 0x62, 0x63,
|
||||||
|
];
|
||||||
|
auto integer = Integer(Sign.positive, expected[]);
|
||||||
|
|
||||||
|
auto array = integer.toArray();
|
||||||
|
assert(equal(array[], expected[]));
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[14] expected = [
|
||||||
|
0x22, 0x33, 0x44, 0x55, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x3a, 0x3b, 0x00, 0x61, 0x62, 0x63,
|
||||||
|
];
|
||||||
|
auto integer = Integer(Sign.positive, expected[]);
|
||||||
|
|
||||||
|
auto array = integer.toArray();
|
||||||
|
assert(equal(array[], expected[]));
|
||||||
|
}
|
49
tests/tanya/math/tests/package.d
Normal file
49
tests/tanya/math/tests/package.d
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.math.tests;
|
||||||
|
|
||||||
|
import tanya.math;
|
||||||
|
|
||||||
|
static if (ieeePrecision!float == IEEEPrecision.doubleExtended)
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(classify(1.68105e-10) == FloatingPointClass.normal);
|
||||||
|
assert(classify(1.68105e-4932L) == FloatingPointClass.subnormal);
|
||||||
|
|
||||||
|
// Emulate unnormals, because they aren't generated anymore since i386
|
||||||
|
FloatBits!real unnormal;
|
||||||
|
unnormal.exp = 0x123;
|
||||||
|
unnormal.mantissa = 0x1;
|
||||||
|
assert(classify(unnormal) == FloatingPointClass.subnormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(74653.isPseudoprime);
|
||||||
|
assert(74687.isPseudoprime);
|
||||||
|
assert(74699.isPseudoprime);
|
||||||
|
assert(74707.isPseudoprime);
|
||||||
|
assert(74713.isPseudoprime);
|
||||||
|
assert(74717.isPseudoprime);
|
||||||
|
assert(74719.isPseudoprime);
|
||||||
|
assert(74747.isPseudoprime);
|
||||||
|
assert(74759.isPseudoprime);
|
||||||
|
assert(74761.isPseudoprime);
|
||||||
|
assert(74771.isPseudoprime);
|
||||||
|
assert(74779.isPseudoprime);
|
||||||
|
assert(74797.isPseudoprime);
|
||||||
|
assert(74821.isPseudoprime);
|
||||||
|
assert(74827.isPseudoprime);
|
||||||
|
assert(9973.isPseudoprime);
|
||||||
|
assert(49979693.isPseudoprime);
|
||||||
|
assert(104395303.isPseudoprime);
|
||||||
|
assert(593441861.isPseudoprime);
|
||||||
|
assert(104729.isPseudoprime);
|
||||||
|
assert(15485867.isPseudoprime);
|
||||||
|
assert(49979693.isPseudoprime);
|
||||||
|
assert(104395303.isPseudoprime);
|
||||||
|
assert(593441861.isPseudoprime);
|
||||||
|
assert(899809363.isPseudoprime);
|
||||||
|
assert(982451653.isPseudoprime);
|
||||||
|
}
|
17
tests/tanya/math/tests/random.d
Normal file
17
tests/tanya/math/tests/random.d
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.math.tests.random;
|
||||||
|
|
||||||
|
import tanya.math.random;
|
||||||
|
import tanya.memory;
|
||||||
|
|
||||||
|
static if (is(PlatformEntropySource)) @nogc @system unittest
|
||||||
|
{
|
||||||
|
import tanya.memory.smartref : unique;
|
||||||
|
|
||||||
|
auto source = defaultAllocator.unique!PlatformEntropySource();
|
||||||
|
|
||||||
|
assert(source.threshold == 32);
|
||||||
|
assert(source.strong);
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.memory.tests.lifetime;
|
module tanya.memory.tests.lifetime;
|
||||||
|
|
||||||
import tanya.memory;
|
import tanya.memory;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.memory.tests.mallocator;
|
module tanya.memory.tests.mallocator;
|
||||||
|
|
||||||
version (TanyaNative)
|
version (TanyaNative)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.memory.tests.mmappool;
|
module tanya.memory.tests.mmappool;
|
||||||
|
|
||||||
version (TanyaNative):
|
version (TanyaNative):
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.memory.tests.op;
|
module tanya.memory.tests.op;
|
||||||
|
|
||||||
import tanya.memory.op;
|
import tanya.memory.op;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.memory.tests.smartref;
|
module tanya.memory.tests.smartref;
|
||||||
|
|
||||||
import tanya.memory;
|
import tanya.memory;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.meta.tests.metafunction;
|
module tanya.meta.tests.metafunction;
|
||||||
|
|
||||||
import tanya.meta.metafunction;
|
import tanya.meta.metafunction;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.meta.tests.trait;
|
module tanya.meta.tests.trait;
|
||||||
|
|
||||||
import tanya.meta.metafunction;
|
import tanya.meta.metafunction;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.meta.tests.transform;
|
module tanya.meta.tests.transform;
|
||||||
|
|
||||||
import tanya.meta.transform;
|
import tanya.meta.transform;
|
||||||
|
24
tests/tanya/net/tests/iface.d
Normal file
24
tests/tanya/net/tests/iface.d
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.net.tests.iface;
|
||||||
|
|
||||||
|
import tanya.algorithm.comparison;
|
||||||
|
import tanya.net.iface;
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
version (linux)
|
||||||
|
{
|
||||||
|
assert(equal(indexToName(1)[], "lo"));
|
||||||
|
}
|
||||||
|
else version (Windows)
|
||||||
|
{
|
||||||
|
assert(equal(indexToName(1)[], "loopback_0"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(equal(indexToName(1)[], "lo0"));
|
||||||
|
}
|
||||||
|
assert(indexToName(uint.max).empty);
|
||||||
|
}
|
16
tests/tanya/net/tests/inet.d
Normal file
16
tests/tanya/net/tests/inet.d
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.net.tests.inet;
|
||||||
|
|
||||||
|
import tanya.net.inet;
|
||||||
|
import tanya.range;
|
||||||
|
|
||||||
|
// Static tests
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
static assert(isBidirectionalRange!(NetworkOrder!4));
|
||||||
|
static assert(isBidirectionalRange!(NetworkOrder!8));
|
||||||
|
static assert(!is(NetworkOrder!9));
|
||||||
|
static assert(!is(NetworkOrder!1));
|
||||||
|
}
|
154
tests/tanya/net/tests/ip.d
Normal file
154
tests/tanya/net/tests/ip.d
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.net.tests.ip;
|
||||||
|
|
||||||
|
import tanya.net.ip;
|
||||||
|
import tanya.range;
|
||||||
|
|
||||||
|
// Rejects malformed addresses
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(address4("256.0.0.1").isNothing);
|
||||||
|
assert(address4(".0.0.1").isNothing);
|
||||||
|
assert(address4("0..0.1").isNothing);
|
||||||
|
assert(address4("0.0.0.").isNothing);
|
||||||
|
assert(address4("0.0.").isNothing);
|
||||||
|
assert(address4("").isNothing);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(address4(cast(ubyte[]) []).isNothing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assignment and comparison works
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
auto address1 = Address4.loopback();
|
||||||
|
auto address2 = Address4.any();
|
||||||
|
address1 = address2;
|
||||||
|
assert(address1 == address2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
char[18] actual;
|
||||||
|
|
||||||
|
address6("ff00:2:3:4:5:6:7:8").get.toString(arrayInserter(actual));
|
||||||
|
assert(actual[] == "ff00:2:3:4:5:6:7:8");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skips zero group in the middle
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
char[12] actual;
|
||||||
|
|
||||||
|
address6("1::4:5:6:7:8").get.toString(arrayInserter(actual));
|
||||||
|
assert(actual[] == "1::4:5:6:7:8");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Doesn't replace lonely zeroes
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
char[15] actual;
|
||||||
|
|
||||||
|
address6("0:1:0:2:3:0:4:0").get.toString(arrayInserter(actual));
|
||||||
|
assert(actual[] == "0:1:0:2:3:0:4:0");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skips zero group at the beginning
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
char[13] actual;
|
||||||
|
|
||||||
|
address6("::3:4:5:6:7:8").get.toString(arrayInserter(actual));
|
||||||
|
assert(actual[] == "::3:4:5:6:7:8");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skips zero group at the end
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
char[13] actual;
|
||||||
|
|
||||||
|
address6("1:2:3:4:5:6::").get.toString(arrayInserter(actual));
|
||||||
|
assert(actual[] == "1:2:3:4:5:6::");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[16] expected = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8];
|
||||||
|
auto actual = address6("1:2:3:4:5:6:7:8");
|
||||||
|
assert(actual.get.toBytes() == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[16] expected;
|
||||||
|
auto actual = address6("::");
|
||||||
|
assert(actual.get.toBytes() == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
|
||||||
|
auto actual = address6("::1");
|
||||||
|
assert(actual.get.toBytes() == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[16] expected = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
|
auto actual = address6("1::");
|
||||||
|
assert(actual.get.toBytes() == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rejects malformed addresses
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
assert(address6("").isNothing);
|
||||||
|
assert(address6(":").isNothing);
|
||||||
|
assert(address6(":a").isNothing);
|
||||||
|
assert(address6("a:").isNothing);
|
||||||
|
assert(address6("1:2:3:4::6:").isNothing);
|
||||||
|
assert(address6("fe80:2:3:4::6:7:8%").isNothing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parses embedded IPv4 address
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4];
|
||||||
|
auto actual = address6("0:0:0:0:0:0:1.2.3.4");
|
||||||
|
assert(actual.get.toBytes() == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4];
|
||||||
|
auto actual = address6("::1.2.3.4");
|
||||||
|
assert(actual.get.toBytes() == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
ubyte[16] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 1, 2, 3, 4];
|
||||||
|
auto actual = address6("::5:6:1.2.3.4");
|
||||||
|
assert(actual.get.toBytes() == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow @safe unittest
|
||||||
|
{
|
||||||
|
assert(address6("0:0:0:0:0:0:1.2.3.").isNothing);
|
||||||
|
assert(address6("0:0:0:0:0:0:1.2:3.4").isNothing);
|
||||||
|
assert(address6("0:0:0:0:0:0:1.2.3.4.").isNothing);
|
||||||
|
assert(address6("fe80:0:0:0:0:0:1.2.3.4%1").get.scopeID == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can assign another address
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
Address actual = Address4.loopback;
|
||||||
|
Address expected = Address6.loopback;
|
||||||
|
actual = expected;
|
||||||
|
assert(actual == expected);
|
||||||
|
}
|
136
tests/tanya/net/tests/uri.d
Normal file
136
tests/tanya/net/tests/uri.d
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.net.tests.uri;
|
||||||
|
|
||||||
|
import tanya.net.uri;
|
||||||
|
import tanya.test.assertion;
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("127.0.0.1");
|
||||||
|
assert(u.path == "127.0.0.1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("http://127.0.0.1");
|
||||||
|
assert(u.scheme == "http");
|
||||||
|
assert(u.host == "127.0.0.1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("http://127.0.0.1:9000");
|
||||||
|
assert(u.scheme == "http");
|
||||||
|
assert(u.host == "127.0.0.1");
|
||||||
|
assert(u.port == 9000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("127.0.0.1:80");
|
||||||
|
assert(u.host == "127.0.0.1");
|
||||||
|
assert(u.port == 80);
|
||||||
|
assert(u.path is null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("//example.net");
|
||||||
|
assert(u.host == "example.net");
|
||||||
|
assert(u.scheme is null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("//example.net?q=before:after");
|
||||||
|
assert(u.host == "example.net");
|
||||||
|
assert(u.query == "q=before:after");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("localhost:8080");
|
||||||
|
assert(u.host == "localhost");
|
||||||
|
assert(u.port == 8080);
|
||||||
|
assert(u.path is null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("ftp:");
|
||||||
|
assert(u.scheme == "ftp");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("file:///C:\\Users");
|
||||||
|
assert(u.scheme == "file");
|
||||||
|
assert(u.path == "C:\\Users");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("localhost:66000");
|
||||||
|
assert(u.scheme == "localhost");
|
||||||
|
assert(u.path == "66000");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("file:///home/");
|
||||||
|
assert(u.scheme == "file");
|
||||||
|
assert(u.path == "/home/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("file:///home/?q=asdf");
|
||||||
|
assert(u.scheme == "file");
|
||||||
|
assert(u.path == "/home/");
|
||||||
|
assert(u.query == "q=asdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("http://secret@example.org");
|
||||||
|
assert(u.scheme == "http");
|
||||||
|
assert(u.host == "example.org");
|
||||||
|
assert(u.user == "secret");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("h_tp://:80");
|
||||||
|
assert(u.path == "h_tp://:80");
|
||||||
|
assert(u.port == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("zlib:/home/user/file.gz");
|
||||||
|
assert(u.scheme == "zlib");
|
||||||
|
assert(u.path == "/home/user/file.gz");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("h_tp:asdf");
|
||||||
|
assert(u.path == "h_tp:asdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
assertThrown!URIException(() => URL("http://:80"));
|
||||||
|
assertThrown!URIException(() => URL(":80"));
|
||||||
|
assertThrown!URIException(() => URL("http://u1:p1@u2:p2@example.org"));
|
||||||
|
assertThrown!URIException(() => URL("http://blah.com:port"));
|
||||||
|
assertThrown!URIException(() => URL("http://blah.com:66000"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc pure @system unittest
|
||||||
|
{
|
||||||
|
const u = URL("ftp://");
|
||||||
|
assert(u.scheme == "ftp");
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
module tanya.os.tests.error;
|
module tanya.os.tests.error;
|
||||||
|
|
||||||
import tanya.os.error;
|
import tanya.os.error;
|
||||||
|
29
tests/tanya/range/tests/adapter.d
Normal file
29
tests/tanya/range/tests/adapter.d
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.range.tests.adapter;
|
||||||
|
|
||||||
|
import tanya.range;
|
||||||
|
|
||||||
|
private struct Container
|
||||||
|
{
|
||||||
|
void insertBack(const(char)[])
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
auto func()()
|
||||||
|
{
|
||||||
|
Container container;
|
||||||
|
return backInserter(container);
|
||||||
|
}
|
||||||
|
static assert(!is(typeof(func!())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
Container container;
|
||||||
|
static assert(isOutputRange!(typeof(backInserter(container)), string));
|
||||||
|
}
|
387
tests/tanya/range/tests/primitive.d
Normal file
387
tests/tanya/range/tests/primitive.d
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
module tanya.range.tests.primitive;
|
||||||
|
|
||||||
|
import tanya.range;
|
||||||
|
import tanya.test.stub;
|
||||||
|
|
||||||
|
private struct AssertPostblit
|
||||||
|
{
|
||||||
|
this(this) @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
static struct Range1(T)
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
T empty() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(!isInputRange!(Range1!int));
|
||||||
|
static assert(!isInputRange!(Range1!(const bool)));
|
||||||
|
|
||||||
|
static struct Range2
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
int popFront() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(isInputRange!Range2);
|
||||||
|
|
||||||
|
static struct Range3
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
void front() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(!isInputRange!Range3);
|
||||||
|
|
||||||
|
static struct Range4
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
enum bool empty = false;
|
||||||
|
}
|
||||||
|
static assert(isInputRange!Range4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ranges with non-copyable elements can be input ranges
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
@WithLvalueElements
|
||||||
|
static struct R
|
||||||
|
{
|
||||||
|
mixin InputRangeStub!NonCopyable;
|
||||||
|
}
|
||||||
|
static assert(isInputRange!R);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ranges with const non-copyable elements can be input ranges
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
@WithLvalueElements
|
||||||
|
static struct R
|
||||||
|
{
|
||||||
|
mixin InputRangeStub!(const(NonCopyable));
|
||||||
|
}
|
||||||
|
static assert(isInputRange!R);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
static struct Range1
|
||||||
|
{
|
||||||
|
}
|
||||||
|
static struct Range2
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
Range1 save() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return Range1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(!isForwardRange!Range2);
|
||||||
|
|
||||||
|
static struct Range3
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
const(typeof(this)) save() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(!isForwardRange!Range3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
static struct Range(T, U)
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub;
|
||||||
|
|
||||||
|
@property T front() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return T.init;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property U back() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return U.init;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(!isBidirectionalRange!(Range!(int, uint)));
|
||||||
|
static assert(!isBidirectionalRange!(Range!(int, const int)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ranges with non-copyable elements can be bidirectional ranges
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
@WithLvalueElements
|
||||||
|
static struct R
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub!NonCopyable;
|
||||||
|
}
|
||||||
|
static assert(isBidirectionalRange!R);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
static struct Range1
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub;
|
||||||
|
mixin RandomAccessRangeStub;
|
||||||
|
}
|
||||||
|
static assert(!isRandomAccessRange!Range1);
|
||||||
|
|
||||||
|
@Length
|
||||||
|
static struct Range2(Args...)
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub;
|
||||||
|
|
||||||
|
int opIndex(Args) @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(isRandomAccessRange!(Range2!size_t));
|
||||||
|
static assert(!isRandomAccessRange!(Range2!()));
|
||||||
|
static assert(!isRandomAccessRange!(Range2!(size_t, size_t)));
|
||||||
|
|
||||||
|
@Length
|
||||||
|
static struct Range3
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub;
|
||||||
|
|
||||||
|
int opIndex(const size_t pos1, const size_t pos2 = 0)
|
||||||
|
@nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(isRandomAccessRange!Range3);
|
||||||
|
|
||||||
|
static struct Range4
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub;
|
||||||
|
mixin RandomAccessRangeStub;
|
||||||
|
|
||||||
|
size_t opDollar() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static assert(!isRandomAccessRange!Range4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ranges with non-copyable elements can be random-access ranges
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
@WithLvalueElements @Infinite
|
||||||
|
static struct R
|
||||||
|
{
|
||||||
|
mixin RandomAccessRangeStub!NonCopyable;
|
||||||
|
}
|
||||||
|
static assert(isRandomAccessRange!R);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
@Infinite
|
||||||
|
static struct StaticConstRange
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
static bool empty = false;
|
||||||
|
}
|
||||||
|
static assert(!isInfinite!StaticConstRange);
|
||||||
|
|
||||||
|
@Infinite
|
||||||
|
static struct TrueRange
|
||||||
|
{
|
||||||
|
mixin InputRangeStub;
|
||||||
|
|
||||||
|
static const bool empty = true;
|
||||||
|
}
|
||||||
|
static assert(!isInfinite!TrueRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
@Infinite
|
||||||
|
static struct InfiniteRange
|
||||||
|
{
|
||||||
|
mixin ForwardRangeStub;
|
||||||
|
private int i;
|
||||||
|
|
||||||
|
void popFront() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
++this.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void popBack() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
--this.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property int front() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property int back() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
InfiniteRange range;
|
||||||
|
popFrontExactly(range, 2);
|
||||||
|
assert(range.front == 2);
|
||||||
|
popFrontN(range, 2);
|
||||||
|
assert(range.front == 4);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
InfiniteRange range;
|
||||||
|
popBackExactly(range, 2);
|
||||||
|
assert(range.back == -2);
|
||||||
|
popBackN(range, 2);
|
||||||
|
assert(range.back == -4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
static struct Range
|
||||||
|
{
|
||||||
|
private int[5] a = [1, 2, 3, 4, 5];
|
||||||
|
private size_t begin = 0, end = 5;
|
||||||
|
|
||||||
|
Range save() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void popFront() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
++this.begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void popBack() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
--this.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property int front() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.a[this.begin];
|
||||||
|
}
|
||||||
|
|
||||||
|
@property int back() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.a[this.end - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
@property bool empty() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.begin >= this.end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Range range;
|
||||||
|
|
||||||
|
popFrontN(range, 3);
|
||||||
|
assert(range.front == 4);
|
||||||
|
assert(range.back == 5);
|
||||||
|
|
||||||
|
popFrontN(range, 20);
|
||||||
|
assert(range.empty);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Range range;
|
||||||
|
|
||||||
|
popBackN(range, 3);
|
||||||
|
assert(range.front == 1);
|
||||||
|
assert(range.back == 2);
|
||||||
|
|
||||||
|
popBackN(range, 20);
|
||||||
|
assert(range.empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
// Returns its elements by reference.
|
||||||
|
@Infinite @WithLvalueElements
|
||||||
|
static struct R1
|
||||||
|
{
|
||||||
|
mixin InputRangeStub!AssertPostblit;
|
||||||
|
}
|
||||||
|
static assert(is(typeof(moveFront(R1()))));
|
||||||
|
|
||||||
|
// Returns elements with a postblit constructor by value. moveFront fails.
|
||||||
|
@Infinite
|
||||||
|
static struct R2
|
||||||
|
{
|
||||||
|
mixin InputRangeStub!AssertPostblit;
|
||||||
|
}
|
||||||
|
static assert(!is(typeof(moveFront(R2()))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
// Returns its elements by reference.
|
||||||
|
@Infinite @WithLvalueElements
|
||||||
|
static struct R1
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub!AssertPostblit;
|
||||||
|
}
|
||||||
|
static assert(is(typeof(moveBack(R1()))));
|
||||||
|
|
||||||
|
// Returns elements with a postblit constructor by value. moveBack fails.
|
||||||
|
@Infinite
|
||||||
|
static struct R2
|
||||||
|
{
|
||||||
|
mixin BidirectionalRangeStub!AssertPostblit;
|
||||||
|
}
|
||||||
|
static assert(!is(typeof(moveBack(R2()))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
// Returns its elements by reference.
|
||||||
|
@Infinite @WithLvalueElements
|
||||||
|
static struct R1
|
||||||
|
{
|
||||||
|
mixin RandomAccessRangeStub!AssertPostblit;
|
||||||
|
}
|
||||||
|
static assert(is(typeof(moveAt(R1(), 0))));
|
||||||
|
|
||||||
|
// Returns elements with a postblit constructor by value. moveAt fails.
|
||||||
|
@Infinite
|
||||||
|
static struct R2
|
||||||
|
{
|
||||||
|
mixin RandomAccessRangeStub!AssertPostblit;
|
||||||
|
}
|
||||||
|
static assert(!is(typeof(moveAt(R2(), 0))));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Works with non-copyable elements
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
static assert(hasLvalueElements!(NonCopyable[]));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user