From 75fc1506e59c1eaa52971d20df72c7cbeca5ac82 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 9 Jun 2022 23:17:53 +0200 Subject: Pass the sanity test --- src/main.zig | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 14bada3..7460c60 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,6 @@ const std = @import("std"); const field = @import("field.zig"); +const interpreter = @import("interpreter.zig"); const pointer = @import("pointer.zig"); const stackStack = @import("stackStack.zig"); @@ -10,3 +11,51 @@ pub fn main() anyerror!void { test "all" { std.testing.refAllDecls(@This()); } +test "minimal" { + const minimal = std.io.fixedBufferStream("@").reader(); + var f = try field.Field.init(std.testing.allocator); + defer f.deinit(); + try f.load(minimal); + const argv = [_][]const u8{"minimal"}; + var p = try pointer.Pointer.init(std.testing.allocator, f, null, argv[0..]); + defer p.deinit(); + + var i = try interpreter.Interpreter.init(std.testing.allocator, f, p); + defer i.deinit(); + + var code = try i.run(); + try std.testing.expectEqual(code, 0); +} +test "almost minimal" { + const minimal = std.io.fixedBufferStream(" @").reader(); + var f = try field.Field.init(std.testing.allocator); + defer f.deinit(); + try f.load(minimal); + const argv = [_][]const u8{"minimal"}; + var p = try pointer.Pointer.init(std.testing.allocator, f, null, argv[0..]); + defer p.deinit(); + + var i = try interpreter.Interpreter.init(std.testing.allocator, f, p); + defer i.deinit(); + + var code = try i.run(); + try std.testing.expectEqual(code, 0); +} +test "sanity" { + var file = try std.fs.cwd().openFile("mycology/sanity.bf", .{}); + defer file.close(); + + var f = try field.Field.init(std.testing.allocator); + defer f.deinit(); + try f.load(file.reader()); + + const argv = [_][]const u8{"sanity"}; + var p = try pointer.Pointer.init(std.testing.allocator, f, null, argv[0..]); + defer p.deinit(); + + var i = try interpreter.Interpreter.init(std.testing.allocator, f, p); + defer i.deinit(); + + var code = try i.run(); + try std.testing.expectEqual(code, 0); +} -- cgit v1.2.3