ajhahn.de
← Flash
Zig 36 lines
// Integration test: lex the example programs end to end.
//
// Unlike the unit tests inside src/lexer.zig (which feed hand-written
// snippets), this drives the lexer over the real example sources shipped in
// examples/, embedded at comptime so the test needs no filesystem access. A
// new example the lexer chokes on fails the suite here.

const std = @import("std");
const Lexer = @import("flash").Lexer;
const examples = @import("examples").all;

test "every example lexes without an invalid token" {
    for (examples) |src| {
        var lx = Lexer.init(src);
        while (true) {
            const t = lx.next();
            try std.testing.expect(t.kind != .invalid);
            if (t.kind == .eof) break;
        }
    }
}

test "every example is non-empty and reaches eof" {
    for (examples) |src| {
        try std.testing.expect(src.len > 0);
        var lx = Lexer.init(src);
        var count: usize = 0;
        while (true) {
            const t = lx.next();
            count += 1;
            if (t.kind == .eof) break;
        }
        try std.testing.expect(count > 1); // at least one real token before eof
    }
}