mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Initial commit
This commit is contained in:
27
node_modules/table/test/README/usage/basic.js
generated
vendored
Normal file
27
node_modules/table/test/README/usage/basic.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('basic', () => {
|
||||
const data = [
|
||||
['0A', '0B', '0C'],
|
||||
['1A', '1B', '1C'],
|
||||
['2A', '2B', '2C']
|
||||
];
|
||||
|
||||
const output = table(data);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔════╤════╤════╗
|
||||
║ 0A │ 0B │ 0C ║
|
||||
╟────┼────┼────╢
|
||||
║ 1A │ 1B │ 1C ║
|
||||
╟────┼────┼────╢
|
||||
║ 2A │ 2B │ 2C ║
|
||||
╚════╧════╧════╝
|
||||
`);
|
||||
});
|
||||
});
|
47
node_modules/table/test/README/usage/cell_content_alignment.js
generated
vendored
Normal file
47
node_modules/table/test/README/usage/cell_content_alignment.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('cell_content_alignment', () => {
|
||||
const data = [
|
||||
['0A', '0B', '0C'],
|
||||
['1A', '1B', '1C'],
|
||||
['2A', '2B', '2C']
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
alignment: 'left',
|
||||
width: 10
|
||||
},
|
||||
1: {
|
||||
alignment: 'center',
|
||||
width: 10
|
||||
},
|
||||
2: {
|
||||
alignment: 'right',
|
||||
width: 10
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const output = table(data, config);
|
||||
|
||||
// console.log(output);
|
||||
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
expectTable(output, `
|
||||
╔════════════╤════════════╤════════════╗
|
||||
║ 0A │ 0B │ 0C ║
|
||||
╟────────────┼────────────┼────────────╢
|
||||
║ 1A │ 1B │ 1C ║
|
||||
╟────────────┼────────────┼────────────╢
|
||||
║ 2A │ 2B │ 2C ║
|
||||
╚════════════╧════════════╧════════════╝
|
||||
`);
|
||||
/* eslint-enable no-restricted-syntax */
|
||||
});
|
||||
});
|
35
node_modules/table/test/README/usage/column_width.js
generated
vendored
Normal file
35
node_modules/table/test/README/usage/column_width.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('column_width', () => {
|
||||
const data = [
|
||||
['0A', '0B', '0C'],
|
||||
['1A', '1B', '1C'],
|
||||
['2A', '2B', '2C']
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
1: {
|
||||
width: 10
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const output = table(data, config);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔════╤════════════╤════╗
|
||||
║ 0A │ 0B │ 0C ║
|
||||
╟────┼────────────┼────╢
|
||||
║ 1A │ 1B │ 1C ║
|
||||
╟────┼────────────┼────╢
|
||||
║ 2A │ 2B │ 2C ║
|
||||
╚════╧════════════╧════╝
|
||||
`);
|
||||
});
|
||||
});
|
52
node_modules/table/test/README/usage/custom_border.js
generated
vendored
Normal file
52
node_modules/table/test/README/usage/custom_border.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('usage/custom_border', () => {
|
||||
const data = [
|
||||
['0A', '0B', '0C'],
|
||||
['1A', '1B', '1C'],
|
||||
['2A', '2B', '2C']
|
||||
];
|
||||
|
||||
/* eslint-disable sort-keys */
|
||||
const config = {
|
||||
border: {
|
||||
topBody: '─',
|
||||
topJoin: '┬',
|
||||
topLeft: '┌',
|
||||
topRight: '┐',
|
||||
|
||||
bottomBody: '─',
|
||||
bottomJoin: '┴',
|
||||
bottomLeft: '└',
|
||||
bottomRight: '┘',
|
||||
|
||||
bodyLeft: '│',
|
||||
bodyRight: '│',
|
||||
bodyJoin: '│',
|
||||
|
||||
joinBody: '─',
|
||||
joinLeft: '├',
|
||||
joinRight: '┤',
|
||||
joinJoin: '┼'
|
||||
}
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
const output = table(data, config);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
┌────┬────┬────┐
|
||||
│ 0A │ 0B │ 0C │
|
||||
├────┼────┼────┤
|
||||
│ 1A │ 1B │ 1C │
|
||||
├────┼────┼────┤
|
||||
│ 2A │ 2B │ 2C │
|
||||
└────┴────┴────┘
|
||||
`);
|
||||
});
|
||||
});
|
43
node_modules/table/test/README/usage/draw_horizontal_line.js
generated
vendored
Normal file
43
node_modules/table/test/README/usage/draw_horizontal_line.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('usage/draw_horizontal_line', () => {
|
||||
const data = [
|
||||
['0A', '0B', '0C'],
|
||||
['1A', '1B', '1C'],
|
||||
['2A', '2B', '2C'],
|
||||
['3A', '3B', '3C'],
|
||||
['4A', '4B', '4C']
|
||||
];
|
||||
|
||||
const options = {
|
||||
/**
|
||||
* @typedef {Function} drawJoin
|
||||
* @param {number} index
|
||||
* @param {number} size
|
||||
* @returns {boolean}
|
||||
*/
|
||||
drawHorizontalLine: (index, size) => {
|
||||
return index === 0 || index === 1 || index === size - 1 || index === size;
|
||||
}
|
||||
};
|
||||
|
||||
const output = table(data, options);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔════╤════╤════╗
|
||||
║ 0A │ 0B │ 0C ║
|
||||
╟────┼────┼────╢
|
||||
║ 1A │ 1B │ 1C ║
|
||||
║ 2A │ 2B │ 2C ║
|
||||
║ 3A │ 3B │ 3C ║
|
||||
╟────┼────┼────╢
|
||||
║ 4A │ 4B │ 4C ║
|
||||
╚════╧════╧════╝
|
||||
`);
|
||||
});
|
||||
});
|
13
node_modules/table/test/README/usage/expectTable.js
generated
vendored
Normal file
13
node_modules/table/test/README/usage/expectTable.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import _ from 'lodash';
|
||||
|
||||
/**
|
||||
* @param {string} result
|
||||
* @param {string} expectedResult
|
||||
* @returns {undefined}
|
||||
*/
|
||||
export default (result, expectedResult) => {
|
||||
expect(result).to.equal(_.trim(expectedResult) + '\n');
|
||||
};
|
68
node_modules/table/test/README/usage/moon_mission.js
generated
vendored
Normal file
68
node_modules/table/test/README/usage/moon_mission.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import _ from 'lodash';
|
||||
import chalk from 'chalk';
|
||||
import {
|
||||
table,
|
||||
getBorderCharacters
|
||||
} from './../../../src';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('moon_mission', () => {
|
||||
const data = [
|
||||
[
|
||||
chalk.bold('Spacecraft'),
|
||||
chalk.bold('Launch Date'),
|
||||
chalk.bold('Operator'),
|
||||
chalk.bold('Outcome'),
|
||||
chalk.bold('Remarks')
|
||||
],
|
||||
[
|
||||
'Able I',
|
||||
'17 August 1958',
|
||||
'USAF',
|
||||
chalk.white.bold.bgRed('Launch failure'),
|
||||
'First attempted launch beyond Earth orbit; failed to orbit due to turbopump gearbox malfunction resulting in first stage explosion.[3] Reached apogee of 16 kilometres (9.9 mi)'
|
||||
],
|
||||
[
|
||||
'Luna 2',
|
||||
'12 September 1959',
|
||||
'OKB-1',
|
||||
chalk.black.bgGreen('Successful'),
|
||||
'Successful impact at 21:02 on 14 September 1959. First spacecraft to reach lunar surface'
|
||||
],
|
||||
[
|
||||
'Lunar Orbiter 1',
|
||||
'10 August 1966',
|
||||
'NASA',
|
||||
chalk.black.bgYellow('Partial failure'),
|
||||
'Orbital insertion at around 15:36 UTC on 14 August. Deorbited early due to lack of fuel and to avoid communications interference with the next mission, impacted the Moon at 13:30 UTC on 29 October 1966.'
|
||||
],
|
||||
[
|
||||
'Apollo 8',
|
||||
'21 December 1968',
|
||||
'NASA',
|
||||
chalk.black.bgGreen('Successful'),
|
||||
'First manned mission to the Moon; entered orbit around the Moon with four-minute burn beginning at 09:59:52 UTC on 24 December. Completed ten orbits of the Moon before returning to Earth with an engine burn at 06:10:16 UTC on 25 December. Landed in the Pacific Ocean at 15:51 UTC on 27 December.'
|
||||
],
|
||||
[
|
||||
'Apollo 11',
|
||||
'16 July 1969',
|
||||
'NASA',
|
||||
chalk.black.bgGreen('Successful'),
|
||||
'First manned landing on the Moon. LM landed at 20:17 UTC on 20 July 1969'
|
||||
]
|
||||
];
|
||||
|
||||
const tableBorder = _.mapValues(getBorderCharacters('honeywell'), (char) => {
|
||||
return chalk.gray(char);
|
||||
});
|
||||
|
||||
table(data, {
|
||||
border: tableBorder,
|
||||
columns: {
|
||||
4: {
|
||||
width: 50
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
41
node_modules/table/test/README/usage/padding_cell_content.js
generated
vendored
Normal file
41
node_modules/table/test/README/usage/padding_cell_content.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('usage/padding_cell_content', () => {
|
||||
const data = [
|
||||
['0A', 'AABBCC', '0C'],
|
||||
['1A', '1B', '1C'],
|
||||
['2A', '2B', '2C']
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
paddingLeft: 3
|
||||
},
|
||||
1: {
|
||||
paddingRight: 3,
|
||||
width: 2
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const output = table(data, config);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔══════╤══════╤════╗
|
||||
║ 0A │ AA │ 0C ║
|
||||
║ │ BB │ ║
|
||||
║ │ CC │ ║
|
||||
╟──────┼──────┼────╢
|
||||
║ 1A │ 1B │ 1C ║
|
||||
╟──────┼──────┼────╢
|
||||
║ 2A │ 2B │ 2C ║
|
||||
╚══════╧══════╧════╝
|
||||
`);
|
||||
});
|
||||
});
|
92
node_modules/table/test/README/usage/predefined_border_templates.js
generated
vendored
Normal file
92
node_modules/table/test/README/usage/predefined_border_templates.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
table,
|
||||
getBorderCharacters
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/predefined_border_templates', () => {
|
||||
let data;
|
||||
|
||||
before(() => {
|
||||
data = [
|
||||
['0A', '0B', '0C'],
|
||||
['1A', '1B', '1C'],
|
||||
['2A', '2B', '2C']
|
||||
];
|
||||
});
|
||||
|
||||
it('honeywell', () => {
|
||||
const output = table(data, {
|
||||
border: getBorderCharacters('honeywell')
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔════╤════╤════╗
|
||||
║ 0A │ 0B │ 0C ║
|
||||
╟────┼────┼────╢
|
||||
║ 1A │ 1B │ 1C ║
|
||||
╟────┼────┼────╢
|
||||
║ 2A │ 2B │ 2C ║
|
||||
╚════╧════╧════╝
|
||||
`);
|
||||
});
|
||||
|
||||
it('norc', () => {
|
||||
const output = table(data, {
|
||||
border: getBorderCharacters('norc')
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
┌────┬────┬────┐
|
||||
│ 0A │ 0B │ 0C │
|
||||
├────┼────┼────┤
|
||||
│ 1A │ 1B │ 1C │
|
||||
├────┼────┼────┤
|
||||
│ 2A │ 2B │ 2C │
|
||||
└────┴────┴────┘
|
||||
`);
|
||||
});
|
||||
|
||||
it('ramac', () => {
|
||||
const output = table(data, {
|
||||
border: getBorderCharacters('ramac')
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
+----+----+----+
|
||||
| 0A | 0B | 0C |
|
||||
|----|----|----|
|
||||
| 1A | 1B | 1C |
|
||||
|----|----|----|
|
||||
| 2A | 2B | 2C |
|
||||
+----+----+----+
|
||||
`);
|
||||
});
|
||||
|
||||
it('void', () => {
|
||||
const output = table(data, {
|
||||
border: getBorderCharacters('void')
|
||||
});
|
||||
|
||||
expectTable(_.trim(output) + '\n', '0A 0B 0C \n\n 1A 1B 1C \n\n 2A 2B 2C');
|
||||
});
|
||||
|
||||
it('borderless', () => {
|
||||
const output = table(data, {
|
||||
border: getBorderCharacters('void'),
|
||||
columnDefault: {
|
||||
paddingLeft: 0,
|
||||
paddingRight: 1
|
||||
},
|
||||
drawHorizontalLine: () => {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
expectTable(_.trim(output) + '\n', '0A 0B 0C \n1A 1B 1C \n2A 2B 2C');
|
||||
});
|
||||
});
|
56
node_modules/table/test/README/usage/streaming.js
generated
vendored
Normal file
56
node_modules/table/test/README/usage/streaming.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
createStream
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
describe('process.stdout.write', () => {
|
||||
let processStdoutWriteBuffer;
|
||||
|
||||
/**
|
||||
* @var {Function} Reference to the original process.stdout.write function.
|
||||
*/
|
||||
const processStdoutWrite = process.stdout.write;
|
||||
|
||||
/**
|
||||
* @returns {undefined}
|
||||
*/
|
||||
const overwriteProcessStdoutWrite = () => {
|
||||
processStdoutWriteBuffer = '';
|
||||
|
||||
process.stdout.write = (text) => {
|
||||
processStdoutWriteBuffer += text;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
const resetProcessStdoudWrite = () => {
|
||||
process.stdout.write = processStdoutWrite;
|
||||
|
||||
return processStdoutWriteBuffer;
|
||||
};
|
||||
|
||||
it('streaming', () => {
|
||||
const config = {
|
||||
columnCount: 3,
|
||||
columnDefault: {
|
||||
width: 2
|
||||
}
|
||||
};
|
||||
|
||||
const stream = createStream(config);
|
||||
|
||||
overwriteProcessStdoutWrite();
|
||||
|
||||
stream.write(['0A', '0B', '0C']);
|
||||
stream.write(['1A', '1B', '1C']);
|
||||
stream.write(['2A', '2B', '2C']);
|
||||
|
||||
const output = resetProcessStdoudWrite();
|
||||
|
||||
expectTable(output + '\n', '╔════╤════╤════╗\n║ 0A │ 0B │ 0C ║\n╚════╧════╧════╝\r\u001b[K╟────┼────┼────╢\n║ 1A │ 1B │ 1C ║\n╚════╧════╧════╝\r\u001b[K╟────┼────┼────╢\n║ 2A │ 2B │ 2C ║\n╚════╧════╧════╝');
|
||||
});
|
||||
});
|
||||
});
|
34
node_modules/table/test/README/usage/text_truncating.js
generated
vendored
Normal file
34
node_modules/table/test/README/usage/text_truncating.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('text_truncating', () => {
|
||||
const data = [
|
||||
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
truncate: 100,
|
||||
width: 20
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const output = table(data, config);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔══════════════════════╗
|
||||
║ Lorem ipsum dolor si ║
|
||||
║ t amet, consectetur ║
|
||||
║ adipiscing elit. Pha ║
|
||||
║ sellus pulvinar nibh ║
|
||||
║ sed mauris conva... ║
|
||||
╚══════════════════════╝
|
||||
`);
|
||||
});
|
||||
});
|
69
node_modules/table/test/README/usage/text_wrapping.js
generated
vendored
Normal file
69
node_modules/table/test/README/usage/text_wrapping.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
table
|
||||
} from './../../../src';
|
||||
import expectTable from './expectTable';
|
||||
|
||||
describe('README.md usage/', () => {
|
||||
it('text_wrapping (no wrap word)', () => {
|
||||
const data = [
|
||||
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 20
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const output = table(data, config);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔══════════════════════╗
|
||||
║ Lorem ipsum dolor si ║
|
||||
║ t amet, consectetur ║
|
||||
║ adipiscing elit. Pha ║
|
||||
║ sellus pulvinar nibh ║
|
||||
║ sed mauris convallis ║
|
||||
║ dapibus. Nunc venena ║
|
||||
║ tis tempus nulla sit ║
|
||||
║ amet viverra. ║
|
||||
╚══════════════════════╝
|
||||
`);
|
||||
});
|
||||
|
||||
it('text_wrapping (wrap word)', () => {
|
||||
const data = [
|
||||
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 20,
|
||||
wrapWord: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const output = table(data, config);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
expectTable(output, `
|
||||
╔══════════════════════╗
|
||||
║ Lorem ipsum dolor ║
|
||||
║ sit amet, ║
|
||||
║ consectetur ║
|
||||
║ adipiscing elit. ║
|
||||
║ Phasellus pulvinar ║
|
||||
║ nibh sed mauris ║
|
||||
║ convallis dapibus. ║
|
||||
║ Nunc venenatis ║
|
||||
║ tempus nulla sit ║
|
||||
║ amet viverra. ║
|
||||
╚══════════════════════╝
|
||||
`);
|
||||
});
|
||||
});
|
102
node_modules/table/test/alignString.js
generated
vendored
Normal file
102
node_modules/table/test/alignString.js
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import chalk from 'chalk';
|
||||
import alignString from './../src/alignString';
|
||||
|
||||
describe('alignString', () => {
|
||||
context('subject parameter value is not a string', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
alignString();
|
||||
}).to.throw(Error, 'Subject parameter value must be a string.');
|
||||
});
|
||||
});
|
||||
context('container width parameter value is not a string', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
alignString('');
|
||||
}).to.throw(Error, 'Container width parameter value must be a number.');
|
||||
});
|
||||
});
|
||||
context('subject parameter value width is greater than the container width', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
alignString('aa', 1, 'left');
|
||||
}).to.throw(Error, 'Subject parameter value width cannot be greater than the container width.');
|
||||
});
|
||||
});
|
||||
context('container alignment parameter value is not a string', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
alignString('', 1);
|
||||
}).to.throw(Error, 'Alignment parameter value must be a string.');
|
||||
});
|
||||
});
|
||||
context('container alignment parameter value is not a known alignment parameter value', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
alignString('', 1, 'foo');
|
||||
}).to.throw(Error, 'Alignment parameter value must be a known alignment parameter value (left, right, center).');
|
||||
});
|
||||
});
|
||||
context('subject parameter value', () => {
|
||||
context('0 width', () => {
|
||||
it('produces a string consisting of container width number of whitespace characters', () => {
|
||||
expect(alignString('', 5, 'left')).to.equal(' ', 'left');
|
||||
expect(alignString('', 5, 'center')).to.equal(' ', 'center');
|
||||
expect(alignString('', 5, 'right')).to.equal(' ', 'right');
|
||||
});
|
||||
});
|
||||
context('plain text', () => {
|
||||
context('alignment', () => {
|
||||
context('left', () => {
|
||||
it('pads the string on the right side using a whitespace character', () => {
|
||||
expect(alignString('aa', 6, 'left')).to.equal('aa ');
|
||||
});
|
||||
});
|
||||
context('right', () => {
|
||||
it('pads the string on the left side using a whitespace character', () => {
|
||||
expect(alignString('aa', 6, 'right')).to.equal(' aa');
|
||||
});
|
||||
});
|
||||
context('center', () => {
|
||||
it('pads the string on both sides using a whitespace character', () => {
|
||||
expect(alignString('aa', 6, 'center')).to.equal(' aa ');
|
||||
});
|
||||
context('uneven number of available with', () => {
|
||||
it('floors the available width; adds extra space to the end of the string', () => {
|
||||
expect(alignString('aa', 7, 'center')).to.equal(' aa ');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
context('text containing ANSI escape codes', () => {
|
||||
context('alignment', () => {
|
||||
context('left', () => {
|
||||
it('pads the string on the right side using a whitespace character', () => {
|
||||
expect(alignString(chalk.red('aa'), 6, 'left')).to.equal(chalk.red('aa') + ' ');
|
||||
});
|
||||
});
|
||||
context('right', () => {
|
||||
it('pads the string on the left side using a whitespace character', () => {
|
||||
expect(alignString(chalk.red('aa'), 6, 'right')).to.equal(' ' + chalk.red('aa'));
|
||||
});
|
||||
});
|
||||
context('center', () => {
|
||||
it('pads the string on both sides using a whitespace character', () => {
|
||||
expect(alignString(chalk.red('aa'), 6, 'center')).to.equal(' ' + chalk.red('aa') + ' ');
|
||||
});
|
||||
context('uneven number of available with', () => {
|
||||
it('floors the available width; adds extra space to the end of the string', () => {
|
||||
expect(alignString(chalk.red('aa'), 7, 'center')).to.equal(' ' + chalk.red('aa') + ' ');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
44
node_modules/table/test/calculateCellHeight.js
generated
vendored
Normal file
44
node_modules/table/test/calculateCellHeight.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import calculateCellHeight from './../src/calculateCellHeight';
|
||||
|
||||
describe('calculateCellHeight', () => {
|
||||
describe('value', () => {
|
||||
context('is not a string', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
calculateCellHeight(null);
|
||||
}).to.throw(Error, 'Value must be a string.');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('context width', () => {
|
||||
context('is not an integer', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
calculateCellHeight('foo', null);
|
||||
}).to.throw(Error, 'Column width must be an integer.');
|
||||
});
|
||||
});
|
||||
context('is 0', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
calculateCellHeight('foo', 0);
|
||||
}).to.throw(Error, 'Column width must be greater than 0.');
|
||||
});
|
||||
});
|
||||
context('is lesser than the column width', () => {
|
||||
it('has height 1', () => {
|
||||
expect(calculateCellHeight('foo', 10)).to.equal(1);
|
||||
});
|
||||
});
|
||||
context('is 2 and half times greater than the column width', () => {
|
||||
it('has height 3', () => {
|
||||
expect(calculateCellHeight('aabbc', 2)).to.equal(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
20
node_modules/table/test/calculateCellWidthIndex.js
generated
vendored
Normal file
20
node_modules/table/test/calculateCellWidthIndex.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import calculateCellWidthIndex from './../src/calculateCellWidthIndex';
|
||||
|
||||
describe('calculateCellWidthIndex', () => {
|
||||
context('all cells have different width', () => {
|
||||
it('describes each cell contents width', () => {
|
||||
const cellWidthIndex = calculateCellWidthIndex([
|
||||
'a',
|
||||
'aaa',
|
||||
'aaaaaa'
|
||||
]);
|
||||
|
||||
expect(cellWidthIndex[0]).to.equal(1, 'first column');
|
||||
expect(cellWidthIndex[1]).to.equal(3, 'second column');
|
||||
expect(cellWidthIndex[2]).to.equal(6, 'third column');
|
||||
});
|
||||
});
|
||||
});
|
59
node_modules/table/test/calculateMaximumColumnWidthIndex.js
generated
vendored
Normal file
59
node_modules/table/test/calculateMaximumColumnWidthIndex.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import chalk from 'chalk';
|
||||
import calculateMaximumColumnWidthIndex from './../src/calculateMaximumColumnWidthIndex';
|
||||
|
||||
describe('calculateMaximumColumnWidthIndex', () => {
|
||||
it('throws an error when attempting to calculate maximum column value index for an empty data set', () => {
|
||||
expect(() => {
|
||||
calculateMaximumColumnWidthIndex([]);
|
||||
}).to.throw(Error, 'Dataset must have at least one row.');
|
||||
});
|
||||
it('calculates the maximum column value index', () => {
|
||||
const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
|
||||
[
|
||||
'',
|
||||
'a',
|
||||
'b',
|
||||
'c'
|
||||
],
|
||||
[
|
||||
'',
|
||||
'a',
|
||||
'bbbbbbbbbb',
|
||||
'c'
|
||||
],
|
||||
[
|
||||
'',
|
||||
'',
|
||||
'b',
|
||||
'ccccc'
|
||||
]
|
||||
]);
|
||||
|
||||
expect(maximumColumnValueIndex).to.deep.equal([0, 1, 10, 5]);
|
||||
});
|
||||
context('cell values contain ANSI codes', () => {
|
||||
it('uses visual width of the string', () => {
|
||||
const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
|
||||
[
|
||||
chalk.red('aaaaa')
|
||||
]
|
||||
]);
|
||||
|
||||
expect(maximumColumnValueIndex[0]).to.equal(5);
|
||||
});
|
||||
});
|
||||
context('cell values contain fullwidth characters', () => {
|
||||
it('uses visual width of the string', () => {
|
||||
const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
|
||||
[
|
||||
chalk.red('古')
|
||||
]
|
||||
]);
|
||||
|
||||
expect(maximumColumnValueIndex[0]).to.equal(2);
|
||||
});
|
||||
});
|
||||
});
|
78
node_modules/table/test/calculateRowHeightIndex.js
generated
vendored
Normal file
78
node_modules/table/test/calculateRowHeightIndex.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import calculateRowHeightIndex from './../src/calculateRowHeightIndex';
|
||||
|
||||
describe('calculateRowHeightIndex', () => {
|
||||
context('single column', () => {
|
||||
context('cell content width is lesser than column width', () => {
|
||||
it('is equal to 1', () => {
|
||||
const data = [
|
||||
[
|
||||
'aaa'
|
||||
]
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 10,
|
||||
wrapWord: false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rowSpanIndex = calculateRowHeightIndex(data, config);
|
||||
|
||||
expect(rowSpanIndex[0]).to.equal(1);
|
||||
});
|
||||
});
|
||||
context('cell content width is twice the size of the column width', () => {
|
||||
it('is equal to 2', () => {
|
||||
const data = [
|
||||
[
|
||||
'aaabbb'
|
||||
]
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 3,
|
||||
wrapWord: false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rowSpanIndex = calculateRowHeightIndex(data, config);
|
||||
|
||||
expect(rowSpanIndex[0]).to.equal(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
context('multiple columns', () => {
|
||||
context('multiple cell content width is greater than the column width', () => {
|
||||
it('uses the largest height', () => {
|
||||
const data = [
|
||||
['aaabbb'],
|
||||
['aaabbb']
|
||||
];
|
||||
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 2,
|
||||
wrapWord: false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rowSpanIndex = calculateRowHeightIndex(data, config);
|
||||
|
||||
expect(rowSpanIndex[0]).to.equal(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
43
node_modules/table/test/config.js
generated
vendored
Normal file
43
node_modules/table/test/config.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import configSamples from './configSamples';
|
||||
import validateConfig from '../dist/validateConfig';
|
||||
import configSchema from '../src/schemas/config.json';
|
||||
import Ajv from 'ajv';
|
||||
import ajvKeywords from 'ajv-keywords';
|
||||
|
||||
describe('config.json schema', () => {
|
||||
var validate;
|
||||
|
||||
before(() => {
|
||||
var ajv = new Ajv({allErrors: true});
|
||||
ajvKeywords(ajv, 'typeof');
|
||||
validate = ajv.compile(configSchema);
|
||||
});
|
||||
|
||||
it('should pass validation of valid config samples', () => {
|
||||
configSamples.valid.forEach((sample, i) => {
|
||||
testValid(sample, validate);
|
||||
testValid(sample, validateConfig);
|
||||
});
|
||||
|
||||
function testValid(sample, validate) {
|
||||
var valid = validate(sample);
|
||||
if (!valid) console.log(validate.errors);
|
||||
expect(valid).to.equal(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should fail validation of invalid config samples', () => {
|
||||
configSamples.invalid.forEach((sample, i) => {
|
||||
testInvalid(sample, validate);
|
||||
testInvalid(sample, validateConfig);
|
||||
});
|
||||
|
||||
function testInvalid(sample, validate) {
|
||||
var valid = validate(sample);
|
||||
expect(valid).to.equal(false);
|
||||
}
|
||||
});
|
||||
});
|
153
node_modules/table/test/configSamples.js
generated
vendored
Normal file
153
node_modules/table/test/configSamples.js
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
export default {
|
||||
valid: [
|
||||
{
|
||||
columns: {
|
||||
0: {
|
||||
alignment: 'left',
|
||||
// minWidth: 10,
|
||||
width: 10
|
||||
},
|
||||
1: {
|
||||
alignment: 'center',
|
||||
// minWidth: 10,
|
||||
width: 10
|
||||
},
|
||||
2: {
|
||||
alignment: 'right',
|
||||
// minWidth: 10,
|
||||
width: 10
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
border: {
|
||||
topBody: `─`,
|
||||
topJoin: `┬`,
|
||||
topLeft: `┌`,
|
||||
topRight: `┐`,
|
||||
|
||||
bottomBody: `─`,
|
||||
bottomJoin: `┴`,
|
||||
bottomLeft: `└`,
|
||||
bottomRight: `┘`,
|
||||
|
||||
bodyLeft: `│`,
|
||||
bodyRight: `│`,
|
||||
bodyJoin: `│`,
|
||||
|
||||
joinBody: `─`,
|
||||
joinLeft: `├`,
|
||||
joinRight: `┤`,
|
||||
joinJoin: `┼`
|
||||
}
|
||||
},
|
||||
{
|
||||
columns: {
|
||||
0: {
|
||||
paddingLeft: 3
|
||||
},
|
||||
1: {
|
||||
width: 2,
|
||||
paddingRight: 3
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
border: {},
|
||||
columnDefault: {
|
||||
paddingLeft: 0,
|
||||
paddingRight: 1
|
||||
},
|
||||
// drawJoin: () => {
|
||||
// return false
|
||||
// }
|
||||
},
|
||||
{
|
||||
columnDefault: {
|
||||
width: 50
|
||||
},
|
||||
// columnCount: 3,
|
||||
columns: {
|
||||
0: {
|
||||
width: 10,
|
||||
alignment: 'right'
|
||||
},
|
||||
1: {
|
||||
alignment: 'center',
|
||||
},
|
||||
2: {
|
||||
width: 10
|
||||
}
|
||||
}
|
||||
},
|
||||
{ border: { topBody: '-' } },
|
||||
{ border: { topJoin: '-' } },
|
||||
{ border: { topLeft: '-' } },
|
||||
{ border: { topRight: '-' } },
|
||||
{ border: { bottomBody: '-' } },
|
||||
{ border: { bottomJoin: '-' } },
|
||||
{ border: { bottomLeft: '-' } },
|
||||
{ border: { bottomRight: '-' } },
|
||||
{ border: { bodyLeft: '-' } },
|
||||
{ border: { bodyRight: '-' } },
|
||||
{ border: { bodyJoin: '-' } },
|
||||
{ border: { joinBody: '-' } },
|
||||
{ border: { joinLeft: '-' } },
|
||||
{ border: { joinRight: '-' } },
|
||||
{ border: { joinJoin: '-' } },
|
||||
{ columns: { '1': { alignment: 'left' } } },
|
||||
{ columns: { '1': { width: 5 } } },
|
||||
{ columns: { '1': { wrapWord: true } } },
|
||||
{ columns: { '1': { truncate: 1 } } },
|
||||
{ columns: { '1': { paddingLeft: 1 } } },
|
||||
{ columns: { '1': { paddingRight: 1 } } },
|
||||
{ columnDefault: { alignment: 'left' } },
|
||||
{ columnDefault: { width: 5 } },
|
||||
{ columnDefault: { wrapWord: true } },
|
||||
{ columnDefault: { truncate: 1 } },
|
||||
{ columnDefault: { paddingLeft: 1 } },
|
||||
{ columnDefault: { paddingRight: 1 } },
|
||||
{ drawHorizontalLine: function(){} }
|
||||
],
|
||||
invalid: [
|
||||
{ border: 1 },
|
||||
{ border: { unknown: '-' } },
|
||||
{ border: { topBody: 1 } },
|
||||
{ border: { topJoin: 1 } },
|
||||
{ border: { topLeft: 1 } },
|
||||
{ border: { topRight: 1 } },
|
||||
{ border: { bottomBody: 1 } },
|
||||
{ border: { bottomJoin: 1 } },
|
||||
{ border: { bottomLeft: 1 } },
|
||||
{ border: { bottomRight: 1 } },
|
||||
{ border: { bodyLeft: 1 } },
|
||||
{ border: { bodyRight: 1 } },
|
||||
{ border: { bodyJoin: 1 } },
|
||||
{ border: { joinBody: 1 } },
|
||||
{ border: { joinLeft: 1 } },
|
||||
{ border: { joinRight: 1 } },
|
||||
{ border: { joinJoin: 1 } },
|
||||
{ columns: 1 },
|
||||
{ columns: { a: { width: 5 } } },
|
||||
{ columns: { '1': 1 } },
|
||||
{ columns: { '1': { unknown: 1 } } },
|
||||
{ columns: { '1': { alignment: 1 } } },
|
||||
{ columns: { '1': { alignment: '1' } } },
|
||||
{ columns: { '1': { width: '5' } } },
|
||||
{ columns: { '1': { wrapWord: 1 } } },
|
||||
{ columns: { '1': { truncate: '1' } } },
|
||||
{ columns: { '1': { paddingLeft: '1' } } },
|
||||
{ columns: { '1': { paddingRight: '1' } } },
|
||||
{ columnDefault: 1 },
|
||||
{ columnDefault: { unknown: 1 } },
|
||||
{ columnDefault: { alignment: 1 } },
|
||||
{ columnDefault: { alignment: '1' } },
|
||||
{ columnDefault: { width: '5' } },
|
||||
{ columnDefault: { wrapWord: 1 } },
|
||||
{ columnDefault: { truncate: '1' } },
|
||||
{ columnDefault: { paddingLeft: '1' } },
|
||||
{ columnDefault: { paddingRight: '1' } },
|
||||
{ drawHorizontalLine: 1 },
|
||||
{ unknown: 1 }
|
||||
]
|
||||
};
|
41
node_modules/table/test/createStream.js
generated
vendored
Normal file
41
node_modules/table/test/createStream.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import createStream from './../src/createStream';
|
||||
|
||||
describe('createStream', () => {
|
||||
context('"config.columnDefault.width" property is not provided', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
createStream();
|
||||
}).to.throw(Error, 'Must provide config.columnDefault.width when creating a stream.');
|
||||
});
|
||||
});
|
||||
context('"config.columnCount" property is not provided', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
createStream({
|
||||
columnDefault: {
|
||||
width: 10
|
||||
}
|
||||
});
|
||||
}).to.throw(Error, 'Must provide config.columnCount.');
|
||||
});
|
||||
});
|
||||
context('Table data cell count does not match the columnCount.', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
const stream = createStream({
|
||||
columnCount: 10,
|
||||
columnDefault: {
|
||||
width: 10
|
||||
}
|
||||
});
|
||||
|
||||
stream.write(['foo']);
|
||||
}).to.throw(Error, 'Row cell count does not match the config.columnCount.');
|
||||
});
|
||||
});
|
||||
});
|
71
node_modules/table/test/drawBorder.js
generated
vendored
Normal file
71
node_modules/table/test/drawBorder.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import {
|
||||
drawBorder,
|
||||
drawBorderTop,
|
||||
drawBorderJoin,
|
||||
drawBorderBottom
|
||||
} from './../src/drawBorder';
|
||||
|
||||
describe('drawBorder', () => {
|
||||
it('draws a border using parts', () => {
|
||||
const parts = {
|
||||
left: '╔',
|
||||
right: '╗',
|
||||
body: '═',
|
||||
join: '╤'
|
||||
};
|
||||
|
||||
expect(drawBorder([1], parts)).to.equal('╔═╗\n');
|
||||
expect(drawBorder([1, 1], parts)).to.equal('╔═╤═╗\n');
|
||||
expect(drawBorder([5, 10], parts)).to.equal('╔═════╤══════════╗\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('drawBorderTop', () => {
|
||||
it('draws a border using parts', () => {
|
||||
const parts = {
|
||||
topLeft: '╔',
|
||||
topRight: '╗',
|
||||
topBody: '═',
|
||||
topJoin: '╤'
|
||||
};
|
||||
|
||||
expect(drawBorderTop([1], parts)).to.equal('╔═╗\n');
|
||||
expect(drawBorderTop([1, 1], parts)).to.equal('╔═╤═╗\n');
|
||||
expect(drawBorderTop([5, 10], parts)).to.equal('╔═════╤══════════╗\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('drawBorderJoin', () => {
|
||||
it('draws a border using parts', () => {
|
||||
const parts = {
|
||||
joinBody: '─',
|
||||
joinLeft: '╟',
|
||||
joinRight: '╢',
|
||||
joinJoin: '┼'
|
||||
};
|
||||
|
||||
expect(drawBorderJoin([1], parts)).to.equal('╟─╢\n');
|
||||
expect(drawBorderJoin([1, 1], parts)).to.equal('╟─┼─╢\n');
|
||||
expect(drawBorderJoin([5, 10], parts)).to.equal('╟─────┼──────────╢\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('drawBorderBottom', () => {
|
||||
it('draws a border using parts', () => {
|
||||
const parts = {
|
||||
bottomBody: '═',
|
||||
bottomJoin: '╧',
|
||||
bottomLeft: '╚',
|
||||
bottomRight: '╝'
|
||||
};
|
||||
|
||||
expect(drawBorderBottom([1], parts)).to.equal('╚═╝\n');
|
||||
expect(drawBorderBottom([1, 1], parts)).to.equal('╚═╧═╝\n');
|
||||
expect(drawBorderBottom([5, 10], parts)).to.equal('╚═════╧══════════╝\n');
|
||||
});
|
||||
});
|
75
node_modules/table/test/makeConfig.js
generated
vendored
Normal file
75
node_modules/table/test/makeConfig.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import makeConfig from './../src/makeConfig';
|
||||
|
||||
describe('makeConfig', () => {
|
||||
it('does not affect the parameter configuration object', () => {
|
||||
const config = {};
|
||||
|
||||
makeConfig([
|
||||
[
|
||||
'aaaaa'
|
||||
]
|
||||
], config);
|
||||
|
||||
expect(config).to.deep.equal({});
|
||||
});
|
||||
|
||||
context('column', () => {
|
||||
context('"alignment"', () => {
|
||||
context('is not provided', () => {
|
||||
it('defaults to "left"', () => {
|
||||
const config = makeConfig([
|
||||
[
|
||||
'aaaaa'
|
||||
]
|
||||
]);
|
||||
|
||||
expect(config.columns[0].alignment).to.equal('left');
|
||||
});
|
||||
});
|
||||
});
|
||||
context('"width"', () => {
|
||||
context('is not provided', () => {
|
||||
it('defaults to the maximum column width', () => {
|
||||
const config = makeConfig([
|
||||
[
|
||||
'aaaaa'
|
||||
]
|
||||
]);
|
||||
|
||||
expect(config.columns[0].width).to.equal(5);
|
||||
});
|
||||
});
|
||||
});
|
||||
context('"paddingLeft"', () => {
|
||||
context('is not provided', () => {
|
||||
it('defaults to 1', () => {
|
||||
const config = makeConfig([
|
||||
[
|
||||
'aaaaa'
|
||||
]
|
||||
]);
|
||||
|
||||
expect(config.columns[0].paddingLeft).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
context('"paddingRight"', () => {
|
||||
context('is not provided', () => {
|
||||
it('defaults to 1', () => {
|
||||
const config = makeConfig([
|
||||
[
|
||||
'aaaaa'
|
||||
]
|
||||
]);
|
||||
|
||||
expect(config.columns[0].paddingRight).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
119
node_modules/table/test/mapDataUsingRowHeightIndex.js
generated
vendored
Normal file
119
node_modules/table/test/mapDataUsingRowHeightIndex.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import mapDataUsingRowHeightIndex from './../src/mapDataUsingRowHeightIndex';
|
||||
|
||||
describe('mapDataUsingRowHeightIndex', () => {
|
||||
context('no data spans multiple rows', () => {
|
||||
it('maps data to a single cell', () => {
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 2
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rowSpanIndex = [
|
||||
1
|
||||
];
|
||||
|
||||
const data = [
|
||||
[
|
||||
'aa'
|
||||
]
|
||||
];
|
||||
|
||||
const mappedData = mapDataUsingRowHeightIndex(data, rowSpanIndex, config);
|
||||
|
||||
expect(mappedData).to.deep.equal([
|
||||
[
|
||||
'aa'
|
||||
]
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
context('single cell spans multiple rows', () => {
|
||||
it('maps data to multiple rows', () => {
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 2
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rowSpanIndex = [
|
||||
5
|
||||
];
|
||||
|
||||
const data = [
|
||||
[
|
||||
'aabbccddee'
|
||||
]
|
||||
];
|
||||
|
||||
const mappedData = mapDataUsingRowHeightIndex(data, rowSpanIndex, config);
|
||||
|
||||
expect(mappedData).to.deep.equal([
|
||||
['aa'],
|
||||
['bb'],
|
||||
['cc'],
|
||||
['dd'],
|
||||
['ee']
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
context('multiple cells spans multiple rows', () => {
|
||||
it('maps data to multiple rows', () => {
|
||||
const config = {
|
||||
columns: {
|
||||
0: {
|
||||
width: 2
|
||||
},
|
||||
1: {
|
||||
width: 4
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rowSpanIndex = [
|
||||
5
|
||||
];
|
||||
|
||||
const data = [
|
||||
[
|
||||
'aabbccddee',
|
||||
'00001111'
|
||||
]
|
||||
];
|
||||
|
||||
const mappedData = mapDataUsingRowHeightIndex(data, rowSpanIndex, config);
|
||||
|
||||
expect(mappedData).to.deep.equal([
|
||||
[
|
||||
'aa',
|
||||
'0000'
|
||||
],
|
||||
[
|
||||
'bb',
|
||||
'1111'
|
||||
],
|
||||
[
|
||||
'cc',
|
||||
''
|
||||
],
|
||||
[
|
||||
'dd',
|
||||
''
|
||||
],
|
||||
[
|
||||
'ee',
|
||||
''
|
||||
]
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
43
node_modules/table/test/streamConfig.js
generated
vendored
Normal file
43
node_modules/table/test/streamConfig.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import configSamples from './streamConfigSamples';
|
||||
import validateConfig from '../dist/validateStreamConfig';
|
||||
import configSchema from '../src/schemas/streamConfig.json';
|
||||
import Ajv from 'ajv';
|
||||
import ajvKeywords from 'ajv-keywords';
|
||||
|
||||
describe('streamConfig.json schema', () => {
|
||||
var validate;
|
||||
|
||||
before(() => {
|
||||
var ajv = new Ajv({allErrors: true});
|
||||
ajvKeywords(ajv, 'typeof');
|
||||
validate = ajv.compile(configSchema);
|
||||
});
|
||||
|
||||
it('should pass validation of valid streamConfig samples', () => {
|
||||
configSamples.valid.forEach((sample, i) => {
|
||||
testValid(sample, validate);
|
||||
testValid(sample, validateConfig);
|
||||
});
|
||||
|
||||
function testValid(sample, validate) {
|
||||
var valid = validate(sample);
|
||||
if (!valid) console.log(validate.errors);
|
||||
expect(valid).to.equal(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should fail validation of invalid streamConfig samples', () => {
|
||||
configSamples.invalid.forEach((sample, i) => {
|
||||
testInvalid(sample, validate);
|
||||
testInvalid(sample, validateConfig);
|
||||
});
|
||||
|
||||
function testInvalid(sample, validate) {
|
||||
var valid = validate(sample);
|
||||
expect(valid).to.equal(false);
|
||||
}
|
||||
});
|
||||
});
|
151
node_modules/table/test/streamConfigSamples.js
generated
vendored
Normal file
151
node_modules/table/test/streamConfigSamples.js
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
export default {
|
||||
valid: [
|
||||
{
|
||||
columns: {
|
||||
0: {
|
||||
alignment: 'left',
|
||||
// minWidth: 10,
|
||||
width: 10
|
||||
},
|
||||
1: {
|
||||
alignment: 'center',
|
||||
// minWidth: 10,
|
||||
width: 10
|
||||
},
|
||||
2: {
|
||||
alignment: 'right',
|
||||
// minWidth: 10,
|
||||
width: 10
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
border: {
|
||||
topBody: `─`,
|
||||
topJoin: `┬`,
|
||||
topLeft: `┌`,
|
||||
topRight: `┐`,
|
||||
|
||||
bottomBody: `─`,
|
||||
bottomJoin: `┴`,
|
||||
bottomLeft: `└`,
|
||||
bottomRight: `┘`,
|
||||
|
||||
bodyLeft: `│`,
|
||||
bodyRight: `│`,
|
||||
bodyJoin: `│`,
|
||||
|
||||
joinBody: `─`,
|
||||
joinLeft: `├`,
|
||||
joinRight: `┤`,
|
||||
joinJoin: `┼`
|
||||
}
|
||||
},
|
||||
{
|
||||
columns: {
|
||||
0: {
|
||||
paddingLeft: 3
|
||||
},
|
||||
1: {
|
||||
width: 2,
|
||||
paddingRight: 3
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
border: {},
|
||||
columnDefault: {
|
||||
paddingLeft: 0,
|
||||
paddingRight: 1
|
||||
},
|
||||
// drawJoin: () => {
|
||||
// return false
|
||||
// }
|
||||
},
|
||||
{
|
||||
columnDefault: {
|
||||
width: 50
|
||||
},
|
||||
// columnCount: 3,
|
||||
columns: {
|
||||
0: {
|
||||
width: 10,
|
||||
alignment: 'right'
|
||||
},
|
||||
1: {
|
||||
alignment: 'center',
|
||||
},
|
||||
2: {
|
||||
width: 10
|
||||
}
|
||||
}
|
||||
},
|
||||
{ border: { topBody: '-' } },
|
||||
{ border: { topJoin: '-' } },
|
||||
{ border: { topLeft: '-' } },
|
||||
{ border: { topRight: '-' } },
|
||||
{ border: { bottomBody: '-' } },
|
||||
{ border: { bottomJoin: '-' } },
|
||||
{ border: { bottomLeft: '-' } },
|
||||
{ border: { bottomRight: '-' } },
|
||||
{ border: { bodyLeft: '-' } },
|
||||
{ border: { bodyRight: '-' } },
|
||||
{ border: { bodyJoin: '-' } },
|
||||
{ border: { joinBody: '-' } },
|
||||
{ border: { joinLeft: '-' } },
|
||||
{ border: { joinRight: '-' } },
|
||||
{ border: { joinJoin: '-' } },
|
||||
{ columns: { '1': { alignment: 'left' } } },
|
||||
{ columns: { '1': { width: 5 } } },
|
||||
{ columns: { '1': { wrapWord: true } } },
|
||||
{ columns: { '1': { truncate: 1 } } },
|
||||
{ columns: { '1': { paddingLeft: 1 } } },
|
||||
{ columns: { '1': { paddingRight: 1 } } },
|
||||
{ columnDefault: { alignment: 'left' } },
|
||||
{ columnDefault: { width: 5 } },
|
||||
{ columnDefault: { wrapWord: true } },
|
||||
{ columnDefault: { truncate: 1 } },
|
||||
{ columnDefault: { paddingLeft: 1 } },
|
||||
{ columnDefault: { paddingRight: 1 } }
|
||||
],
|
||||
invalid: [
|
||||
{ border: 1 },
|
||||
{ border: { unknown: '-' } },
|
||||
{ border: { topBody: 1 } },
|
||||
{ border: { topJoin: 1 } },
|
||||
{ border: { topLeft: 1 } },
|
||||
{ border: { topRight: 1 } },
|
||||
{ border: { bottomBody: 1 } },
|
||||
{ border: { bottomJoin: 1 } },
|
||||
{ border: { bottomLeft: 1 } },
|
||||
{ border: { bottomRight: 1 } },
|
||||
{ border: { bodyLeft: 1 } },
|
||||
{ border: { bodyRight: 1 } },
|
||||
{ border: { bodyJoin: 1 } },
|
||||
{ border: { joinBody: 1 } },
|
||||
{ border: { joinLeft: 1 } },
|
||||
{ border: { joinRight: 1 } },
|
||||
{ border: { joinJoin: 1 } },
|
||||
{ columns: 1 },
|
||||
{ columns: { a: { width: 5 } } },
|
||||
{ columns: { '1': 1 } },
|
||||
{ columns: { '1': { unknown: 1 } } },
|
||||
{ columns: { '1': { alignment: 1 } } },
|
||||
{ columns: { '1': { alignment: '1' } } },
|
||||
{ columns: { '1': { width: '5' } } },
|
||||
{ columns: { '1': { wrapWord: 1 } } },
|
||||
{ columns: { '1': { truncate: '1' } } },
|
||||
{ columns: { '1': { paddingLeft: '1' } } },
|
||||
{ columns: { '1': { paddingRight: '1' } } },
|
||||
{ columnDefault: 1 },
|
||||
{ columnDefault: { unknown: 1 } },
|
||||
{ columnDefault: { alignment: 1 } },
|
||||
{ columnDefault: { alignment: '1' } },
|
||||
{ columnDefault: { width: '5' } },
|
||||
{ columnDefault: { wrapWord: 1 } },
|
||||
{ columnDefault: { truncate: '1' } },
|
||||
{ columnDefault: { paddingLeft: '1' } },
|
||||
{ columnDefault: { paddingRight: '1' } },
|
||||
{ unknown: 1 }
|
||||
]
|
||||
};
|
65
node_modules/table/test/validateTableData.js
generated
vendored
Normal file
65
node_modules/table/test/validateTableData.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import validateTableData from './../src/validateTableData';
|
||||
|
||||
describe('validateTableData', () => {
|
||||
context('table does not have a row', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTableData([]);
|
||||
}).to.throw(Error, 'Table must define at least one row.');
|
||||
});
|
||||
});
|
||||
|
||||
context('table does not have a column', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTableData([[]]);
|
||||
}).to.throw(Error, 'Table must define at least one column.');
|
||||
});
|
||||
});
|
||||
|
||||
context('row data is not an array', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTableData({});
|
||||
}).to.throw(Error, 'Table data must be an array.');
|
||||
});
|
||||
});
|
||||
|
||||
context('column data is not an array', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTableData([{}]);
|
||||
}).to.throw(Error, 'Table row data must be an array.');
|
||||
});
|
||||
});
|
||||
|
||||
context('cell data contains a control character', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTableData([
|
||||
[
|
||||
[
|
||||
String.fromCodePoint(0x01)
|
||||
]
|
||||
]
|
||||
]);
|
||||
}).to.throw(Error, 'Table data must not contain control characters.');
|
||||
});
|
||||
});
|
||||
|
||||
context('rows have inconsistent number of cells', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTableData([
|
||||
['a', 'b', 'c'],
|
||||
['a', 'b']
|
||||
]);
|
||||
}).to.throw(Error, 'Table must have a consistent number of cells.');
|
||||
});
|
||||
});
|
||||
});
|
45
node_modules/table/test/wrapString.js
generated
vendored
Normal file
45
node_modules/table/test/wrapString.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import chalk from 'chalk';
|
||||
import wrapString from './../src/wrapString';
|
||||
|
||||
describe('wrapString', () => {
|
||||
context('subject is a plain text string', () => {
|
||||
context('subject is lesser than the chunk size', () => {
|
||||
it('returns subject in a single chunk', () => {
|
||||
expect(wrapString('aaa', 3)).to.deep.equal(['aaa']);
|
||||
});
|
||||
});
|
||||
context('subject is larger than the chunk size', () => {
|
||||
it('returns subject sliced into multiple chunks', () => {
|
||||
expect(wrapString('aaabbbc', 3)).to.deep.equal(['aaa', 'bbb', 'c']);
|
||||
});
|
||||
});
|
||||
context('a chunk starts with a space', () => {
|
||||
it('adjusts chunks to offset the space', () => {
|
||||
expect(wrapString('aaa bbb ccc', 3)).to.deep.equal(['aaa', 'bbb', 'ccc']);
|
||||
});
|
||||
});
|
||||
});
|
||||
context('subject string contains ANSI escape codes', () => {
|
||||
describe('subject is lesser than the chunk size', () => {
|
||||
it.skip('returns subject in a single chunk', () => {
|
||||
expect(wrapString(chalk.red('aaa'), 3)).to.deep.equal([
|
||||
'\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31maaa\u001b[39m'
|
||||
]);
|
||||
});
|
||||
});
|
||||
describe('subject is larger than the chunk size', () => {
|
||||
it.skip('returns subject sliced into multiple chunks', () => {
|
||||
expect(wrapString(chalk.red('aaabbbc'), 3)).to.deep.equal([
|
||||
'\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31maaa\u001b[39m',
|
||||
'\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31mbbb\u001b[39m',
|
||||
'\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31mc\u001b[39m'
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
32
node_modules/table/test/wrapWord.js
generated
vendored
Normal file
32
node_modules/table/test/wrapWord.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import wrapWord from './../src/wrapWord';
|
||||
|
||||
describe('wrapWord', () => {
|
||||
it('wraps a string at a nearest whitespace', () => {
|
||||
expect(wrapWord('aaa bbb', 5)).to.deep.equal(['aaa', 'bbb']);
|
||||
expect(wrapWord('a a a bbb', 5)).to.deep.equal(['a a a', 'bbb']);
|
||||
});
|
||||
context('a single word is longer than chunk size', () => {
|
||||
it('cuts the word', () => {
|
||||
expect(wrapWord('aaaaa', 2)).to.deep.equal(['aa', 'aa', 'a']);
|
||||
});
|
||||
});
|
||||
context('a long word with a special character', () => {
|
||||
it('cuts the word at the special character', () => {
|
||||
expect(wrapWord('aaa\\bbb', 5)).to.deep.equal(['aaa\\', 'bbb']);
|
||||
expect(wrapWord('aaa/bbb', 5)).to.deep.equal(['aaa/', 'bbb']);
|
||||
expect(wrapWord('aaa_bbb', 5)).to.deep.equal(['aaa_', 'bbb']);
|
||||
expect(wrapWord('aaa-bbb', 5)).to.deep.equal(['aaa-', 'bbb']);
|
||||
expect(wrapWord('aaa.bbb', 5)).to.deep.equal(['aaa.', 'bbb']);
|
||||
expect(wrapWord('aaa,bbb', 5)).to.deep.equal(['aaa,', 'bbb']);
|
||||
expect(wrapWord('aaa;bbb', 5)).to.deep.equal(['aaa;', 'bbb']);
|
||||
});
|
||||
});
|
||||
context('a special character after the length of a container', () => {
|
||||
it('does not include special character', () => {
|
||||
expect(wrapWord('aa-bbbbb-cccc', 5)).to.deep.equal(['aa-', 'bbbbb', '-cccc']);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user