Update base notes model and exepcted Json

This commit is contained in:
Alex Selimov 2026-06-03 09:18:16 -04:00
parent 82b4eabca7
commit 106639b73a

View file

@ -1,25 +1,27 @@
const std = @import("std");
const Note = @This();
name: []const u8,
const Notes = std.json.ArrayHashMap(Note);
const Note = struct {
tags: []const []const u8,
path: []const u8,
pub fn init() Note {
return .{ .name = "", .tags = .empty, .path = "" };
return .{ .tags = .empty, .path = "" };
}
};
test "Parse from json" {
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));
}