repositories / termux-janitor
termux-janitor
Interactive cleanup assistant for Termux: transparent, safe, confirmed disk reclamation.
owned by admin
tests/fixtures/classification_catalogs.zig
Rawconst std = @import("std");
const spec_data = @import("spec_data");
const expected_basenames = [_][]const u8{
"Makefile", "CMakeLists.txt", "build.zig", "build.gradle", "pom.xml",
"package.json", "Cargo.toml", "go.mod", "Gemfile", "composer.json",
};
const expected_suffixes = [_][]const u8{
".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".java", ".kt", ".kts",
".scala", ".groovy", ".gradle", ".zig", ".zon", ".rs", ".go", ".lua", ".nu", ".py",
".pyi", ".rb", ".php", ".js", ".jsx", ".ts", ".tsx", ".vue", ".svelte", ".sh",
".bash", ".zsh", ".fish", ".sql", ".proto", ".toml", ".yaml", ".yml", ".json", ".xml",
".html", ".css", ".scss", ".md", ".rst",
};
const expected_roots = [_][]const u8{ "Documents", "documents", "Download", "Downloads" };
pub const Fixture = struct {
given: bool = false,
inspected: bool = false,
pub fn init() !Fixture {
return .{};
}
pub fn deinit(fixture: *Fixture) void {
fixture.* = undefined;
}
pub fn given_generated_classification_catalogs(fixture: *Fixture) !void {
std.debug.assert(!fixture.given);
try std.testing.expect(spec_data.classification_source_basenames.len > 0);
try std.testing.expect(spec_data.classification_source_suffixes.len > 0);
try std.testing.expect(spec_data.classification_document_roots.len > 0);
fixture.given = true;
}
pub fn when_inspect_classification_catalogs(fixture: *Fixture) !void {
std.debug.assert(fixture.given);
std.debug.assert(!fixture.inspected);
fixture.inspected = true;
}
pub fn then_inv_classification_basenames(fixture: *Fixture) !void {
std.debug.assert(fixture.inspected);
try expectValues(&expected_basenames, &spec_data.classification_source_basenames);
}
pub fn then_inv_classification_suffixes(fixture: *Fixture) !void {
std.debug.assert(fixture.inspected);
try expectValues(&expected_suffixes, &spec_data.classification_source_suffixes);
}
pub fn then_inv_classification_document_roots(fixture: *Fixture) !void {
std.debug.assert(fixture.inspected);
try expectValues(&expected_roots, &spec_data.classification_document_roots);
}
pub fn forbid_no_classification_duplicates(fixture: *Fixture) !void {
std.debug.assert(fixture.inspected);
try expectUnique(&spec_data.classification_source_basenames);
try expectUnique(&spec_data.classification_source_suffixes);
try expectUnique(&spec_data.classification_document_roots);
}
};
fn expectValues(expected: []const []const u8, actual: []const []const u8) !void {
try std.testing.expectEqual(expected.len, actual.len);
for (expected, 0..) |value, index| try std.testing.expectEqualStrings(value, actual[index]);
}
fn expectUnique(values: []const []const u8) !void {
for (values, 0..) |value, index| {
for (values[0..index]) |previous| {
try std.testing.expect(!std.mem.eql(u8, previous, value));
}
}
}