From 2f814b37e84b3618792c4674805a2bf716e08cdf Mon Sep 17 00:00:00 2001 From: Bryan Lee <38807139+liby@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:44:17 +0800 Subject: [PATCH] Add unit tests for kitty image aspect ratio calculation --- src/terminal/kitty/graphics_storage.zig | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/terminal/kitty/graphics_storage.zig b/src/terminal/kitty/graphics_storage.zig index a04a864c4..06769dc3c 100644 --- a/src/terminal/kitty/graphics_storage.zig +++ b/src/terminal/kitty/graphics_storage.zig @@ -1262,3 +1262,43 @@ test "storage: delete images by range 4" { try testing.expectEqual(@as(usize, 0), s.placements.count()); try testing.expectEqual(tracked, t.screen.pages.countTrackedPins()); } + +test "storage: aspect ratio calculation when only columns or rows specified" { + const testing = std.testing; + const alloc = testing.allocator; + + var t = try terminal.Terminal.init(alloc, .{ .cols = 100, .rows = 100 }); + defer t.deinit(alloc); + t.width_px = 100; + t.height_px = 100; + + // Case 1: Only columns specified + { + const image = Image{ .id = 1, .width = 4, .height = 2 }; + var placement = ImageStorage.Placement{ + .location = .{ .virtual = {} }, + .columns = 6, + .rows = 0, + }; + + const grid_size = placement.gridSize(image, &t); + // 6 columns * (2/4) = 3 rows + try testing.expectEqual(@as(u32, 6), grid_size.cols); + try testing.expectEqual(@as(u32, 3), grid_size.rows); + } + + // Case 2: Only rows specified + { + const image = Image{ .id = 2, .width = 2, .height = 4 }; + var placement = ImageStorage.Placement{ + .location = .{ .virtual = {} }, + .columns = 0, + .rows = 6, + }; + + const grid_size = placement.gridSize(image, &t); + // 6 rows * (2/4) = 3 columns + try testing.expectEqual(@as(u32, 3), grid_size.cols); + try testing.expectEqual(@as(u32, 6), grid_size.rows); + } +}