From 18278d36990d39b2f426b5f5d712edf0c38b02f7 Mon Sep 17 00:00:00 2001 From: worksofliam Date: Sun, 21 Jan 2024 10:35:14 -0500 Subject: [PATCH] New range test --- tests/suite/linter.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/suite/linter.js b/tests/suite/linter.js index 4add3ec3..894b3b66 100644 --- a/tests/suite/linter.js +++ b/tests/suite/linter.js @@ -3463,4 +3463,41 @@ exports.on_excp_2 = async () => { expectedIndent: 2, currentIndent: 0 }); +} + +exports.range_1 = async () => { + const lines = [ + `**free`, + `ctl-opt debug option(*nodebugio: *srcstmt) dftactgrp(*no) actgrp(*caller)`, + `main(Main);`, + `dcl-s x timestamp;`, + `dcl-s y timestamp;`, + `dcl-proc Main;`, + ` dsply %CHAR(CalcDiscount(10000));`, + ` dsply %char(CalcDiscount(1000));`, + ` x = %TIMESTAMP(y);`, + ` y = %TimeStamp(x);`, + ` return;`, + `end-proc;`, + ].join(`\n`); + + const cache = await parser.getDocs(uri, lines, {ignoreCache: true, withIncludes: true}); + Linter.getErrors({ uri, content: lines }, { + CollectReferences: true + }, cache); + + const rangeRefs = cache.referencesInRange({position: 220, end: 260}); + assert.strictEqual(rangeRefs.length, 2); + assert.ok(rangeRefs[0].dec.name === `x`); + assert.ok(rangeRefs[1].dec.name === `y`); + + assert.deepStrictEqual(rangeRefs[0].refs, [ + { position: 220, end: 221 }, + { position: 256, end: 257 } + ]); + + assert.deepStrictEqual(rangeRefs[1].refs, [ + { position: 235, end: 236 }, + { position: 241, end: 242 } + ]); } \ No newline at end of file