From 397b5bc78fc6a9148cebf1573c11d72f9a19a21d Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 3 Mar 2023 17:16:04 +0100 Subject: [PATCH] add more tests to `offsets.zig` --- tests/utility/offsets.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/utility/offsets.zig b/tests/utility/offsets.zig index 02cb0fc..86c0880 100644 --- a/tests/utility/offsets.zig +++ b/tests/utility/offsets.zig @@ -80,6 +80,35 @@ test "offsets - convertPositionEncoding" { try testConvertPositionEncoding("a¶↉🠁", 0, 10, .{ 10, 5, 4 }); try testConvertPositionEncoding("a¶↉🠁\na¶↉🠁", 1, 6, .{ 6, 3, 3 }); } +test "offsets - locIntersect" { + const a = offsets.Loc{ .start = 2, .end = 5 }; + try std.testing.expect(offsets.locIntersect(a, .{ .start = 0, .end = 2 }) == false); + try std.testing.expect(offsets.locIntersect(a, .{ .start = 1, .end = 3 }) == true); + try std.testing.expect(offsets.locIntersect(a, .{ .start = 2, .end = 4 }) == true); + try std.testing.expect(offsets.locIntersect(a, .{ .start = 3, .end = 5 }) == true); + try std.testing.expect(offsets.locIntersect(a, .{ .start = 4, .end = 6 }) == true); + try std.testing.expect(offsets.locIntersect(a, .{ .start = 5, .end = 7 }) == false); +} + +test "offsets - locInside" { + const outer = offsets.Loc{ .start = 2, .end = 5 }; + try std.testing.expect(offsets.locInside(.{ .start = 0, .end = 2 }, outer) == false); + try std.testing.expect(offsets.locInside(.{ .start = 1, .end = 3 }, outer) == false); + try std.testing.expect(offsets.locInside(.{ .start = 2, .end = 4 }, outer) == true); + try std.testing.expect(offsets.locInside(.{ .start = 3, .end = 5 }, outer) == true); + try std.testing.expect(offsets.locInside(.{ .start = 4, .end = 6 }, outer) == false); + try std.testing.expect(offsets.locInside(.{ .start = 5, .end = 7 }, outer) == false); +} + +test "offsets - locMerge" { + const a = offsets.Loc{ .start = 2, .end = 5 }; + try std.testing.expectEqualDeep(offsets.locMerge(a, .{ .start = 0, .end = 2 }), .{ .start = 0, .end = 5 }); + try std.testing.expectEqualDeep(offsets.locMerge(a, .{ .start = 1, .end = 3 }), .{ .start = 1, .end = 5 }); + try std.testing.expectEqualDeep(offsets.locMerge(a, .{ .start = 2, .end = 4 }), .{ .start = 2, .end = 5 }); + try std.testing.expectEqualDeep(offsets.locMerge(a, .{ .start = 3, .end = 5 }), .{ .start = 2, .end = 5 }); + try std.testing.expectEqualDeep(offsets.locMerge(a, .{ .start = 4, .end = 6 }), .{ .start = 2, .end = 6 }); + try std.testing.expectEqualDeep(offsets.locMerge(a, .{ .start = 5, .end = 7 }), .{ .start = 2, .end = 7 }); +} test "offsets - advancePosition" { try testAdvancePosition("", 0, 0, 0, 0, 0, 0);