aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/nav_test.js
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:29:46 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:29:46 +0330
commit1c53304d03414890af0da7432d1aea87e754a14a (patch)
tree97190d86cf548c9bc63f68c86a4d2a4f09809713 /tests/drivers/nav_test.js
parenta (diff)
feat: grow memory limits, add icon/actor libraries, overhaul LSP diagnostics
Compiler and VM - make every memory map limit dynamic and adjustable at both build time and runtime, including compiler tables, stacks, and every execution region - reserve and grow tables, operand and return stacks, frame segments, and image-building output without relocating live code or globals - rename i/o and string helpers consistently (puts -> put_s, putn -> put_n, scat -> cat_s) across compiler, runtime, examples, tests, and docs - recast and consume values assigned to globals from inside functions - allow fixed and const together, add typed closure returns (fn:t(...)), multi-include syntax (include rt, run, core;), and recurse type inference - never infer string literals as word, anywhere, as argument, variable, or return type - draft docs/BORROW.md: a borrow checker less intrusive than Rust's but more intelligent LSP and editor integration - require explicit includes and give every toolchain area its own namespace (rt, lsp, run, core) - hover for built-in types, inferred types, values known at hover time, array and pointer lifetime/size, library names in include statements, and inferred lifetimes with explanations - honor /* */ comments as documentation for variables and arguments, and stop misattributing section headers or trailing comments as variable hints - stream diagnostics and cancel stale requests on change - jump to definition and references, including cross-file - quick fixes with automatic library import, and namespace completion Hints and diagnostics - render hints as blue squigglies by default, with hints on/small/off per file - suppress magic-number hints via a preceding /* */ comment, and say so - warn on unused arguments; allow multiple _ discards in parameters, pattern matching, and tagged enums, warning if a _ is actually used - rewrite hint and comment prose in professional compiler-doc register Libraries - add icon.zc: run-time self-modification, find/replace syntax, type and block edits, and step-through inspection of locals and globals - add actor.zc: async actors with Actor<I,O>, implicit this, spawn/recv/send, injected into the compiler machinery at include time rather than built in Tooling and docs - reorganize sources, tests, and designs into subdirectories - unify windows entry points in tinyvm.bat and add a matching tinyvm.sh - add --help across the toolchain - polish the learning guide, stdlib docs, and design notes Tests - add accept, reject, and regression coverage across the compiler, LSP, - runtime, icon, actors, threads, formatting, and the toolchain contracts, plus fuzzers and property tests
Diffstat (limited to 'tests/drivers/nav_test.js')
-rw-r--r--tests/drivers/nav_test.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/drivers/nav_test.js b/tests/drivers/nav_test.js
new file mode 100644
index 0000000..23afbf8
--- /dev/null
+++ b/tests/drivers/nav_test.js
@@ -0,0 +1,75 @@
+// go to definition and find references, in the document and across includes.
+// usage: node tests/drivers/nav_test.js path/to/zclsp (run from the repository root)
+const assert = require('assert');
+const cp = require('child_process');
+const fs = require('fs');
+const path = require('path');
+const server = process.argv[2];
+const root = path.resolve(__dirname, '..', '..');
+const uri = 'file://' + path.join(root, 'tests', 'drivers', 'nav-fixture.zc');
+const frame = m => { const b = Buffer.from(JSON.stringify(m)); return Buffer.concat([Buffer.from('Content-Length: ' + b.length + '\r\n\r\n'), b]); };
+function request(text, needle, method, extra = {}) {
+ const at = text.indexOf(needle);
+ assert.ok(at >= 0, needle);
+ const before = text.slice(0, at);
+ const position = { line: before.split('\n').length - 1, character: before.length - before.lastIndexOf('\n') - 1 };
+ const input = Buffer.concat([
+ { jsonrpc: '2.0', id: 1, method: 'initialize', params: {} },
+ { jsonrpc: '2.0', method: 'textDocument/didOpen', params: { textDocument: { uri, version: 1, languageId: 'zc', text } } },
+ { jsonrpc: '2.0', id: 2, method, params: { textDocument: { uri }, position, ...extra } },
+ { jsonrpc: '2.0', method: 'exit' }].map(frame));
+ const r = cp.spawnSync(server, process.argv.slice(3), { input, cwd: root, timeout: 30000, maxBuffer: 8 << 20 });
+ assert.strictEqual(r.status, 0, String(r.stderr));
+ let d = r.stdout, init;
+ while (d.length) {
+ const e = d.indexOf('\r\n\r\n'), n = Number(/Content-Length:\s*(\d+)/i.exec(d.subarray(0, e).toString())[1]);
+ const m = JSON.parse(d.subarray(e + 4, e + 4 + n)); d = d.subarray(e + 4 + n);
+ if (m.id === 1) init = m.result.capabilities;
+ if (m.id === 2) return { result: m.result, init };
+ }
+ assert.fail('no reply');
+}
+const lines = r => (r || []).map(l => l.range.start.line + ':' + l.range.start.character).sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
+const src = 'include "tests/drivers/nav-library.zc";\nstruct pt { int x; int y; };\nint twice(int v) { return v * 2; }\nfn main() {\n\tpt p;\n\tp.x = twice(2);\n\tlet n = p.x + twice(3);\n\tNavValue value;\n\treturn n + p.y + nav_helper(value.value);\n}\n';
+const def = (needle, nth) => request(src, needle, 'textDocument/definition').result;
+assert.ok(request(src, 'twice(2', 'textDocument/definition').init.definitionProvider && request(src, 'twice(2', 'textDocument/definition').init.referencesProvider);
+assert.deepStrictEqual(lines(def('twice(2')), ['2:4'], 'a function goes to its definition');
+assert.deepStrictEqual(lines(def('p.y')), ['4:4'], 'a local goes to its declaration');
+assert.deepStrictEqual(lines(def('pt p')), ['1:7'], 'a struct goes to its declaration');
+const inc = def('NavValue value');
+assert.ok(inc && inc.length === 1 && inc[0].uri === 'file://' + path.join(root, 'tests', 'drivers', 'nav-library.zc'), 'a type from an include goes to the included file: ' + JSON.stringify(inc));
+const includeText = fs.readFileSync(path.join(root, 'tests', 'drivers', 'nav-library.zc'), 'utf8').split('\n');
+assert.ok(/NavValue/.test(includeText[inc[0].range.start.line].slice(inc[0].range.start.character, inc[0].range.end.character)), 'the range covers the name');
+assert.strictEqual(request(src, 'return', 'textDocument/definition').result, null, 'a keyword has no definition');
+const refs = (needle, includeDeclaration) => request(src, needle, 'textDocument/references', { context: { includeDeclaration } }).result;
+assert.deepStrictEqual(lines(refs('twice(2', true)), ['2:4', '5:7', '6:15'], 'references with the declaration');
+assert.deepStrictEqual(lines(refs('twice(2', false)), ['5:7', '6:15'], 'references without the declaration');
+assert.deepStrictEqual(lines(refs('n + p.y', true)), ['6:5', '8:8'], 'a local: declaration and uses');
+const shared = refs('nav_helper(value', true);
+assert.ok(shared.some(loc => loc.uri === 'file://' + path.join(root, 'tests', 'drivers', 'nav-library.zc')), 'references include the declaration in another file');
+assert.deepStrictEqual(lines(refs('y; };', true)).length >= 1, true);
+// built-ins: the image carries its sources. the runtime, the compiler and (for include std;) the standard library
+const std = 'include std, rt;\nfn main() {\n\trt.put_s("hi");\n\tlet n = std.Text.atoi("4");\n\tlet m = rt.s_to_n(b"1");\n\treturn n + m + std.Host.now();\n}\n';
+const bdef = needle => request(std, needle, 'textDocument/definition').result;
+const source = name => request(std, 'main', 'zc/source', { path: name }).result;
+const slice = (text, loc) => { const l = text.split('\n')[loc.range.start.line]; return l.slice(loc.range.start.character, loc.range.end.character); };
+let loc = bdef('put_s');
+assert.ok(loc && loc.length === 1 && loc[0].uri === 'tinyvm:/rt.zc', 'a runtime function goes to the runtime source: ' + JSON.stringify(loc));
+assert.strictEqual(slice(source('/rt.zc'), loc[0]), 'put_s');
+assert.strictEqual(source('/rt.zc'), fs.readFileSync(path.join(root, 'src', 'runtime', 'rt.zc'), 'utf8'), 'the embedded runtime is the file');
+loc = bdef('Text.atoi');
+assert.ok(loc && loc[0].uri === 'tinyvm:/std.zc', 'a std type goes to the std source');
+assert.strictEqual(slice(source('std.zc'), loc[0]), 'Text');
+loc = bdef('atoi(');
+assert.strictEqual(loc[0].uri, 'tinyvm:/std.zc');
+assert.strictEqual(slice(source('/std.zc'), loc[0]), 'atoi', 'a method goes to its own line');
+loc = bdef('now(');
+assert.strictEqual(slice(source('/std.zc'), loc[0]), 'now');
+assert.strictEqual(source('/std.zc'), fs.readFileSync(path.join(root, 'src', 'lib', 'std.zc'), 'utf8'), 'the embedded std is the file');
+assert.strictEqual(source('/compiler.zc'), fs.readFileSync(path.join(root, 'src', 'compiler', 'compiler.zc'), 'utf8'), 'the embedded compiler is the file');
+assert.strictEqual(source('/server.zc'), fs.readFileSync(path.join(root, 'src', 'lsp', 'server.zc'), 'utf8'), 'the embedded server is the file');
+loc = bdef('s_to_n(');
+assert.ok(loc && loc.length === 1 && loc[0].uri === 'tinyvm:/rt.zc', 's_to_n opens the runtime source: ' + JSON.stringify(loc));
+assert.strictEqual(slice(source('/rt.zc'), loc[0]), 's_to_n');
+assert.strictEqual(source('/nope.zc'), null);
+console.log('ok definition and references across the document and includes');