2019-03-04 09:24:07 +00:00
|
|
|
const fs = require('fs');
|
2018-11-09 13:22:11 +00:00
|
|
|
const { extractPackageFile } = require('../../../lib/manager/cargo/extract');
|
|
|
|
|
2019-03-11 15:50:10 +00:00
|
|
|
const cargo1toml = fs.readFileSync(
|
2019-04-09 08:25:13 +00:00
|
|
|
'test/manager/cargo/_fixtures/Cargo.1.toml',
|
2019-03-11 15:50:10 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
const cargo2toml = fs.readFileSync(
|
2019-04-09 08:25:13 +00:00
|
|
|
'test/manager/cargo/_fixtures/Cargo.2.toml',
|
2019-03-11 15:50:10 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
const cargo3toml = fs.readFileSync(
|
2019-04-09 08:25:13 +00:00
|
|
|
'test/manager/cargo/_fixtures/Cargo.3.toml',
|
2019-03-11 15:50:10 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
const cargo4toml = fs.readFileSync(
|
2019-04-09 08:25:13 +00:00
|
|
|
'test/manager/cargo/_fixtures/Cargo.4.toml',
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
const cargo5toml = fs.readFileSync(
|
|
|
|
'test/manager/cargo/_fixtures/Cargo.5.toml',
|
2019-03-11 15:50:10 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
2019-03-04 09:24:07 +00:00
|
|
|
|
2018-11-09 13:22:11 +00:00
|
|
|
describe('lib/manager/cargo/extract', () => {
|
|
|
|
describe('extractPackageFile()', () => {
|
|
|
|
let config;
|
|
|
|
beforeEach(() => {
|
|
|
|
config = {};
|
|
|
|
});
|
2019-04-09 08:25:13 +00:00
|
|
|
it('returns null for invalid toml', () => {
|
|
|
|
expect(extractPackageFile('invalid toml', config)).toBeNull();
|
|
|
|
});
|
2018-11-09 13:22:11 +00:00
|
|
|
it('returns null for empty', () => {
|
2019-04-09 08:25:13 +00:00
|
|
|
const cargotoml = '[dependencies]\n';
|
|
|
|
expect(extractPackageFile(cargotoml, config)).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null for empty', () => {
|
|
|
|
const cargotoml = '[dev-dependencies]\n';
|
|
|
|
expect(extractPackageFile(cargotoml, config)).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null for empty', () => {
|
|
|
|
const cargotoml = '[target."foo".dependencies]\n';
|
|
|
|
expect(extractPackageFile(cargotoml, config)).toBeNull();
|
2018-11-09 13:22:11 +00:00
|
|
|
});
|
2019-03-04 09:24:07 +00:00
|
|
|
it('extracts multiple dependencies', () => {
|
|
|
|
const res = extractPackageFile(cargo1toml, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
2019-04-09 08:25:13 +00:00
|
|
|
expect(res.deps).toHaveLength(15);
|
2019-03-04 09:24:07 +00:00
|
|
|
});
|
|
|
|
it('extracts multiple dependencies', () => {
|
|
|
|
const res = extractPackageFile(cargo2toml, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
|
|
|
expect(res.deps).toHaveLength(18 + 6 + 1);
|
|
|
|
});
|
|
|
|
it('handles inline tables', () => {
|
|
|
|
const res = extractPackageFile(cargo3toml, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
2019-04-09 08:25:13 +00:00
|
|
|
expect(res.deps).toHaveLength(8);
|
2019-03-04 09:24:07 +00:00
|
|
|
});
|
|
|
|
it('handles standard tables', () => {
|
|
|
|
const res = extractPackageFile(cargo4toml, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
2019-04-09 08:25:13 +00:00
|
|
|
expect(res.deps).toHaveLength(6);
|
|
|
|
});
|
|
|
|
it('extracts platform specific dependencies', () => {
|
|
|
|
const res = extractPackageFile(cargo5toml, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
|
|
|
expect(res.deps).toHaveLength(4);
|
2019-03-04 09:24:07 +00:00
|
|
|
});
|
2018-11-09 13:22:11 +00:00
|
|
|
});
|
|
|
|
});
|