Compare commits

...

3 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 88cf7be418
Merge c886ba184b into b6106883da 2024-05-02 07:36:51 +00:00
Tristan B. Velloza Kildaire c886ba184b View
- `opSlice()` now forwards to `opSlice(size_t, size_t)`
2024-05-02 09:36:39 +02:00
Tristan B. Velloza Kildaire 6372f2d8c7 View (unittests)
- Added more tests for `opSlice(size_t, size_t)`
2024-05-02 09:35:41 +02:00
1 changed files with 32 additions and 10 deletions

View File

@ -742,16 +742,7 @@ if(isSector!(SectorType)())
public T[] opSlice()
{
T[] buff;
foreach(SectorType sector; this.sectors)
{
buff ~= sector[];
}
// Trim to "fake" size
buff.length = this.curSize;
return buff;
return this[0..this.length];
}
public T[] opSlice(size_t start, size_t end)
@ -1012,4 +1003,35 @@ unittest
view ~= 5;
assert(view[0..5] == [1,2,3,4,5]);
// test: start <= end invariant broken
try
{
auto j = view[1..0];
assert(false);
}
catch(RangeError e)
{
}
// test: end out of bounds
try
{
auto j = view[1..view.length+1];
assert(false);
}
catch(RangeError e)
{
}
int[] d = [1,2,3];
writeln("according to dlang: ", d[1..2]);
writeln("test lekker: ", view[1..2]);
assert(view[1..2] == [2]);
writeln("test lekker: ", view[1..1]);
assert(view[1..1] == []);
}