Update base notes model and exepcted Json
This commit is contained in:
parent
82b4eabca7
commit
106639b73a
1 changed files with 16 additions and 14 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue