Skip to content

Commit afad813

Browse files
add test diffBisect (#6)
1 parent d360348 commit afad813

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

DiffMatchPatch.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,27 @@ fn rebuildtexts(allocator: std.mem.Allocator, diffs: std.ArrayListUnmanaged(Diff
16361636
};
16371637
}
16381638

1639+
test diffBisect {
1640+
// Normal.
1641+
const a = "cat";
1642+
const b = "map";
1643+
// Since the resulting diff hasn't been normalized, it would be ok if
1644+
// the insertion and deletion pairs are swapped.
1645+
// If the order changes, tweak this test as required.
1646+
var diffs = std.ArrayListUnmanaged(Diff){};
1647+
defer diffs.deinit(talloc);
1648+
var this = default;
1649+
try diffs.appendSlice(talloc, &.{ Diff.init(.delete, "c"), Diff.init(.insert, "m"), Diff.init(.equal, "a"), Diff.init(.delete, "t"), Diff.init(.insert, "p") });
1650+
// Travis TODO not sure if maxInt(u64) is correct for DateTime.MaxValue
1651+
try std.testing.expectEqualDeep(diffs, try this.diffBisect(talloc, a, b, std.math.maxInt(u64))); // Normal.
1652+
1653+
// Timeout.
1654+
diffs.items.len = 0;
1655+
try diffs.appendSlice(talloc, &.{ Diff.init(.delete, "cat"), Diff.init(.insert, "map") });
1656+
// Travis TODO not sure if 0 is correct for DateTime.MinValue
1657+
try std.testing.expectEqualDeep(diffs, try this.diffBisect(talloc, a, b, 0)); // Timeout.
1658+
}
1659+
16391660
const talloc = std.testing.allocator;
16401661
test diff {
16411662
// Perform a trivial diff.

0 commit comments

Comments
 (0)