1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 module tanya.memory.tests.op;
5 
6 import tanya.memory.op;
7 
8 @nogc nothrow pure @system unittest
9 {
10     ubyte[2] buffer = 1;
11     fill!0(buffer[1 .. $]);
12     assert(buffer[0] == 1 && buffer[1] == 0);
13 }
14 
15 @nogc nothrow pure @safe unittest
16 {
17     assert(equal(null, null));
18 }
19 
20 @nogc nothrow pure @safe unittest
21 {
22     ubyte[0] source, target;
23     source.copy(target);
24 }
25 
26 @nogc nothrow pure @safe unittest
27 {
28     ubyte[1] source = [1];
29     ubyte[1] target;
30     source.copy(target);
31     assert(target[0] == 1);
32 }
33 
34 @nogc nothrow pure @safe unittest
35 {
36     ubyte[8] source = [1, 2, 3, 4, 5, 6, 7, 8];
37     ubyte[8] target;
38     source.copy(target);
39     assert(equal(source, target));
40 }
41 
42 @nogc nothrow pure @safe unittest
43 {
44     ubyte[9] r1 = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' ];
45     ubyte[9] r2;
46 
47     copyBackward(r1, r2);
48     assert(equal(r1, r2));
49 }
50 
51 // Compares unanligned memory
52 @nogc nothrow pure @safe unittest
53 {
54     ubyte[16] r1 = [
55         'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
56         'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
57     ];
58     ubyte[16] r2 = [
59         'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
60         'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
61     ];
62 
63     assert(equal(r1, r2));
64     assert(equal(r1[1 .. $], r2[1 .. $]));
65     assert(equal(r1[0 .. $ - 1], r2[0 .. $ - 1]));
66     assert(equal(r1[0 .. 8], r2[0 .. 8]));
67 }