| ... | ... | @@ -147,6 +147,46 @@ test "mem.Allocator basics" { |
| 147 | 147 | try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0)); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | test "Allocator.resize" { |
| 151 | const primitiveIntTypes = .{ |
| 152 | i8, |
| 153 | u8, |
| 154 | i16, |
| 155 | u16, |
| 156 | i32, |
| 157 | u32, |
| 158 | i64, |
| 159 | u64, |
| 160 | i128, |
| 161 | u128, |
| 162 | isize, |
| 163 | usize, |
| 164 | }; |
| 165 | inline for (primitiveIntTypes) |T| { |
| 166 | var values = try testing.allocator.alloc(T, 100); |
| 167 | defer testing.allocator.free(values); |
| 168 | |
| 169 | for (values) |*v, i| v.* = @intCast(T, i); |
| 170 | values = try testing.allocator.resize(values, values.len + 10); |
| 171 | try testing.expect(values.len == 110); |
| 172 | } |
| 173 | |
| 174 | const primitiveFloatTypes = .{ |
| 175 | f16, |
| 176 | f32, |
| 177 | f64, |
| 178 | f128, |
| 179 | }; |
| 180 | inline for (primitiveFloatTypes) |T| { |
| 181 | var values = try testing.allocator.alloc(T, 100); |
| 182 | defer testing.allocator.free(values); |
| 183 | |
| 184 | for (values) |*v, i| v.* = @intToFloat(T, i); |
| 185 | values = try testing.allocator.resize(values, values.len + 10); |
| 186 | try testing.expect(values.len == 110); |
| 187 | } |
| 188 | } |
| 189 | |
| 150 | 190 | /// Copy all of source into dest at position 0. |
| 151 | 191 | /// dest.len must be >= source.len. |
| 152 | 192 | /// If the slices overlap, dest.ptr must be <= src.ptr. |