// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! The shape of a case in `synth.zig`. const std = @import("std"); pub const Piece = union(enum) { text: []const u8, repeat: struct { count: usize, pattern: []const u8 }, }; pub const Case = struct { name: []const u8, /// Whether a decoder must accept the stream. ok: bool, /// The reference implementation skips this case. The only one is a /// valid stream followed by junk, which its Go decoder rejects; this /// decoder stops at the end of the stream, as it should, and leaves the /// junk unread. skipped_upstream: bool = false, compressed: []const u8, /// What it decodes to, when it is accepted. output: []const Piece, /// The expected output, assembled from its pieces. pub fn expected(c: Case, gpa: std.mem.Allocator) ![]u8 { var out: std.ArrayList(u8) = .empty; errdefer out.deinit(gpa); for (c.output) |p| switch (p) { .text => |t| try out.appendSlice(gpa, t), .repeat => |r| for (0..r.count) |_| try out.appendSlice(gpa, r.pattern), }; return out.toOwnedSlice(gpa); } };