tty-table 0.1.0 → 0.2.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 +24 -0
- data/README.md +458 -142
- data/lib/tty-table.rb +6 -6
- data/lib/tty/table.rb +34 -34
- data/lib/tty/table/alignment_set.rb +73 -0
- data/lib/tty/table/border.rb +54 -36
- data/lib/tty/table/border/null.rb +4 -4
- data/lib/tty/table/{columns.rb → column_constraint.rb} +30 -32
- data/lib/tty/table/column_set.rb +18 -17
- data/lib/tty/table/field.rb +50 -25
- data/lib/tty/table/header.rb +6 -2
- data/lib/tty/table/indentation.rb +7 -12
- data/lib/tty/table/operation/alignment.rb +59 -0
- data/lib/tty/table/operation/escape.rb +1 -1
- data/lib/tty/table/operation/filter.rb +1 -1
- data/lib/tty/table/operation/padding.rb +12 -61
- data/lib/tty/table/operation/truncation.rb +2 -2
- data/lib/tty/table/operation/wrapped.rb +2 -5
- data/lib/tty/table/operations.rb +35 -17
- data/lib/tty/table/orientation/vertical.rb +4 -4
- data/lib/tty/table/renderer.rb +1 -7
- data/lib/tty/table/renderer/basic.rb +69 -63
- data/lib/tty/table/version.rb +1 -1
- data/spec/spec_helper.rb +3 -4
- data/spec/unit/access_spec.rb +8 -8
- data/spec/unit/{operation/alignment_set → alignment_set}/each_spec.rb +1 -1
- data/spec/unit/{operation/alignment_set → alignment_set}/new_spec.rb +4 -4
- data/spec/unit/{operation/alignment_set → alignment_set}/to_ary_spec.rb +1 -1
- data/spec/unit/alignment_spec.rb +71 -0
- data/spec/unit/border/ascii/rendering_spec.rb +12 -12
- data/spec/unit/border/new_spec.rb +2 -2
- data/spec/unit/border/null/rendering_spec.rb +2 -2
- data/spec/unit/border/unicode/rendering_spec.rb +10 -10
- data/spec/unit/{columns → column_constraint}/enforce_spec.rb +15 -12
- data/spec/unit/{columns → column_constraint}/widths_spec.rb +6 -6
- data/spec/unit/column_set/extract_widths_spec.rb +39 -6
- data/spec/unit/data_spec.rb +4 -6
- data/spec/unit/each_spec.rb +8 -23
- data/spec/unit/each_with_index_spec.rb +27 -33
- data/spec/unit/field/length_spec.rb +23 -9
- data/spec/unit/field/width_spec.rb +1 -1
- data/spec/unit/filter_spec.rb +7 -8
- data/spec/unit/header/new_spec.rb +6 -15
- data/spec/unit/indentation/indent_spec.rb +21 -0
- data/spec/unit/new_spec.rb +73 -0
- data/spec/unit/operation/{alignment_set → alignment}/call_spec.rb +1 -1
- data/spec/unit/operation/escape/call_spec.rb +2 -3
- data/spec/unit/operation/filter/call_spec.rb +2 -3
- data/spec/unit/operation/truncation/call_spec.rb +6 -8
- data/spec/unit/operation/wrapped/call_spec.rb +15 -8
- data/spec/unit/operations/new_spec.rb +1 -1
- data/spec/unit/orientation_spec.rb +6 -6
- data/spec/unit/padding_spec.rb +29 -32
- data/spec/unit/properties_spec.rb +4 -4
- data/spec/unit/render_repeat_spec.rb +42 -0
- data/spec/unit/render_spec.rb +1 -1
- data/spec/unit/render_with_spec.rb +3 -3
- data/spec/unit/renderer/ascii/coloring_spec.rb +70 -0
- data/spec/unit/renderer/ascii/multiline_spec.rb +101 -0
- data/spec/unit/renderer/ascii/padding_spec.rb +37 -10
- data/spec/unit/renderer/ascii/render_spec.rb +4 -4
- data/spec/unit/renderer/ascii/resizing_spec.rb +22 -22
- data/spec/unit/renderer/ascii/separator_spec.rb +1 -1
- data/spec/unit/renderer/basic/alignment_spec.rb +20 -20
- data/spec/unit/renderer/basic/coloring_spec.rb +43 -28
- data/spec/unit/renderer/basic/filter_spec.rb +3 -3
- data/spec/unit/renderer/basic/multiline_spec.rb +74 -0
- data/spec/unit/renderer/basic/options_spec.rb +9 -9
- data/spec/unit/renderer/basic/padding_spec.rb +26 -2
- data/spec/unit/renderer/basic/render_spec.rb +4 -4
- data/spec/unit/renderer/basic/resizing_spec.rb +18 -18
- data/spec/unit/renderer/basic/separator_spec.rb +1 -1
- data/spec/unit/renderer/basic/truncation_spec.rb +6 -6
- data/spec/unit/renderer/basic/wrapping_spec.rb +3 -3
- data/spec/unit/renderer/border_spec.rb +4 -4
- data/spec/unit/renderer/unicode/coloring_spec.rb +70 -0
- data/spec/unit/renderer/unicode/indentation_spec.rb +1 -1
- data/spec/unit/renderer/unicode/padding_spec.rb +26 -26
- data/spec/unit/renderer/unicode/render_spec.rb +4 -4
- data/spec/unit/renderer/unicode/separator_spec.rb +1 -1
- data/spec/unit/to_s_spec.rb +4 -11
- data/spec/unit/utf_spec.rb +33 -0
- data/tty-table.gemspec +2 -1
- metadata +52 -32
- data/lib/tty/table/operation/alignment_set.rb +0 -103
- data/lib/tty/table/padder.rb +0 -180
- data/lib/tty/table/renderer/color.rb +0 -12
- data/spec/unit/indentation/insert_indent_spec.rb +0 -27
- data/spec/unit/initialize_spec.rb +0 -88
- data/spec/unit/padder/parse_spec.rb +0 -45
- data/spec/unit/padder/to_s_spec.rb +0 -14
- data/spec/unit/renderer/basic/multiline_content_spec.rb +0 -135
- data/spec/unit/renderer/style_spec.rb +0 -72
@@ -45,16 +45,43 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'padding' do
|
|
45
45
|
let(:options) { {padding: [1,1,1,1], multiline: true} }
|
46
46
|
|
47
47
|
it 'pads each field' do
|
48
|
-
expect(renderer.render).to eql <<-EOS
|
49
|
-
+-------+---------+------+-----+---------+-------+
|
50
|
-
| | | | | | |
|
51
|
-
| Field | Type | Null | Key | Default | Extra |
|
52
|
-
| | | | | | |
|
53
|
-
+-------+---------+------+-----+---------+-------+
|
54
|
-
| | | | | | |
|
55
|
-
| id | int(11) | YES | nil | NULL | |
|
56
|
-
| | | | | | |
|
57
|
-
+-------+---------+------+-----+---------+-------+
|
48
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
49
|
+
+-------+---------+------+-----+---------+-------+
|
50
|
+
| | | | | | |
|
51
|
+
| Field | Type | Null | Key | Default | Extra |
|
52
|
+
| | | | | | |
|
53
|
+
+-------+---------+------+-----+---------+-------+
|
54
|
+
| | | | | | |
|
55
|
+
| id | int(11) | YES | nil | NULL | |
|
56
|
+
| | | | | | |
|
57
|
+
+-------+---------+------+-----+---------+-------+
|
58
|
+
EOS
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "with multiline content padding" do
|
63
|
+
it "pads around fields" do
|
64
|
+
padding = [1,2,1,2]
|
65
|
+
table = TTY::Table.new header: ['header1', 'header2']
|
66
|
+
table << ["a1\na1\na1",'a2']
|
67
|
+
table << ["b1","b2\nb2"]
|
68
|
+
renderer = described_class.new(table, padding: padding, multiline: true)
|
69
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
70
|
+
+-----------+-----------+
|
71
|
+
| | |
|
72
|
+
| header1 | header2 |
|
73
|
+
| | |
|
74
|
+
+-----------+-----------+
|
75
|
+
| | |
|
76
|
+
| a1 | a2 |
|
77
|
+
| a1 | |
|
78
|
+
| a1 | |
|
79
|
+
| | |
|
80
|
+
| | |
|
81
|
+
| b1 | b2 |
|
82
|
+
| | b2 |
|
83
|
+
| | |
|
84
|
+
+-----------+-----------+
|
58
85
|
EOS
|
59
86
|
end
|
60
87
|
end
|
@@ -13,7 +13,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, '#render' do
|
|
13
13
|
let(:table) { TTY::Table.new rows }
|
14
14
|
|
15
15
|
it 'display table rows' do
|
16
|
-
expect(renderer.render).to eq <<-EOS
|
16
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
17
17
|
+--+--+--+
|
18
18
|
|a1|a2|a3|
|
19
19
|
|b1|b2|b3|
|
@@ -24,7 +24,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, '#render' do
|
|
24
24
|
|
25
25
|
context 'with header' do
|
26
26
|
it 'displays table with header' do
|
27
|
-
expect(renderer.render).to eq <<-EOS
|
27
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
28
28
|
+--+--+--+
|
29
29
|
|h1|h2|h3|
|
30
30
|
+--+--+--+
|
@@ -40,7 +40,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, '#render' do
|
|
40
40
|
let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
|
41
41
|
|
42
42
|
it 'displays table according to widths' do
|
43
|
-
expect(renderer.render).to eq <<-EOS
|
43
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
44
44
|
+----+---+
|
45
45
|
|h1 |h2 |
|
46
46
|
+----+---+
|
@@ -55,7 +55,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, '#render' do
|
|
55
55
|
let(:header) { ['header1', 'header2', 'header3'] }
|
56
56
|
|
57
57
|
it 'header greater than row sizes' do
|
58
|
-
expect(renderer.render).to eq <<-EOS
|
58
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
59
59
|
+-------+-------+-------+
|
60
60
|
|header1|header2|header3|
|
61
61
|
+-------+-------+-------+
|
@@ -14,7 +14,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'resizing' do
|
|
14
14
|
let(:options) { {width: 16, resize: true} }
|
15
15
|
|
16
16
|
it 'resizes each column' do
|
17
|
-
expect(renderer.render).to eql <<-EOS
|
17
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
18
18
|
+----+----+----+
|
19
19
|
|h1 |h2 |h3 |
|
20
20
|
+----+----+----+
|
@@ -31,7 +31,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'resizing' do
|
|
31
31
|
let(:options) { {width: 21, resize: true} }
|
32
32
|
|
33
33
|
it 'resizes each column' do
|
34
|
-
expect(renderer.render).to eql <<-EOS
|
34
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
35
35
|
+----+----+----+----+
|
36
36
|
|h1 |h2 |h3 |h4 |
|
37
37
|
+----+----+----+----+
|
@@ -48,7 +48,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'resizing' do
|
|
48
48
|
let(:options) { {width: 32, resize: true} }
|
49
49
|
|
50
50
|
it 'resizes each column' do
|
51
|
-
expect(renderer.render).to eql <<-EOS
|
51
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
52
52
|
+---------+-------+------------+
|
53
53
|
|h1 |h2 |h3 |
|
54
54
|
+---------+-------+------------+
|
@@ -65,31 +65,31 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'resizing' do
|
|
65
65
|
let(:rows) { [['aaaa1','aaaa2',], ['bbbb1','bbbb2']] }
|
66
66
|
|
67
67
|
context 'even columns' do
|
68
|
-
let(:options) { {width:
|
68
|
+
let(:options) { {width: 9, resize: true} }
|
69
69
|
|
70
70
|
it 'resizes each column' do
|
71
|
-
expect(renderer.render).to eql <<-EOS
|
72
|
-
|
73
|
-
|h
|
74
|
-
|
75
|
-
|a
|
76
|
-
|b
|
77
|
-
|
71
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
72
|
+
+---+---+
|
73
|
+
|h… |h… |
|
74
|
+
+---+---+
|
75
|
+
|a… |a… |
|
76
|
+
|b… |b… |
|
77
|
+
+---+---+
|
78
78
|
EOS
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
context 'even columns with extra width' do
|
83
|
-
let(:options) { {width:
|
83
|
+
let(:options) { {width: 10, resize: true} }
|
84
84
|
|
85
85
|
it 'resizes each column' do
|
86
|
-
expect(renderer.render).to eql <<-EOS
|
87
|
-
|
88
|
-
|he
|
89
|
-
|
90
|
-
|aa
|
91
|
-
|bb
|
92
|
-
|
86
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
87
|
+
+----+---+
|
88
|
+
|he… |h… |
|
89
|
+
+----+---+
|
90
|
+
|aa… |a… |
|
91
|
+
|bb… |b… |
|
92
|
+
+----+---+
|
93
93
|
EOS
|
94
94
|
end
|
95
95
|
end
|
@@ -100,11 +100,11 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'resizing' do
|
|
100
100
|
let(:options) { {width: 15, resize: true} }
|
101
101
|
|
102
102
|
it 'resizes each column' do
|
103
|
-
expect(renderer.render).to eql <<-EOS
|
103
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
104
104
|
+---+---+-----+
|
105
|
-
|
|
105
|
+
|h… |h… |head3|
|
106
106
|
+---+---+-----+
|
107
|
-
|
|
107
|
+
|a… |aa2|aaa… |
|
108
108
|
|b1 |b2 |b3 |
|
109
109
|
+---+---+-----+
|
110
110
|
EOS
|
@@ -14,7 +14,7 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'with separator' do
|
|
14
14
|
context 'when ascii' do
|
15
15
|
it "renders each row" do
|
16
16
|
renderer.border.separator= :each_row
|
17
|
-
expect(renderer.render).to eq <<-EOS
|
17
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
18
18
|
+--+--+--+
|
19
19
|
|h1|h2|h3|
|
20
20
|
+--+--+--+
|
@@ -5,18 +5,18 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe TTY::Table::Renderer::Basic, 'alignment' do
|
6
6
|
let(:header) { ['h1', 'h2', 'h3'] }
|
7
7
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:options) { {
|
8
|
+
let(:options) { { alignments: alignments } }
|
9
9
|
let(:table) { TTY::Table.new(header, rows) }
|
10
10
|
|
11
11
|
subject(:renderer) { described_class.new table, options }
|
12
12
|
|
13
13
|
context 'with default' do
|
14
|
-
let(:header)
|
15
|
-
let(:rows)
|
16
|
-
let(:
|
14
|
+
let(:header) { ['h1', 'h2'] }
|
15
|
+
let(:rows) { [['aaaaa', 'a'], ['b', 'bbbbb']] }
|
16
|
+
let(:alignments) { nil }
|
17
17
|
|
18
18
|
it 'aligns left by default' do
|
19
|
-
expect(renderer.render).to eql <<-EOS
|
19
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
20
20
|
h1 h2
|
21
21
|
aaaaa a
|
22
22
|
b bbbbb
|
@@ -25,11 +25,11 @@ RSpec.describe TTY::Table::Renderer::Basic, 'alignment' do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'with different headers' do
|
28
|
-
let(:header)
|
29
|
-
let(:
|
28
|
+
let(:header) { ['header1', 'head2', 'h3'] }
|
29
|
+
let(:alignments) { [:left, :center, :right] }
|
30
30
|
|
31
31
|
it 'aligns headers' do
|
32
|
-
expect(renderer.render).to eql <<-EOS
|
32
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
33
33
|
header1 head2 h3
|
34
34
|
a1 a2 a3
|
35
35
|
b1 b2 b3
|
@@ -38,12 +38,12 @@ RSpec.describe TTY::Table::Renderer::Basic, 'alignment' do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'with different aligns' do
|
41
|
-
let(:header)
|
42
|
-
let(:rows)
|
43
|
-
let(:
|
41
|
+
let(:header) { nil }
|
42
|
+
let(:rows) { [['aaaaa', 'a'], ['b', 'bbbbb']] }
|
43
|
+
let(:alignments) { [:left, :right] }
|
44
44
|
|
45
45
|
it 'aligns table rows' do
|
46
|
-
expect(renderer.render.to_s).to eql <<-EOS
|
46
|
+
expect(renderer.render.to_s).to eql unindent(<<-EOS)
|
47
47
|
aaaaa a
|
48
48
|
b bbbbb
|
49
49
|
EOS
|
@@ -51,19 +51,19 @@ RSpec.describe TTY::Table::Renderer::Basic, 'alignment' do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
context 'with individual field aligns' do
|
54
|
-
let(:header)
|
55
|
-
let(:
|
56
|
-
let(:options)
|
54
|
+
let(:header) { ['header1', 'header2', 'header3'] }
|
55
|
+
let(:alignments) { [:left, :center, :right] }
|
56
|
+
let(:options) { {alignments: alignments} }
|
57
57
|
let(:table) {
|
58
58
|
TTY::Table.new header: header do |t|
|
59
59
|
t << ['a1', 'a2', 'a3']
|
60
|
-
t << ['b1', {value: 'b2',
|
61
|
-
t << ['c1', 'c2', {value: 'c3',
|
60
|
+
t << ['b1', {value: 'b2', alignment: :right}, 'b3']
|
61
|
+
t << ['c1', 'c2', {value: 'c3', alignment: :center}]
|
62
62
|
end
|
63
63
|
}
|
64
64
|
|
65
65
|
it "takes individual fields over global aligns" do
|
66
|
-
expect(renderer.render).to eq <<-EOS
|
66
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
67
67
|
header1 header2 header3
|
68
68
|
a1 a2 a3
|
69
69
|
b1 b2 b3
|
@@ -74,11 +74,11 @@ RSpec.describe TTY::Table::Renderer::Basic, 'alignment' do
|
|
74
74
|
|
75
75
|
context 'with aligned header' do
|
76
76
|
let(:rows) { [['aaaaa1', 'a2', 'aaa3'], ['b1', 'bbbb2', 'bb3']] }
|
77
|
-
let(:header) {['h1', {:
|
77
|
+
let(:header) {['h1', {value: 'h2', alignment: :right}, {value: 'h3', alignment: :center}] }
|
78
78
|
let(:options) { { renderer: :basic } }
|
79
79
|
|
80
80
|
it "aligns headres" do
|
81
|
-
expect(renderer.render).to eq <<-EOS
|
81
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
82
82
|
h1 h2 h3
|
83
83
|
aaaaa1 a2 aaa3
|
84
84
|
b1 bbbb2 bb3
|
@@ -3,43 +3,58 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe TTY::Table::Renderer::Basic, 'coloring' do
|
6
|
-
let(:header) { ['h1', 'h2'] }
|
7
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
8
6
|
let(:clear) { "\e[0m" }
|
9
|
-
let(:options) { {filter: filter } }
|
10
|
-
let(:table) { TTY::Table.new(header, rows) }
|
11
7
|
let(:color) { Pastel.new(enabled: true) }
|
12
8
|
|
13
|
-
subject(:renderer) { described_class.new(table, options) }
|
14
|
-
|
15
9
|
before { allow(Pastel).to receive(:new).and_return(color) }
|
16
10
|
|
17
|
-
context '
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
11
|
+
context 'when border ' do
|
12
|
+
it "doesn't color" do
|
13
|
+
table = TTY::Table.new header: ['header1', 'header2']
|
14
|
+
table << ['a1', 'a2']
|
15
|
+
table << ['b1', 'b2']
|
16
|
+
renderer = described_class.new(table)
|
17
|
+
renderer.border = {style: :green}
|
18
|
+
|
19
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
20
|
+
header1 header2
|
21
|
+
a1 a2
|
22
|
+
b1 b2
|
27
23
|
EOS
|
28
24
|
end
|
29
25
|
end
|
30
26
|
|
31
|
-
context '
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
expect(renderer.render).to
|
40
|
-
|
41
|
-
a1
|
42
|
-
b1
|
27
|
+
context 'when content' do
|
28
|
+
it "colors individual field" do
|
29
|
+
header = [color.green('header1'), 'header2']
|
30
|
+
table = TTY::Table.new header: header
|
31
|
+
table << [color.green.on_blue('a1'), 'a2']
|
32
|
+
table << ['b1', color.red.on_yellow('b2')]
|
33
|
+
renderer = described_class.new(table)
|
34
|
+
|
35
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
36
|
+
#{color.green('header1')} header2
|
37
|
+
#{color.green.on_blue('a1')} a2
|
38
|
+
b1 #{color.red.on_yellow('b2')}
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
|
42
|
+
it "colors multiline content" do
|
43
|
+
header = [color.yellow("Multi\nHeader"), 'header2']
|
44
|
+
table = TTY::Table.new header: header
|
45
|
+
table << [color.green.on_blue("Multi\nLine\nContent"), 'a2']
|
46
|
+
table << ['b1', color.red.on_yellow("Multi\nLine\nContent")]
|
47
|
+
renderer = described_class.new(table, multiline: true)
|
48
|
+
|
49
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
50
|
+
#{color.yellow('Multi ')} header2
|
51
|
+
#{color.yellow('Header')}
|
52
|
+
#{color.green.on_blue('Multi ')} a2
|
53
|
+
#{color.green.on_blue('Line ')}
|
54
|
+
#{color.green.on_blue('Content')}
|
55
|
+
b1 #{color.red.on_yellow("Multi ")}
|
56
|
+
#{color.red.on_yellow("Line ")}
|
57
|
+
#{color.red.on_yellow("Content")}
|
43
58
|
EOS
|
44
59
|
end
|
45
60
|
end
|
@@ -17,7 +17,7 @@ RSpec.describe TTY::Table::Renderer::Basic, 'filter' do
|
|
17
17
|
}
|
18
18
|
|
19
19
|
it 'filters only rows' do
|
20
|
-
expect(renderer.render).to eq <<-EOS
|
20
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
21
21
|
h1 h2 h3
|
22
22
|
a1 A2 a3
|
23
23
|
b1 B2 b3
|
@@ -29,7 +29,7 @@ RSpec.describe TTY::Table::Renderer::Basic, 'filter' do
|
|
29
29
|
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val }}
|
30
30
|
|
31
31
|
it 'filters only rows' do
|
32
|
-
expect(renderer.render).to eq <<-EOS
|
32
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
33
33
|
h1 H2 h3
|
34
34
|
a1 A2 a3
|
35
35
|
b1 B2 b3
|
@@ -44,7 +44,7 @@ RSpec.describe TTY::Table::Renderer::Basic, 'filter' do
|
|
44
44
|
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val } }
|
45
45
|
|
46
46
|
it 'filters only rows' do
|
47
|
-
expect(renderer.render).to eq <<-EOS
|
47
|
+
expect(renderer.render).to eq unindent(<<-EOS)
|
48
48
|
a1 A2 a3
|
49
49
|
b1 B2 b3
|
50
50
|
EOS
|
@@ -0,0 +1,74 @@
|
|
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
|