diff --git a/src/main_ghostty.zig b/src/main_ghostty.zig index 6089371c2..88d4b00ac 100644 --- a/src/main_ghostty.zig +++ b/src/main_ghostty.zig @@ -325,6 +325,7 @@ test { _ = @import("termio.zig"); _ = @import("input.zig"); _ = @import("cli.zig"); + _ = @import("tcp.zig"); _ = @import("surface_mouse.zig"); // Libraries diff --git a/src/tcp.zig b/src/tcp.zig index d458eae68..cc77459b0 100644 --- a/src/tcp.zig +++ b/src/tcp.zig @@ -1,8 +1,8 @@ //! TCP implementation. The TCP implementation is responsible for //! responding to TCP requests and dispatching them to the app's Mailbox. -pub const Thread = @import("tcp/Thread.zig"); -pub const Server = @import("tcp/Server.zig"); test { @import("std").testing.refAllDecls(@This()); + _ = @import("tcp/Command.zig"); + _ = @import("tcp/Server.zig"); } diff --git a/src/tcp/Command.zig b/src/tcp/Command.zig index 719e88fab..97eb592ee 100644 --- a/src/tcp/Command.zig +++ b/src/tcp/Command.zig @@ -44,4 +44,15 @@ pub const Command = enum { } }; -// TODO: These need proper testing. +test "Command.parse ping" { + const input = "ping"; + const expected = Command.ping; + const result = try Command.parse(input); + try std.testing.expect(result == expected); +} + +test "Command.parse invalid input" { + const input = ""; + const result = Command.parse(input); + try std.testing.expectError(Command.Error.InvalidInput, result); +} diff --git a/src/tcp/Server.zig b/src/tcp/Server.zig index 8ed3a301a..1f7235585 100644 --- a/src/tcp/Server.zig +++ b/src/tcp/Server.zig @@ -125,3 +125,19 @@ pub fn parseAddress(raw_addr: ?[:0]const u8) BindError!std.net.Address { return BindError.InvalidAddress; } + +test "parseAddress unix socket" { + const addr = "unix:///tmp/test.sock"; + const expected = try std.net.Address.initUnix("/tmp/test.sock"); + const actual = try parseAddress(addr); + const result = std.net.Address.eql(actual, expected); + try std.testing.expect(result == true); +} + +test "parseAddress IP address" { + const addr = "tcp://127.0.0.1:9090"; + const expected = try std.net.Address.parseIp4("127.0.0.1", 9090); + const actual = try parseAddress(addr); + const result = std.net.Address.eql(actual, expected); + try std.testing.expect(result == true); +}