diff --git a/cli/src/utils.ts b/cli/src/utils.ts index 62f9ed1..268643e 100644 --- a/cli/src/utils.ts +++ b/cli/src/utils.ts @@ -274,7 +274,7 @@ export function globalEntryIsValid(fullPath: string, search: string, ignoreBase? } const baseParts = fullPath.toUpperCase().split(path.sep); - const nameParts = search.split(path.sep); + const nameParts = search.split(path.posix.sep); // Check the preceding parts of the path match if (nameParts.length > 1) { @@ -297,7 +297,7 @@ export function globalEntryIsValid(fullPath: string, search: string, ignoreBase? const tempName = search.substring(0, search.length - 1); const lastChar = tempName.charAt(tempName.length - 1); const messedUpFullName = fullPath.lastIndexOf(lastChar) >= 0 ? fullPath.substring(0, fullPath.lastIndexOf(lastChar) + 1) : fullPath; - if (messedUpFullName.toUpperCase().endsWith(tempName)) return true; + if (messedUpFullName.replace(/\\/g, '/').toUpperCase().endsWith(tempName)) return true; } else if (!baseName.includes('.')) { // If the name does not include a dot, we check if the current part (without extension) matches let currentPart = baseParts[baseParts.length - 1]; diff --git a/cli/test/includeMismatchFix.test.ts b/cli/test/includeMismatchFix.test.ts index 2379d47..78f8a19 100644 --- a/cli/test/includeMismatchFix.test.ts +++ b/cli/test/includeMismatchFix.test.ts @@ -1,45 +1,45 @@ -import { beforeAll, describe, expect, test } from 'vitest'; - -import { Targets } from '../src/targets' -import path from 'path'; -import { setupFixture } from './fixtures/projects'; -import { ReadFileSystem } from '../src/readFileSystem'; - -// This issue was occuring when you had two files with the same name, but different extensions. - -describe(`include_mismatch_fix tests`, () => { - const project = setupFixture(`include_mismatch_fix`); - - const fs = new ReadFileSystem(); - const targets = new Targets(project.cwd, fs); - targets.setSuggestions({renames: true, includes: true}) - - beforeAll(async () => { - project.setup(); - await targets.loadProject(); - - expect(targets.getTargets().length).toBeGreaterThan(0); - targets.resolveBinder(); - }); - - test(`Ensure rename is against correct file`, async () => { - const articlePf = targets.getTarget({systemName: `ARTICLE`, type: `FILE`}); - expect(articlePf).toBeDefined(); - - const articlePfLogs = targets.logger.getLogsFor(articlePf.relativePath); - expect(articlePfLogs.length).toBe(1); - expect(articlePfLogs[0].message).toBe(`no object found for reference 'SAMREF'`); - expect(articlePfLogs[0].type).toBe(`warning`); - - const articleIncludeLogs = targets.logger.getLogsFor(path.join(`QPROTOSRC`, `ARTICLE.RPGLE`)); - expect(articleIncludeLogs.length).toBe(1); - expect(articleIncludeLogs[0].message).toBe(`Rename suggestion`); - expect(articleIncludeLogs[0].type).toBe(`rename`); - expect(articleIncludeLogs[0].change).toMatchObject({ - rename: { - path: path.join(project.cwd, `QPROTOSRC`, `ARTICLE.RPGLE`), - newName: 'ARTICLE.rpgleinc' - } - }) - }); +import { beforeAll, describe, expect, test } from 'vitest'; + +import { Targets } from '../src/targets' +import path from 'path'; +import { setupFixture } from './fixtures/projects'; +import { ReadFileSystem } from '../src/readFileSystem'; + +// This issue was occuring when you had two files with the same name, but different extensions. + +describe(`include_mismatch_fix tests`, () => { + const project = setupFixture(`include_mismatch_fix`); + + const fs = new ReadFileSystem(); + const targets = new Targets(project.cwd, fs); + targets.setSuggestions({renames: true, includes: true}) + + beforeAll(async () => { + project.setup(); + await targets.loadProject(); + + expect(targets.getTargets().length).toBeGreaterThan(0); + targets.resolveBinder(); + }); + + test(`Ensure rename is against correct file`, async () => { + const articlePf = targets.getTarget({systemName: `ARTICLE`, type: `FILE`}); + expect(articlePf).toBeDefined();articlePf.relativePath + + const articlePfLogs = targets.logger.getLogsFor(path.join(`QDDSSRC`, `ARTICLE.PF`)); + expect(articlePfLogs.length).toBe(1); + expect(articlePfLogs[0].message).toBe(`no object found for reference 'SAMREF'`); + expect(articlePfLogs[0].type).toBe(`warning`); + + const articleIncludeLogs = targets.logger.getLogsFor(path.join(`QPROTOSRC`, `ARTICLE.RPGLE`)); + expect(articleIncludeLogs.length).toBe(1); + expect(articleIncludeLogs[0].message).toBe(`Rename suggestion`); + expect(articleIncludeLogs[0].type).toBe(`rename`); + expect(articleIncludeLogs[0].change).toMatchObject({ + rename: { + path: path.join(project.cwd, `QPROTOSRC`, `ARTICLE.RPGLE`), + newName: 'ARTICLE.rpgleinc' + } + }) + }); }); \ No newline at end of file