aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 7460c6079f127ea5ae43b81e6eb19d9cbdcaaa4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const std = @import("std");
const field = @import("field.zig");
const interpreter = @import("interpreter.zig");
const pointer = @import("pointer.zig");
const stackStack = @import("stackStack.zig");

pub fn main() anyerror!void {
    std.log.info("All your codebase are belong to us.", .{});
}

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