2019-07-25 06:17:19 +00:00
|
|
|
import { readFileSync } from 'fs';
|
2020-02-05 00:14:31 +00:00
|
|
|
import { extractPackageFile } from './extract';
|
2018-11-09 13:22:11 +00:00
|
|
|
|
2019-07-25 06:17:19 +00:00
|
|
|
const cargo1toml = readFileSync(
|
2020-02-05 00:14:31 +00:00
|
|
|
'lib/manager/cargo/__fixtures__/Cargo.1.toml',
|
2019-03-11 15:50:10 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
2019-07-25 06:17:19 +00:00
|
|
|
const cargo2toml = readFileSync(
|
2020-02-05 00:14:31 +00:00
|
|
|
'lib/manager/cargo/__fixtures__/Cargo.2.toml',
|
2019-03-11 15:50:10 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
2019-07-25 06:17:19 +00:00
|
|
|
const cargo3toml = readFileSync(
|
2020-02-05 00:14:31 +00:00
|
|
|
'lib/manager/cargo/__fixtures__/Cargo.3.toml',
|
2019-03-11 15:50:10 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
2019-07-25 06:17:19 +00:00
|
|
|
const cargo4toml = readFileSync(
|
2020-02-05 00:14:31 +00:00
|
|
|
'lib/manager/cargo/__fixtures__/Cargo.4.toml',
|
2019-04-09 08:25:13 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
2019-07-25 06:17:19 +00:00
|
|
|
const cargo5toml = readFileSync(
|
2020-02-05 00:14:31 +00:00
|
|
|
'lib/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();
|
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('returns null for empty dependencies', () => {
|
2019-04-09 08:25:13 +00:00
|
|
|
const cargotoml = '[dependencies]\n';
|
|
|
|
expect(extractPackageFile(cargotoml, config)).toBeNull();
|
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('returns null for empty dev-dependencies', () => {
|
2019-04-09 08:25:13 +00:00
|
|
|
const cargotoml = '[dev-dependencies]\n';
|
|
|
|
expect(extractPackageFile(cargotoml, config)).toBeNull();
|
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('returns null for empty custom target', () => {
|
2019-04-09 08:25:13 +00:00
|
|
|
const cargotoml = '[target."foo".dependencies]\n';
|
|
|
|
expect(extractPackageFile(cargotoml, config)).toBeNull();
|
2018-11-09 13:22:11 +00:00
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('extracts multiple dependencies simple', () => {
|
2019-03-04 09:24:07 +00:00
|
|
|
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
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('extracts multiple dependencies advanced', () => {
|
2019-03-04 09:24:07 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|