Improve the DX of TrackedString
This commit is contained in:
parent
e9b80e659c
commit
4d73010238
3 changed files with 11 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
|||
const std = @import("std");
|
||||
const cham = @import("chameleon");
|
||||
|
||||
const TrackedString = @import("../util/trackedString.zig").TrackedString;
|
||||
const TrackedString = @import("../util/utils.zig").TrackedString;
|
||||
|
||||
const log = std.log;
|
||||
|
||||
|
|
@ -238,13 +238,13 @@ test "logFn works" {
|
|||
defer deinit();
|
||||
|
||||
try config.addScope(.{
|
||||
.scope = TrackedString.initConst("someScope"),
|
||||
.rename = TrackedString.initConst("some rename"),
|
||||
.scope = TrackedString.constant("someScope"),
|
||||
.rename = TrackedString.constant("some rename"),
|
||||
.color = .green,
|
||||
});
|
||||
try config.addScope(.{
|
||||
.scope = TrackedString.initConst("other"),
|
||||
.rename = TrackedString.initConst("other rename"),
|
||||
.scope = TrackedString.constant("other"),
|
||||
.rename = TrackedString.constant("other rename"),
|
||||
.color = .blue,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ pub const TrackedString = struct {
|
|||
data: []const u8,
|
||||
kind: AllocKind,
|
||||
|
||||
pub fn initAlloc(value: []const u8, allocator: std.mem.Allocator) !TrackedString {
|
||||
pub fn alloc(value: []const u8, allocator: std.mem.Allocator) !TrackedString {
|
||||
return .{
|
||||
.data = try allocator.dupe(u8, value),
|
||||
.kind = .{ .Allocated = allocator },
|
||||
};
|
||||
}
|
||||
|
||||
pub fn initConst(comptime value: []const u8) TrackedString {
|
||||
pub fn constant(comptime value: []const u8) TrackedString {
|
||||
return .{
|
||||
.data = value,
|
||||
.kind = .{ .Constant = {} },
|
||||
|
|
@ -64,13 +64,13 @@ const t = std.testing;
|
|||
test "the different kinds work" {
|
||||
const a = t.allocator;
|
||||
|
||||
var strOne = try TrackedString.initAlloc("hello, world", a);
|
||||
var strOne = try TrackedString.alloc("hello, world", a);
|
||||
defer strOne.deinit();
|
||||
|
||||
try t.expectEqualStrings("hello, world", strOne.data);
|
||||
try t.expectEqual(AllocKind{ .Allocated = a }, strOne.kind);
|
||||
|
||||
var strTwo = TrackedString.initConst("hello, world");
|
||||
var strTwo = TrackedString.constant("hello, world");
|
||||
defer strTwo.deinit();
|
||||
|
||||
try t.expectEqualStrings("hello, world", strTwo.data);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
pub const str = @import("trackedString.zig");
|
||||
const str = @import("./trackedString.zig");
|
||||
pub const TrackedString = str.TrackedString;
|
||||
|
||||
comptime {
|
||||
const std = @import("std");
|
||||
|
|
|
|||
Loading…
Reference in a new issue