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,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Border, '#new' do
|
4
|
-
let(:row) { [] }
|
5
|
-
|
6
|
-
subject(:instance) { klass.new row, [0,0,0,0] }
|
7
|
-
|
8
|
-
context 'when abstract' do
|
9
|
-
let(:klass) { described_class }
|
10
|
-
|
11
|
-
it { expect { instance }.to raise_error(NotImplementedError) }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when concrete' do
|
15
|
-
let(:klass) {
|
16
|
-
Class.new do
|
17
|
-
def initialize(row, padding); end
|
18
|
-
end
|
19
|
-
}
|
20
|
-
|
21
|
-
it { expect { instance }.to_not raise_error() }
|
22
|
-
|
23
|
-
it { is_expected.to be_instance_of klass }
|
24
|
-
end
|
25
|
-
end
|
@@ -1,128 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Border::Null, '#rendering' do
|
4
|
-
let(:border) { nil }
|
5
|
-
|
6
|
-
subject { described_class.new column_widths, border }
|
7
|
-
|
8
|
-
context 'with empty row' do
|
9
|
-
let(:row) { TTY::Table::Row.new([]) }
|
10
|
-
let(:column_widths) { [] }
|
11
|
-
|
12
|
-
it 'draws top line' do
|
13
|
-
expect(subject.top_line).to be_nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'draws middle line' do
|
17
|
-
expect(subject.separator).to be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'draw bottom line' do
|
21
|
-
expect(subject.bottom_line).to be_nil
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'draws row line' do
|
25
|
-
expect(subject.row_line(row)).to eq('')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with row' do
|
30
|
-
let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
|
31
|
-
let(:column_widths) { [2,2,2] }
|
32
|
-
|
33
|
-
it 'draws top line' do
|
34
|
-
expect(subject.top_line).to be_nil
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'draw middle line' do
|
38
|
-
expect(subject.separator).to be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'draw bottom line' do
|
42
|
-
expect(subject.bottom_line).to be_nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'draws row line' do
|
46
|
-
expect(subject.row_line(row)).to eq('a1 a2 a3')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'with multiline row' do
|
51
|
-
let(:column_widths) { [2,2,2] }
|
52
|
-
|
53
|
-
context 'with mixed data' do
|
54
|
-
let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
|
55
|
-
|
56
|
-
it 'draws row line' do
|
57
|
-
expect(subject.row_line(row)).to eq unindent(<<-EOS)
|
58
|
-
a1 a2 a3
|
59
|
-
b1
|
60
|
-
c1
|
61
|
-
EOS
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'with sparse data' do
|
66
|
-
let(:row) { TTY::Table::Row.new(["a1\n\n", "\na2\n", "\n\na3"]) }
|
67
|
-
|
68
|
-
it 'draws row line' do
|
69
|
-
expect(subject.row_line(row)).to eq <<-EOS.chomp
|
70
|
-
a1
|
71
|
-
a2
|
72
|
-
a3
|
73
|
-
EOS
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'with empty data' do
|
78
|
-
let(:row) { TTY::Table::Row.new(["\na1\n", "\na2\n", "\na3\n"]) }
|
79
|
-
|
80
|
-
it 'draws row line' do
|
81
|
-
expect(subject.row_line(row)).to eq <<-EOS.chomp
|
82
|
-
|
83
|
-
a1 a2 a3
|
84
|
-
|
85
|
-
EOS
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'with border' do
|
91
|
-
let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
|
92
|
-
let(:column_widths) { [2,2,2] }
|
93
|
-
let(:border) { { :characters => {
|
94
|
-
'top' => '=',
|
95
|
-
'top_mid' => '=',
|
96
|
-
'top_left' => '=',
|
97
|
-
'top_right' => '=',
|
98
|
-
'bottom' => '=',
|
99
|
-
'bottom_mid' => '=',
|
100
|
-
'bottom_left' => '=',
|
101
|
-
'bottom_right' => '=',
|
102
|
-
'mid' => '=',
|
103
|
-
'mid_mid' => '=',
|
104
|
-
'mid_left' => '=',
|
105
|
-
'mid_right' => '=',
|
106
|
-
'left' => '=',
|
107
|
-
'center' => '=',
|
108
|
-
'right' => '='
|
109
|
-
} } }
|
110
|
-
|
111
|
-
|
112
|
-
it 'draws top line' do
|
113
|
-
expect(subject.top_line).to eql '=========='
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'draws separator line' do
|
117
|
-
expect(subject.separator).to eql '=========='
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'draws bottom line' do
|
121
|
-
expect(subject.bottom_line).to eql '=========='
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'draws row line' do
|
125
|
-
expect(subject.row_line(row)).to eql '=a1=a2=a3='
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::BorderOptions, '#from' do
|
4
|
-
|
5
|
-
subject(:options) { described_class.from object }
|
6
|
-
|
7
|
-
context 'when empty hash' do
|
8
|
-
let(:object) { {} }
|
9
|
-
|
10
|
-
it { expect(options.style).to be_nil }
|
11
|
-
|
12
|
-
it { expect(options.separator).to be_nil }
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when hash' do
|
16
|
-
let(:object) { { style: :red, separator: :none } }
|
17
|
-
|
18
|
-
it { expect(options).to be_kind_of(described_class) }
|
19
|
-
|
20
|
-
it { expect(options.style).to eql :red }
|
21
|
-
|
22
|
-
it { expect(options.separator).to eql :none }
|
23
|
-
|
24
|
-
it { expect(options.characters).to eql({}) }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when other BorderOptions' do
|
28
|
-
let(:object) { described_class.new(nil, nil, :blue) }
|
29
|
-
|
30
|
-
it { expect(options).to eql object }
|
31
|
-
|
32
|
-
it { expect(options.characters).to eql({}) }
|
33
|
-
|
34
|
-
it { expect(options.style).to eql :blue }
|
35
|
-
end
|
36
|
-
end # from
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::BorderOptions, '.new' do
|
4
|
-
|
5
|
-
subject(:options) { described_class.new }
|
6
|
-
|
7
|
-
it { expect(subject.characters).to eql({}) }
|
8
|
-
|
9
|
-
it { expect(subject.separator).to be_nil }
|
10
|
-
|
11
|
-
it { expect(subject.style).to be_nil }
|
12
|
-
end # new
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
|
4
|
-
|
5
|
-
subject(:border) { described_class.new(column_widths) }
|
6
|
-
|
7
|
-
context 'with empty row' do
|
8
|
-
let(:row) { TTY::Table::Row.new([]) }
|
9
|
-
let(:column_widths) { [] }
|
10
|
-
|
11
|
-
it 'draws top line' do
|
12
|
-
expect(border.top_line).to eq("┌┐")
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'draws middle line' do
|
16
|
-
expect(border.separator).to eq("├┤")
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'draw bottom line' do
|
20
|
-
expect(border.bottom_line).to eq("└┘")
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'draws row line' do
|
24
|
-
expect(border.row_line(row)).to eq("││")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'with row' do
|
29
|
-
let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
|
30
|
-
let(:column_widths) { [2,2,2] }
|
31
|
-
|
32
|
-
it 'draws top line' do
|
33
|
-
expect(border.top_line).to eq("┌──┬──┬──┐")
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'draw middle line' do
|
37
|
-
expect(border.separator).to eq("├──┼──┼──┤")
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'draw bottom line' do
|
41
|
-
expect(border.bottom_line).to eq("└──┴──┴──┘")
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'draws row line' do
|
45
|
-
expect(border.row_line(row)).to eq("│a1│a2│a3│")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'with multiline row' do
|
50
|
-
let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
|
51
|
-
let(:column_widths) { [2,2,2] }
|
52
|
-
|
53
|
-
it 'draws row line' do
|
54
|
-
expect(border.row_line(row)).to eq unindent(<<-EOS)
|
55
|
-
│a1│a2│a3│
|
56
|
-
│b1│ │ │
|
57
|
-
│c1│ │ │
|
58
|
-
EOS
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::BorderOptions do
|
4
|
-
|
5
|
-
subject { described_class.new(options) }
|
6
|
-
|
7
|
-
context 'with characters' do
|
8
|
-
let(:options) { {top: '**'} }
|
9
|
-
|
10
|
-
it { expect(subject.characters).to eq({top:'**'}) }
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'without characters' do
|
14
|
-
let(:options) { nil }
|
15
|
-
|
16
|
-
it { expect(subject.characters).to eq({}) }
|
17
|
-
end
|
18
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::BorderOptions, '.update' do
|
4
|
-
|
5
|
-
let(:object) { described_class.new }
|
6
|
-
|
7
|
-
let(:params) { {characters: {top: '*'}, separator: '|', style: :red} }
|
8
|
-
|
9
|
-
subject { object.update(params) }
|
10
|
-
|
11
|
-
it 'sets properties from hash object' do
|
12
|
-
expect(subject.characters).to eq({top: '*'})
|
13
|
-
expect(subject.separator).to eq('|')
|
14
|
-
expect(subject.style).to eq(:red)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::ColumnConstraint, '#enforce' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3', 'h4'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
|
8
|
-
subject(:columns) { described_class.new(table, renderer) }
|
9
|
-
|
10
|
-
context 'with width contraint' do
|
11
|
-
let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
|
12
|
-
let(:options) { { width: 5 }}
|
13
|
-
|
14
|
-
it 'raises error when table width is too small' do
|
15
|
-
expect {
|
16
|
-
columns.enforce
|
17
|
-
}.to raise_error(TTY::Table::ResizeError)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with width contraint matching natural width' do
|
22
|
-
let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
|
23
|
-
let(:options) { { width: 11, resize: true }}
|
24
|
-
|
25
|
-
it 'raises error when table width is too small' do
|
26
|
-
allow(columns).to receive(:expand_column_widths)
|
27
|
-
columns.enforce
|
28
|
-
expect(columns).to have_received(:expand_column_widths)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with table larger than allowed width' do
|
33
|
-
let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
|
34
|
-
|
35
|
-
context 'with resize' do
|
36
|
-
let(:options) { { width: 8, resize: true } }
|
37
|
-
|
38
|
-
it 'calls shrink' do
|
39
|
-
allow(columns).to receive(:shrink)
|
40
|
-
columns.enforce
|
41
|
-
expect(columns).to have_received(:shrink)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'without resize' do
|
46
|
-
let(:options) { { width: 8, resize: false }}
|
47
|
-
|
48
|
-
it 'changes table orientation to vertical' do
|
49
|
-
allow(Kernel).to receive(:warn)
|
50
|
-
expect(renderer.column_widths).to eql([2,2,2,2])
|
51
|
-
expect(table.orientation.name).to eql(:horizontal)
|
52
|
-
column_widths = columns.enforce
|
53
|
-
expect(column_widths).to eq([2,2])
|
54
|
-
expect(table.orientation.name).to eql(:vertical)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'with table less than allowed width' do
|
60
|
-
let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
|
61
|
-
let(:options) { { width: 15 }}
|
62
|
-
|
63
|
-
it "doesn't change original widths" do
|
64
|
-
allow(Kernel).to receive(:warn)
|
65
|
-
expect(renderer.column_widths).to eq([2,2,2,2])
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::ColumnConstraint, 'column widths' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3', 'h4'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
|
8
|
-
subject(:columns) { described_class.new(table, renderer) }
|
9
|
-
|
10
|
-
context 'with basic renderer' do
|
11
|
-
let(:renderer) { TTY::Table::Renderer::Basic.new(table) }
|
12
|
-
|
13
|
-
it 'calculates columns natural width' do
|
14
|
-
expect(columns.natural_width).to eq(11)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'calculates miminimum columns width' do
|
18
|
-
expect(columns.minimum_width).to eq(7)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with ascii renderer' do
|
23
|
-
let(:renderer) { TTY::Table::Renderer::ASCII.new(table) }
|
24
|
-
|
25
|
-
it 'calculates columns natural width' do
|
26
|
-
expect(columns.natural_width).to eq(13)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'calculates miminimum columns width' do
|
30
|
-
expect(columns.minimum_width).to eq(9)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Columns, '#extract_widths' do
|
4
|
-
let(:color) { Pastel.new(enabled: true) }
|
5
|
-
|
6
|
-
it 'extract widths' do
|
7
|
-
header = ['h1', 'h2', 'h3']
|
8
|
-
rows = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
|
9
|
-
table = TTY::Table.new(header, rows)
|
10
|
-
expect(described_class.extract_widths(table.data)).to eql([2,2,2])
|
11
|
-
end
|
12
|
-
|
13
|
-
it "extracts widths from utf" do
|
14
|
-
header = ['h1', 'うなじ']
|
15
|
-
rows = [['こんにちは', 'a2'], ['b1','選択']]
|
16
|
-
table = TTY::Table.new(header, rows)
|
17
|
-
expect(described_class.extract_widths(table.data)).to eql([10,6])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "extracts widths from multiline text" do
|
21
|
-
table = TTY::Table.new
|
22
|
-
table << ["Multi\nLine\nContent", "Text\nthat\nwraps"]
|
23
|
-
table << ["Some\nother\ntext", 'Simple']
|
24
|
-
expect(described_class.extract_widths(table.data)).to eq([7,6])
|
25
|
-
end
|
26
|
-
|
27
|
-
it "extracts widths from multiline text" do
|
28
|
-
table = TTY::Table.new
|
29
|
-
table << ["Multi\\nLine\\nContent", "Text\\nthat\\nwraps"]
|
30
|
-
table << ["Some\\nother\\ntext", 'Simple']
|
31
|
-
expect(described_class.extract_widths(table.data)).to eq([20, 17])
|
32
|
-
end
|
33
|
-
|
34
|
-
it "extracts widths from ANSI text" do
|
35
|
-
header = [color.green('h1'), 'h2']
|
36
|
-
table = TTY::Table.new header: header
|
37
|
-
table << [color.green.on_blue('a1'), 'a2']
|
38
|
-
table << ['b1', color.red.on_yellow('b2')]
|
39
|
-
expect(described_class.extract_widths(table.data)).to eq([2,2])
|
40
|
-
end
|
41
|
-
end
|