Skip to content

Commit

Permalink
Merge pull request #6 from tomasz-lisowski/master
Browse files Browse the repository at this point in the history
Port to zig 0.11.0-dev.2317+46b2f1f70
  • Loading branch information
gernest authored Apr 4, 2023
2 parents cec82ea + 4e54541 commit 0414979
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
23 changes: 17 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});

const lib = b.addStaticLibrary("base32", "src/base32.zig");
lib.setBuildMode(mode);
const lib = b.addStaticLibrary(
.{
.name = "base32",
.root_source_file = .{ .path = "src/base32.zig" },
.target = target,
.optimize = optimize,
},
);
lib.install();

const coverage = b.option(bool, "coverage", "Generate test coverage") orelse false;

var main_tests = b.addTest("src/base32.zig");
main_tests.setBuildMode(mode);
var main_tests = b.addTest(
.{
.root_source_file = .{ .path = "src/base32.zig" },
.optimize = optimize,
},
);

if (coverage) {
main_tests.setExecCmd(&[_]?[]const u8{
Expand All @@ -23,5 +34,5 @@ pub fn build(b: *std.build.Builder) void {
}

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
test_step.dependOn(&main_tests.run().step);
}
6 changes: 3 additions & 3 deletions src/base32.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub const Encoding = struct {
},
.decode_map = blk: {
var a = [_]u8{0xFF} ** 256;
for (encoder_string) |c, i| {
for (encoder_string, 0..) |c, i| {
a[@intCast(usize, c)] = @intCast(u8, i);
}
break :blk a;
Expand Down Expand Up @@ -203,7 +203,7 @@ pub const Encoding = struct {
if (dbuf[j] == 0xFF) {
const pos = olen - src.len - 1;
log.warn("{} {}\n", .{ in, self.decode_map[in] });
for (self.decode_map) |m, idx| {
for (self.decode_map, 0..) |m, idx| {
log.warn("== {} ={x}\n", .{ idx, m });
}
log.warn("incorrenct input at {}\n", .{pos});
Expand Down Expand Up @@ -367,4 +367,4 @@ test "Decoding no padding" {
var result = try std_encoding_no_padding.decode(buf[0..size], encoded_no_pad);
try testing.expectEqualSlices(u8, ts.decoded, result);
}
}
}

0 comments on commit 0414979

Please sign in to comment.