Fixed unit tests

This commit is contained in:
Alexandros Naskos 2021-07-10 20:05:16 +03:00
parent bba069526c
commit 70cfba0eb9
No known key found for this signature in database
GPG Key ID: 02BF2E72B0EA32D2
2 changed files with 4 additions and 3 deletions

View File

@ -134,7 +134,7 @@ pub const TextDocument = struct {
}; };
pub fn borrowNullTerminatedSlice(self: *const @This(), start_idx: usize, end_idx: usize) Held { pub fn borrowNullTerminatedSlice(self: *const @This(), start_idx: usize, end_idx: usize) Held {
std.debug.assert(end_idx >= start_idx and end_idx < self.text.len); std.debug.assert(end_idx >= start_idx);
const popped_char = self.mem[end_idx]; const popped_char = self.mem[end_idx];
self.mem[end_idx] = 0; self.mem[end_idx] = 0;
return .{ return .{

View File

@ -8,13 +8,14 @@ const std = @import("std");
const allocator = std.testing.allocator; const allocator = std.testing.allocator;
fn makeDocument(uri: []const u8, text: []const u8) !types.TextDocument { fn makeDocument(uri: []const u8, text: []const u8) !types.TextDocument {
const mem = try allocator.alloc(u8, text.len); const mem = try allocator.alloc(u8, text.len + 1);
std.mem.copy(u8, mem, text); std.mem.copy(u8, mem, text);
mem[text.len] = 0;
return types.TextDocument{ return types.TextDocument{
.uri = uri, .uri = uri,
.mem = mem, .mem = mem,
.text = mem[0..], .text = mem[0..text.len :0],
}; };
} }