From a317fd30fc19e1d1df68ce3fb9c11d5dbfd4a566 Mon Sep 17 00:00:00 2001 From: Jesse Luoto Date: Sun, 6 Oct 2024 23:41:35 +0300 Subject: [PATCH] Add more invalid identifier tests --- .../visit-all-identifiers.test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/plugins/local-llm-rename/visit-all-identifiers.test.ts b/src/plugins/local-llm-rename/visit-all-identifiers.test.ts index a447e97..08ca2e4 100644 --- a/src/plugins/local-llm-rename/visit-all-identifiers.test.ts +++ b/src/plugins/local-llm-rename/visit-all-identifiers.test.ts @@ -213,3 +213,30 @@ test("should handle invalid identifiers", async () => { const result = await visitAllIdentifiers(code, async () => "this.kLength"); assert.equal(result, "const thisKLength = 1;"); }); + +test("should handle space in identifier name (happens for some reason though it shouldn't)", async () => { + const code = `const a = 1`; + const result = await visitAllIdentifiers(code, async () => "foo bar"); + assert.equal(result, "const fooBar = 1;"); +}); + +test("should handle reserved identifiers", async () => { + const code = `const a = 1`; + const result = await visitAllIdentifiers(code, async () => "static"); + assert.equal(result, "const _static = 1;"); +}); + +test("should handle multiple identifiers named the same", async () => { + const code = ` +const a = 1; +const b = 1; +`.trim(); + const result = await visitAllIdentifiers(code, async () => "foo"); + assert.equal( + result, + ` +const foo = 1; +const _foo = 1; +`.trim() + ); +});