// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 // Pseudo answers any text with diagnostics and any run with an output or a stop: never with an exception of the // engine underneath, a run without end, or an allocation the size of the program's mistake. Each test is a case // that once threw, hung or ran out of memory (work/revive/interp-audit-report.md has the audit that found them). import test from 'node:test'; import assert from 'node:assert/strict'; import { studyOf, runPseudo, provePseudo } from '../dist/services/pseudo.js'; import { pseudoToMojo } from '../dist/sync/pseudo-to-mojo.js'; import { pseudoToLingo } from '../dist/sync/pseudo-to-lingo.js'; import { pseudoToMatho } from '../dist/sync/pseudo-to-matho.js'; import { SyncHub } from '../dist/sync/hub.js'; import { checkProperties } from '../dist/engines/pseudo/testing.js'; import { run as runProgram } from '../dist/engines/pseudo/interp.js'; import { within, NO_CLOCK } from './helpers/pace.mjs'; const errors = (src) => studyOf(src).diagnostics.filter((d) => d.severity === 'error').map((d) => d.id); const run = (src, opts = {}) => { const st = studyOf(src); assert.ok(st.ok, st.diagnostics.filter((d) => d.severity === 'error').map((d) => `L${d.line} ${d.id}: ${d.message}`).join(' | ')); return runPseudo(st, opts); }; /** Every reader of pseudo text, on text that does not check: each answers, none throws. */ const everyReader = (src) => { studyOf(src); pseudoToMojo(src); pseudoToLingo(src); pseudoToMatho(src); new SyncHub({ pseudo: src }).fill(); new SyncHub({ pseudo: '' }).edit('pseudo', src); }; test('an arrow that is not the assignment arrow is a character with no meaning, not a crash in the lexer', () => { for (const c of ['→', '↑', '⇒', '↔']) { assert.ok(errors(`X ${c} Y`).includes('bad-character'), c); everyReader(`X ${c} Y`); } assert.deepEqual(run('DECLARE X : INTEGER\nX ← 3\nOUTPUT X').output, ['3']); }); test('FOR EACH X IN with nothing after IN is an error where it is written', () => { const src = 'FOR EACH B IN\n OUTPUT 1\nNEXT B\n'; assert.ok(errors(src).includes('expected')); everyReader(src); }); test('nesting past what the readers can walk is one too-deep error', () => { const deep = [ `OUTPUT ${'('.repeat(5000)}1${')'.repeat(5000)}`, `OUTPUT ${'('.repeat(5000)}1`, `OUTPUT ${'['.repeat(5000)}1${']'.repeat(5000)}`, `OUTPUT ${'-'.repeat(5000)}1`, `OUTPUT ${'NOT '.repeat(5000)}TRUE`, `OUTPUT 1${' ^ 1'.repeat(5000)}`, `OUTPUT 1${' + 1'.repeat(5000)}`, `OUTPUT TRUE${' AND TRUE'.repeat(5000)}`, `OUTPUT "a"${' & "a"'.repeat(5000)}`, `OUTPUT ${'ABS('.repeat(3000)}1${')'.repeat(3000)}`, `DECLARE L : LIST OF INTEGER\nOUTPUT L${'[0]'.repeat(5000)}`, `DECLARE X : ${'LIST OF '.repeat(5000)}INTEGER`, `${'IF TRUE THEN\n'.repeat(3000)}OUTPUT 1\n${'ENDIF\n'.repeat(3000)}`, `${'WHILE FALSE\n'.repeat(3000)}OUTPUT 1\n${'ENDWHILE\n'.repeat(3000)}`, `${'REPEAT\n'.repeat(3000)}OUTPUT 1\n${'UNTIL TRUE\n'.repeat(3000)}`, 'IF\n'.repeat(5000), ]; for (const src of deep) { const ids = errors(src); assert.ok(ids.includes('too-deep'), `${src.slice(0, 30)}: ${[...new Set(ids)].join(', ')}`); assert.ok(ids.filter((id) => id === 'too-deep').length <= 2, `${src.slice(0, 30)}: one message, not one per level`); everyReader(src); } }); test('brackets that each hold a long chain are one too-deep error, though each limit alone is kept', () => { // 200 levels and 400 values are counted apart, and a chain leans left one level per value: these stay inside both // and built trees 800 to 2,000 levels tall, which the checker ended on with the engine's own stack error const chain = ' + 1'.repeat(398); const levels = (n) => { let e = `1${chain}`; for (let i = 1; i < n; i++) e = `(${e})${chain}`; return e; }; const deep = [ `OUTPUT ${levels(2)}`, `OUTPUT ${levels(3)}`, `DECLARE X : INTEGER\nX <- ${levels(5)}\nOUTPUT X`, `OUTPUT ${levels(40)}`, `DECLARE L : LIST OF INTEGER\nOUTPUT L${'[0]'.repeat(398)}${chain}`, `DECLARE L : LIST OF INTEGER\nL[${levels(1)}]${'[0]'.repeat(300)} <- 1`, `OUTPUT ABS(${levels(1)})${chain}`, `DECLARE X : INTEGER <- ${levels(3)}\nOUTPUT X`, `OUTPUT TRUE${' AND TRUE'.repeat(300)} OR (${levels(1)}) > 0`.replace('OUTPUT TRUE', `OUTPUT (${levels(1)} > 0)`), ]; for (const src of deep) { const ids = errors(src); assert.ok(ids.includes('too-deep'), `${src.slice(0, 40)}: ${[...new Set(ids)].join(', ')}`); assert.ok(ids.filter((id) => id === 'too-deep').length <= 2, `${src.slice(0, 40)}: one message, not one per level`); everyReader(src); } // a tree as tall as the limit allows goes through every reader, a run and the prover const tallest = `OUTPUT (1${' + 1'.repeat(298)})${' + 1'.repeat(101)}`; assert.deepEqual(run(tallest).output, ['400']); assert.ok(errors(`OUTPUT (1${' + 1'.repeat(298)})${' + 1'.repeat(102)}`).includes('too-deep'), 'one level more'); everyReader(tallest); provePseudo(studyOf(tallest)); }); test('what is nested as deeply as the limit allows still reads, runs and translates', () => { const parens = `OUTPUT ${'('.repeat(150)}1${')'.repeat(150)}`; assert.deepEqual(run(parens).output, ['1']); const sum = `OUTPUT 1${' + 1'.repeat(399)}`; assert.deepEqual(run(sum).output, ['400']); const ifs = `${'IF TRUE THEN\n'.repeat(150)}OUTPUT 1\n${'ENDIF\n'.repeat(150)}`; assert.deepEqual(run(ifs).output, ['1']); for (const src of [parens, sum, ifs]) { everyReader(src); provePseudo(studyOf(src)); } }); test('a size no run could hold stops the run with a sentence instead of an allocation', () => { const stops = (src, kind, re) => { const r = run(src); assert.equal(r.error?.kind, kind, src); assert.match(r.error.message, re); }; stops('DECLARE L : LIST OF INTEGER <- FILL(1000000000, 0)', 'value', /more values than this lab gives one collection/); stops('DECLARE A : ARRAY[5000000000] OF INTEGER', 'value', /more than this lab gives one collection/); stops('DECLARE A : ARRAY[10000, 10000] OF INTEGER', 'value', /10000 by 10000/); stops('FOR EACH I IN [0, 1000000000)\n OUTPUT I\nNEXT I', 'value', /too large to visit/); assert.deepEqual(run('DECLARE L : LIST OF INTEGER <- FILL(1000, 7)\nOUTPUT LENGTH(L)').output, ['1000']); }); test('SHIFT_LEFT by a count no number survives is an overflow, without building the number', () => { for (const n of ['65', '1073741824', '2147483648', '9007199254740991']) assert.equal(run(`OUTPUT SHIFT_LEFT(1, ${n})`).error?.kind, 'overflow', n); assert.deepEqual(run('OUTPUT SHIFT_LEFT(0, 2147483648), " ", SHIFT_LEFT(1, 52), " ", SHIFT_RIGHT(-1, 2147483648)').output, ['0 4503599627370496 -1']); }); test('the positions quantifiers visit are counted: one inside another cannot run without end', () => { const r = run('OUTPUT SUM I IN [0, 2000000) : SUM J IN [0, 2000000) : 1', { maxSteps: 200 }); assert.equal(r.error?.kind, 'limit'); assert.match(r.error.message, /positions visited by FORALL, EXISTS, SUM/); assert.equal(run('ASSERT FORALL I IN [0, 300) : FORALL J IN [0, 300) : I + J >= 0\nOUTPUT 1', { maxSteps: 200 }).error?.kind, 'limit'); assert.deepEqual(run('OUTPUT SUM I IN [0, 100) : SUM J IN [0, 100) : 1').output, ['10000']); }); test('CHOOSE with a huge K ends at the first step that cannot fit', () => { within(2000, 'CHOOSE with a huge K', () => assert.equal(run('OUTPUT CHOOSE(9007199254740991, 4503599627370495)').error?.kind, 'overflow')); }); test('an error of the engine underneath is a stop of the run, never an exception from it', () => { // a text doubled until the engine refuses its length: the lab's own limit comes first const r = run('DECLARE S : STRING <- "ab"\nFOR I <- 0 TO 40\n S <- S & S\nNEXT I\nOUTPUT LENGTH(S)'); assert.equal(r.error?.kind, 'value'); assert.match(r.error.message, /longer than this lab holds/); }); test('a record that holds itself, and an ARRAY of ARRAYs, are errors before any run', () => { assert.ok(errors('TYPE Node\n DECLARE Value : INTEGER\n DECLARE Link : Node\nENDTYPE\nDECLARE N : Node').includes('recursive-type')); assert.ok(errors('TYPE A\n DECLARE B1 : B\nENDTYPE\nTYPE B\n DECLARE A1 : ARRAY[2] OF A\nENDTYPE\nDECLARE X : A').includes('recursive-type')); assert.deepEqual(run('TYPE Node\n DECLARE Value : INTEGER\n DECLARE Kids : LIST OF Node\nENDTYPE\nDECLARE N, M : Node\nN.Value <- 1\nM.Value <- 2\nAPPEND(N.Kids, M)\nOUTPUT N.Kids[0].Value').output, ['2']); assert.ok(errors('DECLARE A : ARRAY[2] OF ARRAY[2] OF INTEGER').includes('array-of-array')); }); test('an ARRAY keeps its declared shape, and its unset positions stop the built-ins that read them', () => { assert.ok(errors('DECLARE M : ARRAY[2, 2] OF INTEGER\nM <- [1, 2, 3, 4]').includes('type')); // lengths the text shows are an error before the run; others stop it (the next test) assert.ok(errors('DECLARE A : ARRAY[3] OF INTEGER\nA <- [1, 2, 3, 4, 5]').includes('array-length')); assert.ok(errors('DECLARE P : ARRAY[2, 2] OF INTEGER\nDECLARE Q : ARRAY[3, 3] OF INTEGER\nP <- Q').includes('array-length')); assert.equal(run('DECLARE N : INTEGER <- 5\nDECLARE A : ARRAY[3] OF INTEGER\nDECLARE B : ARRAY[N] OF INTEGER\nA <- B').error?.kind, 'value'); assert.deepEqual(run('DECLARE A : ARRAY[3] OF INTEGER\nA <- [3, 1, 2]\nSORT(A)\nA[0] <- 9\nOUTPUT A, " ", LENGTH(A), " ", MAX(A), " ", SORTED(A)').output, ['[9, 2, 3] 3 9 [2, 3, 9]']); const head = 'DECLARE A : ARRAY[2] OF FLOAT\nDECLARE B : ARRAY[2] OF FLOAT\nA[0] <- 1.0\nB[0] <- 2.0\nB[1] <- 2.0\n'; for (const call of ['OUTPUT DOT(A, B)', 'OUTPUT DOT(B, A)', 'OUTPUT MAX(A)', 'OUTPUT MIN(A)', 'OUTPUT SORTED(A)', 'SORT(A)']) assert.equal(run(head + call).error?.kind, 'unset', call); }); test('the inputs provePseudo tries on a slow routine are held to a time budget', () => { // 300 calls deep, then a loop: every run is slow, and 150 of them used to be waited for const src = 'FUNCTION F(N : INTEGER, D : INTEGER) RETURNS INTEGER\n DECLARE T : INTEGER <- 0\n IF D < 300 THEN\n RETURN F(N, D + 1)\n ENDIF\n FOR I <- 0 TO 2000\n T <- T + 1\n NEXT I\n RETURN T\nENDFUNCTION\n'; const st = studyOf(src); const pr = checkProperties(st.program.program, 'F', { count: 150, budgetMs: 50 }); assert.equal(pr.cutShort, true); assert.ok(pr.checked < 150); assert.equal(checkProperties(studyOf('FUNCTION G(N : INTEGER) RETURNS INTEGER\n RETURN N\nENDFUNCTION\n').program.program, 'G', { count: 20, budgetMs: 5000 }).cutShort, undefined); }); // The limits below are processor time at this machine's pace (tests/helpers/pace.mjs): each was seconds or minutes // before its fix, and is a small part of its limit after it, on any machine. test('a long program is studied in time that grows with its length, not its square (B7)', () => { // each case took seconds when the data flow was solved one statement per pass, over sets of every definition const declares = Array.from({ length: 1000 }, (_, i) => `DECLARE V${i} : INTEGER <- ${i}\n`).join(''); within(2000, '1000 declarations', () => assert.ok(studyOf(declares).ok)); within(4000, 'an edit of 1000 declarations', () => new SyncHub({ pseudo: '' }).edit('pseudo', declares)); const nested = `${Array.from({ length: 150 }, (_, i) => `FOR I${i} <- 0 TO 1\n`).join('')}OUTPUT 1\n${Array.from({ length: 150 }, (_, i) => `NEXT I${149 - i}\n`).join('')}`; within(2000, '150 nested FOR loops', () => assert.ok(studyOf(nested).ok)); const arms = 2000; const chain = `DECLARE X : INTEGER <- 1\nIF X == 0 THEN\n OUTPUT X\n${Array.from({ length: arms }, (_, i) => `ELSEIF X == ${i + 1} THEN\n OUTPUT X\n`).join('')}ENDIF\n`; let st; within(2000, `an ELSEIF chain of ${arms} arms`, () => { st = studyOf(chain); }); // and the answer is the whole one: X has its value in every arm, however far down the chain assert.deepEqual(st.diagnostics.filter((d) => /unset/.test(d.id)).map((d) => d.line), []); }); test('English for a text of many routines takes time that grows with their number, not its square (B8)', () => { const funcs = (n) => Array.from({ length: n }, (_, i) => `FUNCTION F${i}(X : INTEGER) RETURNS INTEGER\n RETURN X + ${i}\nENDFUNCTION\n`).join(''); // the English reader takes 200 routines and phrases at most (docs/limits.md): up to there the text is said in full let r; within(1000, '200 functions', () => { r = pseudoToLingo(funcs(200)); }); assert.ok(!('unsupported' in r)); // past it the answer says why, and still comes at once: 2,000 functions took a minute when each was held against every other within(3000, '600 functions', () => { r = pseudoToLingo(funcs(600)); }); assert.match(JSON.stringify(r.unsupported), /more than 200 routines and phrases/); // 2,000 of them are 6,000 lines, past what a pseudocode text is read to (docs/limits.md), and say that instead within(3000, '2000 functions', () => { r = pseudoToLingo(funcs(2000)); }); assert.match(JSON.stringify(r.unsupported), /more than 2,000 lines long/); }); test('a step costs the same at any call depth: frames that did not change are not pictured again (B9)', () => { // 390 calls deep, then a loop of 12,000 passes in the deepest call const src = 'FUNCTION F(N : INTEGER, D : INTEGER) RETURNS INTEGER\n DECLARE T : INTEGER <- 0\n IF D < 390 THEN\n RETURN F(N, D + 1)\n ENDIF\n FOR I <- 0 TO 12000\n T <- T + 1\n NEXT I\n RETURN T\nENDFUNCTION\nOUTPUT F(1, 0)\n'; let tr; within(1500, '20,000 steps 391 frames deep', () => { tr = run(src); }); assert.equal(tr.error?.kind, 'limit'); const [a, b] = [tr.states[tr.count - 2], tr.states[tr.count - 1]]; assert.equal(a.frames.length, 392); // the 391 frames under the one that runs are the same pictures from step to step; the running one is new for (let i = 0; i < 391; i++) assert.equal(a.frames[i], b.frames[i], `frame ${i}`); assert.notEqual(a.frames[391], b.frames[391]); assert.notDeepEqual(a.frames[391].vars, b.frames[391].vars); // a BYREF parameter shares its caller's slot: a write in the callee shows in the caller's frame at that step const byref = run('PROCEDURE Bump(BYREF X : INTEGER)\n X <- X + 1\nENDPROCEDURE\nDECLARE A : INTEGER <- 1\nCALL Bump(A)\nOUTPUT A\n'); const wrote = byref.steps.findIndex((s) => s.line === 2); assert.deepEqual(byref.states[wrote + 1].frames.map((f) => f.vars.A?.value ?? f.vars.X?.value), [2, 2]); assert.deepEqual(byref.states[wrote].frames.map((f) => f.vars.A?.value ?? f.vars.X?.value), [1, 1]); }); test('a recording stops copying a large collection at its budget, says so, and the run goes on (B10)', () => { // 50 passes over an ARRAY of 100, one position written per step: each of those steps copied the whole ARRAY const src = 'DECLARE A : ARRAY[100] OF INTEGER\nFOR P <- 0 TO 50\n FOR I <- 0 TO 100\n A[I] <- P\n NEXT I\nNEXT P\nOUTPUT A[99]\nOUTPUT A[100]\n'; const program = studyOf(src).program.program; const whole = runProgram(program, { maxSteps: 100000 }); assert.equal(whole.unrecorded, null); const cut = runProgram(program, { maxSteps: 100000, maxRecorded: 5000 }); const k = cut.unrecorded.after; assert.ok(k > 10 && k < whole.count, `cut after ${k} of ${whole.count} steps`); // the copies stop within one picture of the budget assert.ok(cut.unrecorded.values > 5000 && cut.unrecorded.values <= 5000 + 2 * 102); // one last step says so, and the steps and states before it are the ones the whole recording has assert.equal(cut.count, k + 1); assert.equal(cut.states.length, k + 2); assert.equal(cut.steps[k].kind, 'unrecorded'); assert.match(cut.steps[k].text, /not recorded/); // (frame ids count up across runs, so they are compared from each run's first) const same = (tr, x) => JSON.stringify(x, (key, v) => ((key === 'id' || key === 'frame') && typeof v === 'number' ? v - tr.states[0].frames[0].id : key === 'slot' ? undefined : typeof v === 'symbol' ? String(v) : v)); assert.ok(same(cut, cut.steps.slice(0, k)) === same(whole, whole.steps.slice(0, k)), 'the steps before the cut'); assert.ok(same(cut, cut.states.slice(0, k + 1)) === same(whole, whole.states.slice(0, k + 1)), 'the states before the cut'); // the run itself went on to the end: its output, its stop, and the lines it ran are the whole run's assert.deepEqual(cut.output, ['49']); assert.equal(cut.error?.kind, 'index'); assert.equal(cut.error.message, whole.error.message); assert.deepEqual([...cut.hits], [...whole.hits]); assert.equal(cut.work.steps, whole.work.steps); }); test('an ARRAY parameter and an ARRAY RETURN keep their declared lengths, as a store does (C12)', () => { const first = 'FUNCTION FIRST(A : ARRAY[3] OF INTEGER) RETURNS INTEGER\n RETURN A[0] + LENGTH(A)\nENDFUNCTION\n'; // lengths the text shows: an error where it is written assert.ok(errors(`${first}OUTPUT FIRST([7, 8])`).includes('array-length')); assert.ok(errors('PROCEDURE P(BYREF A : ARRAY[3] OF INTEGER)\n A[0] <- 1\nENDPROCEDURE\nDECLARE B : ARRAY[5] OF INTEGER\nCALL P(B)').includes('array-length')); assert.ok(errors('FUNCTION MAKE() RETURNS ARRAY[3] OF INTEGER\n DECLARE B : ARRAY[5] OF INTEGER\n RETURN B\nENDFUNCTION\nOUTPUT LENGTH(MAKE())').includes('array-length')); assert.ok(errors('DECLARE L : LIST OF ARRAY[2] OF INTEGER\nAPPEND(L, [1, 2, 3])').includes('array-length')); // lengths only the run knows: the run stops at the call or the RETURN const stop = run(`${first}DECLARE L : LIST OF INTEGER\nAPPEND(L, 7)\nAPPEND(L, 8)\nOUTPUT FIRST(L)`); assert.equal(stop.error?.kind, 'value'); assert.equal(stop.error.line, 7); assert.match(stop.error.message, /Parameter A of FIRST is an ARRAY of 3 positions, and the LIST given to it has 2/); const back = run('FUNCTION MAKE(N : INTEGER) RETURNS ARRAY[3] OF INTEGER\n DECLARE B : ARRAY[N] OF INTEGER\n RETURN B\nENDFUNCTION\nOUTPUT LENGTH(MAKE(5))'); assert.equal(back.error?.kind, 'value'); assert.match(back.error.message, /the RESULT of MAKE is an ARRAY of 3 positions/); // the right lengths run as before, a LIST becoming the ARRAY's positions assert.deepEqual(run(`${first}OUTPUT FIRST([7, 8, 9])`).output, ['10']); assert.deepEqual(run('FUNCTION MAKE(N : INTEGER) RETURNS ARRAY[3] OF INTEGER\n DECLARE B : ARRAY[N] OF INTEGER\n B[0] <- 1\n RETURN B\nENDFUNCTION\nOUTPUT LENGTH(MAKE(3))').output, ['3']); // and the prover knows a parameter's lengths, and asks for them where the text does not show them const pr = provePseudo(studyOf(`${first}DECLARE L : LIST OF INTEGER\nAPPEND(L, 7)\nOUTPUT FIRST(L)`), NO_CLOCK); const obs = pr.units.flatMap((u) => u.obligations); assert.equal(obs.find((o) => o.kind === 'index' && o.line === 2)?.status, 'proved'); assert.notEqual(obs.find((o) => o.kind === 'argument' && o.line === 6)?.status, 'proved'); assert.equal(obs.filter((o) => o.kind === 'argument').length, 1); }); test('a SET holds single values: a LIST, an ARRAY or a record as a member is an error (C5, prover O)', () => { // a run found such a member by identity, and it could change after it was added for (const src of [ 'DECLARE S : SET OF LIST OF INTEGER\nADD(S, [1, 2])\nASSERT [1, 2] IN S', 'TYPE P\n DECLARE X : INTEGER\nENDTYPE\nDECLARE S : SET OF P', 'DECLARE S : SET OF ARRAY[2] OF INTEGER', 'DECLARE L : LIST OF INTEGER\nOUTPUT {L}', 'DECLARE L : LIST OF LIST OF INTEGER\nOUTPUT {X IN L : LENGTH(X) > 0}', 'TYPE Rows = SET OF LIST OF CHAR\nOUTPUT 1', 'DECLARE S : SET OF SET OF INTEGER', ]) assert.ok(errors(src).includes('bad-member'), src); assert.deepEqual(run("DECLARE S : SET OF INT8\nDECLARE T : SET OF STRING\nADD(S, 3)\nADD(T, \"AC\")\nOUTPUT 3 IN S, \" \", \"AC\" IN T").output, ['TRUE TRUE']); }); test('NaN or an infinity passed straight to run() for a FLOAT parameter is refused without USE IEEE (prover Q)', () => { const body = 'PROCEDURE P(X : FLOAT, L : LIST OF FLOAT)\n ASSERT X == X\n OUTPUT X\nENDPROCEDURE\n'; const program = studyOf(body).program.program; for (const [x, l] of [[NaN, []], [Infinity, []], [-Infinity, []], [1.5, [NaN]], [1.5, [2, Infinity]]]) { const r = runProgram(program, { call: { name: 'P', args: [x, l] } }); assert.equal(r.error?.kind, 'value', `${x} ${l}`); assert.match(r.error.message, /not a finite number/); } assert.deepEqual(runProgram(program, { call: { name: 'P', args: [1.5, [2]] } }).output, ['1.5']); // with USE IEEE they are values like any other const ieee = studyOf(`USE IEEE\n${body.replace(' ASSERT X == X\n', '')}`).program.program; assert.deepEqual(runProgram(ieee, { call: { name: 'P', args: [Infinity, [NaN]] } }).output, ['infinity']); }); test('a routine the program cannot call by name is still checked, with its own record', () => { // named after a built-in, with a contract below its first line: the checker read `kind` of a record it never made, and threw const builtin = 'FUNCTION LENGTH(X : INTEGER) RETURNS INTEGER\n DECLARE Y : INTEGER\n REQUIRE X > 0\n RETURN X\nENDFUNCTION'; assert.deepEqual(errors(builtin), ['builtin-name', 'contract-place']); everyReader(builtin); // its parameters are its own: X is declared, Nope is not (before, both were reported) assert.deepEqual(errors('PROCEDURE ABS(BYREF X : INTEGER)\n X <- Nope\nENDPROCEDURE'), ['builtin-name', 'undeclared']); // a second routine of a name was checked with the first one's record: the first body twice, the second never const twice = 'FUNCTION F(X : INTEGER) RETURNS INTEGER\n RETURN X\nENDFUNCTION\nFUNCTION F(A : STRING) RETURNS STRING\n RETURN A & Undeclared\nENDFUNCTION'; const found = studyOf(twice).diagnostics.filter((d) => d.severity === 'error').map((d) => `${d.line} ${d.id}`); assert.deepEqual(found, ['4 duplicate', '5 undeclared']); everyReader(twice); });