diff options
Diffstat (limited to 'src/surface.zig')
| -rw-r--r-- | src/surface.zig | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/surface.zig b/src/surface.zig index 5bee28d7..9333a75e 100644 --- a/src/surface.zig +++ b/src/surface.zig @@ -54,21 +54,6 @@ pub const Cell = struct { } }; -test "cell visual equality ignores dead grapheme tail bytes" { - var a: Cell = .{ .default = false }; - var b = a; - a.text[0] = 'x'; - b.text[0] = 'x'; - a.text[4] = 'a'; - b.text[4] = 'b'; - try std.testing.expect(a.visuallyEqual(&b)); - b.style.bold = true; - try std.testing.expect(!a.visuallyEqual(&b)); - a.default = true; - b.default = true; - try std.testing.expect(a.visuallyEqual(&b)); -} - /// A rectangle in pixels. pub const RectPx = struct { x: u32 = 0, @@ -128,20 +113,6 @@ pub fn containGeometry(iw: usize, ih: usize, max_w: u32, max_h: u32) ?NativeGeom return .{ .src = .{ .w = src_w, .h = src_h }, .dst = dst }; } -test "native image contain keeps aspect, bounds, top-left, and small-image size" { - try std.testing.expectEqual(RectPx{ .w = 40, .h = 20 }, containGeometry(400, 200, 40, 40).?.dst); - try std.testing.expectEqual(RectPx{ .w = 20, .h = 40 }, containGeometry(200, 400, 40, 40).?.dst); - try std.testing.expectEqual(RectPx{ .w = 17, .h = 9 }, containGeometry(17, 9, 40, 40).?.dst); - try std.testing.expect(containGeometry(17, 9, 0, 40) == null); - - const odd = containGeometry(403, 211, 101, 47).?; - try std.testing.expectEqual(RectPx{ .w = 89, .h = 47 }, odd.dst); - try std.testing.expectEqual(RectPx{ .w = 403, .h = 211 }, odd.src); - // Nothing its backend contract cannot represent. - try std.testing.expect(containGeometry(0, 10, 20, 20) == null); - if (@bitSizeOf(usize) > 32) try std.testing.expect(containGeometry(@as(usize, std.math.maxInt(u32)) + 1, 10, 20, 20) == null); -} - /// A rectangle in the frame's cells. pub const RectCell = struct { x: u16 = 0, y: u16 = 0, w: u16 = 0, h: u16 = 0 }; @@ -210,14 +181,6 @@ pub const Placement = struct { } }; -test "a placement's key follows its pane, its page and the revision of its pixels, and nothing of where it goes" { - const first = Placement.keyOf(41, 7, 3); - try std.testing.expectEqual(first, Placement.keyOf(41, 7, 3)); - try std.testing.expect(first != Placement.keyOf(41, 8, 3)); - try std.testing.expect(first != Placement.keyOf(41, 7, 4)); - try std.testing.expect(first != Placement.keyOf(42, 7, 3)); -} - /// One part of the frame and where it is, placed once by `draw.place` /// before anything is painted: every painter and every shell reads the /// geometry here instead of working it out again. `rect` is in grid cells @@ -517,6 +480,43 @@ pub const Surface = struct { } }; +test "cell visual equality ignores dead grapheme tail bytes" { + var a: Cell = .{ .default = false }; + var b = a; + a.text[0] = 'x'; + b.text[0] = 'x'; + a.text[4] = 'a'; + b.text[4] = 'b'; + try std.testing.expect(a.visuallyEqual(&b)); + b.style.bold = true; + try std.testing.expect(!a.visuallyEqual(&b)); + a.default = true; + b.default = true; + try std.testing.expect(a.visuallyEqual(&b)); +} + +test "native image contain keeps aspect, bounds, top-left, and small-image size" { + try std.testing.expectEqual(RectPx{ .w = 40, .h = 20 }, containGeometry(400, 200, 40, 40).?.dst); + try std.testing.expectEqual(RectPx{ .w = 20, .h = 40 }, containGeometry(200, 400, 40, 40).?.dst); + try std.testing.expectEqual(RectPx{ .w = 17, .h = 9 }, containGeometry(17, 9, 40, 40).?.dst); + try std.testing.expect(containGeometry(17, 9, 0, 40) == null); + + const odd = containGeometry(403, 211, 101, 47).?; + try std.testing.expectEqual(RectPx{ .w = 89, .h = 47 }, odd.dst); + try std.testing.expectEqual(RectPx{ .w = 403, .h = 211 }, odd.src); + // Nothing its backend contract cannot represent. + try std.testing.expect(containGeometry(0, 10, 20, 20) == null); + if (@bitSizeOf(usize) > 32) try std.testing.expect(containGeometry(@as(usize, std.math.maxInt(u32)) + 1, 10, 20, 20) == null); +} + +test "a placement's key follows its pane, its page and the revision of its pixels, and nothing of where it goes" { + const first = Placement.keyOf(41, 7, 3); + try std.testing.expectEqual(first, Placement.keyOf(41, 7, 3)); + try std.testing.expect(first != Placement.keyOf(41, 8, 3)); + try std.testing.expect(first != Placement.keyOf(41, 7, 4)); + try std.testing.expect(first != Placement.keyOf(42, 7, 3)); +} + test "surface print expands configured tabs and normalizes other controls" { const tab_cells: usize = @as(usize, config.tab_width) * 2; const replacement_cells = 5; |
