lang: add tests

- lang: add deinit()
This commit is contained in:
Luna 2019-08-07 21:04:51 -03:00
parent b8dcb84294
commit 7e6b85ef48
2 changed files with 30 additions and 2 deletions

View file

@ -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);
}

View file

@ -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();