Skip to content

Instantly share code, notes, and snippets.

@ibebrett
Created November 26, 2018 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibebrett/16894bb263637f15a5ff9fd575c5b042 to your computer and use it in GitHub Desktop.
Save ibebrett/16894bb263637f15a5ff9fd575c5b042 to your computer and use it in GitHub Desktop.
const zalloc = @import("zalloc/index.zig");
const std = @import("std");
const debug = std.debug;
const Allocator = std.mem.Allocator;
test "test idiotic alloc low value" {
var allocator: Allocator = zalloc.IdioticAllocator(200).init().allocator;
var slice = try allocator.alloc(*i32, 100);
debug.assert(slice.len == 100);
}
test "test alloc too big" {
var allocator: Allocator = zalloc.IdioticAllocator(200).init().allocator;
if (allocator.alloc(*i32, 10000)) |slice| {
@panic("Should not be able to reserve an array of 10000");
} else |err| {
debug.assert(err == Allocator.Error.OutOfMemory);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment