35 lines
1.2 KiB
Zig
35 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const testing = std.testing;
|
|
const Context = @import("context.zig").Context;
|
|
const Value = @import("context.zig").Value;
|
|
|
|
test "context set amigável e get com ponto" {
|
|
const allocator = testing.allocator;
|
|
var ctx = Context.init(allocator);
|
|
defer ctx.deinit();
|
|
|
|
try ctx.set("nome", "Lucas");
|
|
try ctx.set("idade", 30);
|
|
try ctx.set("ativo", true);
|
|
try ctx.set("preco", 99.99);
|
|
try ctx.set("vazio", "");
|
|
|
|
// struct
|
|
const Person = struct { nome: []const u8, idade: i64 };
|
|
const p = Person{ .nome = "Ana", .idade = 25 };
|
|
try ctx.set("user", p);
|
|
|
|
// list
|
|
const numeros = [_]i64{ 1, 2, 3 };
|
|
try ctx.set("lista", numeros);
|
|
|
|
// 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.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);
|
|
try testing.expect(ctx.get("ativo").?.bool == true);
|
|
}
|