Skip to content

Commit

Permalink
Coverage complete
Browse files Browse the repository at this point in the history
I want to spend some time documenting what I've built here before
sharing with the public, but my work here is done.
  • Loading branch information
mnemnion committed Jun 25, 2024
1 parent 2718aa2 commit 8b2510f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
30 changes: 20 additions & 10 deletions src/elements.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub const Rune = packed struct(u32) {
.c = 0,
.d = 0,
},
.follow => return null,
.follow => unreachable, // nbytes is null for this case
.lead => {
switch (nB) {
2 => {
Expand Down Expand Up @@ -385,15 +385,7 @@ pub const Mask = struct {
/// Return the next element of the Mask.
/// It is illegal to pass this function a nonexistent element.
pub inline fn after(self: Mask, cu: CodeUnit) ?CodeUnit {
if (safeMode) {
if (!self.isIn(cu)) {
std.debug.print(
"{} with body {d}, byte {d}, not in 0x{x:0>16}\n",
.{ cu.kind, cu.body, cu.byte(), self.m },
);
std.debug.assert(false);
}
}
std.debug.assert(self.isIn(cu));
if (cu.body == 63) return null;
const kind = cu.kind;
var next: u6 = cu.body + 1;
Expand Down Expand Up @@ -730,3 +722,21 @@ test "rune tests" {
try expect(rD.equalToCodepoint('🤔'));
try expectError(error.CodepointTooHigh, Rune.fromCodepoint(0x110000));
}

test "invalid Rune tests" {
try expectEqual(null, Rune.fromSlice("\x81abc"));
try expectEqual(null, Rune.fromSlice("\x9f0"));
try expectEqual(null, Rune.fromSlice("\xcer"));
try expectEqual(null, Rune.fromSlice("\xff\xff\xff"));
try expectEqual(null, Rune.fromSlice("\xe2✓"));
try expectEqual(null, Rune.fromSlice("\xf0\x9f\x98q"));
try expectError(
error.InvalidUnicode,
(Rune{
.a = 0xff,
.b = 0xff,
.c = 0,
.d = 0,
}).toCodepoint(),
);
}
38 changes: 4 additions & 34 deletions src/test-runeset.zig
Original file line number Diff line number Diff line change
Expand Up @@ -127,39 +127,10 @@ fn verifySetIteration(set: RuneSet) !void {
}
codeunits += rune.byteCount();
rune_count += 1;
if (lastRune.rawInt() == rune.rawInt()) {
std.debug.print(
"Saw {u} and {u}\n",
.{ lastRune.toCodepoint() catch unreachable, rune.toCodepoint() catch unreachable },
);
std.debug.print(
"rune bytes: {x} {x} {x} {x}\n",
.{ rune.a, rune.b, rune.c, rune.d },
);
try expect(false);
} else {
lastRune = rune;
}
lastRune = rune;
const runeArray = rune.toByteArray();
const matchedBytes = set.matchOne(&runeArray).?;
const byteCount = rune.byteCount();
if (safemode and byteCount != matchedBytes) {
const rune_point = rune.toCodepoint();
if (rune_point) |r| {
std.debug.print("rune {u} not a member of set\n", .{r});
std.debug.print(
"rune bytes: {x} {x} {x} {x}\n",
.{ rune.a, rune.b, rune.c, rune.d },
);
std.debug.print("set length {d}, idx {d}\n", .{ set.body.len, setIter.idx });
} else |_| {
std.debug.print(
"rune is invalid! {x} {x} {x} {x}\n",
.{ rune.a, rune.b, rune.c, rune.d },
);
}
}
// std.debug.print("{u}", .{rune.toCodepoint() catch unreachable});
try expectEqual(byteCount, matchedBytes);
}
std.debug.print("\n", .{});
Expand Down Expand Up @@ -371,11 +342,10 @@ fn verifySetsOfTwoLRstrings(L: LRstrings, R: LRstrings, alloc: Allocator) !void

//| Test Suite

test "workshop" {
test "iterator edge cases" {
const allocator = std.testing.allocator;
const g_set = try RuneSet.createFromConstString(greek.str, allocator);
defer g_set.deinit(allocator);
try verifySetsOfTwoLRstrings(deseret, greek, allocator);
try withStringVerifySetProperties("abcdefghijklmnopqrstuvwxyz", allocator);
try withStringVerifySetProperties("012345" ++ greek.str, allocator);
}

test "verify sets of LRstrings data" {
Expand Down

0 comments on commit 8b2510f

Please sign in to comment.