summaryrefslogtreecommitdiff
path: root/test/consumer/one.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 05:29:51 -0300
committerGabriel Schneider <[email protected]>2026-11-21 05:29:51 -0300
commit63538d28cee238ff53c731f965c22e615d43bec1 (patch)
treefb00203f05512a9f14d0e8089a2f4b1919edffc9 /test/consumer/one.zig
parent638122f18a66669c433e332c91fc8b068019681e (diff)
parentd04f4acfb9af968caaa53d6cf10a486622c95400 (diff)
downloadpardes-63538d28cee238ff53c731f965c22e615d43bec1.tar.gz
pardes-63538d28cee238ff53c731f965c22e615d43bec1.zip
integration: the library for a browser reader on the gathered line: pardes-syntax-lib (`wqlkznns`: a dependent package names its languages, the patch view without the editor as formatPatch, build.zig's wasmModule and abi/wasm.zig, the manual) and pardes-reorg (`ukkqwpqu`: the terminals' line, the wire at 26); no conflict; its gate: .scratch/sketch/reorg/merge47, the numbers in PARDES.md (2026-11-21)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/consumer/one.zig')
-rw-r--r--test/consumer/one.zig45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/consumer/one.zig b/test/consumer/one.zig
new file mode 100644
index 00000000..4a113842
--- /dev/null
+++ b/test/consumer/one.zig
@@ -0,0 +1,45 @@
+//! `pardes-syntax` built with one language named (`.languages`, build.zig
+//! here: the build's loop over pardes's manifest makes one of these a
+//! language): that language and what it needs (the manifest's `needs`) are
+//! compiled in, and no other.
+const std = @import("std");
+const ps = @import("pardes-syntax");
+const language = @import("language").name;
+
+test "one language named: it and what it needs are in the build, no other grammar is linked" {
+ const gpa = std.testing.allocator;
+ ps.start(gpa);
+ defer ps.stop();
+ const g = ps.grammars;
+ const named = comptime named: {
+ @setEvalBranchQuota(10_000);
+ break :named g.all[g.byName(language).?];
+ };
+ // This test program's own bytes (a Debug build keeps its symbols): a
+ // name is spelled whole only in its symbol table.
+ const self = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "/proc/self/exe", gpa, .unlimited);
+ defer gpa.free(self);
+ var name: [64]u8 = undefined;
+ inline for (g.all) |other| {
+ const in = comptime std.mem.eql(u8, other.name, named.name) or for (named.needs) |n| {
+ if (std.mem.eql(u8, n, other.name)) break true;
+ } else false;
+ // the parser itself, by its symbol in this program's symbol table:
+ // linked, or not in it
+ const symbol = try std.fmt.bufPrint(&name, "\x00tree_sitter_{s}\x00", .{other.name});
+ try std.testing.expectEqual(in, std.mem.indexOf(u8, self, symbol) != null);
+ if (other.exts.len > 0) try std.testing.expectEqual(in, ps.supportsPath(ps.pathFor(other.name).?));
+ }
+
+ // what two of them colour: rust alone, and markdown with the inline
+ // grammar it brings (its bold is markdown_inline's)
+ for ([_]struct { []const u8, []const u8, []const u8, ps.Syn }{
+ .{ "rust", "fn main() { let x = 1; }\n", "fn", .keyword },
+ .{ "markdown", "# Title\n\nsome **bold** text\n", "bold", .comment },
+ }) |case| if (std.mem.eql(u8, case[0], named.name)) {
+ const styles = try ps.highlightFileRange(gpa, ps.pathFor(language).?, case[1], 0, case[1].len);
+ defer gpa.free(styles);
+ const at = std.mem.indexOf(u8, case[1], case[2]).?;
+ for (styles[at..][0..case[2].len]) |s| try std.testing.expectEqual(case[3], @as(ps.Syn, @fromBackingInt(s)));
+ };
+}