From 106639b73a2f38b704b214d07edf29dbd537b8a4 Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Wed, 3 Jun 2026 09:18:16 -0400 Subject: [PATCH] Update base notes model and exepcted Json --- src/notes/model.zig | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/notes/model.zig b/src/notes/model.zig index 0bd3889..a5c92b7 100644 --- a/src/notes/model.zig +++ b/src/notes/model.zig @@ -1,25 +1,27 @@ const std = @import("std"); -const Note = @This(); -name: []const u8, -tags: []const []const u8, -path: []const u8, +const Notes = std.json.ArrayHashMap(Note); -pub fn init() Note { - return .{ .name = "", .tags = .empty, .path = "" }; -} +const Note = struct { + tags: []const []const u8, + path: []const u8, -test "Parse from json" { + pub fn init() Note { + return .{ .tags = .empty, .path = "" }; + } +}; + +test "Parse Notes from json" { const allocator = std.testing.allocator; - const json_string = "{\"name\": \"test\", \"tags\":[\"tag1\", \"tag2\"], \"path\":\"/path/to/test\"}"; + const json_string = "{\"test\":{ \"tags\":[\"tag1\", \"tag2\"], \"path\":\"/path/to/test\" }}"; - const result = try std.json.parseFromSlice(Note, allocator, json_string, .{}); + const result = try std.json.parseFromSlice(Notes, allocator, json_string, .{}); defer result.deinit(); const expect = std.testing.expect; - try expect(std.mem.eql(u8, "test", result.value.name)); - try expect(std.mem.eql(u8, "tag1", result.value.tags[0])); - try expect(std.mem.eql(u8, "tag2", result.value.tags[1])); - try expect(std.mem.eql(u8, "/path/to/test", result.value.path)); + const item = result.value.map.get("test").?; + try expect(std.mem.eql(u8, "tag1", item.tags[0])); + try expect(std.mem.eql(u8, "tag2", item.tags[1])); + try expect(std.mem.eql(u8, "/path/to/test", item.path)); }