diff options
Diffstat (limited to 'src/locations.zig')
| -rw-r--r-- | src/locations.zig | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/src/locations.zig b/src/locations.zig index f6a0cf9c..fc39f92d 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -646,20 +646,6 @@ fn appendContext(arena: std.mem.Allocator, rows: *std.ArrayList(Pending), path: }); } -test "locations tab delimiter preserves source indentation and spaced paths" { - const row = parse("some directory/界.zig:12:3-5 \t\t value"); - try std.testing.expectEqualStrings("some directory/界.zig", row.path); - try std.testing.expectEqual(@as(usize, 12), row.at.line); - try std.testing.expectEqualStrings("\t value", "some directory/界.zig:12:3-5 \t\t value"[row.code_start..]); -} - -test "locations native results retain the first source tab" { - const text = "some directory/a.zig:3:2 \t value"; - const row = parseRaw(text); - try std.testing.expectEqualStrings("some directory/a.zig", row.path); - try std.testing.expectEqualStrings("\t value", text[row.code_start..]); -} - // ---- the Locations setting ---- pub const Config = struct { @@ -712,32 +698,6 @@ pub const Config = struct { } }; -test "LocationsConfig reflection round trip and partial updates" { - var config: Config = .{}; - config = try config.parse("context:5 tscontext:on"); - config = try config.parse("tslocations:off"); - try std.testing.expectEqual(Config{ .context = 5, .tscontext = true, .tslocations = false }, config); - var out: std.Io.Writer.Allocating = .init(std.testing.allocator); - defer out.deinit(); - try config.write(&out.writer); - try std.testing.expectEqualStrings("context:5 tscontext:on tslocations:off layout:stacked", out.written()); - try std.testing.expectEqual(config, try (Config{}).parse(out.written())); - try std.testing.expectEqual(config, try config.parse(" \n\t")); - try std.testing.expectEqual(@as(u16, 2), (try config.parse("context:1 context:2")).context); - try std.testing.expectEqual(Config.Layout.@"inline", (try config.parse("layout:inline")).layout); -} - -test "LocationsConfig rejects invalid updates atomically" { - const config: Config = .{ .context = 3, .tscontext = true }; - try std.testing.expectError(error.UnknownLocationSetting, config.parse("context:5 unknown:on")); - try std.testing.expectError(error.ExpectedOnOrOff, config.parse("context:5 tscontext:true")); - try std.testing.expectError(error.ExpectedKeyValue, config.parse("context")); - try std.testing.expectError(error.InvalidLayout, config.parse("context:5 layout:sideways")); - for ([_][]const u8{ "context:", "context:-1", "context:65536", "context:five" }) |input| - try std.testing.expectError(error.InvalidContext, config.parse(input)); - try std.testing.expectEqual(@as(u16, 3), config.context); -} - // ---- the analysis cache ---- /// Owned source snapshots keep analysis valid across filesystem changes and @@ -890,6 +850,46 @@ pub const Cache = struct { } }; +test "locations tab delimiter preserves source indentation and spaced paths" { + const row = parse("some directory/界.zig:12:3-5 \t\t value"); + try std.testing.expectEqualStrings("some directory/界.zig", row.path); + try std.testing.expectEqual(@as(usize, 12), row.at.line); + try std.testing.expectEqualStrings("\t value", "some directory/界.zig:12:3-5 \t\t value"[row.code_start..]); +} + +test "locations native results retain the first source tab" { + const text = "some directory/a.zig:3:2 \t value"; + const row = parseRaw(text); + try std.testing.expectEqualStrings("some directory/a.zig", row.path); + try std.testing.expectEqualStrings("\t value", text[row.code_start..]); +} + +test "LocationsConfig reflection round trip and partial updates" { + var config: Config = .{}; + config = try config.parse("context:5 tscontext:on"); + config = try config.parse("tslocations:off"); + try std.testing.expectEqual(Config{ .context = 5, .tscontext = true, .tslocations = false }, config); + var out: std.Io.Writer.Allocating = .init(std.testing.allocator); + defer out.deinit(); + try config.write(&out.writer); + try std.testing.expectEqualStrings("context:5 tscontext:on tslocations:off layout:stacked", out.written()); + try std.testing.expectEqual(config, try (Config{}).parse(out.written())); + try std.testing.expectEqual(config, try config.parse(" \n\t")); + try std.testing.expectEqual(@as(u16, 2), (try config.parse("context:1 context:2")).context); + try std.testing.expectEqual(Config.Layout.@"inline", (try config.parse("layout:inline")).layout); +} + +test "LocationsConfig rejects invalid updates atomically" { + const config: Config = .{ .context = 3, .tscontext = true }; + try std.testing.expectError(error.UnknownLocationSetting, config.parse("context:5 unknown:on")); + try std.testing.expectError(error.ExpectedOnOrOff, config.parse("context:5 tscontext:true")); + try std.testing.expectError(error.ExpectedKeyValue, config.parse("context")); + try std.testing.expectError(error.InvalidLayout, config.parse("context:5 layout:sideways")); + for ([_][]const u8{ "context:", "context:-1", "context:65536", "context:five" }) |input| + try std.testing.expectError(error.InvalidContext, config.parse(input)); + try std.testing.expectEqual(@as(u16, 3), config.context); +} + test "locations cache validates exact source and path and upgrades analysis" { const gpa = std.testing.allocator; syntax.start(gpa); |
