Skip to content

Commit af7abf4

Browse files
fix: @W-20411063 Make Apex package namespace replacement case insensitive (#454)
1 parent 99676b4 commit af7abf4

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

src/utils/apex/parser/apexparser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class InterfaceMatcher {
259259
} else if (
260260
checkFor.namespace &&
261261
typeNameContexts.length === 2 &&
262-
checkFor.namespace === typeNameContexts[0]?.id()?.Identifier()?.symbol?.text &&
262+
checkFor.namespace === typeNameContexts[0]?.id()?.Identifier()?.symbol?.text?.toLowerCase() &&
263263
checkFor.name === typeNameContexts[1]?.id()?.Identifier()?.symbol?.text
264264
) {
265265
tokens.push(typeNameContexts[0].id().Identifier().symbol);

test/migration/related/ApexASTParser.test.ts

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ describe('ApexASTParser', () => {
360360

361361
it('should get matching tokens for interface with namespace', () => {
362362
// Arrange
363-
const interfaceImpl = new InterfaceImplements('TestInterface', 'testNamespace');
363+
const interfaceImpl = new InterfaceImplements('TestInterface', 'testnamespace'); // lowercase
364364
const mockContext = {
365365
typeName: () => [
366366
{
@@ -384,6 +384,7 @@ describe('ApexASTParser', () => {
384384
const tokens = InterfaceMatcher.getMatchingTokens(interfaceImpl, mockContext as any);
385385

386386
// Assert
387+
// Should match because: 'testnamespace' === 'testNamespace'.toLowerCase()
387388
expect(tokens).to.have.length(2);
388389
expect(tokens[0].text).to.equal('testNamespace');
389390
expect(tokens[1].text).to.equal('TestInterface');
@@ -417,6 +418,108 @@ describe('ApexASTParser', () => {
417418
// Assert
418419
expect(tokens).to.have.length(0);
419420
});
421+
422+
it('should match namespace when checkFor.namespace equals lowercased code namespace - uppercase code', () => {
423+
// Arrange
424+
// Tests line 262: checkFor.namespace === typeNameContexts[0]?.id()?.Identifier()?.symbol?.text?.toLowerCase()
425+
// checkFor.namespace='devopsimpkg15', code='DEVOPSIMPKG15' → 'devopsimpkg15' === 'devopsimpkg15' ✓
426+
const interfaceImpl = new InterfaceImplements('VlocityOpenInterface', 'devopsimpkg15');
427+
const mockContext = {
428+
typeName: () => [
429+
{
430+
id: () => ({
431+
Identifier: () => ({
432+
symbol: { text: 'DEVOPSIMPKG15' }, // Uppercase in code - will be lowercased for comparison
433+
}),
434+
}),
435+
},
436+
{
437+
id: () => ({
438+
Identifier: () => ({
439+
symbol: { text: 'VlocityOpenInterface' },
440+
}),
441+
}),
442+
},
443+
],
444+
};
445+
446+
// Act
447+
const tokens = InterfaceMatcher.getMatchingTokens(interfaceImpl, mockContext as any);
448+
449+
// Assert
450+
// Should match because: 'devopsimpkg15' === 'DEVOPSIMPKG15'.toLowerCase()
451+
expect(tokens).to.have.length(2);
452+
expect(tokens[0].text).to.equal('DEVOPSIMPKG15');
453+
expect(tokens[1].text).to.equal('VlocityOpenInterface');
454+
});
455+
456+
it('should not match when checkFor.namespace is uppercase and code is lowercase', () => {
457+
// Arrange
458+
// Tests line 262: checkFor.namespace === typeNameContexts[0]?.id()?.Identifier()?.symbol?.text?.toLowerCase()
459+
// checkFor.namespace='DEVOPSIMPKG15', code='devopsimpkg15' → 'DEVOPSIMPKG15' === 'devopsimpkg15' ✗
460+
// Note: Only code side is lowercased, so uppercase checkFor.namespace won't match
461+
const interfaceImpl = new InterfaceImplements('VlocityOpenInterface', 'DEVOPSIMPKG15');
462+
const mockContext = {
463+
typeName: () => [
464+
{
465+
id: () => ({
466+
Identifier: () => ({
467+
symbol: { text: 'devopsimpkg15' }, // Lowercase namespace in code
468+
}),
469+
}),
470+
},
471+
{
472+
id: () => ({
473+
Identifier: () => ({
474+
symbol: { text: 'VlocityOpenInterface' },
475+
}),
476+
}),
477+
},
478+
],
479+
};
480+
481+
// Act
482+
const tokens = InterfaceMatcher.getMatchingTokens(interfaceImpl, mockContext as any);
483+
484+
// Assert
485+
// Current implementation: 'DEVOPSIMPKG15' === 'devopsimpkg15'.toLowerCase() = 'DEVOPSIMPKG15' === 'devopsimpkg15' = false
486+
// So this should NOT match with current implementation
487+
expect(tokens).to.have.length(0);
488+
});
489+
490+
it('should match namespace when checkFor.namespace equals lowercased code namespace - mixed case code', () => {
491+
// Arrange
492+
// Tests line 262: checkFor.namespace === typeNameContexts[0]?.id()?.Identifier()?.symbol?.text?.toLowerCase()
493+
// checkFor.namespace='devopsimpkg15', code='DevOpsImpkg15' → 'devopsimpkg15' === 'devopsimpkg15' ✓
494+
const interfaceImpl = new InterfaceImplements('VlocityOpenInterface', 'devopsimpkg15');
495+
const mockContext = {
496+
typeName: () => [
497+
{
498+
id: () => ({
499+
Identifier: () => ({
500+
symbol: { text: 'DevOpsImpkg15' }, // Mixed case namespace in code
501+
}),
502+
}),
503+
},
504+
{
505+
id: () => ({
506+
Identifier: () => ({
507+
symbol: { text: 'VlocityOpenInterface' },
508+
}),
509+
}),
510+
},
511+
],
512+
};
513+
514+
// Act
515+
const tokens = InterfaceMatcher.getMatchingTokens(interfaceImpl, mockContext as any);
516+
517+
// Assert
518+
// Should match because: 'devopsimpkg15' === 'DevOpsImpkg15'.toLowerCase()
519+
expect(tokens).to.have.length(2);
520+
expect(tokens[0].text).to.equal('DevOpsImpkg15');
521+
expect(tokens[1].text).to.equal('VlocityOpenInterface');
522+
});
420523
});
421524

422525
describe('TokenUpdater classes', () => {

0 commit comments

Comments
 (0)