From c0498fffa198ecc5105b75d2ce556eae74c72f90 Mon Sep 17 00:00:00 2001 From: Techarix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:25:20 +0200 Subject: [PATCH] add completion tests on struct init fields --- tests/lsp_features/completion.zig | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig index 149db0b..eb63bdb 100644 --- a/tests/lsp_features/completion.zig +++ b/tests/lsp_features/completion.zig @@ -358,6 +358,68 @@ test "completion - error union" { }); } +test "completion - struct init" { + try testCompletion( + \\const S = struct { + \\ alpha: u32, + \\ beta: []const u8, + \\}; + \\const foo = S{ . }; + , &.{ + .{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" }, + .{ .label = "beta", .kind = .Field, .detail = "beta: []const u8" }, + }); + try testCompletion( + \\const S = struct { + \\ alpha: u32, + \\ beta: []const u8, + \\ gamma: ?*S, + \\}; + \\const foo = S{ .alpha = 3, ., .gamma = null }; + , &.{ + // TODO `alpha` should be excluded + .{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" }, + .{ .label = "beta", .kind = .Field, .detail = "beta: []const u8" }, + // TODO `gamma` should be excluded + .{ .label = "gamma", .kind = .Field, .detail = "gamma: ?*S" }, + }); + try testCompletion( + \\const S = struct { + \\ alpha: *const S, + \\ beta: []const u8, + \\}; + \\const foo = S{ .alpha = S{ .beta = "{}" }, . }; + , &.{ + // TODO `alpha` should be excluded + .{ .label = "alpha", .kind = .Field, .detail = "alpha: *const S" }, + .{ .label = "beta", .kind = .Field, .detail = "beta: []const u8" }, + }); + try testCompletion( + \\const S = struct { + \\ alpha: *const S, + \\ beta: u32, + \\}; + \\const foo = S{ .alpha = S{ . } }; + , &.{ + .{ .label = "alpha", .kind = .Field, .detail = "alpha: *const S" }, + .{ .label = "beta", .kind = .Field, .detail = "beta: u32" }, + }); + try testCompletion( + \\const S = struct { + \\ alpha: *const S, + \\ beta: u32, + \\ gamma: ?*S, + \\}; + \\const foo = S{ .gamma = undefined, . , .alpha = undefined }; + , &.{ + // TODO `gamma` should be excluded + .{ .label = "gamma", .kind = .Field, .detail = "gamma: ?*S" }, + .{ .label = "beta", .kind = .Field, .detail = "beta: u32" }, + // TODO `alpha` should be excluded + .{ .label = "alpha", .kind = .Field, .detail = "alpha: *const S" }, + }); +} + test "completion - declarations" { try testCompletion( \\const S = struct {