tty-table 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +104 -98
- data/lib/tty-table.rb +1 -1
- data/lib/tty/table.rb +70 -34
- data/lib/tty/table/alignment_set.rb +1 -3
- data/lib/tty/table/border.rb +50 -57
- data/lib/tty/table/border/ascii.rb +16 -16
- data/lib/tty/table/border/null.rb +19 -22
- data/lib/tty/table/border/row_line.rb +3 -2
- data/lib/tty/table/border/unicode.rb +16 -16
- data/lib/tty/table/border_dsl.rb +24 -22
- data/lib/tty/table/border_options.rb +32 -27
- data/lib/tty/table/column_constraint.rb +12 -9
- data/lib/tty/table/columns.rb +6 -6
- data/lib/tty/table/field.rb +46 -28
- data/lib/tty/table/header.rb +5 -5
- data/lib/tty/table/indentation.rb +7 -4
- data/lib/tty/table/operation/alignment.rb +1 -1
- data/lib/tty/table/operation/escape.rb +1 -2
- data/lib/tty/table/operation/padding.rb +1 -1
- data/lib/tty/table/operation/truncation.rb +1 -1
- data/lib/tty/table/operation/wrapped.rb +1 -1
- data/lib/tty/table/options.rb +1 -1
- data/lib/tty/table/orientation.rb +4 -4
- data/lib/tty/table/renderer.rb +8 -8
- data/lib/tty/table/renderer/ascii.rb +2 -2
- data/lib/tty/table/renderer/basic.rb +37 -40
- data/lib/tty/table/renderer/unicode.rb +1 -1
- data/lib/tty/table/row.rb +7 -7
- data/lib/tty/table/validatable.rb +23 -7
- data/lib/tty/table/version.rb +1 -1
- metadata +23 -272
- data/Rakefile +0 -10
- data/examples/alignment.rb +0 -10
- data/examples/basic.rb +0 -6
- data/examples/orientation.rb +0 -13
- data/examples/padding.rb +0 -15
- data/examples/resize.rb +0 -15
- data/spec/spec_helper.rb +0 -50
- data/spec/unit/access_spec.rb +0 -84
- data/spec/unit/add_row_spec.rb +0 -26
- data/spec/unit/alignment_set/each_spec.rb +0 -15
- data/spec/unit/alignment_set/new_spec.rb +0 -25
- data/spec/unit/alignment_set/to_ary_spec.rb +0 -12
- data/spec/unit/alignment_spec.rb +0 -69
- data/spec/unit/border/ascii/rendering_spec.rb +0 -88
- data/spec/unit/border/new_spec.rb +0 -25
- data/spec/unit/border/null/rendering_spec.rb +0 -128
- data/spec/unit/border/options/from_spec.rb +0 -36
- data/spec/unit/border/options/new_spec.rb +0 -12
- data/spec/unit/border/unicode/rendering_spec.rb +0 -61
- data/spec/unit/border_options/new_spec.rb +0 -18
- data/spec/unit/border_options/update_spec.rb +0 -16
- data/spec/unit/column_constraint/enforce_spec.rb +0 -68
- data/spec/unit/column_constraint/widths_spec.rb +0 -33
- data/spec/unit/columns/extract_widths_spec.rb +0 -41
- data/spec/unit/columns/total_width_spec.rb +0 -11
- data/spec/unit/columns/widths_from_spec.rb +0 -49
- data/spec/unit/data_spec.rb +0 -10
- data/spec/unit/each_spec.rb +0 -24
- data/spec/unit/each_with_index_spec.rb +0 -49
- data/spec/unit/empty_spec.rb +0 -21
- data/spec/unit/eql_spec.rb +0 -32
- data/spec/unit/field/equality_spec.rb +0 -49
- data/spec/unit/field/length_spec.rb +0 -33
- data/spec/unit/field/lines_spec.rb +0 -19
- data/spec/unit/field/new_spec.rb +0 -27
- data/spec/unit/field/width_spec.rb +0 -21
- data/spec/unit/filter_spec.rb +0 -20
- data/spec/unit/header/call_spec.rb +0 -28
- data/spec/unit/header/color_spec.rb +0 -17
- data/spec/unit/header/equality_spec.rb +0 -49
- data/spec/unit/header/height_spec.rb +0 -25
- data/spec/unit/header/new_spec.rb +0 -13
- data/spec/unit/header/set_spec.rb +0 -18
- data/spec/unit/header/to_ary_spec.rb +0 -12
- data/spec/unit/header_spec.rb +0 -11
- data/spec/unit/indentation/indent_spec.rb +0 -15
- data/spec/unit/new_spec.rb +0 -71
- data/spec/unit/operation/alignment/call_spec.rb +0 -37
- data/spec/unit/operation/escape/call_spec.rb +0 -13
- data/spec/unit/operation/filter/call_spec.rb +0 -14
- data/spec/unit/operation/truncation/call_spec.rb +0 -28
- data/spec/unit/operation/wrapped/call_spec.rb +0 -38
- data/spec/unit/operations/new_spec.rb +0 -28
- data/spec/unit/options/access_spec.rb +0 -12
- data/spec/unit/options_spec.rb +0 -23
- data/spec/unit/orientation_spec.rb +0 -143
- data/spec/unit/padding_spec.rb +0 -115
- data/spec/unit/properties_spec.rb +0 -23
- data/spec/unit/render_repeat_spec.rb +0 -39
- data/spec/unit/render_spec.rb +0 -61
- data/spec/unit/render_with_spec.rb +0 -104
- data/spec/unit/renderer/ascii/coloring_spec.rb +0 -83
- data/spec/unit/renderer/ascii/indentation_spec.rb +0 -39
- data/spec/unit/renderer/ascii/multiline_spec.rb +0 -99
- data/spec/unit/renderer/ascii/padding_spec.rb +0 -115
- data/spec/unit/renderer/ascii/render_spec.rb +0 -66
- data/spec/unit/renderer/ascii/resizing_spec.rb +0 -112
- data/spec/unit/renderer/ascii/separator_spec.rb +0 -38
- data/spec/unit/renderer/basic/alignment_spec.rb +0 -86
- data/spec/unit/renderer/basic/coloring_spec.rb +0 -59
- data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -26
- data/spec/unit/renderer/basic/filter_spec.rb +0 -51
- data/spec/unit/renderer/basic/indentation_spec.rb +0 -46
- data/spec/unit/renderer/basic/multiline_spec.rb +0 -72
- data/spec/unit/renderer/basic/new_spec.rb +0 -24
- data/spec/unit/renderer/basic/options_spec.rb +0 -50
- data/spec/unit/renderer/basic/padding_spec.rb +0 -74
- data/spec/unit/renderer/basic/render_spec.rb +0 -55
- data/spec/unit/renderer/basic/resizing_spec.rb +0 -94
- data/spec/unit/renderer/basic/separator_spec.rb +0 -41
- data/spec/unit/renderer/basic/single_row_separator_spec.rb +0 -80
- data/spec/unit/renderer/basic/truncation_spec.rb +0 -33
- data/spec/unit/renderer/basic/wrapping_spec.rb +0 -38
- data/spec/unit/renderer/border_spec.rb +0 -102
- data/spec/unit/renderer/render_spec.rb +0 -34
- data/spec/unit/renderer/select_spec.rb +0 -20
- data/spec/unit/renderer/unicode/coloring_spec.rb +0 -68
- data/spec/unit/renderer/unicode/indentation_spec.rb +0 -39
- data/spec/unit/renderer/unicode/padding_spec.rb +0 -59
- data/spec/unit/renderer/unicode/render_spec.rb +0 -66
- data/spec/unit/renderer/unicode/separator_spec.rb +0 -36
- data/spec/unit/renderer_spec.rb +0 -17
- data/spec/unit/rotate_spec.rb +0 -84
- data/spec/unit/row/access_spec.rb +0 -23
- data/spec/unit/row/call_spec.rb +0 -43
- data/spec/unit/row/data_spec.rb +0 -24
- data/spec/unit/row/each_spec.rb +0 -29
- data/spec/unit/row/equality_spec.rb +0 -71
- data/spec/unit/row/height_spec.rb +0 -25
- data/spec/unit/row/new_spec.rb +0 -39
- data/spec/unit/row/to_ary_spec.rb +0 -12
- data/spec/unit/to_s_spec.rb +0 -56
- data/spec/unit/transformation/extract_tuples_spec.rb +0 -33
- data/spec/unit/utf_spec.rb +0 -31
- data/spec/unit/validatable/validate_options_spec.rb +0 -31
- data/spec/unit/validatable_spec.rb +0 -30
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-table.gemspec +0 -41
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'coloring' do
|
4
|
-
let(:clear) { "\e[0m" }
|
5
|
-
let(:color) { Pastel.new(enabled: true) }
|
6
|
-
|
7
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
8
|
-
|
9
|
-
context 'when border ' do
|
10
|
-
it "doesn't color" do
|
11
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
12
|
-
table << ['a1', 'a2']
|
13
|
-
table << ['b1', 'b2']
|
14
|
-
renderer = described_class.new(table)
|
15
|
-
renderer.border = {style: :green}
|
16
|
-
|
17
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
18
|
-
header1 header2
|
19
|
-
a1 a2
|
20
|
-
b1 b2
|
21
|
-
EOS
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when content' do
|
26
|
-
it "colors individual field" do
|
27
|
-
header = [color.green('header1'), 'header2']
|
28
|
-
table = TTY::Table.new header: header
|
29
|
-
table << [color.green.on_blue('a1'), 'a2']
|
30
|
-
table << ['b1', color.red.on_yellow('b2')]
|
31
|
-
renderer = described_class.new(table)
|
32
|
-
|
33
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
34
|
-
#{color.green('header1')} header2
|
35
|
-
#{color.green.on_blue('a1')} a2
|
36
|
-
b1 #{color.red.on_yellow('b2')}
|
37
|
-
EOS
|
38
|
-
end
|
39
|
-
|
40
|
-
it "colors multiline content" do
|
41
|
-
header = [color.yellow("Multi\nHeader"), 'header2']
|
42
|
-
table = TTY::Table.new header: header
|
43
|
-
table << [color.green.on_blue("Multi\nLine\nContent"), 'a2']
|
44
|
-
table << ['b1', color.red.on_yellow("Multi\nLine\nContent")]
|
45
|
-
renderer = described_class.new(table, multiline: true)
|
46
|
-
|
47
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
48
|
-
#{color.yellow('Multi ')} header2
|
49
|
-
#{color.yellow('Header')}
|
50
|
-
#{color.green.on_blue('Multi ')} a2
|
51
|
-
#{color.green.on_blue('Line ')}
|
52
|
-
#{color.green.on_blue('Content')}
|
53
|
-
b1 #{color.red.on_yellow("Multi ")}
|
54
|
-
#{color.red.on_yellow("Line ")}
|
55
|
-
#{color.red.on_yellow("Content")}
|
56
|
-
EOS
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, '#column_widths' do
|
4
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
5
|
-
let(:renderer) { described_class.new(table) }
|
6
|
-
|
7
|
-
subject { renderer.render }
|
8
|
-
|
9
|
-
context 'with rows only' do
|
10
|
-
let(:rows) { [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']] }
|
11
|
-
let(:table) { TTY::Table.new rows }
|
12
|
-
|
13
|
-
it 'calculates column widths' do
|
14
|
-
expect(renderer.column_widths).to eq([5,6])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with header' do
|
19
|
-
let(:header) { ['header1', 'head2', 'h3'] }
|
20
|
-
let(:table) { TTY::Table.new header, rows }
|
21
|
-
|
22
|
-
it 'calcualtes column widths with header' do
|
23
|
-
expect(renderer.column_widths).to eq([7,5,2])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'filter' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
|
8
|
-
subject(:renderer) { described_class.new(table, {filter: filter}) }
|
9
|
-
|
10
|
-
context 'with header' do
|
11
|
-
context 'filtering only rows' do
|
12
|
-
let(:filter) { Proc.new { |val, row, col|
|
13
|
-
(col == 1 and row > 0) ? val.capitalize : val
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
it 'filters only rows' do
|
18
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
19
|
-
h1 h2 h3
|
20
|
-
a1 A2 a3
|
21
|
-
b1 B2 b3
|
22
|
-
EOS
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'filtering header and rows' do
|
27
|
-
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val }}
|
28
|
-
|
29
|
-
it 'filters only rows' do
|
30
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
31
|
-
h1 H2 h3
|
32
|
-
a1 A2 a3
|
33
|
-
b1 B2 b3
|
34
|
-
EOS
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'without header' do
|
40
|
-
let(:header) { nil }
|
41
|
-
|
42
|
-
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val } }
|
43
|
-
|
44
|
-
it 'filters only rows' do
|
45
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
46
|
-
a1 A2 a3
|
47
|
-
b1 B2 b3
|
48
|
-
EOS
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'indentation' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
let(:options) { {indent: indent } }
|
8
|
-
|
9
|
-
subject(:renderer) { described_class.new(table, options)}
|
10
|
-
|
11
|
-
context 'when default' do
|
12
|
-
let(:indent) { 0 }
|
13
|
-
|
14
|
-
it 'indents by value' do
|
15
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
16
|
-
h1 h2 h3
|
17
|
-
a1 a2 a3
|
18
|
-
b1 b2 b3
|
19
|
-
EOS
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when custom' do
|
24
|
-
let(:indent) { 2 }
|
25
|
-
|
26
|
-
it 'indents by value' do
|
27
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
28
|
-
h1 h2 h3
|
29
|
-
a1 a2 a3
|
30
|
-
b1 b2 b3
|
31
|
-
EOS
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when changed' do
|
36
|
-
let(:indent) { 2 }
|
37
|
-
let(:header) { ['h1', 'h2'] }
|
38
|
-
let(:rows) { [['a1', 'a2']] }
|
39
|
-
|
40
|
-
it 'changes indentation and reuses renderer' do
|
41
|
-
expect(renderer.render).to eq(" h1 h2\n a1 a2")
|
42
|
-
renderer.indent = 1
|
43
|
-
expect(renderer.render).to eq(" h1 h2\n a1 a2")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'multiline content' do
|
4
|
-
context 'with escaping' do
|
5
|
-
it "renders multiline as single line" do
|
6
|
-
rows = [ ["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']]
|
7
|
-
table = TTY::Table.new rows
|
8
|
-
renderer = described_class.new(table, multiline: false)
|
9
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
10
|
-
First 1
|
11
|
-
Multiline\\nContent 2
|
12
|
-
Third 3
|
13
|
-
EOS
|
14
|
-
end
|
15
|
-
|
16
|
-
it "truncates multiline content" do
|
17
|
-
rows = [ ["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']]
|
18
|
-
table = TTY::Table.new rows
|
19
|
-
renderer = described_class.new(table, multiline: false, column_widths: [8,1])
|
20
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
21
|
-
First 1
|
22
|
-
Multil… 2
|
23
|
-
Third 3
|
24
|
-
EOS
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'without escaping' do
|
29
|
-
it "renders every line" do
|
30
|
-
rows = [["First", '1'],
|
31
|
-
["Multi\nLine\nContent", '2'],
|
32
|
-
["Third", "Multi\nLine"]]
|
33
|
-
table = TTY::Table.new rows
|
34
|
-
renderer = described_class.new(table, multiline: true)
|
35
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
36
|
-
First 1
|
37
|
-
Multi 2
|
38
|
-
Line
|
39
|
-
Content
|
40
|
-
Third Multi
|
41
|
-
Line
|
42
|
-
EOS
|
43
|
-
end
|
44
|
-
|
45
|
-
it "renders multiline with column widths" do
|
46
|
-
rows = [["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']]
|
47
|
-
table = TTY::Table.new rows
|
48
|
-
renderer = described_class.new(table, multiline: true, column_widths: [8,1])
|
49
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
50
|
-
First 1
|
51
|
-
Multi 2
|
52
|
-
Line
|
53
|
-
Content
|
54
|
-
Third 3
|
55
|
-
EOS
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'wraps multi line' do
|
59
|
-
rows = [["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']]
|
60
|
-
table = TTY::Table.new rows
|
61
|
-
renderer = described_class.new(table, multiline: true, column_widths: [5,1])
|
62
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
63
|
-
First 1
|
64
|
-
Multi 2
|
65
|
-
Line
|
66
|
-
Conte
|
67
|
-
nt
|
68
|
-
Third 3
|
69
|
-
EOS
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, '.new' do
|
4
|
-
let(:header) { ['h1'] }
|
5
|
-
let(:rows) { [['a1']] }
|
6
|
-
|
7
|
-
subject(:renderer) { described_class }
|
8
|
-
|
9
|
-
context 'without table' do
|
10
|
-
let(:table) { nil }
|
11
|
-
|
12
|
-
it {
|
13
|
-
expect {
|
14
|
-
renderer.new(table)
|
15
|
-
}.to raise_error(TTY::Table::ArgumentRequired)
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with table' do
|
20
|
-
let(:table) { TTY::Table.new(header, rows) }
|
21
|
-
|
22
|
-
it { expect { renderer.new(table) }.not_to raise_error }
|
23
|
-
end
|
24
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'options' do
|
4
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
5
|
-
let(:object) { described_class }
|
6
|
-
let(:table) { TTY::Table.new(rows) }
|
7
|
-
let(:widths) { nil }
|
8
|
-
let(:alignments) { [] }
|
9
|
-
let(:options) {
|
10
|
-
{
|
11
|
-
column_widths: widths,
|
12
|
-
alignments: alignments,
|
13
|
-
renderer: :basic
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
subject(:renderer) { object.new table, options }
|
18
|
-
|
19
|
-
it { expect(renderer.border).to be_kind_of(TTY::Table::BorderOptions) }
|
20
|
-
|
21
|
-
it { expect(renderer.column_widths).to eql([2,2]) }
|
22
|
-
|
23
|
-
it { expect(renderer.alignments.to_a).to eql(alignments) }
|
24
|
-
|
25
|
-
it { expect(renderer.alignments.to_a).to be_empty }
|
26
|
-
|
27
|
-
context '#column_widths' do
|
28
|
-
let(:widths) { [10, 10] }
|
29
|
-
|
30
|
-
it { expect(renderer.column_widths).to eq(widths) }
|
31
|
-
end
|
32
|
-
|
33
|
-
context '#column_widths empty' do
|
34
|
-
let(:widths) { [] }
|
35
|
-
|
36
|
-
it {
|
37
|
-
expect {
|
38
|
-
renderer.column_widths
|
39
|
-
}.to raise_error(TTY::Table::InvalidArgument)
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
context '#alignments' do
|
44
|
-
let(:alignments) { [:center, :center] }
|
45
|
-
|
46
|
-
it 'unwraps original array' do
|
47
|
-
expect(renderer.alignments.to_a).to eq(alignments)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'padding' do
|
4
|
-
let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
|
5
|
-
let(:rows) { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
|
8
|
-
subject(:renderer) { described_class.new(table, options) }
|
9
|
-
|
10
|
-
context 'with left & right padding' do
|
11
|
-
let(:options) { {padding: [0,1,0,1]} }
|
12
|
-
|
13
|
-
it 'pads each field' do
|
14
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
15
|
-
Field Type Null Key Default Extra
|
16
|
-
id int(11) YES nil NULL
|
17
|
-
EOS
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with top & bottom padding' do
|
22
|
-
let(:options) { {padding: [1,0,1,0]} }
|
23
|
-
|
24
|
-
it 'pads each field' do
|
25
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
26
|
-
|
27
|
-
Field Type Null Key Default Extra
|
28
|
-
|
29
|
-
|
30
|
-
id int(11) YES nil NULL
|
31
|
-
|
32
|
-
EOS
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with full padding' do
|
37
|
-
let(:options) { {padding: [1,1,1,1]} }
|
38
|
-
|
39
|
-
it 'pads each field' do
|
40
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
41
|
-
|
42
|
-
Field Type Null Key Default Extra
|
43
|
-
|
44
|
-
|
45
|
-
id int(11) YES nil NULL
|
46
|
-
|
47
|
-
EOS
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "with multiline content padding" do
|
52
|
-
it "pads around fields" do
|
53
|
-
padding = [1,2,1,2]
|
54
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
55
|
-
table << ["a1\na1\na1",'a2']
|
56
|
-
table << ["b1","b2\nb2"]
|
57
|
-
renderer = TTY::Table::Renderer::Basic.new(table, padding: padding, multiline: true)
|
58
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
59
|
-
|
60
|
-
header1 header2
|
61
|
-
|
62
|
-
|
63
|
-
a1 a2
|
64
|
-
a1
|
65
|
-
a1
|
66
|
-
|
67
|
-
|
68
|
-
b1 b2
|
69
|
-
b2
|
70
|
-
|
71
|
-
EOS
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Basic, '#render' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new header, rows }
|
7
|
-
|
8
|
-
subject(:renderer) { described_class.new(table) }
|
9
|
-
|
10
|
-
context 'with rows' do
|
11
|
-
let(:table) { TTY::Table.new rows }
|
12
|
-
|
13
|
-
it 'displays table without styling' do
|
14
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
15
|
-
a1 a2 a3
|
16
|
-
b1 b2 b3
|
17
|
-
EOS
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with header and rows' do
|
22
|
-
it 'displays table with header' do
|
23
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
24
|
-
h1 h2 h3
|
25
|
-
a1 a2 a3
|
26
|
-
b1 b2 b3
|
27
|
-
EOS
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with short header' do
|
32
|
-
let(:header) { ['h1', 'h2'] }
|
33
|
-
let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
|
34
|
-
|
35
|
-
it 'displays table according to widths' do
|
36
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
37
|
-
h1 h2
|
38
|
-
aaa1 a2
|
39
|
-
b1 bb1
|
40
|
-
EOS
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'with long header' do
|
45
|
-
let(:header) { ['header1', 'header2', 'header3'] }
|
46
|
-
|
47
|
-
it 'header greater than row sizes' do
|
48
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
49
|
-
header1 header2 header3
|
50
|
-
a1 a2 a3
|
51
|
-
b1 b2 b3
|
52
|
-
EOS
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|