Compare commits

..

No commits in common. "90f503f7c0d7c479ee93c1364259d10e344c5312" and "e24868406cb848a826e9dd796bd7e6bc2d1c0ced" have entirely different histories.

3 changed files with 27 additions and 55 deletions

View File

@ -36,7 +36,6 @@ pub fn build(builder: *std.build.Builder) void {
{
const tests = builder.addTestExe("test", "./src/tests.zig");
tests.addPackage(core_pkg);
tests.setTarget(target);
tests.setBuildMode(mode);
builder.step("test", "Run unit tests").dependOn(&tests.step);

View File

@ -187,23 +187,6 @@ test "Spliterating text" {
///
pub const Writer = meta.Function(@sizeOf(usize), []const u8, usize);
///
/// Returns `true` if `elements` starts with the characters in `with`, otherwise `false`.
///
pub fn begins(comptime Element: type, elements: []const Element, with: []const Element) bool {
if (elements.len < with.len) return false;
return equals(Element, elements[0 .. with.len], with);
}
test "Check memory begins with" {
const bytes_sequence = &.{69, 42};
const testing = std.testing;
try testing.expect(begins(u8, &.{69, 42, 0, 89}, bytes_sequence));
try testing.expect(!begins(u8, &.{69, 89, 42, 0}, bytes_sequence));
}
///
/// Returns `true` if `this` is the same length and contains the same data as `that`, otherwise
/// `false`.
@ -220,7 +203,7 @@ pub fn equals(comptime Element: type, this: []const Element, that: []const Eleme
return true;
}
test "Check memory is equals" {
test "Memory buffers equal" {
const bytes_sequence = &.{69, 42, 0};
const testing = std.testing;

View File

@ -76,7 +76,7 @@ pub const Path = extern struct {
/// Returns `true` if `this_path` is equal to `that_path, otherwise `false`.
///
pub fn equals(this_path: Path, that_path: Path) bool {
return core.io.equals(u8, this_path.buffer[0 ..this_path.
return core.io.equalsBytes(this_path.buffer[0 ..this_path.
length], that_path.buffer[0 .. that_path.length]);
}
@ -145,54 +145,44 @@ pub const Path = extern struct {
pub const seperator = '/';
};
test "Path" {
const testing = std.testing;
const empty_path = Path.empty;
try testing.expectEqual(empty_path.length, 0);
try testing.expect(empty_path.equals(Path.empty));
const joined_component_path = try Path.joined(&.{"path", "to/my", "/file"});
const joined_normalized_path = try Path.joined(&.{"path/to/my/file"});
try testing.expectEqual(empty_path.length, joined_normalized_path.length);
try testing.expect(joined_component_path.equals(joined_normalized_path));
}
///
/// Starts the **O**na **Ar**chive packer utility.
///
pub fn main() u8 {
pub fn main() !u8 {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(!gpa.deinit());
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const out_writer = std.io.getStdOut().writer();
const process = std.process;
const args = process.argsAlloc(allocator) catch {
try out_writer.print("Failed to allocate args memory", .{});
return 1;
};
const allocator = gpa.allocator();
const args = try process.argsAlloc(allocator);
defer process.argsFree(allocator, args);
if (args.len < 2) {
try out_writer.print("Usage: oar [OPTION]... [FILE]...", .{});
try out_writer.print("Options and arguments", .{});
const outWriter = std.io.getStdOut().writer();
return 0;
if (args.len > 1) {
const command = args[1];
const io = core.io;
if (io.equalsBytes(command, "pack")) {
return 0;
}
if (io.equalsBytes(command, "unpack")) {
return 0;
}
try outWriter.print("Unknown command: {s}", .{command});
return 1;
}
const arg = std.mem.sliceTo(args[1], 0);
if (core.io.begins(arg, "--create")) {
return 0;
}
try out_writer.print("Unrecognized command-line option `{s}`", .{arg});
try outWriter.print("{s}", .{args[0]});
return 0;
}
test {
}