Skip to content

Commit

Permalink
link same day twice
Browse files Browse the repository at this point in the history
  • Loading branch information
schmee committed Jan 24, 2024
1 parent 7c2c3f9 commit ece4a80
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Allocator = std.mem.Allocator;
const LocalDate = date.LocalDate;
const ChainDb = main.ChainDb;
const LinkDb = main.LinkDb;
const Link = main.Link;

var allocator = std.heap.c_allocator;
const print_output = false;
Expand Down Expand Up @@ -50,6 +51,11 @@ const TmpDb = struct {
}
}

fn unloadFiles(self: *Self) void {
if (self.files) |*fs| fs.close();
self.files = null;
}

fn deinit(self: *Self) void {
if (self.files) |*fs| fs.close();
self.tmpdir.cleanup();
Expand Down Expand Up @@ -103,6 +109,44 @@ test "basic" {
try expectEqual(@as(i64, 1704063600), link_db.links.items[0].timestamp);
}

test "linking same day twice" {
var db = try TmpDb.init();
defer db.deinit();

const commands = [_][]const u8{
"",
"add Foo daily",
"link 1 20240101",
};

for (commands) |arg| {
try runCommand(db.path, arg);
}

{
defer db.unloadFiles();

var link_db = db.linkDb();
try link_db.materialize(1);

const meta = link_db.meta;
try expectEqual(meta.len, 1);

try expectEqualSlices(Link, link_db.links.items, &.{ Link{ .chain_id = 0, .timestamp = 1704063600, .tags = 0}});
}

try runCommand(db.path, "link 1 20240101");
{
var link_db = db.linkDb();
try link_db.materialize(1);

const meta = link_db.meta;
try expectEqual(meta.len, 1);

try expectEqualSlices(Link, link_db.links.items, &.{ Link{ .chain_id = 0, .timestamp = 1704063600, .tags = 0}});
}
}

test "parse date" {
try testDateParse(try LocalDate.init(2023, 1, 1), "20230101");
}
Expand Down

0 comments on commit ece4a80

Please sign in to comment.