update: cleanup

This commit is contained in:
Lucas F. 2026-01-20 19:03:22 -03:00
parent 8fd9086d98
commit a0645cb0d1

View file

@ -4,6 +4,9 @@ const Context = @import("context.zig").Context;
const Value = @import("context.zig").Value;
test "context set amigável e get com ponto" {
std.debug.print("____________________________________________________\n", .{});
std.debug.print("1 - context set amigável e get com ponto\n", .{});
const allocator = testing.allocator;
var ctx = Context.init(allocator);
defer ctx.deinit();
@ -17,17 +20,26 @@ test "context set amigável e get com ponto" {
// struct
const Person = struct { nome: []const u8, idade: i64 };
const p = Person{ .nome = "Ana", .idade = 25 };
try ctx.set("user", p);
const p2 = Person{ .nome = "Fulana", .idade = 28 };
const people = [_]Person{ p, p2 };
// try ctx.set("user", p);
try ctx.set("user", people);
// list
const numeros = [_]i64{ 1, 2, 3 };
try ctx.set("lista", numeros);
for (ctx.get("user").?.list) |item| {
std.debug.print("user {any}\n", .{item.dict.get("nome").?});
}
// acesso
try testing.expectEqualStrings("Lucas", ctx.get("nome").?.string);
try testing.expect(ctx.get("idade").?.int == 30);
try testing.expectEqualStrings("Ana", ctx.get("user.nome").?.string);
try testing.expect(ctx.get("user.idade").?.int == 25);
// try testing.expectEqualStrings("Ana", ctx.get("user.nome").?.string);
// try testing.expect(ctx.get("user.idade").?.int == 25);
try testing.expect(ctx.get("lista.1").?.int == 2);
try testing.expect(ctx.get("vazio").?.string.len == 0);
try testing.expect(ctx.get("preco").?.float == 99.99);