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