Skip to content

Commit

Permalink
test: be more explicit on where remappings are replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
0xteddybear committed Nov 26, 2024
1 parent 0b2c27b commit 5f90b8c
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions test/unit/transformRemappings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,50 @@ describe('transformRemappings', () => {
after(() => {
mock.restore();
});

describe('with remapping for local file only', function () {
before(function () {
mock({
'remappings.txt': 'interfaces=../../interfaces',
});
});

// Foundry produces a warning when doing this, but compiles the project doing
// the substitution regardless. We do the same to be compatible, but foundry's
// behaviour might change in the future.
it('should replace remapped path if its not at the beggining of string', function() {
const fileContent = `import '../../interfaces/ITest.sol';`
const transformedContent = transformRemappings(fileContent);

expect(transformedContent).to.include(`import '../../../../interfaces/ITest.sol';`);
})

it('should replace path as instructed by remapping with all import syntaxes', function () {
const fileContent = `
import '../../../interfaces/ITest.sol';
import {ITest} from '../../../interfaces/ITest.sol';
import {ITest, ITest2} from '../../../interfaces/ITest.sol';
import {IBar as IFoo, ITest} from '../../../interfaces/ITest.sol';
import * as Interfaces '../../../interfaces/ITest.sol';
import "../../../interfaces/ITest.sol";
import {ITest} from "../../../interfaces/ITest.sol";
import {ITest, ITest2} from "../../../interfaces/ITest.sol";
import {IBar as IFoo, ITest} from "../../../interfaces/ITest.sol";
import * as Interfaces "../../../interfaces/ITest.sol";
import 'interfaces/ITest.sol';
import {ITest} from 'interfaces/ITest.sol';
import {ITest, ITest2} from 'interfaces/ITest.sol';
import {IBar as IFoo, ITest} from 'interfaces/ITest.sol';
import * as Interfaces 'interfaces/ITest.sol';
import "interfaces/ITest.sol";
import {ITest} from "interfaces/ITest.sol";
import {ITest, ITest2} from "interfaces/ITest.sol";
import {IBar as IFoo, ITest} from "interfaces/ITest.sol";
import * as Interfaces "interfaces/ITest.sol";
`;

const transformedContent = transformRemappings(fileContent);

expect(transformedContent).to.include(`import '../../../../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import {ITest} from '../../../../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import {ITest, ITest2} from '../../../../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import {IBar as IFoo, ITest} from '../../../../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import * as Interfaces '../../../../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import "../../../../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import {ITest} from "../../../../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import {ITest, ITest2} from "../../../../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import {IBar as IFoo, ITest} from "../../../../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import * as Interfaces "../../../../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import '../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import {ITest} from '../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import {ITest, ITest2} from '../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import {IBar as IFoo, ITest} from '../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import * as Interfaces '../../interfaces/ITest.sol';`);
expect(transformedContent).to.include(`import "../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import {ITest} from "../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import {ITest, ITest2} from "../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import {IBar as IFoo, ITest} from "../../interfaces/ITest.sol";`);
expect(transformedContent).to.include(`import * as Interfaces "../../interfaces/ITest.sol";`);
});

it('should remove node_modules from import paths', function () {
Expand Down

0 comments on commit 5f90b8c

Please sign in to comment.