From 68aede7ffaae6e3d8bcad59b8adec3cce85a51fa Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sat, 14 Sep 2024 01:05:15 +0200 Subject: [PATCH] fix tests, add new test --- tests/processor.test.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/processor.test.js b/tests/processor.test.js index 2aa556e0..b714a9ec 100644 --- a/tests/processor.test.js +++ b/tests/processor.test.js @@ -723,7 +723,7 @@ describe("processor", () => { " function boolean(arg) {", " \treturn", " \t!!arg;", - "};", + " };", " ```", ].join("\n"); const messages = [ @@ -767,7 +767,7 @@ describe("processor", () => { column: 2, message: "Unnecessary semicolon.", ruleId: "no-extra-semi", - fix: { range: [38, 39], text: "" }, + fix: { range: [41, 42], text: "" }, }, ], ]; @@ -840,14 +840,40 @@ describe("processor", () => { assert.strictEqual(result[2].column, 9); assert.strictEqual(result[3].column, 4); - assert.strictEqual(result[4].column, 2); + assert.strictEqual(result[4].column, 4); }); it("should adjust fix range properties", () => { const result = processor.postprocess(messages); - assert(result[2].fix.range, [185, 185]); - assert(result[4].fix.range, [264, 265]); + assert.deepStrictEqual(result[2].fix.range, [179, 179]); + assert.deepStrictEqual(result[4].fix.range, [267, 268]); + }); + + // https://github.com/eslint/markdown/pull/282 + it("should adjust fix range properties (2)", () => { + const codeWithSpaceInParens = + prefix + ["```js", "( a)", "```"].join("\n"); + + processor.preprocess(codeWithSpaceInParens); + + const messagesForBlocks = [ + [ + { + line: 1, + endLine: 1, + column: 2, + message: + "There should be no space after this paren.", + ruleId: "space-in-parens", + fix: { range: [1, 2], text: "" }, + }, + ], + ]; + + const result = processor.postprocess(messagesForBlocks); + + assert.deepStrictEqual(result[0].fix.range, [7, 8]); }); describe("should exclude messages from unsatisfiable rules", () => {