From 7e6b85ef480847cbf933550eeac192969fabc4df Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 7 Aug 2019 21:04:51 -0300 Subject: [PATCH] lang: add tests - lang: add deinit() --- src/lang.zig | 26 +++++++++++++++++++++++++- src/main.zig | 6 +++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 9dc588a..cf99bc0 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -141,6 +141,10 @@ pub const Lang = struct { }; } + pub fn deinit(self: *Lang) void { + self.keywords.deinit(); + } + fn fillKeywords(self: *Lang) !void { _ = try self.keywords.put("noop", .Noop); _ = try self.keywords.put("load", .Load); @@ -273,4 +277,24 @@ pub const Lang = struct { } }; -// TODO tests +test "noop" { + var lang = Lang.init(std.heap.direct_allocator); + var cmds = try lang.parse("noop;"); + std.testing.expectEqual(cmds.len, 1); + std.testing.expectEqual(cmds.at(0).command, .Noop); +} + +test "load, phaser, quicksave" { + var lang = Lang.init(std.heap.direct_allocator); + const prog = + \\load :0; + \\phaser 3 1 25 0.25 0 1; + \\quicksave; + ; + var cmds = try lang.parse(prog); + + std.testing.expectEqual(cmds.len, 3); + std.testing.expectEqual(cmds.at(0).command, .Load); + std.testing.expectEqual(cmds.at(1).command, .Phaser); + std.testing.expectEqual(cmds.at(2).command, .Quicksave); +} diff --git a/src/main.zig b/src/main.zig index bdbf8a6..ebe507d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,6 +2,10 @@ const std = @import("std"); const langs = @import("lang.zig"); const runners = @import("runner.zig"); +test "scritcher" { + _ = @import("lang.zig"); +} + pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.c_allocator); defer arena.deinit(); @@ -9,7 +13,7 @@ pub fn main() !void { const allocator = &arena.allocator; var lang = langs.Lang.init(allocator); - //defer lang.deinit(); + defer lang.deinit(); var runner = runners.Runner.init(allocator); defer runner.deinit();