diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 05:29:51 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 05:29:51 -0300 |
| commit | 63538d28cee238ff53c731f965c22e615d43bec1 (patch) | |
| tree | fb00203f05512a9f14d0e8089a2f4b1919edffc9 /test | |
| parent | 638122f18a66669c433e332c91fc8b068019681e (diff) | |
| parent | d04f4acfb9af968caaa53d6cf10a486622c95400 (diff) | |
| download | pardes-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')
| -rw-r--r-- | test/consumer/build.zig | 77 | ||||
| -rw-r--r-- | test/consumer/lib.zig | 95 | ||||
| -rw-r--r-- | test/consumer/none.zig | 56 | ||||
| -rw-r--r-- | test/consumer/one.zig | 45 | ||||
| -rw-r--r-- | test/consumer/wasm.mjs | 113 |
5 files changed, 379 insertions, 7 deletions
diff --git a/test/consumer/build.zig b/test/consumer/build.zig index c643bfb3..45e1e2e5 100644 --- a/test/consumer/build.zig +++ b/test/consumer/build.zig @@ -1,33 +1,96 @@ //! A package that depends on pardes, as a program would (build.zig's head //! comment has its lines): pardes's `consumer-test`, which `unit-test` runs, //! runs `zig build test` here. `pardes-syntax` with the minimal grammars, -//! as a program that draws source text itself takes it; and -//! `pardes-editor` with no grammar of pardes's and one of its own, C's, -//! compiled here from the package pardes pins and handed in at run time, -//! as sketchbook's `examples/live` takes it. +//! as a program that draws source text itself takes it; with one language +//! named, for each language of pardes's manifest, read here at configure +//! time; `pardes-editor` with no grammar of pardes's and one of its own, +//! C's, compiled here from the package pardes pins and handed in at run +//! time, as sketchbook's `examples/live` takes it; and the browser's modules +//! pardes's build makes (`wasmModule`), run under node when it is there. const std = @import("std"); +const pardes = @import("pardes"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + // A name pardes's manifest does not have ends the configure: the step + // `bad-language` below runs this build with one. + if (b.option([]const u8, "language", "configure pardes with this one language named, and stop")) |name| { + _ = b.dependency("pardes", .{ .target = target, .optimize = optimize, .languages = name }); + return; + } const syntax = b.dependency("pardes", .{ .target = target, .optimize = optimize, .grammars = .minimal }); const editor = b.dependency("pardes", .{ .target = target, .optimize = optimize, .grammars = .none, .editor = true }); // The grammar of its own: C's, from the package pardes's manifest pins // (so `--pkg-dir` at pardes's zig-pkg has it), as that package builds it. const grammar = b.dependency("ts_c", .{ .target = target, .optimize = .ReleaseFast, .@"build-shared" = false }).artifact("tree-sitter-c"); - const step = b.step("test", "colour, outline and walk a C and a Zig source through pardes's syntax, and edit a text with its editor and a grammar of this package's"); + const step = b.step("test", "colour, outline and walk a C and a Zig source through pardes's syntax, build it with one language named, edit a text with its editor and a grammar of this package's, and run a browser's modules"); // A file belongs to one module: the syntax alone, and the editor (which // has it as `.syntax`), each a test of its own. - for ([_]struct { []const u8, []const u8, *std.Build.Dependency }{ .{ "lib.zig", "pardes-syntax", syntax }, .{ "editor.zig", "pardes-editor", editor } }) |t| { + // The patch view with no grammar at all: the editor's package has + // `pardes-syntax` too. + for ([_]struct { []const u8, []const u8, *std.Build.Dependency }{ .{ "lib.zig", "pardes-syntax", syntax }, .{ "editor.zig", "pardes-editor", editor }, .{ "none.zig", "pardes-syntax", editor } }) |t| { const mod = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path(t[0]), .imports = &.{.{ .name = t[1], .module = t[2].module(t[1]) }}, }); - if (t[2] == editor) mod.linkLibrary(grammar); + if (std.mem.eql(u8, t[1], "pardes-editor")) mod.linkLibrary(grammar); step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = mod })).step); } + + // Each language a file names, from pardes's manifest: `pardes-syntax` + // with it alone (and what it needs). `test` runs two: rust, alone, and + // markdown, which brings its inline grammar. + const each = b.step("each-language", "build and test pardes-syntax with each language of its manifest named alone"); + // A browser's module a language, and the patch view's: `sizes` + // installs every one; `test` runs the patch view's and rust's. + const sizes = b.step("sizes", "install a browser's module for each language, and the patch view's, into <prefix>/bin"); + const patch = pardes.wasmModule(b, .{}); + sizes.dependOn(&b.addInstallArtifact(patch, .{}).step); + var rust: ?*std.Build.Step.Compile = null; + for (pardes.grammar_manifest.all) |g| if (g.exts.len > 0) { + const module = pardes.wasmModule(b, .{ .language = g.name }); + sizes.dependOn(&b.addInstallArtifact(module, .{}).step); + if (std.mem.eql(u8, g.name, "rust")) rust = module; + const name = b.addOptions(); + name.addOption([]const u8, "name", g.name); + const one = b.addRunArtifact(b.addTest(.{ .name = b.fmt("one-{s}", .{g.name}), .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("one.zig"), + .imports = &.{ + .{ .name = "pardes-syntax", .module = b.dependency("pardes", .{ .target = target, .optimize = optimize, .languages = g.name }).module("pardes-syntax") }, + .{ .name = "language", .module = name.createModule() }, + }, + }) })); + each.dependOn(&one.step); + if (std.mem.eql(u8, g.name, "rust") or std.mem.eql(u8, g.name, "markdown")) step.dependOn(&one.step); + }; + // Each run as a page runs it, its WASI imports stubs. + if (b.findProgram(.{ .names = &.{"node"} })) |node| { + const run = b.addSystemCommand(&.{node}); + run.setName("node: the patch view's module and rust's"); + run.addFileArg(b.path("wasm.mjs")); + run.addArtifactArg(patch); + run.addArtifactArg(rust.?); + run.expectExitCode(0); + step.dependOn(&run.step); + } else { + std.debug.print("consumer-test: no node on PATH: the browser's modules are built, not run\n", .{}); + step.dependOn(&patch.step); + step.dependOn(&rust.?.step); + } + // ...and a name it does not have: the configure fails, saying so. + const bad = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "-Dlanguage=klingon", "--pkg-dir", "../../zig-pkg" }); + bad.setName("a language pardes does not have fails the configure"); + bad.setCwd(b.path(".")); + bad.expectExitCode(1); + bad.addCheck(.{ .expect_stderr_match = "no language \"klingon\"" }); + bad.has_side_effects = true; + step.dependOn(&bad.step); + // What a key costs, a page count and a parse: `zig build bench -- <KiB> <keys>`. const bench = b.addExecutable(.{ .name = "bench", .root_module = b.createModule(.{ .target = target, diff --git a/test/consumer/lib.zig b/test/consumer/lib.zig index 7e297920..fa0f8aee 100644 --- a/test/consumer/lib.zig +++ b/test/consumer/lib.zig @@ -159,3 +159,98 @@ test "a diff is a language: its hunks coloured as their file's, its added and re test "every name the library has compiles outside pardes" { std.testing.refAllDecls(pardes); } + +// ---- the patch view (+Diff), without the editor ---- + +const patch_c = + \\diff --git a/main.c b/main.c + \\--- a/main.c + \\+++ b/main.c + \\@@ -2,4 +2,4 @@ int main(void) + \\ { + \\- int x = foo(1); + \\+ int x = bar(1); + \\ return x; + \\ } + \\\ No newline at end of file + \\ +; +/// main.c as the patch leaves it: what a reader hands in as its source. +const main_c = "int main(void)\n{\n int x = bar(1);\n return x;\n}"; + +/// Each byte of `text` that has `bit`, the rest as dots. +fn marked(buf: []u8, text: []const u8, styles: []const u8, bit: u8) []const u8 { + for (buf[0..text.len], text, styles) |*o, c, s| o.* = if (s & bit != 0) c else '.'; + return buf[0..text.len]; +} + +test "a diff stacked with no file to read: numbered by the diff, under git's function line, its changed words emphasised" { + const gpa = std.testing.allocator; + pardes.start(gpa); + defer pardes.stop(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const ctx: pardes.PatchCtx = .{ .arena = arena.allocator(), .colors = pardes.PatchCtx.languages }; + const p = try pardes.formatPatch(&ctx, "", patch_c); + try std.testing.expectEqualStrings("main.c:3\n int main(void)\n {\n- int x = foo(1);\n+ int x = bar(1);\n return x;\n }\n", p.text); + const Kind = pardes.PatchRow.Kind; + const want = [_]struct { Kind, ?usize, ?usize }{ + .{ .hunk, null, null }, + // the `@@`'s own words: the hunk's context + .{ .declaration, null, null }, + .{ .context, 2, 2 }, + .{ .removed, 3, null }, + .{ .added, null, 3 }, + .{ .context, 4, 4 }, + .{ .context, 5, 5 }, + }; + try std.testing.expectEqual(want.len, p.rows.len); + for (want, p.rows) |w, row| { + try std.testing.expectEqual(w[0], row.kind); + try std.testing.expectEqual(w[1], row.old); + try std.testing.expectEqual(w[2], row.new); + try std.testing.expectEqualStrings("main.c", row.path); + } + try std.testing.expectEqual(3, p.rows[0].line); + try std.testing.expectEqual("main.c:3".len, p.rows[0].location_end); + try std.testing.expect(p.rows[6].no_newline and !p.rows[5].no_newline); + var lines = std.mem.splitScalar(u8, p.text, '\n'); + var buf: [64]u8 = undefined; + for (p.rows) |row| { + const line = lines.next().?; + if (row.styles.len > 0) try std.testing.expectEqual(line.len, row.styles.len); + switch (row.kind) { + // the words a changed line changed, on both lines; each on its + // ground, its marker not on the line's own (it was paired) + .removed => try std.testing.expectEqualStrings(".............foo....", marked(&buf, line, row.styles, pardes.ground_emph)), + .added => try std.testing.expectEqualStrings(".............bar....", marked(&buf, line, row.styles, pardes.ground_emph)), + else => {}, + } + if (row.kind == .removed) try std.testing.expectEqual(pardes.ground_del, row.styles[0]); + if (row.kind == .added) try std.testing.expectEqual(pardes.ground_add, row.styles[0]); + } + // coloured as C: `return` a keyword + const ret = p.rows[5].styles[std.mem.indexOf(u8, " return x;", "return").?]; + try std.testing.expectEqual(pardes.Syn.keyword, @as(pardes.Syn, @fromBackingInt(ret & pardes.syn_bits))); +} + +test "a diff stacked with its file handed in: the declaration it stands in, from the file's own parse" { + const gpa = std.testing.allocator; + pardes.start(gpa); + defer pardes.stop(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const Given = struct { + fn source(_: *const pardes.PatchCtx, _: []const u8, path: []const u8) ?pardes.PatchSource { + return if (std.mem.eql(u8, path, "main.c")) .{ .path = path, .bytes = main_c } else null; + } + }; + const ctx: pardes.PatchCtx = .{ .arena = arena.allocator(), .source = Given.source, .declarations = pardes.PatchCtx.parsed, .colors = pardes.PatchCtx.languages }; + const p = try pardes.formatPatch(&ctx, "", patch_c); + try std.testing.expectEqualStrings("main.c:1\n int main(void)\nmain.c:3 *\n {\n- int x = foo(1);\n+ int x = bar(1);\n return x;\n }\n", p.text); + try std.testing.expectEqual(pardes.PatchRow.Kind.declaration, p.rows[0].kind); + try std.testing.expectEqual(1, p.rows[0].line); + try std.testing.expectEqual(pardes.PatchRow.Kind.declaration, p.rows[1].kind); + try std.testing.expectEqual(pardes.PatchRow.Kind.hunk, p.rows[2].kind); + try std.testing.expectEqual("main.c:3".len, p.rows[2].location_end); +} diff --git a/test/consumer/none.zig b/test/consumer/none.zig new file mode 100644 index 00000000..a389d429 --- /dev/null +++ b/test/consumer/none.zig @@ -0,0 +1,56 @@ +//! The patch view in a build with no grammar at all (`.grammars = .none`): +//! a diff of a file in a language it does not have still gets its grounds, +//! its changed words and its rows, and the colours it is not given stay +//! out. +const std = @import("std"); +const ps = @import("pardes-syntax"); + +const patch_rs = + \\diff --git a/src/lib.rs b/src/lib.rs + \\--- a/src/lib.rs + \\+++ b/src/lib.rs + \\@@ -10,3 +10,3 @@ fn total(items: &[u32]) -> u32 { + \\ let mut sum = 0; + \\- for i in items { sum += i; } + \\+ for i in items { sum += *i; } + \\ sum + \\ +; + +test "a diff with no grammar in the build: rows, grounds and changed words, no colours" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + try std.testing.expect(!ps.supportsPath("lib.rs")); + const ctx: ps.PatchCtx = .{ .arena = arena.allocator() }; + const p = try ps.formatPatch(&ctx, "", patch_rs); + try std.testing.expectEqualStrings("src/lib.rs:11\n fn total(items: &[u32]) -> u32 {\n let mut sum = 0;\n- for i in items { sum += i; }\n+ for i in items { sum += *i; }\n sum\n", p.text); + try std.testing.expectEqual(ps.PatchRow.Kind.hunk, p.rows[0].kind); + try std.testing.expectEqual(ps.PatchRow.Kind.declaration, p.rows[1].kind); + const removed = p.rows[3]; + const added = p.rows[4]; + try std.testing.expectEqual(.{ 11, null }, .{ removed.old, removed.new }); + try std.testing.expectEqual(.{ null, 11 }, .{ added.old, added.new }); + try std.testing.expectEqual(ps.ground_del, removed.styles[0]); + try std.testing.expectEqual(ps.ground_add, added.styles[0]); + // `*` added: the one word emphasised; no byte has a colour of its own + const star = std.mem.indexOfScalar(u8, "+ for i in items { sum += *i; }", '*').?; + for (added.styles, 0..) |s, i| try std.testing.expectEqual(i == star, s & ps.ground_emph != 0); + for (p.rows) |row| for (row.styles) |s| try std.testing.expectEqual(0, s & ps.syn_bits); +} + +test "with no grammar, a file handed in still places the hunk, and no declaration is made up" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const Given = struct { + fn source(_: *const ps.PatchCtx, _: []const u8, path: []const u8) ?ps.PatchSource { + return .{ .path = path, .bytes = "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++ + "fn total(items: &[u32]) -> u32 {\n let mut sum = 0;\n for i in items { sum += *i; }\n sum\n}\n" }; + } + }; + const ctx: ps.PatchCtx = .{ .arena = arena.allocator(), .source = Given.source, .declarations = ps.PatchCtx.parsed }; + const p = try ps.formatPatch(&ctx, "", patch_rs); + // found (no `@@` words then: git's guess would only contradict the + // file's own), and no grammar to read a declaration from + try std.testing.expectEqualStrings("src/lib.rs:11\n let mut sum = 0;\n- for i in items { sum += i; }\n+ for i in items { sum += *i; }\n sum\n", p.text); + for (p.rows) |row| try std.testing.expect(row.kind != .declaration); +} 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))); + }; +} diff --git a/test/consumer/wasm.mjs b/test/consumer/wasm.mjs new file mode 100644 index 00000000..9e76af0f --- /dev/null +++ b/test/consumer/wasm.mjs @@ -0,0 +1,113 @@ +// The browser's modules pardes builds (build.zig `wasmModule`), run as a +// page runs them: `node wasm.mjs PATCH.wasm LANGUAGE.wasm`. Every WASI +// import is a stub (fd_prestat_get says there is no directory, the rest +// that they are not there), and each module prints what it imports. +import { readFileSync } from "node:fs"; + +let failed = 0; +function expect(what, got, want) { + if (JSON.stringify(got) !== JSON.stringify(want)) { + console.error(`${what}: got ${JSON.stringify(got)}, want ${JSON.stringify(want)}`); + failed++; + } +} + +function load(file) { + const mod = new WebAssembly.Module(readFileSync(file)); + const imports = WebAssembly.Module.imports(mod); + console.log(`${file}: ${imports.length} imports: ${imports.map((i) => i.module + "." + i.name).join(" ")}`); + let memory; + const wasi = new Proxy({}, { + get: (_, name) => (...a) => { + if (name === "fd_prestat_get") return 8; // EBADF: no preopened directory + if (name === "proc_exit") throw Error(`exit ${a[0]}`); + if (name === "fd_write") { + const [, iovs, n, written] = a; + const v = new DataView(memory.buffer); + let sum = 0; + for (let i = 0; i < n; i++) { + const p = v.getUint32(iovs + 8 * i, true), l = v.getUint32(iovs + 8 * i + 4, true); + process.stderr.write(Buffer.from(memory.buffer, p, l)); + sum += l; + } + v.setUint32(written, sum, true); + return 0; + } + return 52; // ENOSYS + }, + }); + const inst = new WebAssembly.Instance(mod, { wasi_snapshot_preview1: wasi }); + memory = inst.exports.memory; + inst.exports._initialize(); + return { ex: inst.exports, mem: () => memory.buffer }; +} + +const enc = new TextEncoder(), dec = new TextDecoder(); +function put(m, text) { + const b = enc.encode(text); + const p = m.ex.reserve(b.length); + new Uint8Array(m.mem(), p, b.length).set(b); + return [p, b.length]; +} + +// patch: the diff stacked, read from the header and its 36-byte records +const kinds = ["other", "meta", "hunk", "declaration", "context", "added", "removed"]; +function patch(m, diff) { + const [p, n] = put(m, diff); + const h = m.ex.patch(p, n); + m.ex.release(p, n); + const v = new DataView(m.mem()); + const [text, textLen, styles, rows, count] = [0, 4, 8, 12, 16].map((o) => v.getUint32(h + o, true)); + const bytes = new Uint8Array(m.mem(), text); + const out = []; + for (let i = 0; i < count; i++) { + const [kind, old, nw, codeStart, off, len, pathOff, pathLen, flags] = [...Array(9)].map((_, f) => v.getUint32(rows + 36 * i + 4 * f, true)); + out.push({ + kind: kinds[kind], old, new: nw, codeStart, flags, + text: dec.decode(bytes.subarray(off, off + len)), + path: dec.decode(bytes.subarray(pathOff, pathOff + pathLen)), + styles: [...new Uint8Array(m.mem(), styles + off, len)], + }); + } + return { text: dec.decode(bytes.subarray(0, textLen)), rows: out }; +} + +const diff = "diff --git a/src/lib.rs b/src/lib.rs\n--- a/src/lib.rs\n+++ b/src/lib.rs\n@@ -10,3 +10,3 @@ fn total(items: &[u32]) -> u32 {\n let mut sum = 0;\n- for i in items { sum += i; }\n+ for i in items { sum += *i; }\n sum\n\\ No newline at end of file\n"; +for (const file of process.argv.slice(2)) { + const m = load(file); + // reserve(0) is a pointer still + const zero = m.ex.reserve(0); + expect(`${file} reserve(0)`, zero !== 0, true); + m.ex.release(zero, 0); + + const p = patch(m, diff); + expect(`${file} patch text`, p.text, "src/lib.rs:11\n fn total(items: &[u32]) -> u32 {\n let mut sum = 0;\n- for i in items { sum += i; }\n+ for i in items { sum += *i; }\n sum\n"); + expect(`${file} patch rows`, p.rows.map((r) => [r.kind, r.old, r.new, r.path, r.flags]), [ + ["hunk", 0, 0, "src/lib.rs", 0], + ["declaration", 0, 0, "src/lib.rs", 0], + ["context", 10, 10, "src/lib.rs", 0], + ["removed", 11, 0, "src/lib.rs", 0], + ["added", 0, 11, "src/lib.rs", 0], + ["context", 12, 12, "src/lib.rs", 1], + ]); + expect(`${file} hunk code start`, p.rows[0].codeStart, "src/lib.rs:11".length); + // the added line: its ground on the marker (0x80), and `*` its changed word (0x20) + const added = p.rows[4]; + expect(`${file} added styles`, added.styles.map((s, i) => (s & 0x20 ? added.text[i] : s & 0x80 ? "+" : ".")).join(""), [...added.text].map((c, i) => (i === 0 ? "+" : c === "*" ? "*" : ".")).join("")); + + if (m.ex.highlight) { + const src = 'fn main() { let s = "x"; }\n'; + const [pp, pn] = put(m, "main.rs"); + const [tp, tn] = put(m, src); + // (a call can grow the memory: its buffer is taken after it) + const at = m.ex.highlight(pp, pn, tp, tn); + const s = new Uint8Array(m.mem(), at, tn); + expect(`${file} highlight fn`, [s[0], s[1]], [1, 1]); + expect(`${file} highlight "x"`, s[src.indexOf('"')], 2); + const c = put(m, "main.c"); + const other = m.ex.highlight(c[0], c[1], tp, tn); + expect(`${file} highlight another language`, [...new Uint8Array(m.mem(), other, tn)].every((b) => b === 0), true); + } +} +if (failed) process.exit(1); +console.log("wasm: the modules run"); |
