diff --git a/examples/basic-usage-examples.js b/examples/basic-usage-examples.js index 8cb3fab..9a473fd 100644 --- a/examples/basic-usage-examples.js +++ b/examples/basic-usage-examples.js @@ -1,13 +1,13 @@ const Table = require('../src/table'); const colors = require('colors/safe'); -module.exports = function(runTest) { +module.exports = function (runTest) { function it(name, fn) { let result = fn(); runTest(name, result[0], result[1], result[2]); } - it('Basic Usage', function() { + it('Basic Usage', function () { function makeTable() { // By default, headers will be red, and borders will be grey let table = new Table({ head: ['a', 'b'] }); @@ -28,7 +28,7 @@ module.exports = function(runTest) { return [makeTable, expected, 'basic-usage-with-colors']; }); - it('Basic Usage - disable colors - (used often in the examples and tests)', function() { + it('Basic Usage - disable colors - (used often in the examples and tests)', function () { function makeTable() { // For most of these examples, and most of the unit tests we disable colors. // It makes unit tests easier to write/understand, and allows these pages to @@ -63,7 +63,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('Create vertical tables by adding objects a that specify key-value pairs', function() { + it('Create vertical tables by adding objects a that specify key-value pairs', function () { function makeTable() { let table = new Table({ style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, @@ -85,7 +85,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('Cross tables are similar to vertical tables, but include an empty string for the first header', function() { + it('Cross tables are similar to vertical tables, but include an empty string for the first header', function () { function makeTable() { let table = new Table({ head: ['', 'Header 1', 'Header 2'], @@ -113,7 +113,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('Stylize the table with custom border characters', function() { + it('Stylize the table with custom border characters', function () { function makeTable() { let table = new Table({ chars: { @@ -152,7 +152,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines', function() { + it('Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines', function () { function makeTable() { let table = new Table({ style: { border: [], header: [] } }); @@ -173,7 +173,7 @@ module.exports = function(runTest) { return [makeTable, expected, 'multi-line-colors']; }); - it('Set `wordWrap` to true to make lines of text wrap instead of being truncated', function() { + it('Set `wordWrap` to true to make lines of text wrap instead of being truncated', function () { function makeTable() { let table = new Table({ style: { border: [], header: [] }, diff --git a/examples/col-and-row-span-examples.js b/examples/col-and-row-span-examples.js index 58dd7a1..28bae50 100644 --- a/examples/col-and-row-span-examples.js +++ b/examples/col-and-row-span-examples.js @@ -1,13 +1,13 @@ const Table = require('../src/table'); const colors = require('colors/safe'); -module.exports = function(runTest) { +module.exports = function (runTest) { function it(name, fn) { let result = fn(); runTest(name, result[0], result[1], result[2]); } - it('use colSpan to span columns - (colSpan above normal cell)', function() { + it('use colSpan to span columns - (colSpan above normal cell)', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -29,7 +29,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('use colSpan to span columns - (colSpan below normal cell)', function() { + it('use colSpan to span columns - (colSpan below normal cell)', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -51,7 +51,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('use rowSpan to span rows - (rowSpan on the left side)', function() { + it('use rowSpan to span rows - (rowSpan on the left side)', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -74,7 +74,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('use rowSpan to span rows - (rowSpan on the right side)', function() { + it('use rowSpan to span rows - (rowSpan on the right side)', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -97,12 +97,16 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('mix rowSpan and colSpan together for complex table layouts', function() { + it('mix rowSpan and colSpan together for complex table layouts', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); table.push( - [{ content: 'hello', colSpan: 2 }, { rowSpan: 2, colSpan: 2, content: 'sup' }, { rowSpan: 3, content: 'hi' }], + [ + { content: 'hello', colSpan: 2 }, + { rowSpan: 2, colSpan: 2, content: 'sup' }, + { rowSpan: 3, content: 'hi' }, + ], [{ content: 'howdy', colSpan: 2 }], ['o', 'k', '', ''] ); @@ -123,7 +127,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('multi-line content will flow across rows in rowSpan cells', function() { + it('multi-line content will flow across rows in rowSpan cells', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -146,7 +150,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('multi-line content will flow across rows in rowSpan cells - (complex layout)', function() { + it('multi-line content will flow across rows in rowSpan cells - (complex layout)', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -176,7 +180,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('rowSpan cells can have a staggered layout', function() { + it('rowSpan cells can have a staggered layout', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -190,7 +194,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('the layout manager automatically create empty cells to fill in the table', function() { + it('the layout manager automatically create empty cells to fill in the table', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -214,7 +218,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('use table `rowHeights` option to fix row height. The truncation symbol will be shown on the last line.', function() { + it('use table `rowHeights` option to fix row height. The truncation symbol will be shown on the last line.', function () { function makeTable() { let table = new Table({ rowHeights: [2], @@ -231,7 +235,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('if `colWidths` is not specified, the layout manager will automatically widen rows to fit the content', function() { + it('if `colWidths` is not specified, the layout manager will automatically widen rows to fit the content', function () { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); @@ -245,7 +249,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('you can specify a column width for only the first row, other rows will be automatically widened to fit content', function() { + it('you can specify a column width for only the first row, other rows will be automatically widened to fit content', function () { function makeTable() { let table = new Table({ colWidths: [4], @@ -262,7 +266,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('a column with a null column width will be automatically widened to fit content', function() { + it('a column with a null column width will be automatically widened to fit content', function () { function makeTable() { let table = new Table({ colWidths: [null, 4], @@ -279,7 +283,7 @@ module.exports = function(runTest) { return [makeTable, expected]; }); - it('feel free to use colors in your content strings, column widths will be calculated correctly', function() { + it('feel free to use colors in your content strings, column widths will be calculated correctly', function () { function makeTable() { let table = new Table({ colWidths: [5], diff --git a/lib/print-example.js b/lib/print-example.js index e19316e..f89cf16 100644 --- a/lib/print-example.js +++ b/lib/print-example.js @@ -61,12 +61,12 @@ function mdExample(fn, file, cb) { */ function runTest(name, fn) { function testExample(name, fn, expected) { - it(name, function() { + it(name, function () { expect(fn().toString()).toEqual(expected.join('\n')); }); } - describe(name, function() { + describe(name, function () { fn(testExample, identity); }); } @@ -89,11 +89,7 @@ function runPrintingExample(fn, logName, logTable, logCode, logSeparator, logScr * @param screenshot - If present, there is an image containing a screenshot of the output */ function printExample(name, makeTable, expected, screenshot) { - let code = makeTable - .toString() - .split('\n') - .slice(1, -2) - .join('\n'); + let code = makeTable.toString().split('\n').slice(1, -2).join('\n'); logName(name); if (screenshot && logScreenShot) { diff --git a/package.json b/package.json index 388f360..4390a16 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "jest": "^24.0.0", "jest-runner-eslint": "^0.7.0", "lerna-changelog": "^1.0.1", - "prettier": "1.18.2" + "prettier": "2.0.2" }, "optionalDependencies": { "colors": "^1.1.2" diff --git a/src/cell.js b/src/cell.js index 2db7f74..b8da994 100644 --- a/src/cell.js +++ b/src/cell.js @@ -44,7 +44,7 @@ class Cell { let optionsChars = this.options.chars || {}; let tableChars = tableOptions.chars; let chars = (this.chars = {}); - CHAR_NAMES.forEach(function(name) { + CHAR_NAMES.forEach(function (name) { setOption(optionsChars, tableChars, name, chars); }); @@ -138,7 +138,7 @@ class Cell { let content = []; if (this.cells) { //TODO: cells should always exist - some tests don't fill it in though - this.widths.forEach(function(width, index) { + this.widths.forEach(function (width, index) { content.push(this._topLeftChar(index)); content.push(utils.repeat(this.chars[this.y == 0 ? 'top' : 'mid'], width)); }, this); diff --git a/src/layout-manager.js b/src/layout-manager.js index 908040e..8bcef03 100644 --- a/src/layout-manager.js +++ b/src/layout-manager.js @@ -2,10 +2,10 @@ const objectAssign = require('object-assign'); const Cell = require('./cell'); const { ColSpanCell, RowSpanCell } = Cell; -(function() { +(function () { function layoutTable(table) { - table.forEach(function(row, rowIndex) { - row.forEach(function(cell, columnIndex) { + table.forEach(function (row, rowIndex) { + row.forEach(function (cell, columnIndex) { cell.y = rowIndex; cell.x = columnIndex; for (let y = rowIndex; y >= 0; y--) { @@ -24,8 +24,8 @@ const { ColSpanCell, RowSpanCell } = Cell; function maxWidth(table) { let mw = 0; - table.forEach(function(row) { - row.forEach(function(cell) { + table.forEach(function (row) { + row.forEach(function (cell) { mw = Math.max(mw, cell.x + (cell.colSpan || 1)); }); }); @@ -76,8 +76,8 @@ const { ColSpanCell, RowSpanCell } = Cell; } function addRowSpanCells(table) { - table.forEach(function(row, rowIndex) { - row.forEach(function(cell) { + table.forEach(function (row, rowIndex) { + row.forEach(function (cell) { for (let i = 1; i < cell.rowSpan; i++) { let rowSpanCell = new RowSpanCell(cell); rowSpanCell.x = cell.x; @@ -140,7 +140,7 @@ const { ColSpanCell, RowSpanCell } = Cell; } function generateCells(rows) { - return rows.map(function(row) { + return rows.map(function (row) { if (!Array.isArray(row)) { let key = Object.keys(row)[0]; row = row[key]; @@ -151,7 +151,7 @@ const { ColSpanCell, RowSpanCell } = Cell; row = [key, row]; } } - return row.map(function(cell) { + return row.map(function (cell) { return new Cell(cell); }); }); @@ -178,11 +178,11 @@ const { ColSpanCell, RowSpanCell } = Cell; })(); function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) { - return function(vals, table) { + return function (vals, table) { let result = []; let spanners = []; - table.forEach(function(row) { - row.forEach(function(cell) { + table.forEach(function (row) { + row.forEach(function (cell) { if ((cell[colSpan] || 1) > 1) { spanners.push(cell); } else { @@ -191,7 +191,7 @@ function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) { }); }); - vals.forEach(function(val, index) { + vals.forEach(function (val, index) { if (typeof val === 'number') { result[index] = val; } diff --git a/src/table.js b/src/table.js index af4f146..4fb33ec 100644 --- a/src/table.js +++ b/src/table.js @@ -22,8 +22,8 @@ class Table extends Array { let cells = tableLayout.makeTableLayout(array); - cells.forEach(function(row) { - row.forEach(function(cell) { + cells.forEach(function (row) { + row.forEach(function (cell) { cell.mergeTableOptions(this.options, cells); }, this); }, this); @@ -31,8 +31,8 @@ class Table extends Array { tableLayout.computeWidths(this.options.colWidths, cells); tableLayout.computeHeights(this.options.rowHeights, cells); - cells.forEach(function(row) { - row.forEach(function(cell) { + cells.forEach(function (row) { + row.forEach(function (cell) { cell.init(this.options); }, this); }, this); @@ -67,7 +67,7 @@ class Table extends Array { function doDraw(row, lineNum, result) { let line = []; - row.forEach(function(cell) { + row.forEach(function (cell) { line.push(cell.draw(lineNum)); }); let str = line.join(''); diff --git a/src/utils.js b/src/utils.js index e6f82b2..3ac919c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -9,7 +9,7 @@ function strlen(str) { let code = codeRegex(); let stripped = ('' + str).replace(code, ''); let split = stripped.split('\n'); - return split.reduce(function(memo, s) { + return split.reduce(function (memo, s) { return stringWidth(s) > memo ? stringWidth(s) : memo; }, 0); } @@ -102,7 +102,7 @@ function unwindState(state, ret) { delete state.lastBackgroundAdded; delete state.lastForegroundAdded; - Object.keys(state).forEach(function(key) { + Object.keys(state).forEach(function (key) { if (state[key]) { ret += codeCache[key].off; } @@ -125,7 +125,7 @@ function rewindState(state, ret) { delete state.lastBackgroundAdded; delete state.lastForegroundAdded; - Object.keys(state).forEach(function(key) { + Object.keys(state).forEach(function (key) { if (state[key]) { ret = codeCache[key].on + ret; } diff --git a/test/cell-test.js b/test/cell-test.js index 795b176..5ebb8e9 100644 --- a/test/cell-test.js +++ b/test/cell-test.js @@ -1,4 +1,4 @@ -describe('Cell', function() { +describe('Cell', function () { const colors = require('colors'); const Cell = require('../src/cell'); const { ColSpanCell, RowSpanCell } = Cell; @@ -29,75 +29,75 @@ describe('Cell', function() { }; } - describe('constructor', function() { - it('colSpan and rowSpan default to 1', function() { + describe('constructor', function () { + it('colSpan and rowSpan default to 1', function () { let cell = new Cell(); expect(cell.colSpan).toEqual(1); expect(cell.rowSpan).toEqual(1); }); - it('colSpan and rowSpan can be set via constructor', function() { + it('colSpan and rowSpan can be set via constructor', function () { let cell = new Cell({ rowSpan: 2, colSpan: 3 }); expect(cell.rowSpan).toEqual(2); expect(cell.colSpan).toEqual(3); }); - it('content can be set as a string', function() { + it('content can be set as a string', function () { let cell = new Cell('hello\nworld'); expect(cell.content).toEqual('hello\nworld'); }); - it('content can be set as a options property', function() { + it('content can be set as a options property', function () { let cell = new Cell({ content: 'hello\nworld' }); expect(cell.content).toEqual('hello\nworld'); }); - it('default content is an empty string', function() { + it('default content is an empty string', function () { let cell = new Cell(); expect(cell.content).toEqual(''); }); - it('new Cell(null) will have empty string content', function() { + it('new Cell(null) will have empty string content', function () { let cell = new Cell(null); expect(cell.content).toEqual(''); }); - it('new Cell({content: null}) will have empty string content', function() { + it('new Cell({content: null}) will have empty string content', function () { let cell = new Cell({ content: null }); expect(cell.content).toEqual(''); }); - it('new Cell(0) will have "0" as content', function() { + it('new Cell(0) will have "0" as content', function () { let cell = new Cell(0); expect(cell.content).toEqual('0'); }); - it('new Cell({content: 0}) will have "0" as content', function() { + it('new Cell({content: 0}) will have "0" as content', function () { let cell = new Cell({ content: 0 }); expect(cell.content).toEqual('0'); }); - it('new Cell(false) will have "false" as content', function() { + it('new Cell(false) will have "false" as content', function () { let cell = new Cell(false); expect(cell.content).toEqual('false'); }); - it('new Cell({content: false}) will have "false" as content', function() { + it('new Cell({content: false}) will have "false" as content', function () { let cell = new Cell({ content: false }); expect(cell.content).toEqual('false'); }); }); - describe('mergeTableOptions', function() { - describe('chars', function() { - it('unset chars take on value of table', function() { + describe('mergeTableOptions', function () { + describe('chars', function () { + it('unset chars take on value of table', function () { let cell = new Cell(); let tableOptions = defaultOptions(); cell.mergeTableOptions(tableOptions); expect(cell.chars).toEqual(defaultChars()); }); - it('set chars override the value of table', function() { + it('set chars override the value of table', function () { let cell = new Cell({ chars: { bottomRight: '=' } }); cell.mergeTableOptions(defaultOptions()); let chars = defaultChars(); @@ -105,7 +105,7 @@ describe('Cell', function() { expect(cell.chars).toEqual(chars); }); - it('hyphenated names will be converted to camel-case', function() { + it('hyphenated names will be converted to camel-case', function () { let cell = new Cell({ chars: { 'bottom-left': '=' } }); cell.mergeTableOptions(defaultOptions()); let chars = defaultChars(); @@ -114,22 +114,22 @@ describe('Cell', function() { }); }); - describe('truncate', function() { - it('if unset takes on value of table', function() { + describe('truncate', function () { + it('if unset takes on value of table', function () { let cell = new Cell(); cell.mergeTableOptions(defaultOptions()); expect(cell.truncate).toEqual('…'); }); - it('if set overrides value of table', function() { + it('if set overrides value of table', function () { let cell = new Cell({ truncate: '...' }); cell.mergeTableOptions(defaultOptions()); expect(cell.truncate).toEqual('...'); }); }); - describe('style.padding-left', function() { - it('if unset will be copied from tableOptions.style', function() { + describe('style.padding-left', function () { + it('if unset will be copied from tableOptions.style', function () { let cell = new Cell(); cell.mergeTableOptions(defaultOptions()); expect(cell.paddingLeft).toEqual(1); @@ -147,7 +147,7 @@ describe('Cell', function() { expect(cell.paddingLeft).toEqual(3); }); - it('if set will override tableOptions.style', function() { + it('if set will override tableOptions.style', function () { let cell = new Cell({ style: { 'padding-left': 2 } }); cell.mergeTableOptions(defaultOptions()); expect(cell.paddingLeft).toEqual(2); @@ -158,8 +158,8 @@ describe('Cell', function() { }); }); - describe('style.padding-right', function() { - it('if unset will be copied from tableOptions.style', function() { + describe('style.padding-right', function () { + it('if unset will be copied from tableOptions.style', function () { let cell = new Cell(); cell.mergeTableOptions(defaultOptions()); expect(cell.paddingRight).toEqual(1); @@ -177,7 +177,7 @@ describe('Cell', function() { expect(cell.paddingRight).toEqual(3); }); - it('if set will override tableOptions.style', function() { + it('if set will override tableOptions.style', function () { let cell = new Cell({ style: { 'padding-right': 2 } }); cell.mergeTableOptions(defaultOptions()); expect(cell.paddingRight).toEqual(2); @@ -188,21 +188,21 @@ describe('Cell', function() { }); }); - describe('desiredWidth', function() { - it('content(hello) padding(1,1) == 7', function() { + describe('desiredWidth', function () { + it('content(hello) padding(1,1) == 7', function () { let cell = new Cell('hello'); cell.mergeTableOptions(defaultOptions()); expect(cell.desiredWidth).toEqual(7); }); - it('content(hi) padding(1,2) == 5', function() { + it('content(hi) padding(1,2) == 5', function () { let cell = new Cell({ content: 'hi', style: { paddingRight: 2 } }); let tableOptions = defaultOptions(); cell.mergeTableOptions(tableOptions); expect(cell.desiredWidth).toEqual(5); }); - it('content(hi) padding(3,2) == 7', function() { + it('content(hi) padding(3,2) == 7', function () { let cell = new Cell({ content: 'hi', style: { paddingLeft: 3, paddingRight: 2 } }); let tableOptions = defaultOptions(); cell.mergeTableOptions(tableOptions); @@ -210,20 +210,20 @@ describe('Cell', function() { }); }); - describe('desiredHeight', function() { - it('1 lines of text', function() { + describe('desiredHeight', function () { + it('1 lines of text', function () { let cell = new Cell('hi'); cell.mergeTableOptions(defaultOptions()); expect(cell.desiredHeight).toEqual(1); }); - it('2 lines of text', function() { + it('2 lines of text', function () { let cell = new Cell('hi\nbye'); cell.mergeTableOptions(defaultOptions()); expect(cell.desiredHeight).toEqual(2); }); - it('2 lines of text', function() { + it('2 lines of text', function () { let cell = new Cell('hi\nbye\nyo'); cell.mergeTableOptions(defaultOptions()); expect(cell.desiredHeight).toEqual(3); @@ -231,9 +231,9 @@ describe('Cell', function() { }); }); - describe('init', function() { - describe('hAlign', function() { - it('if unset takes colAlign value from tableOptions', function() { + describe('init', function () { + describe('hAlign', function () { + it('if unset takes colAlign value from tableOptions', function () { let tableOptions = defaultOptions(); tableOptions.colAligns = ['left', 'right', 'both']; let cell = new Cell(); @@ -253,7 +253,7 @@ describe('Cell', function() { expect(cell.hAlign).toEqual('both'); }); - it('if set overrides tableOptions', function() { + it('if set overrides tableOptions', function () { let tableOptions = defaultOptions(); tableOptions.colAligns = ['left', 'right', 'both']; let cell = new Cell({ hAlign: 'right' }); @@ -274,8 +274,8 @@ describe('Cell', function() { }); }); - describe('vAlign', function() { - it('if unset takes rowAlign value from tableOptions', function() { + describe('vAlign', function () { + it('if unset takes rowAlign value from tableOptions', function () { let tableOptions = defaultOptions(); tableOptions.rowAligns = ['top', 'bottom', 'center']; let cell = new Cell(); @@ -295,7 +295,7 @@ describe('Cell', function() { expect(cell.vAlign).toEqual('center'); }); - it('if set overrides tableOptions', function() { + it('if set overrides tableOptions', function () { let tableOptions = defaultOptions(); tableOptions.rowAligns = ['top', 'bottom', 'center']; @@ -319,8 +319,8 @@ describe('Cell', function() { }); }); - describe('width', function() { - it('will match colWidth of x', function() { + describe('width', function () { + it('will match colWidth of x', function () { let tableOptions = defaultOptions(); tableOptions.colWidths = [5, 10, 15]; @@ -343,7 +343,7 @@ describe('Cell', function() { expect(cell.width).toEqual(15); }); - it('will add colWidths if colSpan > 1 with wordWrap false', function() { + it('will add colWidths if colSpan > 1 with wordWrap false', function () { let tableOptions = defaultOptions(); tableOptions.colWidths = [5, 10, 15]; @@ -366,7 +366,7 @@ describe('Cell', function() { expect(cell.width).toEqual(32); }); - it('will add colWidths if colSpan > 1 with wordWrap true', function() { + it('will add colWidths if colSpan > 1 with wordWrap true', function () { let tableOptions = defaultOptions(); tableOptions.colWidths = [5, 10, 15]; tableOptions.wordWrap = true; @@ -390,7 +390,7 @@ describe('Cell', function() { expect(cell.width).toEqual(32); }); - it('will use multiple columns for wordWrap text when using colSpan and wordWrap together', function() { + it('will use multiple columns for wordWrap text when using colSpan and wordWrap together', function () { let tableOptions = defaultOptions(); tableOptions.colWidths = [7, 7, 17]; tableOptions.wordWrap = true; @@ -418,7 +418,7 @@ describe('Cell', function() { expect(cell.lines[0]).toContain('fox'); }); - it('will only use one column for wordWrap text when not using colSpan', function() { + it('will only use one column for wordWrap text when not using colSpan', function () { let tableOptions = defaultOptions(); tableOptions.colWidths = [7, 7, 7]; tableOptions.wordWrap = true; @@ -433,8 +433,8 @@ describe('Cell', function() { }); }); - describe('height', function() { - it('will match rowHeight of x', function() { + describe('height', function () { + it('will match rowHeight of x', function () { let tableOptions = defaultOptions(); tableOptions.rowHeights = [5, 10, 15]; @@ -457,7 +457,7 @@ describe('Cell', function() { expect(cell.height).toEqual(15); }); - it('will add rowHeights if rowSpan > 1', function() { + it('will add rowHeights if rowSpan > 1', function () { let tableOptions = defaultOptions(); tableOptions.rowHeights = [5, 10, 15]; @@ -481,15 +481,15 @@ describe('Cell', function() { }); }); - describe('drawRight', function() { + describe('drawRight', function () { let tableOptions; - beforeEach(function() { + beforeEach(function () { tableOptions = defaultOptions(); tableOptions.colWidths = [20, 20, 20]; }); - it('col 1 of 3, with default colspan', function() { + it('col 1 of 3, with default colspan', function () { let cell = new Cell(); cell.x = 0; cell.mergeTableOptions(tableOptions); @@ -497,7 +497,7 @@ describe('Cell', function() { expect(cell.drawRight).toEqual(false); }); - it('col 2 of 3, with default colspan', function() { + it('col 2 of 3, with default colspan', function () { let cell = new Cell(); cell.x = 1; cell.mergeTableOptions(tableOptions); @@ -505,7 +505,7 @@ describe('Cell', function() { expect(cell.drawRight).toEqual(false); }); - it('col 3 of 3, with default colspan', function() { + it('col 3 of 3, with default colspan', function () { let cell = new Cell(); cell.x = 2; cell.mergeTableOptions(tableOptions); @@ -513,7 +513,7 @@ describe('Cell', function() { expect(cell.drawRight).toEqual(true); }); - it('col 3 of 4, with default colspan', function() { + it('col 3 of 4, with default colspan', function () { let cell = new Cell(); cell.x = 2; tableOptions.colWidths = [20, 20, 20, 20]; @@ -522,7 +522,7 @@ describe('Cell', function() { expect(cell.drawRight).toEqual(false); }); - it('col 2 of 3, with colspan of 2', function() { + it('col 2 of 3, with colspan of 2', function () { let cell = new Cell({ colSpan: 2 }); cell.x = 1; cell.mergeTableOptions(tableOptions); @@ -530,7 +530,7 @@ describe('Cell', function() { expect(cell.drawRight).toEqual(true); }); - it('col 1 of 3, with colspan of 3', function() { + it('col 1 of 3, with colspan of 3', function () { let cell = new Cell({ colSpan: 3 }); cell.x = 0; cell.mergeTableOptions(tableOptions); @@ -538,7 +538,7 @@ describe('Cell', function() { expect(cell.drawRight).toEqual(true); }); - it('col 1 of 3, with colspan of 2', function() { + it('col 1 of 3, with colspan of 2', function () { let cell = new Cell({ colSpan: 2 }); cell.x = 0; cell.mergeTableOptions(tableOptions); @@ -548,10 +548,10 @@ describe('Cell', function() { }); }); - describe('drawLine', function() { + describe('drawLine', function () { let cell; - beforeEach(function() { + beforeEach(function () { cell = new Cell(); //manually init @@ -569,15 +569,15 @@ describe('Cell', function() { cell.x = cell.y = 0; }); - describe('top line', function() { - it('will draw the top left corner when x=0,y=0', function() { + describe('top line', function () { + it('will draw the top left corner when x=0,y=0', function () { cell.x = cell.y = 0; expect(cell.draw('top')).toEqual('┌───────'); cell.drawRight = true; expect(cell.draw('top')).toEqual('┌───────┐'); }); - it('will draw the top mid corner when x=1,y=0', function() { + it('will draw the top mid corner when x=1,y=0', function () { cell.x = 1; cell.y = 0; expect(cell.draw('top')).toEqual('┬───────'); @@ -585,7 +585,7 @@ describe('Cell', function() { expect(cell.draw('top')).toEqual('┬───────┐'); }); - it('will draw the left mid corner when x=0,y=1', function() { + it('will draw the left mid corner when x=0,y=1', function () { cell.x = 0; cell.y = 1; expect(cell.draw('top')).toEqual('├───────'); @@ -593,7 +593,7 @@ describe('Cell', function() { expect(cell.draw('top')).toEqual('├───────┤'); }); - it('will draw the mid mid corner when x=1,y=1', function() { + it('will draw the mid mid corner when x=1,y=1', function () { cell.x = 1; cell.y = 1; expect(cell.draw('top')).toEqual('┼───────'); @@ -601,14 +601,14 @@ describe('Cell', function() { expect(cell.draw('top')).toEqual('┼───────┤'); }); - it('will draw in the color specified by border style', function() { + it('will draw in the color specified by border style', function () { cell.border = ['gray']; expect(cell.draw('top')).toEqual(colors.gray('┌───────')); }); }); - describe('bottom line', function() { - it('will draw the bottom left corner if x=0', function() { + describe('bottom line', function () { + it('will draw the bottom left corner if x=0', function () { cell.x = 0; cell.y = 1; expect(cell.draw('bottom')).toEqual('└───────'); @@ -616,7 +616,7 @@ describe('Cell', function() { expect(cell.draw('bottom')).toEqual('└───────┘'); }); - it('will draw the bottom left corner if x=1', function() { + it('will draw the bottom left corner if x=1', function () { cell.x = 1; cell.y = 1; expect(cell.draw('bottom')).toEqual('┴───────'); @@ -624,19 +624,19 @@ describe('Cell', function() { expect(cell.draw('bottom')).toEqual('┴───────┘'); }); - it('will draw in the color specified by border style', function() { + it('will draw in the color specified by border style', function () { cell.border = ['gray']; expect(cell.draw('bottom')).toEqual(colors.gray('└───────')); }); }); - describe('drawBottom', function() { - it('draws an empty line', function() { + describe('drawBottom', function () { + it('draws an empty line', function () { expect(cell.drawEmpty()).toEqual('L '); expect(cell.drawEmpty(true)).toEqual('L R'); }); - it('draws an empty line', function() { + it('draws an empty line', function () { cell.border = ['gray']; cell.head = ['red']; expect(cell.drawEmpty()).toEqual(colors.gray('L') + colors.red(' ')); @@ -644,26 +644,26 @@ describe('Cell', function() { }); }); - describe('first line of text', function() { - beforeEach(function() { + describe('first line of text', function () { + beforeEach(function () { cell.width = 9; }); - it('will draw left side if x=0', function() { + it('will draw left side if x=0', function () { cell.x = 0; expect(cell.draw(0)).toEqual('L hello '); cell.drawRight = true; expect(cell.draw(0)).toEqual('L hello R'); }); - it('will draw mid side if x=1', function() { + it('will draw mid side if x=1', function () { cell.x = 1; expect(cell.draw(0)).toEqual('M hello '); cell.drawRight = true; expect(cell.draw(0)).toEqual('M hello R'); }); - it('will align left', function() { + it('will align left', function () { cell.x = 1; cell.hAlign = 'left'; expect(cell.draw(0)).toEqual('M hello '); @@ -671,7 +671,7 @@ describe('Cell', function() { expect(cell.draw(0)).toEqual('M hello R'); }); - it('will align right', function() { + it('will align right', function () { cell.x = 1; cell.hAlign = 'right'; expect(cell.draw(0)).toEqual('M hello '); @@ -679,7 +679,7 @@ describe('Cell', function() { expect(cell.draw(0)).toEqual('M hello R'); }); - it('left and right will be drawn in color of border style', function() { + it('left and right will be drawn in color of border style', function () { cell.border = ['gray']; cell.x = 0; expect(cell.draw(0)).toEqual(colors.gray('L') + ' hello '); @@ -687,7 +687,7 @@ describe('Cell', function() { expect(cell.draw(0)).toEqual(colors.gray('L') + ' hello ' + colors.gray('R')); }); - it('text will be drawn in color of head style if y == 0', function() { + it('text will be drawn in color of head style if y == 0', function () { cell.head = ['red']; cell.x = cell.y = 0; expect(cell.draw(0)).toEqual('L' + colors.red(' hello ')); @@ -695,7 +695,7 @@ describe('Cell', function() { expect(cell.draw(0)).toEqual('L' + colors.red(' hello ') + 'R'); }); - it('text will NOT be drawn in color of head style if y == 1', function() { + it('text will NOT be drawn in color of head style if y == 1', function () { cell.head = ['red']; cell.x = cell.y = 1; expect(cell.draw(0)).toEqual('M hello '); @@ -703,7 +703,7 @@ describe('Cell', function() { expect(cell.draw(0)).toEqual('M hello R'); }); - it('head and border colors together', function() { + it('head and border colors together', function () { cell.border = ['gray']; cell.head = ['red']; cell.x = cell.y = 0; @@ -713,26 +713,26 @@ describe('Cell', function() { }); }); - describe('second line of text', function() { - beforeEach(function() { + describe('second line of text', function () { + beforeEach(function () { cell.width = 9; }); - it('will draw left side if x=0', function() { + it('will draw left side if x=0', function () { cell.x = 0; expect(cell.draw(1)).toEqual('L howdy '); cell.drawRight = true; expect(cell.draw(1)).toEqual('L howdy R'); }); - it('will draw mid side if x=1', function() { + it('will draw mid side if x=1', function () { cell.x = 1; expect(cell.draw(1)).toEqual('M howdy '); cell.drawRight = true; expect(cell.draw(1)).toEqual('M howdy R'); }); - it('will align left', function() { + it('will align left', function () { cell.x = 1; cell.hAlign = 'left'; expect(cell.draw(1)).toEqual('M howdy '); @@ -740,7 +740,7 @@ describe('Cell', function() { expect(cell.draw(1)).toEqual('M howdy R'); }); - it('will align right', function() { + it('will align right', function () { cell.x = 1; cell.hAlign = 'right'; expect(cell.draw(1)).toEqual('M howdy '); @@ -749,26 +749,26 @@ describe('Cell', function() { }); }); - describe('truncated line of text', function() { - beforeEach(function() { + describe('truncated line of text', function () { + beforeEach(function () { cell.width = 9; }); - it('will draw left side if x=0', function() { + it('will draw left side if x=0', function () { cell.x = 0; expect(cell.draw(2)).toEqual('L goodni… '); cell.drawRight = true; expect(cell.draw(2)).toEqual('L goodni… R'); }); - it('will draw mid side if x=1', function() { + it('will draw mid side if x=1', function () { cell.x = 1; expect(cell.draw(2)).toEqual('M goodni… '); cell.drawRight = true; expect(cell.draw(2)).toEqual('M goodni… R'); }); - it('will not change when aligned left', function() { + it('will not change when aligned left', function () { cell.x = 1; cell.hAlign = 'left'; expect(cell.draw(2)).toEqual('M goodni… '); @@ -776,7 +776,7 @@ describe('Cell', function() { expect(cell.draw(2)).toEqual('M goodni… R'); }); - it('will not change when aligned right', function() { + it('will not change when aligned right', function () { cell.x = 1; cell.hAlign = 'right'; expect(cell.draw(2)).toEqual('M goodni… '); @@ -785,12 +785,12 @@ describe('Cell', function() { }); }); - describe('vAlign', function() { - beforeEach(function() { + describe('vAlign', function () { + beforeEach(function () { cell.height = '5'; }); - it('center', function() { + it('center', function () { cell.vAlign = 'center'; expect(cell.draw(0)).toEqual('L '); expect(cell.draw(1)).toEqual('L hello '); @@ -814,7 +814,7 @@ describe('Cell', function() { expect(cell.draw(4)).toEqual('M '); }); - it('top', function() { + it('top', function () { cell.vAlign = 'top'; expect(cell.draw(0)).toEqual('L hello '); expect(cell.draw(1)).toEqual('L howdy '); @@ -839,7 +839,7 @@ describe('Cell', function() { expect(cell.draw(4)).toEqual('M '); }); - it('center', function() { + it('center', function () { cell.vAlign = 'bottom'; expect(cell.draw(0)).toEqual('L '); expect(cell.draw(1)).toEqual('L '); @@ -864,13 +864,13 @@ describe('Cell', function() { }); }); - it('vertically truncated will show truncation on last visible line', function() { + it('vertically truncated will show truncation on last visible line', function () { cell.height = 2; expect(cell.draw(0)).toEqual('L hello '); expect(cell.draw(1)).toEqual('L howd… '); }); - it("won't vertically truncate if the lines just fit", function() { + it("won't vertically truncate if the lines just fit", function () { cell.height = 2; cell.content = 'hello\nhowdy'; cell.lines = cell.content.split('\n'); @@ -878,7 +878,7 @@ describe('Cell', function() { expect(cell.draw(1)).toEqual('L howdy '); }); - it('will vertically truncate even if last line is short', function() { + it('will vertically truncate even if last line is short', function () { cell.height = 2; cell.content = 'hello\nhi\nhowdy'; cell.lines = cell.content.split('\n'); @@ -886,7 +886,7 @@ describe('Cell', function() { expect(cell.draw(1)).toEqual('L hi… '); }); - it('allows custom truncation', function() { + it('allows custom truncation', function () { cell.height = 2; cell.truncate = '...'; cell.content = 'hello\nhi\nhowdy'; @@ -901,23 +901,23 @@ describe('Cell', function() { }); }); - describe('ColSpanCell', function() { - it('has an init function', function() { + describe('ColSpanCell', function () { + it('has an init function', function () { expect(new ColSpanCell()).toHaveProperty('init'); new ColSpanCell().init(); // nothing happens. }); - it('draw returns an empty string', function() { + it('draw returns an empty string', function () { expect(new ColSpanCell().draw('top')).toEqual(''); expect(new ColSpanCell().draw('bottom')).toEqual(''); expect(new ColSpanCell().draw(1)).toEqual(''); }); }); - describe('RowSpanCell', function() { + describe('RowSpanCell', function () { let original, tableOptions; - beforeEach(function() { + beforeEach(function () { original = { rowSpan: 3, y: 0, @@ -928,7 +928,7 @@ describe('Cell', function() { }; }); - it('drawing top of the next row', function() { + it('drawing top of the next row', function () { let spanner = new RowSpanCell(original); spanner.x = 0; spanner.y = 1; @@ -938,7 +938,7 @@ describe('Cell', function() { expect(original.draw).toHaveBeenCalledWith(2, 1); }); - it('drawing line 0 of the next row', function() { + it('drawing line 0 of the next row', function () { let spanner = new RowSpanCell(original); spanner.x = 0; spanner.y = 1; @@ -948,7 +948,7 @@ describe('Cell', function() { expect(original.draw).toHaveBeenCalledWith(3); }); - it('drawing line 1 of the next row', function() { + it('drawing line 1 of the next row', function () { let spanner = new RowSpanCell(original); spanner.x = 0; spanner.y = 1; @@ -958,7 +958,7 @@ describe('Cell', function() { expect(original.draw).toHaveBeenCalledWith(4); }); - it('drawing top of two rows below', function() { + it('drawing top of two rows below', function () { let spanner = new RowSpanCell(original); spanner.x = 0; spanner.y = 2; @@ -968,7 +968,7 @@ describe('Cell', function() { expect(original.draw).toHaveBeenCalledWith(6, 2); }); - it('drawing line 0 of two rows below', function() { + it('drawing line 0 of two rows below', function () { let spanner = new RowSpanCell(original); spanner.x = 0; spanner.y = 2; @@ -978,7 +978,7 @@ describe('Cell', function() { expect(original.draw).toHaveBeenCalledWith(7); }); - it('drawing line 1 of two rows below', function() { + it('drawing line 1 of two rows below', function () { let spanner = new RowSpanCell(original); spanner.x = 0; spanner.y = 2; @@ -988,7 +988,7 @@ describe('Cell', function() { expect(original.draw).toHaveBeenCalledWith(8); }); - it('drawing bottom', function() { + it('drawing bottom', function () { let spanner = new RowSpanCell(original); spanner.x = 0; spanner.y = 1; diff --git a/test/layout-manager-test.js b/test/layout-manager-test.js index 62347cb..86f6830 100644 --- a/test/layout-manager-test.js +++ b/test/layout-manager-test.js @@ -1,55 +1,88 @@ -describe('layout-manager', function() { +describe('layout-manager', function () { const layoutManager = require('../src/layout-manager'); const { layoutTable, addRowSpanCells, maxWidth } = layoutManager; const Cell = require('../src/cell'); const { RowSpanCell } = Cell; - describe('layoutTable', function() { - it('sets x and y', function() { - let table = [[{}, {}], [{}, {}]]; + describe('layoutTable', function () { + it('sets x and y', function () { + let table = [ + [{}, {}], + [{}, {}], + ]; layoutTable(table); - expect(table).toEqual([[{ x: 0, y: 0 }, { x: 1, y: 0 }], [{ x: 0, y: 1 }, { x: 1, y: 1 }]]); + expect(table).toEqual([ + [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + ], + [ + { x: 0, y: 1 }, + { x: 1, y: 1 }, + ], + ]); let w = maxWidth(table); expect(w).toEqual(2); }); - it('colSpan will push x values to the right', function() { - let table = [[{ colSpan: 2 }, {}], [{}, { colSpan: 2 }]]; + it('colSpan will push x values to the right', function () { + let table = [ + [{ colSpan: 2 }, {}], + [{}, { colSpan: 2 }], + ]; layoutTable(table); expect(table).toEqual([ - [{ x: 0, y: 0, colSpan: 2 }, { x: 2, y: 0 }], - [{ x: 0, y: 1 }, { x: 1, y: 1, colSpan: 2 }], + [ + { x: 0, y: 0, colSpan: 2 }, + { x: 2, y: 0 }, + ], + [ + { x: 0, y: 1 }, + { x: 1, y: 1, colSpan: 2 }, + ], ]); expect(maxWidth(table)).toEqual(3); }); - it('rowSpan will push x values on cells below', function() { + it('rowSpan will push x values on cells below', function () { let table = [[{ rowSpan: 2 }, {}], [{}]]; layoutTable(table); - expect(table).toEqual([[{ x: 0, y: 0, rowSpan: 2 }, { x: 1, y: 0 }], [{ x: 1, y: 1 }]]); + expect(table).toEqual([ + [ + { x: 0, y: 0, rowSpan: 2 }, + { x: 1, y: 0 }, + ], + [{ x: 1, y: 1 }], + ]); expect(maxWidth(table)).toEqual(2); }); - it('colSpan and rowSpan together', function() { + it('colSpan and rowSpan together', function () { let table = [[{ rowSpan: 2, colSpan: 2 }, {}], [{}]]; layoutTable(table); - expect(table).toEqual([[{ x: 0, y: 0, rowSpan: 2, colSpan: 2 }, { x: 2, y: 0 }], [{ x: 2, y: 1 }]]); + expect(table).toEqual([ + [ + { x: 0, y: 0, rowSpan: 2, colSpan: 2 }, + { x: 2, y: 0 }, + ], + [{ x: 2, y: 1 }], + ]); expect(maxWidth(table)).toEqual(3); }); - it('complex layout', function() { + it('complex layout', function () { let table = [ [{ c: 'a' }, { c: 'b' }, { c: 'c', rowSpan: 3, colSpan: 2 }, { c: 'd' }], [{ c: 'e', rowSpan: 2, colSpan: 2 }, { c: 'f' }], @@ -65,57 +98,100 @@ describe('layout-manager', function() { { c: 'c', y: 0, x: 2, rowSpan: 3, colSpan: 2 }, { c: 'd', y: 0, x: 4 }, ], - [{ c: 'e', rowSpan: 2, colSpan: 2, y: 1, x: 0 }, { c: 'f', y: 1, x: 4 }], + [ + { c: 'e', rowSpan: 2, colSpan: 2, y: 1, x: 0 }, + { c: 'f', y: 1, x: 4 }, + ], [{ c: 'g', y: 2, x: 4 }], ]); }); - it('maxWidth of single element', function() { + it('maxWidth of single element', function () { let table = [[{}]]; layoutTable(table); expect(maxWidth(table)).toEqual(1); }); }); - describe('addRowSpanCells', function() { - it('will insert a rowSpan cell - beginning of line', function() { - let table = [[{ x: 0, y: 0, rowSpan: 2 }, { x: 1, y: 0 }], [{ x: 1, y: 1 }]]; + describe('addRowSpanCells', function () { + it('will insert a rowSpan cell - beginning of line', function () { + let table = [ + [ + { x: 0, y: 0, rowSpan: 2 }, + { x: 1, y: 0 }, + ], + [{ x: 1, y: 1 }], + ]; addRowSpanCells(table); - expect(table[0]).toEqual([{ x: 0, y: 0, rowSpan: 2 }, { x: 1, y: 0 }]); + expect(table[0]).toEqual([ + { x: 0, y: 0, rowSpan: 2 }, + { x: 1, y: 0 }, + ]); expect(table[1].length).toEqual(2); expect(table[1][0]).toBeInstanceOf(RowSpanCell); expect(table[1][1]).toEqual({ x: 1, y: 1 }); }); - it('will insert a rowSpan cell - end of line', function() { - let table = [[{ x: 0, y: 0 }, { x: 1, y: 0, rowSpan: 2 }], [{ x: 0, y: 1 }]]; + it('will insert a rowSpan cell - end of line', function () { + let table = [ + [ + { x: 0, y: 0 }, + { x: 1, y: 0, rowSpan: 2 }, + ], + [{ x: 0, y: 1 }], + ]; addRowSpanCells(table); - expect(table[0]).toEqual([{ x: 0, y: 0 }, { rowSpan: 2, x: 1, y: 0 }]); + expect(table[0]).toEqual([ + { x: 0, y: 0 }, + { rowSpan: 2, x: 1, y: 0 }, + ]); expect(table[1].length).toEqual(2); expect(table[1][0]).toEqual({ x: 0, y: 1 }); expect(table[1][1]).toBeInstanceOf(RowSpanCell); }); - it('will insert a rowSpan cell - middle of line', function() { - let table = [[{ x: 0, y: 0 }, { x: 1, y: 0, rowSpan: 2 }, { x: 2, y: 0 }], [{ x: 0, y: 1 }, { x: 2, y: 1 }]]; + it('will insert a rowSpan cell - middle of line', function () { + let table = [ + [ + { x: 0, y: 0 }, + { x: 1, y: 0, rowSpan: 2 }, + { x: 2, y: 0 }, + ], + [ + { x: 0, y: 1 }, + { x: 2, y: 1 }, + ], + ]; addRowSpanCells(table); - expect(table[0]).toEqual([{ x: 0, y: 0 }, { rowSpan: 2, x: 1, y: 0 }, { x: 2, y: 0 }]); + expect(table[0]).toEqual([ + { x: 0, y: 0 }, + { rowSpan: 2, x: 1, y: 0 }, + { x: 2, y: 0 }, + ]); expect(table[1].length).toEqual(3); expect(table[1][0]).toEqual({ x: 0, y: 1 }); expect(table[1][1]).toBeInstanceOf(RowSpanCell); expect(table[1][2]).toEqual({ x: 2, y: 1 }); }); - it('will insert a rowSpan cell - multiple on the same line', function() { + it('will insert a rowSpan cell - multiple on the same line', function () { let table = [ - [{ x: 0, y: 0 }, { x: 1, y: 0, rowSpan: 2 }, { x: 2, y: 0, rowSpan: 2 }, { x: 3, y: 0 }], - [{ x: 0, y: 1 }, { x: 3, y: 1 }], + [ + { x: 0, y: 0 }, + { x: 1, y: 0, rowSpan: 2 }, + { x: 2, y: 0, rowSpan: 2 }, + { x: 3, y: 0 }, + ], + [ + { x: 0, y: 1 }, + { x: 3, y: 1 }, + ], ]; addRowSpanCells(table); diff --git a/test/original-cli-table-index-tests.js b/test/original-cli-table-index-tests.js index 8774586..aa765cf 100644 --- a/test/original-cli-table-index-tests.js +++ b/test/original-cli-table-index-tests.js @@ -1,7 +1,7 @@ -describe('@api original-cli-table index tests', function() { +describe('@api original-cli-table index tests', function () { const Table = require('../src/table'); - it('test complete table', function() { + it('test complete table', function () { let table = new Table({ head: ['Rel', 'Change', 'By', 'When'], style: { @@ -32,7 +32,7 @@ describe('@api original-cli-table index tests', function() { //expect(table.render()).should.eql(expected.join("\n")); }); - it('test width property', function() { + it('test width property', function () { let table = new Table({ head: ['Cool'], style: { @@ -44,7 +44,7 @@ describe('@api original-cli-table index tests', function() { expect(table.width).toEqual(8); }); - it('test vertical table output', function() { + it('test vertical table output', function () { let table = new Table({ style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] } }); // clear styles to prevent color output table.push({ 'v0.1': 'Testing something cool' }, { 'v0.1': 'Testing something cool' }); @@ -60,7 +60,7 @@ describe('@api original-cli-table index tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test cross table output', function() { + it('test cross table output', function () { let table = new Table({ head: ['', 'Header 1', 'Header 2'], style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, @@ -81,7 +81,7 @@ describe('@api original-cli-table index tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test table colors', function() { + it('test table colors', function () { let table = new Table({ head: ['Rel', 'By'], style: { head: ['red'], border: ['grey'] }, @@ -122,7 +122,7 @@ describe('@api original-cli-table index tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test custom chars', function() { + it('test custom chars', function () { let table = new Table({ chars: { top: '═', @@ -157,7 +157,7 @@ describe('@api original-cli-table index tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test compact shortand', function() { + it('test compact shortand', function () { let table = new Table({ style: { head: [], @@ -173,7 +173,7 @@ describe('@api original-cli-table index tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test compact empty mid line', function() { + it('test compact empty mid line', function () { let table = new Table({ chars: { mid: '', @@ -194,7 +194,7 @@ describe('@api original-cli-table index tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test decoration lines disabled', function() { + it('test decoration lines disabled', function () { let table = new Table({ chars: { top: '', @@ -228,7 +228,7 @@ describe('@api original-cli-table index tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test with null/undefined as values or column names', function() { + it('test with null/undefined as values or column names', function () { let table = new Table({ style: { head: [], diff --git a/test/original-cli-table-newlines-test.js b/test/original-cli-table-newlines-test.js index 64e8a66..b2d3c8b 100644 --- a/test/original-cli-table-newlines-test.js +++ b/test/original-cli-table-newlines-test.js @@ -1,7 +1,7 @@ -describe('@api original-cli-table newline tests', function() { +describe('@api original-cli-table newline tests', function () { const Table = require('../src/table'); - it('test table with newlines in headers', function() { + it('test table with newlines in headers', function () { let table = new Table({ head: ['Test', '1\n2\n3'], style: { @@ -17,12 +17,12 @@ describe('@api original-cli-table newline tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test column width is accurately reflected when newlines are present', function() { + it('test column width is accurately reflected when newlines are present', function () { let table = new Table({ head: ['Test\nWidth'], style: { head: [], border: [] } }); expect(table.width).toEqual(9); }); - it('test newlines in body cells', function() { + it('test newlines in body cells', function () { let table = new Table({ style: { head: [], border: [] } }); table.push(['something\nwith\nnewlines']); @@ -32,7 +32,7 @@ describe('@api original-cli-table newline tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test newlines in vertical cell header and body', function() { + it('test newlines in vertical cell header and body', function () { let table = new Table({ style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] } }); table.push({ 'v\n0.1': 'Testing\nsomething cool' }); @@ -42,7 +42,7 @@ describe('@api original-cli-table newline tests', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('test newlines in cross table header and body', function() { + it('test newlines in cross table header and body', function () { let table = new Table({ head: ['', 'Header\n1'], style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, diff --git a/test/table-layout-test.js b/test/table-layout-test.js index 61ecbf2..2338457 100644 --- a/test/table-layout-test.js +++ b/test/table-layout-test.js @@ -1,57 +1,78 @@ -describe('tableLayout', function() { +describe('tableLayout', function () { const Cell = require('../src/cell'); const layoutManager = require('../src/layout-manager'); const { makeTableLayout, addRowSpanCells, fillInTable, computeWidths, computeHeights } = layoutManager; - it('simple 2x2 layout', function() { - let actual = makeTableLayout([['hello', 'goodbye'], ['hola', 'adios']]); + it('simple 2x2 layout', function () { + let actual = makeTableLayout([ + ['hello', 'goodbye'], + ['hola', 'adios'], + ]); - let expected = [['hello', 'goodbye'], ['hola', 'adios']]; + let expected = [ + ['hello', 'goodbye'], + ['hola', 'adios'], + ]; checkLayout(actual, expected); }); - it('cross table', function() { + it('cross table', function () { let actual = makeTableLayout([{ '1.0': ['yes', 'no'] }, { '2.0': ['hello', 'goodbye'] }]); - let expected = [['1.0', 'yes', 'no'], ['2.0', 'hello', 'goodbye']]; + let expected = [ + ['1.0', 'yes', 'no'], + ['2.0', 'hello', 'goodbye'], + ]; checkLayout(actual, expected); }); - it('vertical table', function() { + it('vertical table', function () { let actual = makeTableLayout([{ '1.0': 'yes' }, { '2.0': 'hello' }]); - let expected = [['1.0', 'yes'], ['2.0', 'hello']]; + let expected = [ + ['1.0', 'yes'], + ['2.0', 'hello'], + ]; checkLayout(actual, expected); }); - it('colSpan adds RowSpanCells to the right', function() { + it('colSpan adds RowSpanCells to the right', function () { let actual = makeTableLayout([[{ content: 'hello', colSpan: 2 }], ['hola', 'adios']]); - let expected = [[{ content: 'hello', colSpan: 2 }, null], ['hola', 'adios']]; + let expected = [ + [{ content: 'hello', colSpan: 2 }, null], + ['hola', 'adios'], + ]; checkLayout(actual, expected); }); - it('rowSpan adds RowSpanCell below', function() { + it('rowSpan adds RowSpanCell below', function () { let actual = makeTableLayout([[{ content: 'hello', rowSpan: 2 }, 'goodbye'], ['adios']]); - let expected = [['hello', 'goodbye'], [{ spannerFor: [0, 0] }, 'adios']]; + let expected = [ + ['hello', 'goodbye'], + [{ spannerFor: [0, 0] }, 'adios'], + ]; checkLayout(actual, expected); }); - it('rowSpan and cellSpan together', function() { + it('rowSpan and cellSpan together', function () { let actual = makeTableLayout([[{ content: 'hello', rowSpan: 2, colSpan: 2 }, 'goodbye'], ['adios']]); - let expected = [['hello', null, 'goodbye'], [{ spannerFor: [0, 0] }, null, 'adios']]; + let expected = [ + ['hello', null, 'goodbye'], + [{ spannerFor: [0, 0] }, null, 'adios'], + ]; checkLayout(actual, expected); }); - it('complex layout', function() { + it('complex layout', function () { let actual = makeTableLayout([ [{ content: 'hello', rowSpan: 2, colSpan: 2 }, { content: 'yo', rowSpan: 2, colSpan: 2 }, 'goodbye'], ['adios'], @@ -65,7 +86,7 @@ describe('tableLayout', function() { checkLayout(actual, expected); }); - it('complex layout2', function() { + it('complex layout2', function () { let actual = makeTableLayout([ ['a', 'b', { content: 'c', rowSpan: 3, colSpan: 2 }, 'd'], [{ content: 'e', rowSpan: 2, colSpan: 2 }, 'f'], @@ -81,7 +102,7 @@ describe('tableLayout', function() { checkLayout(actual, expected); }); - it('stairstep spans', function() { + it('stairstep spans', function () { let actual = makeTableLayout([[{ content: '', rowSpan: 2 }, ''], [{ content: '', rowSpan: 2 }], ['']]); let expected = [ @@ -93,7 +114,7 @@ describe('tableLayout', function() { checkLayout(actual, expected); }); - describe('fillInTable', function() { + describe('fillInTable', function () { function mc(opts, y, x) { let cell = new Cell(opts); cell.x = x; @@ -101,29 +122,38 @@ describe('tableLayout', function() { return cell; } - it('will blank out individual cells', function() { + it('will blank out individual cells', function () { let cells = [[mc('a', 0, 1)], [mc('b', 1, 0)]]; fillInTable(cells); - checkLayout(cells, [['', 'a'], ['b', '']]); + checkLayout(cells, [ + ['', 'a'], + ['b', ''], + ]); }); - it('will autospan to the right', function() { + it('will autospan to the right', function () { let cells = [[], [mc('a', 1, 1)]]; fillInTable(cells); - checkLayout(cells, [[{ content: '', colSpan: 2 }, null], ['', 'a']]); + checkLayout(cells, [ + [{ content: '', colSpan: 2 }, null], + ['', 'a'], + ]); }); - it('will autospan down', function() { + it('will autospan down', function () { let cells = [[mc('a', 0, 1)], []]; fillInTable(cells); addRowSpanCells(cells); - checkLayout(cells, [[{ content: '', rowSpan: 2 }, 'a'], [{ spannerFor: [0, 0] }, '']]); + checkLayout(cells, [ + [{ content: '', rowSpan: 2 }, 'a'], + [{ spannerFor: [0, 0] }, ''], + ]); }); - it('will autospan right and down', function() { + it('will autospan right and down', function () { let cells = [[mc('a', 0, 2)], [], [mc('b', 2, 1)]]; fillInTable(cells); addRowSpanCells(cells); @@ -136,12 +166,12 @@ describe('tableLayout', function() { }); }); - describe('computeWidths', function() { + describe('computeWidths', function () { function mc(y, x, desiredWidth, colSpan) { return { x: x, y: y, desiredWidth: desiredWidth, colSpan: colSpan }; } - it('finds the maximum desired width of each column', function() { + it('finds the maximum desired width of each column', function () { let widths = []; let cells = [ [mc(0, 0, 7), mc(0, 1, 3), mc(0, 2, 5)], @@ -154,7 +184,7 @@ describe('tableLayout', function() { expect(widths).toEqual([8, 9, 5]); }); - it("won't touch hard coded values", function() { + it("won't touch hard coded values", function () { let widths = [null, 3]; let cells = [ [mc(0, 0, 7), mc(0, 1, 3), mc(0, 2, 5)], @@ -167,14 +197,14 @@ describe('tableLayout', function() { expect(widths).toEqual([8, 3, 5]); }); - it('assumes undefined desiredWidth is 1', function() { + it('assumes undefined desiredWidth is 1', function () { let widths = []; let cells = [[{ x: 0, y: 0 }], [{ x: 0, y: 1 }], [{ x: 0, y: 2 }]]; computeWidths(widths, cells); expect(widths).toEqual([1]); }); - it('takes into account colSpan and wont over expand', function() { + it('takes into account colSpan and wont over expand', function () { let widths = []; let cells = [ [mc(0, 0, 10, 2), mc(0, 2, 5)], @@ -185,7 +215,7 @@ describe('tableLayout', function() { expect(widths).toEqual([5, 5, 5]); }); - it('will expand rows involved in colSpan in a balanced way', function() { + it('will expand rows involved in colSpan in a balanced way', function () { let widths = []; let cells = [ [mc(0, 0, 13, 2), mc(0, 2, 5)], @@ -196,28 +226,28 @@ describe('tableLayout', function() { expect(widths).toEqual([6, 6, 5]); }); - it('expands across 3 cols', function() { + it('expands across 3 cols', function () { let widths = []; let cells = [[mc(0, 0, 25, 3)], [mc(1, 0, 5), mc(1, 1, 5), mc(1, 2, 2)], [mc(2, 0, 4), mc(2, 1, 2), mc(2, 2, 1)]]; computeWidths(widths, cells); expect(widths).toEqual([9, 9, 5]); }); - it('multiple spans in same table', function() { + it('multiple spans in same table', function () { let widths = []; let cells = [[mc(0, 0, 25, 3)], [mc(1, 0, 30, 3)], [mc(2, 0, 4), mc(2, 1, 2), mc(2, 2, 1)]]; computeWidths(widths, cells); expect(widths).toEqual([11, 9, 8]); }); - it('spans will only edit uneditable tables', function() { + it('spans will only edit uneditable tables', function () { let widths = [null, 3]; let cells = [[mc(0, 0, 20, 3)], [mc(1, 0, 4), mc(1, 1, 20), mc(1, 2, 5)]]; computeWidths(widths, cells); expect(widths).toEqual([7, 3, 8]); }); - it('spans will only edit uneditable tables - first column uneditable', function() { + it('spans will only edit uneditable tables - first column uneditable', function () { let widths = [3]; let cells = [[mc(0, 0, 20, 3)], [mc(1, 0, 4), mc(1, 1, 3), mc(1, 2, 5)]]; computeWidths(widths, cells); @@ -225,12 +255,12 @@ describe('tableLayout', function() { }); }); - describe('computeHeights', function() { + describe('computeHeights', function () { function mc(y, x, desiredHeight, colSpan) { return { x: x, y: y, desiredHeight: desiredHeight, rowSpan: colSpan }; } - it('finds the maximum desired height of each row', function() { + it('finds the maximum desired height of each row', function () { let heights = []; let cells = [ [mc(0, 0, 7), mc(0, 1, 3), mc(0, 2, 5)], @@ -243,7 +273,7 @@ describe('tableLayout', function() { expect(heights).toEqual([7, 8, 9]); }); - it("won't touch hard coded values", function() { + it("won't touch hard coded values", function () { let heights = [null, 3]; let cells = [ [mc(0, 0, 7), mc(0, 1, 3), mc(0, 2, 5)], @@ -256,14 +286,20 @@ describe('tableLayout', function() { expect(heights).toEqual([7, 3, 9]); }); - it('assumes undefined desiredHeight is 1', function() { + it('assumes undefined desiredHeight is 1', function () { let heights = []; - let cells = [[{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }]]; + let cells = [ + [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + ], + ]; computeHeights(heights, cells); expect(heights).toEqual([1]); }); - it('takes into account rowSpan and wont over expand', function() { + it('takes into account rowSpan and wont over expand', function () { let heights = []; let cells = [ [mc(0, 0, 10, 2), mc(0, 1, 5), mc(0, 2, 2)], @@ -274,7 +310,7 @@ describe('tableLayout', function() { expect(heights).toEqual([5, 5, 4]); }); - it('will expand rows involved in rowSpan in a balanced way', function() { + it('will expand rows involved in rowSpan in a balanced way', function () { let heights = []; let cells = [ [mc(0, 0, 13, 2), mc(0, 1, 5), mc(0, 2, 5)], @@ -285,14 +321,18 @@ describe('tableLayout', function() { expect(heights).toEqual([6, 6, 4]); }); - it('expands across 3 rows', function() { + it('expands across 3 rows', function () { let heights = []; - let cells = [[mc(0, 0, 25, 3), mc(0, 1, 5), mc(0, 2, 4)], [mc(1, 1, 5), mc(1, 2, 2)], [mc(2, 1, 2), mc(2, 2, 1)]]; + let cells = [ + [mc(0, 0, 25, 3), mc(0, 1, 5), mc(0, 2, 4)], + [mc(1, 1, 5), mc(1, 2, 2)], + [mc(2, 1, 2), mc(2, 2, 1)], + ]; computeHeights(heights, cells); expect(heights).toEqual([9, 9, 5]); }); - it('multiple spans in same table', function() { + it('multiple spans in same table', function () { let heights = []; let cells = [[mc(0, 0, 25, 3), mc(0, 1, 30, 3), mc(0, 2, 4)], [mc(1, 2, 2)], [mc(2, 2, 1)]]; computeHeights(heights, cells); @@ -321,8 +361,8 @@ describe('tableLayout', function() { */ function checkLayout(actualTable, expectedTable) { - expectedTable.forEach(function(expectedRow, y) { - expectedRow.forEach(function(expectedCell, x) { + expectedTable.forEach(function (expectedRow, y) { + expectedRow.forEach(function (expectedCell, x) { if (expectedCell !== null) { let actualCell = findCell(actualTable, x, y); checkExpectation(actualCell, expectedCell, x, y, actualTable); diff --git a/test/table-test.js b/test/table-test.js index d105694..32466a9 100644 --- a/test/table-test.js +++ b/test/table-test.js @@ -1,8 +1,8 @@ -describe('@api Table ', function() { +describe('@api Table ', function () { const Table = require('..'); const colors = require('colors/safe'); - it('wordWrap with colored text', function() { + it('wordWrap with colored text', function () { let table = new Table({ style: { border: [], head: [] }, wordWrap: true, colWidths: [7, 9] }); table.push([colors.red('Hello how are you?'), colors.blue('I am fine thanks!')]); @@ -19,7 +19,7 @@ describe('@api Table ', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('allows numbers as `content` property of cells defined using object notation', function() { + it('allows numbers as `content` property of cells defined using object notation', function () { let table = new Table({ style: { border: [], head: [] } }); table.push([{ content: 12 }]); @@ -29,16 +29,16 @@ describe('@api Table ', function() { expect(table.toString()).toEqual(expected.join('\n')); }); - it('throws if content is not a string or number', function() { + it('throws if content is not a string or number', function () { let table = new Table({ style: { border: [], head: [] } }); - expect(function() { + expect(function () { table.push([{ content: { a: 'b' } }]); table.toString(); }).toThrow(); }); - it('works with CJK values', function() { + it('works with CJK values', function () { let table = new Table({ style: { border: [], head: [] }, colWidths: [5, 10, 5] }); table.push( diff --git a/test/utils-test.js b/test/utils-test.js index 7e971ef..96954c4 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -1,180 +1,180 @@ -describe('utils', function() { +describe('utils', function () { const colors = require('colors/safe'); const utils = require('../src/utils'); const { strlen, repeat, pad, truncate, mergeOptions, wordWrap } = utils; - describe('strlen', function() { - it('length of "hello" is 5', function() { + describe('strlen', function () { + it('length of "hello" is 5', function () { expect(strlen('hello')).toEqual(5); }); - it('length of "hi" is 2', function() { + it('length of "hi" is 2', function () { expect(strlen('hi')).toEqual(2); }); - it('length of "hello" in red is 5', function() { + it('length of "hello" in red is 5', function () { expect(strlen(colors.red('hello'))).toEqual(5); }); - it('length of "hello" in zebra is 5', function() { + it('length of "hello" in zebra is 5', function () { expect(strlen(colors.zebra('hello'))).toEqual(5); }); - it('length of "hello\\nhi\\nheynow" is 6', function() { + it('length of "hello\\nhi\\nheynow" is 6', function () { expect(strlen('hello\nhi\nheynow')).toEqual(6); }); - it('length of "中文字符" is 8', function() { + it('length of "中文字符" is 8', function () { expect(strlen('中文字符')).toEqual(8); }); - it('length of "日本語の文字" is 12', function() { + it('length of "日本語の文字" is 12', function () { expect(strlen('日本語の文字')).toEqual(12); }); - it('length of "한글" is 4', function() { + it('length of "한글" is 4', function () { expect(strlen('한글')).toEqual(4); }); }); - describe('repeat', function() { - it('"-" x 3', function() { + describe('repeat', function () { + it('"-" x 3', function () { expect(repeat('-', 3)).toEqual('---'); }); - it('"-" x 4', function() { + it('"-" x 4', function () { expect(repeat('-', 4)).toEqual('----'); }); - it('"=" x 4', function() { + it('"=" x 4', function () { expect(repeat('=', 4)).toEqual('===='); }); }); - describe('pad', function() { - it("pad('hello',6,' ', right) == ' hello'", function() { + describe('pad', function () { + it("pad('hello',6,' ', right) == ' hello'", function () { expect(pad('hello', 6, ' ', 'right')).toEqual(' hello'); }); - it("pad('hello',7,' ', left) == 'hello '", function() { + it("pad('hello',7,' ', left) == 'hello '", function () { expect(pad('hello', 7, ' ', 'left')).toEqual('hello '); }); - it("pad('hello',8,' ', center) == ' hello '", function() { + it("pad('hello',8,' ', center) == ' hello '", function () { expect(pad('hello', 8, ' ', 'center')).toEqual(' hello '); }); - it("pad('hello',9,' ', center) == ' hello '", function() { + it("pad('hello',9,' ', center) == ' hello '", function () { expect(pad('hello', 9, ' ', 'center')).toEqual(' hello '); }); - it("pad('yo',4,' ', center) == ' yo '", function() { + it("pad('yo',4,' ', center) == ' yo '", function () { expect(pad('yo', 4, ' ', 'center')).toEqual(' yo '); }); - it('pad red(hello)', function() { + it('pad red(hello)', function () { expect(pad(colors.red('hello'), 7, ' ', 'right')).toEqual(' ' + colors.red('hello')); }); - it("pad('hello', 2, ' ', right) == 'hello'", function() { + it("pad('hello', 2, ' ', right) == 'hello'", function () { expect(pad('hello', 2, ' ', 'right')).toEqual('hello'); }); }); - describe('truncate', function() { - it('truncate("hello", 5) === "hello"', function() { + describe('truncate', function () { + it('truncate("hello", 5) === "hello"', function () { expect(truncate('hello', 5)).toEqual('hello'); }); - it('truncate("hello sir", 7, "…") == "hello …"', function() { + it('truncate("hello sir", 7, "…") == "hello …"', function () { expect(truncate('hello sir', 7, '…')).toEqual('hello …'); }); - it('truncate("hello sir", 6, "…") == "hello…"', function() { + it('truncate("hello sir", 6, "…") == "hello…"', function () { expect(truncate('hello sir', 6, '…')).toEqual('hello…'); }); - it('truncate("goodnight moon", 8, "…") == "goodnig…"', function() { + it('truncate("goodnight moon", 8, "…") == "goodnig…"', function () { expect(truncate('goodnight moon', 8, '…')).toEqual('goodnig…'); }); - it('truncate(colors.zebra("goodnight moon"), 15, "…") == colors.zebra("goodnight moon")', function() { + it('truncate(colors.zebra("goodnight moon"), 15, "…") == colors.zebra("goodnight moon")', function () { let original = colors.zebra('goodnight moon'); expect(truncate(original, 15, '…')).toEqual(original); }); - it('truncate(colors.zebra("goodnight moon"), 8, "…") == colors.zebra("goodnig") + "…"', function() { + it('truncate(colors.zebra("goodnight moon"), 8, "…") == colors.zebra("goodnig") + "…"', function () { let original = colors.zebra('goodnight moon'); let expected = colors.zebra('goodnig') + '…'; expect(truncate(original, 8, '…')).toEqual(expected); }); - it('truncate(colors.zebra("goodnight moon"), 9, "…") == colors.zebra("goodnig") + "…"', function() { + it('truncate(colors.zebra("goodnight moon"), 9, "…") == colors.zebra("goodnig") + "…"', function () { let original = colors.zebra('goodnight moon'); let expected = colors.zebra('goodnigh') + '…'; expect(truncate(original, 9, '…')).toEqual(expected); }); - it('red(hello) + green(world) truncated to 9 chars', function() { + it('red(hello) + green(world) truncated to 9 chars', function () { let original = colors.red('hello') + colors.green(' world'); let expected = colors.red('hello') + colors.green(' wo') + '…'; expect(truncate(original, 9)).toEqual(expected); }); - it('red-on-green(hello) + green-on-red(world) truncated to 9 chars', function() { + it('red-on-green(hello) + green-on-red(world) truncated to 9 chars', function () { let original = colors.red.bgGreen('hello') + colors.green.bgRed(' world'); let expected = colors.red.bgGreen('hello') + colors.green.bgRed(' wo') + '…'; expect(truncate(original, 9)).toEqual(expected); }); - it('red-on-green(hello) + green-on-red(world) truncated to 10 chars - using inverse', function() { + it('red-on-green(hello) + green-on-red(world) truncated to 10 chars - using inverse', function () { let original = colors.red.bgGreen('hello' + colors.inverse(' world')); let expected = colors.red.bgGreen('hello' + colors.inverse(' wor')) + '…'; expect(truncate(original, 10)).toEqual(expected); }); - it('red-on-green( zebra (hello world) ) truncated to 11 chars', function() { + it('red-on-green( zebra (hello world) ) truncated to 11 chars', function () { let original = colors.red.bgGreen(colors.zebra('hello world')); let expected = colors.red.bgGreen(colors.zebra('hello world')); expect(truncate(original, 11)).toEqual(expected); }); - it('red-on-green( zebra (hello world) ) truncated to 10 chars', function() { + it('red-on-green( zebra (hello world) ) truncated to 10 chars', function () { let original = colors.red.bgGreen(colors.zebra('hello world')); let expected = colors.red.bgGreen(colors.zebra('hello wor')) + '…'; expect(truncate(original, 10)).toEqual(expected); }); - it('handles reset code', function() { + it('handles reset code', function () { let original = '\x1b[31mhello\x1b[0m world'; let expected = '\x1b[31mhello\x1b[0m wor…'; expect(truncate(original, 10)).toEqual(expected); }); - it('handles reset code (EMPTY VERSION)', function() { + it('handles reset code (EMPTY VERSION)', function () { let original = '\x1b[31mhello\x1b[0m world'; let expected = '\x1b[31mhello\x1b[0m wor…'; expect(truncate(original, 10)).toEqual(expected); }); - it('truncateWidth("漢字テスト", 15) === "漢字テスト"', function() { + it('truncateWidth("漢字テスト", 15) === "漢字テスト"', function () { expect(truncate('漢字テスト', 15)).toEqual('漢字テスト'); }); - it('truncateWidth("漢字テスト", 6) === "漢字…"', function() { + it('truncateWidth("漢字テスト", 6) === "漢字…"', function () { expect(truncate('漢字テスト', 6)).toEqual('漢字…'); }); - it('truncateWidth("漢字テスト", 5) === "漢字…"', function() { + it('truncateWidth("漢字テスト", 5) === "漢字…"', function () { expect(truncate('漢字テスト', 5)).toEqual('漢字…'); }); - it('truncateWidth("漢字testてすと", 12) === "漢字testて…"', function() { + it('truncateWidth("漢字testてすと", 12) === "漢字testて…"', function () { expect(truncate('漢字testてすと', 12)).toEqual('漢字testて…'); }); - it('handles color code with CJK chars', function() { + it('handles color code with CJK chars', function () { let original = '漢字\x1b[31m漢字\x1b[0m漢字'; let expected = '漢字\x1b[31m漢字\x1b[0m漢…'; expect(truncate(original, 11)).toEqual(expected); @@ -216,31 +216,31 @@ describe('utils', function() { }; } - describe('mergeOptions', function() { - it('allows you to override chars', function() { + describe('mergeOptions', function () { + it('allows you to override chars', function () { expect(mergeOptions()).toEqual(defaultOptions()); }); - it('chars will be merged deeply', function() { + it('chars will be merged deeply', function () { let expected = defaultOptions(); expected.chars.left = 'L'; expect(mergeOptions({ chars: { left: 'L' } })).toEqual(expected); }); - it('style will be merged deeply', function() { + it('style will be merged deeply', function () { let expected = defaultOptions(); expected.style['padding-left'] = 2; expect(mergeOptions({ style: { 'padding-left': 2 } })).toEqual(expected); }); - it('head will be overwritten', function() { + it('head will be overwritten', function () { let expected = defaultOptions(); expected.style.head = []; //we can't use lodash's `merge()` in implementation because it would deeply copy array. expect(mergeOptions({ style: { head: [] } })).toEqual(expected); }); - it('border will be overwritten', function() { + it('border will be overwritten', function () { let expected = defaultOptions(); expected.style.border = []; //we can't use lodash's `merge()` in implementation because it would deeply copy array. @@ -248,8 +248,8 @@ describe('utils', function() { }); }); - describe('wordWrap', function() { - it('length', function() { + describe('wordWrap', function () { + it('length', function () { let input = 'Hello, how are you today? I am fine, thank you!'; let expected = 'Hello, how\nare you\ntoday? I\nam fine,\nthank you!'; @@ -257,7 +257,7 @@ describe('utils', function() { expect(wordWrap(10, input).join('\n')).toEqual(expected); }); - it.skip('length with colors', function() { + it.skip('length with colors', function () { let input = colors.red('Hello, how are') + colors.blue(' you today? I') + colors.green(' am fine, thank you!'); let expected = @@ -266,7 +266,7 @@ describe('utils', function() { expect(wordWrap(10, input).join('\n')).toEqual(expected); }); - it('will not create an empty last line', function() { + it('will not create an empty last line', function () { let input = 'Hello Hello '; let expected = 'Hello\nHello'; @@ -274,7 +274,7 @@ describe('utils', function() { expect(wordWrap(5, input).join('\n')).toEqual(expected); }); - it('will handle color reset code', function() { + it('will handle color reset code', function () { let input = '\x1b[31mHello\x1b[0m Hello '; let expected = '\x1b[31mHello\x1b[0m\nHello'; @@ -282,7 +282,7 @@ describe('utils', function() { expect(wordWrap(5, input).join('\n')).toEqual(expected); }); - it('will handle color reset code (EMPTY version)', function() { + it('will handle color reset code (EMPTY version)', function () { let input = '\x1b[31mHello\x1b[m Hello '; let expected = '\x1b[31mHello\x1b[m\nHello'; @@ -290,7 +290,7 @@ describe('utils', function() { expect(wordWrap(5, input).join('\n')).toEqual(expected); }); - it('words longer than limit will not create extra newlines', function() { + it('words longer than limit will not create extra newlines', function () { let input = 'disestablishment is a multiplicity someotherlongword'; let expected = 'disestablishment\nis a\nmultiplicity\nsomeotherlongword'; @@ -298,78 +298,78 @@ describe('utils', function() { expect(wordWrap(7, input).join('\n')).toEqual(expected); }); - it('multiple line input', function() { + it('multiple line input', function () { let input = 'a\nb\nc d e d b duck\nm\nn\nr'; let expected = ['a', 'b', 'c d', 'e d', 'b', 'duck', 'm', 'n', 'r']; expect(wordWrap(4, input)).toEqual(expected); }); - it('will not start a line with whitespace', function() { + it('will not start a line with whitespace', function () { let input = 'ab cd ef gh ij kl'; let expected = ['ab cd', 'ef gh', 'ij kl']; expect(wordWrap(7, input)).toEqual(expected); }); - it('wraps CJK chars', function() { + it('wraps CJK chars', function () { let input = '漢字 漢\n字 漢字'; let expected = ['漢字 漢', '字 漢字']; expect(wordWrap(7, input)).toEqual(expected); }); - it('wraps CJK chars with colors', function() { + it('wraps CJK chars with colors', function () { let input = '\x1b[31m漢字\x1b[0m\n 漢字'; let expected = ['\x1b[31m漢字\x1b[0m', ' 漢字']; expect(wordWrap(5, input)).toEqual(expected); }); }); - describe('colorizeLines', function() { - it('foreground colors continue on each line', function() { + describe('colorizeLines', function () { + it('foreground colors continue on each line', function () { let input = colors.red('Hello\nHi').split('\n'); expect(utils.colorizeLines(input)).toEqual([colors.red('Hello'), colors.red('Hi')]); }); - it('foreground colors continue on each line', function() { + it('foreground colors continue on each line', function () { let input = colors.bgRed('Hello\nHi').split('\n'); expect(utils.colorizeLines(input)).toEqual([colors.bgRed('Hello'), colors.bgRed('Hi')]); }); - it('styles will continue on each line', function() { + it('styles will continue on each line', function () { let input = colors.underline('Hello\nHi').split('\n'); expect(utils.colorizeLines(input)).toEqual([colors.underline('Hello'), colors.underline('Hi')]); }); - it('styles that end before the break will not be applied to the next line', function() { + it('styles that end before the break will not be applied to the next line', function () { let input = (colors.underline('Hello') + '\nHi').split('\n'); expect(utils.colorizeLines(input)).toEqual([colors.underline('Hello'), 'Hi']); }); - it('the reset code can be used to drop styles', function() { + it('the reset code can be used to drop styles', function () { let input = '\x1b[31mHello\x1b[0m\nHi'.split('\n'); expect(utils.colorizeLines(input)).toEqual(['\x1b[31mHello\x1b[0m', 'Hi']); }); - it('handles aixterm 16-color foreground', function() { + it('handles aixterm 16-color foreground', function () { let input = '\x1b[90mHello\nHi\x1b[0m'.split('\n'); expect(utils.colorizeLines(input)).toEqual(['\x1b[90mHello\x1b[39m', '\x1b[90mHi\x1b[0m']); }); - it('handles aixterm 16-color background', function() { + it('handles aixterm 16-color background', function () { let input = '\x1b[100mHello\nHi\x1b[m\nHowdy'.split('\n'); expect(utils.colorizeLines(input)).toEqual(['\x1b[100mHello\x1b[49m', '\x1b[100mHi\x1b[m', 'Howdy']); }); - it('handles aixterm 256-color foreground', function() { + it('handles aixterm 256-color foreground', function () { let input = '\x1b[48;5;8mHello\nHi\x1b[0m\nHowdy'.split('\n'); expect(utils.colorizeLines(input)).toEqual(['\x1b[48;5;8mHello\x1b[49m', '\x1b[48;5;8mHi\x1b[0m', 'Howdy']); }); - it('handles CJK chars', function() { + it('handles CJK chars', function () { let input = colors.red('漢字\nテスト').split('\n'); expect(utils.colorizeLines(input)).toEqual([colors.red('漢字'), colors.red('テスト')]); diff --git a/test/verify-legacy-compatibility-test.js b/test/verify-legacy-compatibility-test.js index e3df856..fff19f1 100644 --- a/test/verify-legacy-compatibility-test.js +++ b/test/verify-legacy-compatibility-test.js @@ -1,22 +1,22 @@ -(function() { - describe('verify original cli-table behavior', function() { +(function () { + describe('verify original cli-table behavior', function () { commonTests(require('cli-table')); }); - describe('@api cli-table2 matches verified behavior', function() { + describe('@api cli-table2 matches verified behavior', function () { commonTests(require('../src/table')); }); function commonTests(Table) { const colors = require('colors/safe'); - it('empty table has a width of 0', function() { + it('empty table has a width of 0', function () { let table = new Table(); expect(table.width).toEqual(0); expect(table.toString()).toEqual(''); }); - it('header text will be colored according to style', function() { + it('header text will be colored according to style', function () { let table = new Table({ head: ['hello', 'goodbye'], style: { border: [], head: ['red', 'bgWhite'] } }); let expected = [ @@ -28,7 +28,7 @@ expect(table.toString()).toEqual(expected.join('\n')); }); - it('tables with one row of data will not be treated as headers', function() { + it('tables with one row of data will not be treated as headers', function () { let table = new Table({ style: { border: [], head: ['red'] } }); table.push(['hello', 'goodbye']); @@ -38,7 +38,7 @@ expect(table.toString()).toEqual(expected.join('\n')); }); - it('table with headers and data headers', function() { + it('table with headers and data headers', function () { let table = new Table({ head: ['hello', 'goodbye'], style: { border: [], head: ['red'] } }); table.push(['hola', 'adios']); @@ -54,7 +54,7 @@ expect(table.toString()).toEqual(expected.join('\n')); }); - it('compact shorthand', function() { + it('compact shorthand', function () { let table = new Table({ style: { compact: true, border: [], head: ['red'] } }); table.push(['hello', 'goodbye'], ['hola', 'adios']); @@ -64,7 +64,7 @@ expect(table.toString()).toEqual(expected.join('\n')); }); - it('compact shorthand - headers are still rendered with separator', function() { + it('compact shorthand - headers are still rendered with separator', function () { let table = new Table({ head: ['hello', 'goodbye'], style: { compact: true, border: [], head: [] } }); table.push(['hola', 'adios'], ['hi', 'bye']); @@ -81,7 +81,7 @@ expect(table.toString()).toEqual(expected.join('\n')); }); - it('compact longhand - headers are not rendered with separator', function() { + it('compact longhand - headers are not rendered with separator', function () { let table = new Table({ chars: { mid: '', @@ -106,7 +106,7 @@ expect(table.toString()).toEqual(expected.join('\n')); }); - it('compact longhand', function() { + it('compact longhand', function () { let table = new Table({ chars: { mid: '', @@ -124,7 +124,7 @@ expect(table.toString()).toEqual(expected.join('\n')); }); - it('objects with multiple properties in a cross-table', function() { + it('objects with multiple properties in a cross-table', function () { let table = new Table({ style: { border: [], head: [] } }); table.push( diff --git a/yarn.lock b/yarn.lock index 07a59c6..488b167 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3625,10 +3625,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@1.18.2: - version "1.18.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" - integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw== +prettier@2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.2.tgz#1ba8f3eb92231e769b7fcd7cb73ae1b6b74ade08" + integrity sha512-5xJQIPT8BraI7ZnaDwSbu5zLrB6vvi8hVV58yHQ+QK64qrY40dULy0HSRlQ2/2IdzeBpjhDkqdcFBnFeDEMVdg== pretty-format@^24.9.0: version "24.9.0"