Debian Codegraph @

libphobos/src/std/internal/test/range.d

raw
1 /**
2 For testing only.
3 Contains tests related to member privacy that cannot be verified inside
4 std.range itself.
5 */
6 module std.internal.test.range;
7
8 // Note: currently can't be @safe because RefCounted, which is used by chunks,
9 // isn't.
10 @system /*@safe*/ unittest
11 {
12 import std.algorithm.comparison : equal;
13 import std.range : chunks;
14
15 struct R
16 {
17 int state = 0;
18 @property bool empty() { return state >= 5; }
19 @property int front() { return state; }
20 void popFront() { state++; }
21 }
22
23 auto r = R().chunks(3);
24 assert(r.equal!equal([[ 0, 1, 2 ], [ 3, 4 ]]));
25 }
26
27 // https://issues.dlang.org/show_bug.cgi?id=24415
28 @safe unittest
29 {
30 import std.range : only;
31
32 static struct S(T)
33 {
34 T i;
35
36 this(ref return scope inout(S) rhs) scope @safe inout pure nothrow
37 {
38 i = rhs.i;
39 }
40 }
41 {
42 auto a = only(S!int(42));
43 auto b = a;
44 assert(!b.empty);
45 assert(b.front == S!int(42));
46
47 a.popFront();
48 auto c = a;
49 assert(c.empty);
50 }
51 {
52 auto a = only(S!(const int)(42));
53 auto b = a;
54 assert(!b.empty);
55 assert(b.front == S!(const int)(42));
56
57 a.popFront();
58 auto c = a;
59 assert(c.empty);
60 }
61 {
62 auto a = only(S!(immutable int)(42));
63 auto b = a;
64 assert(!b.empty);
65 assert(b.front == S!(immutable int)(42));
66
67 a.popFront();
68 auto c = a;
69 assert(c.empty);
70 }
71 {
72 auto a = only(S!int(42), S!int(192));
73 auto b = a;
74 assert(!b.empty);
75 assert(b.front == S!int(42));
76
77 a.popFront();
78 auto c = a;
79 assert(!c.empty);
80 assert(c.front == S!int(192));
81
82 a.popFront();
83 auto d = a;
84 assert(d.empty);
85 }
86 {
87 auto a = only(S!(const int)(42), S!(const int)(192));
88 auto b = a;
89 assert(!b.empty);
90 assert(b.front == S!(const int)(42));
91
92 a.popFront();
93 auto c = a;
94 assert(!c.empty);
95 assert(c.front == S!(const int)(192));
96
97 a.popFront();
98 auto d = a;
99 assert(d.empty);
100 }
101 {
102 auto a = only(S!(immutable int)(42), S!(immutable int)(192));
103 auto b = a;
104 assert(!b.empty);
105 assert(b.front == S!(immutable int)(42));
106
107 a.popFront();
108 auto c = a;
109 assert(!c.empty);
110 assert(c.front == S!(immutable int)(192));
111
112 a.popFront();
113 auto d = a;
114 assert(d.empty);
115 }
116 }