tty-table 0.7.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +57 -0
- data/LICENSE.txt +1 -1
- data/README.md +165 -94
- data/lib/tty-table.rb +1 -5
- data/lib/tty/table.rb +102 -42
- data/lib/tty/table/alignment_set.rb +3 -6
- data/lib/tty/table/border.rb +57 -68
- data/lib/tty/table/border/ascii.rb +17 -17
- data/lib/tty/table/border/null.rb +20 -22
- data/lib/tty/table/border/row_line.rb +4 -3
- data/lib/tty/table/border/unicode.rb +17 -17
- data/lib/tty/table/border_dsl.rb +28 -25
- data/lib/tty/table/border_options.rb +50 -25
- data/lib/tty/table/column_constraint.rb +29 -17
- data/lib/tty/table/{column_set.rb → columns.rb} +44 -69
- data/lib/tty/table/empty.rb +2 -0
- data/lib/tty/table/error.rb +1 -1
- data/lib/tty/table/field.rb +43 -35
- data/lib/tty/table/header.rb +7 -5
- data/lib/tty/table/indentation.rb +16 -25
- data/lib/tty/table/operation/alignment.rb +10 -8
- data/lib/tty/table/operation/escape.rb +2 -3
- data/lib/tty/table/operation/filter.rb +1 -1
- data/lib/tty/table/operation/padding.rb +4 -12
- data/lib/tty/table/operation/truncation.rb +4 -4
- data/lib/tty/table/operation/wrapped.rb +4 -4
- data/lib/tty/table/operations.rb +4 -15
- data/lib/tty/table/options.rb +2 -4
- data/lib/tty/table/orientation.rb +5 -5
- data/lib/tty/table/orientation/horizontal.rb +1 -1
- data/lib/tty/table/orientation/vertical.rb +1 -1
- data/lib/tty/table/renderer.rb +40 -35
- data/lib/tty/table/renderer/ascii.rb +4 -4
- data/lib/tty/table/renderer/basic.rb +85 -88
- data/lib/tty/table/renderer/unicode.rb +3 -3
- data/lib/tty/table/row.rb +10 -8
- data/lib/tty/table/transformation.rb +2 -2
- data/lib/tty/table/validatable.rb +25 -7
- data/lib/tty/table/version.rb +3 -3
- metadata +33 -283
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -24
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -18
- data/Rakefile +0 -8
- data/benchmarks/speed.rb +0 -41
- data/spec/spec_helper.rb +0 -50
- data/spec/unit/access_spec.rb +0 -86
- data/spec/unit/add_row_spec.rb +0 -28
- data/spec/unit/alignment_set/each_spec.rb +0 -17
- data/spec/unit/alignment_set/new_spec.rb +0 -27
- data/spec/unit/alignment_set/to_ary_spec.rb +0 -14
- data/spec/unit/alignment_spec.rb +0 -71
- data/spec/unit/border/ascii/rendering_spec.rb +0 -90
- data/spec/unit/border/new_spec.rb +0 -27
- data/spec/unit/border/null/rendering_spec.rb +0 -130
- data/spec/unit/border/options/from_spec.rb +0 -38
- data/spec/unit/border/options/new_spec.rb +0 -14
- data/spec/unit/border/unicode/rendering_spec.rb +0 -63
- data/spec/unit/border_options/new_spec.rb +0 -20
- data/spec/unit/border_options/update_spec.rb +0 -18
- data/spec/unit/column_constraint/enforce_spec.rb +0 -70
- data/spec/unit/column_constraint/widths_spec.rb +0 -35
- data/spec/unit/column_set/extract_widths_spec.rb +0 -48
- data/spec/unit/column_set/total_width_spec.rb +0 -15
- data/spec/unit/column_set/widths_from_spec.rb +0 -51
- data/spec/unit/data_spec.rb +0 -12
- data/spec/unit/each_spec.rb +0 -26
- data/spec/unit/each_with_index_spec.rb +0 -51
- data/spec/unit/empty_spec.rb +0 -23
- data/spec/unit/eql_spec.rb +0 -34
- data/spec/unit/field/equality_spec.rb +0 -51
- data/spec/unit/field/length_spec.rb +0 -35
- data/spec/unit/field/lines_spec.rb +0 -21
- data/spec/unit/field/new_spec.rb +0 -29
- data/spec/unit/field/width_spec.rb +0 -23
- data/spec/unit/filter_spec.rb +0 -22
- data/spec/unit/header/call_spec.rb +0 -30
- data/spec/unit/header/color_spec.rb +0 -19
- data/spec/unit/header/equality_spec.rb +0 -51
- data/spec/unit/header/height_spec.rb +0 -27
- data/spec/unit/header/new_spec.rb +0 -16
- data/spec/unit/header/set_spec.rb +0 -20
- data/spec/unit/header/to_ary_spec.rb +0 -14
- data/spec/unit/header_spec.rb +0 -13
- data/spec/unit/indentation/indent_spec.rb +0 -21
- data/spec/unit/new_spec.rb +0 -73
- data/spec/unit/operation/alignment/call_spec.rb +0 -39
- data/spec/unit/operation/escape/call_spec.rb +0 -15
- data/spec/unit/operation/filter/call_spec.rb +0 -16
- data/spec/unit/operation/truncation/call_spec.rb +0 -30
- data/spec/unit/operation/wrapped/call_spec.rb +0 -40
- data/spec/unit/operations/new_spec.rb +0 -30
- data/spec/unit/options/access_spec.rb +0 -14
- data/spec/unit/options_spec.rb +0 -25
- data/spec/unit/orientation_spec.rb +0 -145
- data/spec/unit/padding_spec.rb +0 -117
- data/spec/unit/properties_spec.rb +0 -25
- data/spec/unit/render_repeat_spec.rb +0 -42
- data/spec/unit/render_spec.rb +0 -63
- data/spec/unit/render_with_spec.rb +0 -106
- data/spec/unit/renderer/ascii/coloring_spec.rb +0 -70
- data/spec/unit/renderer/ascii/indentation_spec.rb +0 -41
- data/spec/unit/renderer/ascii/multiline_spec.rb +0 -101
- data/spec/unit/renderer/ascii/padding_spec.rb +0 -88
- data/spec/unit/renderer/ascii/render_spec.rb +0 -68
- data/spec/unit/renderer/ascii/resizing_spec.rb +0 -114
- data/spec/unit/renderer/ascii/separator_spec.rb +0 -28
- data/spec/unit/renderer/basic/alignment_spec.rb +0 -88
- data/spec/unit/renderer/basic/coloring_spec.rb +0 -61
- data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -28
- data/spec/unit/renderer/basic/filter_spec.rb +0 -53
- data/spec/unit/renderer/basic/indentation_spec.rb +0 -48
- data/spec/unit/renderer/basic/multiline_spec.rb +0 -74
- data/spec/unit/renderer/basic/new_spec.rb +0 -26
- data/spec/unit/renderer/basic/options_spec.rb +0 -52
- data/spec/unit/renderer/basic/padding_spec.rb +0 -76
- data/spec/unit/renderer/basic/render_spec.rb +0 -57
- data/spec/unit/renderer/basic/resizing_spec.rb +0 -96
- data/spec/unit/renderer/basic/separator_spec.rb +0 -43
- data/spec/unit/renderer/basic/truncation_spec.rb +0 -35
- data/spec/unit/renderer/basic/wrapping_spec.rb +0 -40
- data/spec/unit/renderer/border_spec.rb +0 -104
- data/spec/unit/renderer/render_spec.rb +0 -36
- data/spec/unit/renderer/select_spec.rb +0 -22
- data/spec/unit/renderer/unicode/coloring_spec.rb +0 -70
- data/spec/unit/renderer/unicode/indentation_spec.rb +0 -41
- data/spec/unit/renderer/unicode/padding_spec.rb +0 -61
- data/spec/unit/renderer/unicode/render_spec.rb +0 -68
- data/spec/unit/renderer/unicode/separator_spec.rb +0 -26
- data/spec/unit/renderer_spec.rb +0 -19
- data/spec/unit/rotate_spec.rb +0 -86
- data/spec/unit/row/access_spec.rb +0 -25
- data/spec/unit/row/call_spec.rb +0 -45
- data/spec/unit/row/data_spec.rb +0 -26
- data/spec/unit/row/each_spec.rb +0 -31
- data/spec/unit/row/equality_spec.rb +0 -73
- data/spec/unit/row/height_spec.rb +0 -27
- data/spec/unit/row/new_spec.rb +0 -41
- data/spec/unit/row/to_ary_spec.rb +0 -14
- data/spec/unit/to_s_spec.rb +0 -56
- data/spec/unit/transformation/extract_tuples_spec.rb +0 -35
- data/spec/unit/utf_spec.rb +0 -33
- data/spec/unit/validatable/validate_options_spec.rb +0 -33
- data/spec/unit/validatable_spec.rb +0 -32
- data/tasks/console.rake +0 -10
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-table.gemspec +0 -30
@@ -1,48 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'indentation' do
|
6
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:table) { TTY::Table.new(header, rows) }
|
9
|
-
let(:options) { {indent: indent } }
|
10
|
-
|
11
|
-
subject(:renderer) { described_class.new(table, options)}
|
12
|
-
|
13
|
-
context 'when default' do
|
14
|
-
let(:indent) { 0 }
|
15
|
-
|
16
|
-
it 'indents by value' do
|
17
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
18
|
-
h1 h2 h3
|
19
|
-
a1 a2 a3
|
20
|
-
b1 b2 b3
|
21
|
-
EOS
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when custom' do
|
26
|
-
let(:indent) { 2 }
|
27
|
-
|
28
|
-
it 'indents by value' do
|
29
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
30
|
-
h1 h2 h3
|
31
|
-
a1 a2 a3
|
32
|
-
b1 b2 b3
|
33
|
-
EOS
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when changed' do
|
38
|
-
let(:indent) { 2 }
|
39
|
-
let(:header) { ['h1', 'h2'] }
|
40
|
-
let(:rows) { [['a1', 'a2']] }
|
41
|
-
|
42
|
-
it 'changes indentation and reuses renderer' do
|
43
|
-
expect(renderer.render).to eq(" h1 h2\n a1 a2")
|
44
|
-
renderer.indent = 1
|
45
|
-
expect(renderer.render).to eq(" h1 h2\n a1 a2")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'multiline content' do
|
6
|
-
context 'with escaping' do
|
7
|
-
it "renders multiline as single line" do
|
8
|
-
rows = [ ["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']]
|
9
|
-
table = TTY::Table.new rows
|
10
|
-
renderer = described_class.new(table, multiline: false)
|
11
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
12
|
-
First 1
|
13
|
-
Multiline\\nContent 2
|
14
|
-
Third 3
|
15
|
-
EOS
|
16
|
-
end
|
17
|
-
|
18
|
-
it "truncates multiline content" do
|
19
|
-
rows = [ ["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']]
|
20
|
-
table = TTY::Table.new rows
|
21
|
-
renderer = described_class.new(table, multiline: false, column_widths: [8,1])
|
22
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
23
|
-
First 1
|
24
|
-
Multil… 2
|
25
|
-
Third 3
|
26
|
-
EOS
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'without escaping' do
|
31
|
-
it "renders every line" do
|
32
|
-
rows = [["First", '1'],
|
33
|
-
["Multi\nLine\nContent", '2'],
|
34
|
-
["Third", "Multi\nLine"]]
|
35
|
-
table = TTY::Table.new rows
|
36
|
-
renderer = described_class.new(table, multiline: true)
|
37
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
38
|
-
First 1
|
39
|
-
Multi 2
|
40
|
-
Line
|
41
|
-
Content
|
42
|
-
Third Multi
|
43
|
-
Line
|
44
|
-
EOS
|
45
|
-
end
|
46
|
-
|
47
|
-
it "renders multiline with column widths" do
|
48
|
-
rows = [["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']]
|
49
|
-
table = TTY::Table.new rows
|
50
|
-
renderer = described_class.new(table, multiline: true, column_widths: [8,1])
|
51
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
52
|
-
First 1
|
53
|
-
Multi 2
|
54
|
-
Line
|
55
|
-
Content
|
56
|
-
Third 3
|
57
|
-
EOS
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'wraps multi line' do
|
61
|
-
rows = [["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']]
|
62
|
-
table = TTY::Table.new rows
|
63
|
-
renderer = described_class.new(table, multiline: true, column_widths: [5,1])
|
64
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
65
|
-
First 1
|
66
|
-
Multi 2
|
67
|
-
Line
|
68
|
-
Conte
|
69
|
-
nt
|
70
|
-
Third 3
|
71
|
-
EOS
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, '.new' do
|
6
|
-
let(:header) { ['h1'] }
|
7
|
-
let(:rows) { [['a1']] }
|
8
|
-
|
9
|
-
subject(:renderer) { described_class }
|
10
|
-
|
11
|
-
context 'without table' do
|
12
|
-
let(:table) { nil }
|
13
|
-
|
14
|
-
it {
|
15
|
-
expect {
|
16
|
-
renderer.new(table)
|
17
|
-
}.to raise_error(TTY::Table::ArgumentRequired)
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with table' do
|
22
|
-
let(:table) { TTY::Table.new(header, rows) }
|
23
|
-
|
24
|
-
it { expect { renderer.new(table) }.not_to raise_error }
|
25
|
-
end
|
26
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'options' do
|
6
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
7
|
-
let(:object) { described_class }
|
8
|
-
let(:table) { TTY::Table.new(rows) }
|
9
|
-
let(:widths) { nil }
|
10
|
-
let(:alignments) { [] }
|
11
|
-
let(:options) {
|
12
|
-
{
|
13
|
-
column_widths: widths,
|
14
|
-
alignments: alignments,
|
15
|
-
renderer: :basic
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
subject(:renderer) { object.new table, options }
|
20
|
-
|
21
|
-
it { expect(renderer.border).to be_kind_of(TTY::Table::BorderOptions) }
|
22
|
-
|
23
|
-
it { expect(renderer.column_widths).to eql([2,2]) }
|
24
|
-
|
25
|
-
it { expect(renderer.alignments.to_a).to eql(alignments) }
|
26
|
-
|
27
|
-
it { expect(renderer.alignments.to_a).to be_empty }
|
28
|
-
|
29
|
-
context '#column_widths' do
|
30
|
-
let(:widths) { [10, 10] }
|
31
|
-
|
32
|
-
it { expect(renderer.column_widths).to eq(widths) }
|
33
|
-
end
|
34
|
-
|
35
|
-
context '#column_widths empty' do
|
36
|
-
let(:widths) { [] }
|
37
|
-
|
38
|
-
it {
|
39
|
-
expect {
|
40
|
-
renderer.column_widths
|
41
|
-
}.to raise_error(TTY::Table::InvalidArgument)
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
context '#alignments' do
|
46
|
-
let(:alignments) { [:center, :center] }
|
47
|
-
|
48
|
-
it 'unwraps original array' do
|
49
|
-
expect(renderer.alignments.to_a).to eq(alignments)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'padding' do
|
6
|
-
let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
|
7
|
-
let(:rows) { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
|
8
|
-
let(:table) { TTY::Table.new(header, rows) }
|
9
|
-
|
10
|
-
subject(:renderer) { described_class.new(table, options) }
|
11
|
-
|
12
|
-
context 'with left & right padding' do
|
13
|
-
let(:options) { {padding: [0,1,0,1]} }
|
14
|
-
|
15
|
-
it 'pads each field' do
|
16
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
17
|
-
Field Type Null Key Default Extra
|
18
|
-
id int(11) YES nil NULL
|
19
|
-
EOS
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'with top & bottom padding' do
|
24
|
-
let(:options) { {padding: [1,0,1,0]} }
|
25
|
-
|
26
|
-
it 'pads each field' do
|
27
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
28
|
-
|
29
|
-
Field Type Null Key Default Extra
|
30
|
-
|
31
|
-
|
32
|
-
id int(11) YES nil NULL
|
33
|
-
|
34
|
-
EOS
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'with full padding' do
|
39
|
-
let(:options) { {padding: [1,1,1,1]} }
|
40
|
-
|
41
|
-
it 'pads each field' do
|
42
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
43
|
-
|
44
|
-
Field Type Null Key Default Extra
|
45
|
-
|
46
|
-
|
47
|
-
id int(11) YES nil NULL
|
48
|
-
|
49
|
-
EOS
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "with multiline content padding" do
|
54
|
-
it "pads around fields" do
|
55
|
-
padding = [1,2,1,2]
|
56
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
57
|
-
table << ["a1\na1\na1",'a2']
|
58
|
-
table << ["b1","b2\nb2"]
|
59
|
-
renderer = TTY::Table::Renderer::Basic.new(table, padding: padding, multiline: true)
|
60
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
61
|
-
|
62
|
-
header1 header2
|
63
|
-
|
64
|
-
|
65
|
-
a1 a2
|
66
|
-
a1
|
67
|
-
a1
|
68
|
-
|
69
|
-
|
70
|
-
b1 b2
|
71
|
-
b2
|
72
|
-
|
73
|
-
EOS
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, '#render' do
|
6
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:table) { TTY::Table.new header, rows }
|
9
|
-
|
10
|
-
subject(:renderer) { described_class.new(table) }
|
11
|
-
|
12
|
-
context 'with rows' do
|
13
|
-
let(:table) { TTY::Table.new rows }
|
14
|
-
|
15
|
-
it 'displays table without styling' do
|
16
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
17
|
-
a1 a2 a3
|
18
|
-
b1 b2 b3
|
19
|
-
EOS
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'with header and rows' do
|
24
|
-
it 'displays table with header' do
|
25
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
26
|
-
h1 h2 h3
|
27
|
-
a1 a2 a3
|
28
|
-
b1 b2 b3
|
29
|
-
EOS
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'with short header' do
|
34
|
-
let(:header) { ['h1', 'h2'] }
|
35
|
-
let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
|
36
|
-
|
37
|
-
it 'displays table according to widths' do
|
38
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
39
|
-
h1 h2
|
40
|
-
aaa1 a2
|
41
|
-
b1 bb1
|
42
|
-
EOS
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'with long header' do
|
47
|
-
let(:header) { ['header1', 'header2', 'header3'] }
|
48
|
-
|
49
|
-
it 'header greater than row sizes' do
|
50
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
51
|
-
header1 header2 header3
|
52
|
-
a1 a2 a3
|
53
|
-
b1 b2 b3
|
54
|
-
EOS
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'resizing' do
|
6
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:table) { TTY::Table.new(header, rows) }
|
9
|
-
|
10
|
-
subject(:renderer) { described_class.new(table, options) }
|
11
|
-
|
12
|
-
context 'when expanding' do
|
13
|
-
context 'even columns' do
|
14
|
-
let(:options) { {width: 16, resize: true} }
|
15
|
-
|
16
|
-
it 'resizes each column' do
|
17
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
18
|
-
h1 h2 h3
|
19
|
-
a1 a2 a3
|
20
|
-
b1 b2 b3
|
21
|
-
EOS
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'even columns with extra width' do
|
26
|
-
let(:header) { ['h1', 'h2', 'h3', 'h4'] }
|
27
|
-
let(:rows) { [['a1','a2','a3','a4'], ['b1','b2','b3','b4']] }
|
28
|
-
let(:options) { {width: 21, resize: true} }
|
29
|
-
|
30
|
-
it 'resizes each column' do
|
31
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
32
|
-
h1 h2 h3 h4
|
33
|
-
a1 a2 a3 a4
|
34
|
-
b1 b2 b3 b4
|
35
|
-
EOS
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'uneven columns' do
|
40
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
41
|
-
let(:rows) { [['aaa1', 'aa2', 'aaaaaaa3'], ['b1', 'b2', 'b3']] }
|
42
|
-
let(:options) { {width: 32, resize: true} }
|
43
|
-
|
44
|
-
it 'resizes each column' do
|
45
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
46
|
-
h1 h2 h3
|
47
|
-
aaa1 aa2 aaaaaaa3
|
48
|
-
b1 b2 b3
|
49
|
-
EOS
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when shrinking' do
|
55
|
-
let(:header) { ['head1', 'head2'] }
|
56
|
-
let(:rows) { [['aaaa1','aaaa2',], ['bbbb1','bbbb2']] }
|
57
|
-
|
58
|
-
context 'even columns' do
|
59
|
-
let(:options) { {width: 8, resize: true} }
|
60
|
-
|
61
|
-
it 'resizes each column' do
|
62
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
63
|
-
he… h…
|
64
|
-
aa… a…
|
65
|
-
bb… b…
|
66
|
-
EOS
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'even columns with extra width' do
|
71
|
-
let(:options) { {width: 9, resize: true} }
|
72
|
-
|
73
|
-
it 'resizes each column' do
|
74
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
75
|
-
he… he…
|
76
|
-
aa… aa…
|
77
|
-
bb… bb…
|
78
|
-
EOS
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'uneven columns' do
|
83
|
-
let(:header) { ['head1', 'head2', 'head3'] }
|
84
|
-
let(:rows) { [['aaa1', 'aa2', 'aaaaaaa3'], ['b1', 'b2', 'b3']] }
|
85
|
-
let(:options) { {width: 16, resize: true} }
|
86
|
-
|
87
|
-
it 'resizes each column' do
|
88
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
89
|
-
he… he… head3
|
90
|
-
aaa1 aa2 aaaa…
|
91
|
-
b1 b2 b3
|
92
|
-
EOS
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::Renderer::Basic, 'with separator' do
|
6
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:table) { TTY::Table.new(header, rows) }
|
9
|
-
|
10
|
-
let(:object) { described_class.new table }
|
11
|
-
|
12
|
-
subject(:renderer) { object }
|
13
|
-
|
14
|
-
context 'when default' do
|
15
|
-
it "sets through hash" do
|
16
|
-
renderer.border :separator => :each_row
|
17
|
-
expect(renderer.border.separator).to eql(:each_row)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "sets through attribute" do
|
21
|
-
renderer.border.separator= :each_row
|
22
|
-
expect(renderer.border.separator).to eql(:each_row)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "sets through block" do
|
26
|
-
renderer.border do
|
27
|
-
separator :each_row
|
28
|
-
end
|
29
|
-
expect(renderer.border.separator).to eql(:each_row)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "renders each row" do
|
33
|
-
renderer.border.separator= :each_row
|
34
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
35
|
-
h1 h2 h3
|
36
|
-
|
37
|
-
a1 a2 a3
|
38
|
-
|
39
|
-
b1 b2 b3
|
40
|
-
EOS
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|