zls/tests/lsp_features/folding_range.zig
Techatrix 61c0981294
Use zig-lsp-codegen (#850)
* add lsp.zig

* change references from types.zig to lsp.zig

* remove types.zig and requests.zig

* add tres as a submodule

* transition codebase from types.zig to lsp.zig

* update lsp.zig

* completely overhaul message handler

* fix memory errors

* partially transition tests to lsp.zig

* update lsp.zig

* more test fixes

* disable failing tests

* fix message handling bugs

* fix remaining tests

* access correct union in diff.applyTextEdits

* more message handler fixes

* run zig fmt

* update tres submodule

* fix memory access to freed memory

* simplify initialize_msg for testing

* check if publishDiagnostics is supported
2022-12-27 01:47:57 -05:00

69 lines
1.7 KiB
Zig

const std = @import("std");
const zls = @import("zls");
const builtin = @import("builtin");
const tres = @import("tres");
const Context = @import("../context.zig").Context;
const types = zls.types;
const allocator: std.mem.Allocator = std.testing.allocator;
test "foldingRange - empty" {
try testFoldingRange("", "[]");
}
test "foldingRange - smoke" {
try testFoldingRange(
\\fn main() u32 {
\\ return 1 + 1;
\\}
,
\\[{"startLine":0,"endLine":1}]
);
}
test "foldingRange - #801" {
try testFoldingRange(
\\fn score(c: u8) !u32 {
\\ return switch(c) {
\\ 'a'...'z' => c - 'a',
\\ 'A'...'Z' => c - 'A',
\\ _ => error
\\ };
\\}
,
\\[]
);
}
fn testFoldingRange(source: []const u8, expect: []const u8) !void {
var ctx = try Context.init();
defer ctx.deinit();
const test_uri: []const u8 = switch (builtin.os.tag) {
.windows => "file:///C:\\test.zig",
else => "file:///test.zig",
};
try ctx.requestDidOpen(test_uri, source);
const params = types.FoldingRangeParams{ .textDocument = .{ .uri = test_uri } };
const response = try ctx.requestGetResponse(?[]types.FoldingRange, "textDocument/foldingRange", params);
var actual = std.ArrayList(u8).init(allocator);
defer actual.deinit();
try tres.stringify(response.result, .{
.emit_null_optional_fields = false,
}, actual.writer());
try expectEqualJson(expect, actual.items);
}
fn expectEqualJson(expect: []const u8, actual: []const u8) !void {
// TODO: Actually compare strings as JSON values.
return std.testing.expectEqualStrings(expect, actual);
}