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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +458 -142
  4. data/lib/tty-table.rb +6 -6
  5. data/lib/tty/table.rb +34 -34
  6. data/lib/tty/table/alignment_set.rb +73 -0
  7. data/lib/tty/table/border.rb +54 -36
  8. data/lib/tty/table/border/null.rb +4 -4
  9. data/lib/tty/table/{columns.rb → column_constraint.rb} +30 -32
  10. data/lib/tty/table/column_set.rb +18 -17
  11. data/lib/tty/table/field.rb +50 -25
  12. data/lib/tty/table/header.rb +6 -2
  13. data/lib/tty/table/indentation.rb +7 -12
  14. data/lib/tty/table/operation/alignment.rb +59 -0
  15. data/lib/tty/table/operation/escape.rb +1 -1
  16. data/lib/tty/table/operation/filter.rb +1 -1
  17. data/lib/tty/table/operation/padding.rb +12 -61
  18. data/lib/tty/table/operation/truncation.rb +2 -2
  19. data/lib/tty/table/operation/wrapped.rb +2 -5
  20. data/lib/tty/table/operations.rb +35 -17
  21. data/lib/tty/table/orientation/vertical.rb +4 -4
  22. data/lib/tty/table/renderer.rb +1 -7
  23. data/lib/tty/table/renderer/basic.rb +69 -63
  24. data/lib/tty/table/version.rb +1 -1
  25. data/spec/spec_helper.rb +3 -4
  26. data/spec/unit/access_spec.rb +8 -8
  27. data/spec/unit/{operation/alignment_set → alignment_set}/each_spec.rb +1 -1
  28. data/spec/unit/{operation/alignment_set → alignment_set}/new_spec.rb +4 -4
  29. data/spec/unit/{operation/alignment_set → alignment_set}/to_ary_spec.rb +1 -1
  30. data/spec/unit/alignment_spec.rb +71 -0
  31. data/spec/unit/border/ascii/rendering_spec.rb +12 -12
  32. data/spec/unit/border/new_spec.rb +2 -2
  33. data/spec/unit/border/null/rendering_spec.rb +2 -2
  34. data/spec/unit/border/unicode/rendering_spec.rb +10 -10
  35. data/spec/unit/{columns → column_constraint}/enforce_spec.rb +15 -12
  36. data/spec/unit/{columns → column_constraint}/widths_spec.rb +6 -6
  37. data/spec/unit/column_set/extract_widths_spec.rb +39 -6
  38. data/spec/unit/data_spec.rb +4 -6
  39. data/spec/unit/each_spec.rb +8 -23
  40. data/spec/unit/each_with_index_spec.rb +27 -33
  41. data/spec/unit/field/length_spec.rb +23 -9
  42. data/spec/unit/field/width_spec.rb +1 -1
  43. data/spec/unit/filter_spec.rb +7 -8
  44. data/spec/unit/header/new_spec.rb +6 -15
  45. data/spec/unit/indentation/indent_spec.rb +21 -0
  46. data/spec/unit/new_spec.rb +73 -0
  47. data/spec/unit/operation/{alignment_set → alignment}/call_spec.rb +1 -1
  48. data/spec/unit/operation/escape/call_spec.rb +2 -3
  49. data/spec/unit/operation/filter/call_spec.rb +2 -3
  50. data/spec/unit/operation/truncation/call_spec.rb +6 -8
  51. data/spec/unit/operation/wrapped/call_spec.rb +15 -8
  52. data/spec/unit/operations/new_spec.rb +1 -1
  53. data/spec/unit/orientation_spec.rb +6 -6
  54. data/spec/unit/padding_spec.rb +29 -32
  55. data/spec/unit/properties_spec.rb +4 -4
  56. data/spec/unit/render_repeat_spec.rb +42 -0
  57. data/spec/unit/render_spec.rb +1 -1
  58. data/spec/unit/render_with_spec.rb +3 -3
  59. data/spec/unit/renderer/ascii/coloring_spec.rb +70 -0
  60. data/spec/unit/renderer/ascii/multiline_spec.rb +101 -0
  61. data/spec/unit/renderer/ascii/padding_spec.rb +37 -10
  62. data/spec/unit/renderer/ascii/render_spec.rb +4 -4
  63. data/spec/unit/renderer/ascii/resizing_spec.rb +22 -22
  64. data/spec/unit/renderer/ascii/separator_spec.rb +1 -1
  65. data/spec/unit/renderer/basic/alignment_spec.rb +20 -20
  66. data/spec/unit/renderer/basic/coloring_spec.rb +43 -28
  67. data/spec/unit/renderer/basic/filter_spec.rb +3 -3
  68. data/spec/unit/renderer/basic/multiline_spec.rb +74 -0
  69. data/spec/unit/renderer/basic/options_spec.rb +9 -9
  70. data/spec/unit/renderer/basic/padding_spec.rb +26 -2
  71. data/spec/unit/renderer/basic/render_spec.rb +4 -4
  72. data/spec/unit/renderer/basic/resizing_spec.rb +18 -18
  73. data/spec/unit/renderer/basic/separator_spec.rb +1 -1
  74. data/spec/unit/renderer/basic/truncation_spec.rb +6 -6
  75. data/spec/unit/renderer/basic/wrapping_spec.rb +3 -3
  76. data/spec/unit/renderer/border_spec.rb +4 -4
  77. data/spec/unit/renderer/unicode/coloring_spec.rb +70 -0
  78. data/spec/unit/renderer/unicode/indentation_spec.rb +1 -1
  79. data/spec/unit/renderer/unicode/padding_spec.rb +26 -26
  80. data/spec/unit/renderer/unicode/render_spec.rb +4 -4
  81. data/spec/unit/renderer/unicode/separator_spec.rb +1 -1
  82. data/spec/unit/to_s_spec.rb +4 -11
  83. data/spec/unit/utf_spec.rb +33 -0
  84. data/tty-table.gemspec +2 -1
  85. metadata +52 -32
  86. data/lib/tty/table/operation/alignment_set.rb +0 -103
  87. data/lib/tty/table/padder.rb +0 -180
  88. data/lib/tty/table/renderer/color.rb +0 -12
  89. data/spec/unit/indentation/insert_indent_spec.rb +0 -27
  90. data/spec/unit/initialize_spec.rb +0 -88
  91. data/spec/unit/padder/parse_spec.rb +0 -45
  92. data/spec/unit/padder/to_s_spec.rb +0 -14
  93. data/spec/unit/renderer/basic/multiline_content_spec.rb +0 -135
  94. data/spec/unit/renderer/style_spec.rb +0 -72
@@ -3,30 +3,28 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe TTY::Table::Operation::Truncation, '#call' do
6
- let(:object) { described_class.new column_widths }
7
6
  let(:text) { '太丸ゴシック体' }
8
7
  let(:field) { TTY::Table::Field.new(text) }
9
8
 
9
+ subject(:operation) { described_class.new(column_widths) }
10
+
10
11
  context 'without column width' do
11
12
  let(:column_widths) { [] }
12
13
 
13
14
  it "truncates string" do
14
- object.call(field, 0, 0)
15
- expect(field.value).to eql(text)
15
+ expect(operation.call(field, 0, 0)).to eql(text)
16
16
  end
17
17
  end
18
18
 
19
19
  context 'with column width ' do
20
- let(:column_widths) { [3, 6] }
20
+ let(:column_widths) { [6, 8] }
21
21
 
22
22
  it "truncates string for 0 column" do
23
- object.call(field, 0, 0)
24
- expect(field.value).to eql('太丸…')
23
+ expect(operation.call(field, 0, 0)).to eql('太丸…')
25
24
  end
26
25
 
27
26
  it "truncates string for 1 column" do
28
- object.call(field, 0, 1)
29
- expect(field.value).to eql('太丸ゴシッ…')
27
+ expect(operation.call(field, 0, 1)).to eql('太丸ゴ…')
30
28
  end
31
29
  end
32
30
  end
@@ -3,17 +3,16 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe TTY::Table::Operation::Wrapped, '#call' do
6
- let(:padding) { TTY::Table::Padder.parse }
7
- let(:object) { described_class.new(column_widths, padding) }
8
6
  let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
9
7
  let(:field) { TTY::Table::Field.new(text) }
10
8
 
9
+ subject(:operation) { described_class.new(column_widths) }
10
+
11
11
  context 'without column width' do
12
12
  let(:column_widths) { [] }
13
13
 
14
14
  it "doesn't wrap string" do
15
- object.call(field, 0, 0)
16
- expect(field.value).to eql(text)
15
+ expect(operation.call(field, 0, 0)).to eql(text)
17
16
  end
18
17
  end
19
18
 
@@ -21,13 +20,21 @@ RSpec.describe TTY::Table::Operation::Wrapped, '#call' do
21
20
  let(:column_widths) { [12, 14] }
22
21
 
23
22
  it "wraps string for 0 column" do
24
- object.call(field, 0, 0)
25
- expect(field.value).to eql("ラドクリフ、マラソン五輪\n代表に1万m出場にも含み")
23
+ expect(operation.call(field, 0, 0)).to eql([
24
+ "ラドクリフ、",
25
+ "マラソン五輪",
26
+ "代表に1万m出",
27
+ "場にも含み"
28
+ ].join("\n"))
26
29
  end
27
30
 
28
31
  it "wraps string for 1 column" do
29
- object.call(field, 0, 1)
30
- expect(field.value).to eql("ラドクリフ、マラソン五輪代表\nに1万m出場にも含み")
32
+ expect(operation.call(field, 0, 1)).to eql([
33
+ "ラドクリフ、マ",
34
+ "ラソン五輪代表",
35
+ "に1万m出場にも",
36
+ "含み"
37
+ ].join("\n"))
31
38
  end
32
39
  end
33
40
  end
@@ -20,7 +20,7 @@ RSpec.describe TTY::Table::Operations, '#new' do
20
20
  before { subject.add(:alignment, instance) }
21
21
 
22
22
  it 'stores away operations' do
23
- expect(subject.operations[:alignment]).to include(instance)
23
+ expect(subject[:alignment]).to include(instance)
24
24
  end
25
25
 
26
26
  it 'runs selected operations' do
@@ -30,7 +30,7 @@ RSpec.describe TTY::Table, 'orientation' do
30
30
 
31
31
  context 'without border' do
32
32
  it 'displays table' do
33
- expect(subject.to_s).to eq <<-EOS.normalize
33
+ expect(subject.to_s).to eq unindent(<<-EOS)
34
34
  h1 h2 h3
35
35
  a1 a2 a3
36
36
  b1 b2 b3
@@ -42,7 +42,7 @@ RSpec.describe TTY::Table, 'orientation' do
42
42
  let(:renderer) { :ascii }
43
43
 
44
44
  it 'diplays table' do
45
- expect(subject.render(renderer)).to eq <<-EOS.normalize
45
+ expect(subject.render(renderer)).to eq unindent(<<-EOS)
46
46
  +--+--+--+
47
47
  |h1|h2|h3|
48
48
  +--+--+--+
@@ -71,7 +71,7 @@ RSpec.describe TTY::Table, 'orientation' do
71
71
 
72
72
  context 'without border' do
73
73
  it 'displays table' do
74
- expect(subject.to_s).to eq <<-EOS.normalize
74
+ expect(subject.to_s).to eq unindent(<<-EOS)
75
75
  h1 a1
76
76
  h2 a2
77
77
  h3 a3
@@ -86,7 +86,7 @@ RSpec.describe TTY::Table, 'orientation' do
86
86
  let(:renderer) { :ascii }
87
87
 
88
88
  it 'diplays table' do
89
- expect(subject.render(renderer)).to eq <<-EOS.normalize
89
+ expect(subject.render(renderer)).to eq unindent(<<-EOS)
90
90
  +--+--+
91
91
  |h1|a1|
92
92
  |h2|a2|
@@ -113,7 +113,7 @@ RSpec.describe TTY::Table, 'orientation' do
113
113
 
114
114
  context 'without border' do
115
115
  it 'displays table' do
116
- expect(subject.to_s).to eq <<-EOS.normalize
116
+ expect(subject.to_s).to eq unindent(<<-EOS)
117
117
  1 a1
118
118
  2 a2
119
119
  3 a3
@@ -128,7 +128,7 @@ RSpec.describe TTY::Table, 'orientation' do
128
128
  let(:renderer) { :ascii }
129
129
 
130
130
  it 'diplays table' do
131
- expect(subject.render(renderer)).to eq <<-EOS.normalize
131
+ expect(subject.render(renderer)).to eq unindent(<<-EOS)
132
132
  +-+--+
133
133
  |1|a1|
134
134
  |2|a2|
@@ -9,10 +9,9 @@ RSpec.describe TTY::Table, 'padding' do
9
9
 
10
10
  it 'sets specific padding' do
11
11
  expect(table.render(:ascii) { |renderer|
12
- renderer.multiline = true
13
12
  renderer.padding.right = 2
14
13
  renderer.padding.top = 1
15
- }).to eq <<-EOS.normalize
14
+ }).to eq unindent(<<-EOS)
16
15
  +----+----+----+
17
16
  | | | |
18
17
  |h1 |h2 |h3 |
@@ -27,9 +26,8 @@ RSpec.describe TTY::Table, 'padding' do
27
26
 
28
27
  it 'sets padding for all' do
29
28
  expect(table.render(:ascii) { |renderer|
30
- renderer.multiline = true
31
29
  renderer.padding= [1,2,1,2]
32
- }).to eq <<-EOS.normalize
30
+ }).to eq unindent(<<-EOS)
33
31
  +------+------+------+
34
32
  | | | |
35
33
  | h1 | h2 | h3 |
@@ -51,9 +49,8 @@ RSpec.describe TTY::Table, 'padding' do
51
49
  it 'sets padding for all' do
52
50
  expect(table.render(:ascii) { |renderer|
53
51
  renderer.column_widths = column_widths
54
- renderer.multiline = true
55
52
  renderer.padding= [1,2,1,2]
56
- }).to eq <<-EOS.normalize
53
+ }).to eq unindent(<<-EOS)
57
54
  +--------+--------+--------+
58
55
  | | | |
59
56
  | h1 | h2 | h3 |
@@ -71,8 +68,8 @@ RSpec.describe TTY::Table, 'padding' do
71
68
  end
72
69
 
73
70
  context 'with multi line text' do
74
- let(:header) { ['head1', 'head2'] }
75
- let(:rows) { [["Multi\nLine\nContent", "Text\nthat\nwraps",],
71
+ let(:header) { ['h1', 'head2'] }
72
+ let(:rows) { [["Multi\nLine", "Text\nthat\nwraps"],
76
73
  ["Some\nother\ntext", 'Simple']] }
77
74
 
78
75
  context 'when wrapped' do
@@ -80,23 +77,23 @@ RSpec.describe TTY::Table, 'padding' do
80
77
  expect(table.render(:ascii) { |renderer|
81
78
  renderer.multiline = true
82
79
  renderer.padding= [1,2,1,2]
83
- }).to eq <<-EOS.normalize
84
- +-----------+----------+
85
- | | |
86
- | head1 | head2 |
87
- | | |
88
- +-----------+----------+
89
- | | |
90
- | Multi | Text |
91
- | Line | that |
92
- | Content | wraps |
93
- | | |
94
- | | |
95
- | Some | Simple |
96
- | other | |
97
- | text | |
98
- | | |
99
- +-----------+----------+
80
+ }).to eq unindent(<<-EOS)
81
+ +---------+----------+
82
+ | | |
83
+ | h1 | head2 |
84
+ | | |
85
+ +---------+----------+
86
+ | | |
87
+ | Multi | Text |
88
+ | Line | that |
89
+ | | wraps |
90
+ | | |
91
+ | | |
92
+ | Some | Simple |
93
+ | other | |
94
+ | text | |
95
+ | | |
96
+ +---------+----------+
100
97
  EOS
101
98
  end
102
99
  end
@@ -106,13 +103,13 @@ RSpec.describe TTY::Table, 'padding' do
106
103
  expect(table.render(:ascii) { |renderer|
107
104
  renderer.multiline = false
108
105
  renderer.padding= [0,2,0,2]
109
- }).to eq <<-EOS.normalize
110
- +------------------------+---------------------+
111
- | head1 | head2 |
112
- +------------------------+---------------------+
113
- | Multi\\nLine\\nContent | Text\\nthat\\nwraps |
114
- | Some\\nother\\ntext | Simple |
115
- +------------------------+---------------------+
106
+ }).to eq unindent(<<-EOS)
107
+ +---------------------+---------------------+
108
+ | h1 | head2 |
109
+ +---------------------+---------------------+
110
+ | Multi\\nLine | Text\\nthat\\nwraps |
111
+ | Some\\nother\\ntext | Simple |
112
+ +---------------------+---------------------+
116
113
  EOS
117
114
  end
118
115
  end
@@ -9,17 +9,17 @@ RSpec.describe TTY::Table, 'properties' do
9
9
 
10
10
  it { expect(table.width).to eq(6) }
11
11
 
12
- it { expect(table.row_size).to eq(2) }
12
+ it { expect(table.rows_size).to eq(2) }
13
13
 
14
- it { expect(table.column_size).to eq(3) }
14
+ it { expect(table.columns_size).to eq(3) }
15
15
 
16
16
  it { expect(table.size).to eq([2,3]) }
17
17
 
18
18
  context 'no size' do
19
19
  let(:rows) { [] }
20
20
 
21
- it { expect(table.row_size).to eq(0) }
21
+ it { expect(table.rows_size).to eq(0) }
22
22
 
23
- it { expect(table.column_size).to eq(0) }
23
+ it { expect(table.columns_size).to eq(0) }
24
24
  end
25
25
  end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::Table, 'render repeat' do
6
+
7
+ it "renders consistently" do
8
+ table = TTY::Table.new header: ['header1', 'header2']
9
+ table << ['a1', 'a2']
10
+ table << ['b1', 'b2']
11
+ options = {padding: [1,1,1,1], alignments: [:right, :center]}
12
+ expect(table.render(:ascii, options)).to eq unindent(<<-EOS)
13
+ +---------+---------+
14
+ | | |
15
+ | header1 | header2 |
16
+ | | |
17
+ +---------+---------+
18
+ | | |
19
+ | a1 | a2 |
20
+ | | |
21
+ | | |
22
+ | b1 | b2 |
23
+ | | |
24
+ +---------+---------+
25
+ EOS
26
+
27
+ expect(table.render(:ascii, options)).to eq unindent(<<-EOS)
28
+ +---------+---------+
29
+ | | |
30
+ | header1 | header2 |
31
+ | | |
32
+ +---------+---------+
33
+ | | |
34
+ | a1 | a2 |
35
+ | | |
36
+ | | |
37
+ | b1 | b2 |
38
+ | | |
39
+ +---------+---------+
40
+ EOS
41
+ end
42
+ end
@@ -35,7 +35,7 @@ RSpec.describe TTY::Table, '#render' do
35
35
  result = table.render :ascii do |renderer|
36
36
  renderer.border.style = :red
37
37
  end
38
- expect(result).to eq <<-EOS.normalize
38
+ expect(result).to eq unindent(<<-EOS)
39
39
  \e[31m+--+--+\e[0m
40
40
  \e[31m|\e[0mh1\e[31m|\e[0mh2\e[31m|\e[0m
41
41
  \e[31m+--+--+\e[0m
@@ -46,7 +46,7 @@ RSpec.describe TTY::Table, '#render_with' do
46
46
  }
47
47
 
48
48
  it 'displays custom border' do
49
- expect(table.render_with(MyBorder)).to eq <<-EOS.normalize
49
+ expect(table.render_with(MyBorder)).to eq unindent(<<-EOS)
50
50
  *==*==*==*
51
51
  $h1$h2$h3$
52
52
  *==*==*==*
@@ -73,7 +73,7 @@ RSpec.describe TTY::Table, '#render_with' do
73
73
  }
74
74
 
75
75
  it 'displays border' do
76
- expect(table.render_with(MyBorder)).to eq <<-EOS.normalize
76
+ expect(table.render_with(MyBorder)).to eq unindent(<<-EOS)
77
77
  $h1$h2$h3$
78
78
  $a1$a2$a3$
79
79
  $b1$b2$b3$
@@ -96,7 +96,7 @@ RSpec.describe TTY::Table, '#render_with' do
96
96
  result = table.render_with MyBorder do |renderer|
97
97
  renderer.border.style = :red
98
98
  end
99
- expect(result).to eq <<-EOS.normalize
99
+ expect(result).to eq unindent(<<-EOS)
100
100
  \e[31m|\e[0mh1h2h3\e[31m|\e[0m
101
101
  \e[31m|\e[0ma1a2a3\e[31m|\e[0m
102
102
  \e[31m|\e[0mb1b2b3\e[31m|\e[0m
@@ -0,0 +1,70 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::Table::Renderer::ASCII, 'coloring' do
6
+
7
+ let(:color) { Pastel.new(enabled: true) }
8
+
9
+ before { allow(Pastel).to receive(:new).and_return(color) }
10
+
11
+ context 'when border' do
12
+ it "colors border" 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 eq unindent(<<-EOS)
20
+ #{color.green('+-------+-------+')}
21
+ #{color.green('|')}header1#{color.green('|')}header2#{color.green('|')}
22
+ #{color.green('+-------+-------+')}
23
+ #{color.green('|')}a1 #{color.green('|')}a2 #{color.green('|')}
24
+ #{color.green('|')}b1 #{color.green('|')}b2 #{color.green('|')}
25
+ #{color.green('+-------+-------+')}
26
+ EOS
27
+ end
28
+ end
29
+
30
+ context 'when content' do
31
+ it "colors individual field" do
32
+ header = [color.yellow('header1'), 'header2']
33
+ table = TTY::Table.new header: header
34
+ table << [color.green.on_blue('a1'), 'a2']
35
+ table << ['b1', color.red.on_yellow('b2')]
36
+ renderer = described_class.new(table)
37
+
38
+ expect(renderer.render).to eq unindent(<<-EOS)
39
+ +-------+-------+
40
+ |#{color.yellow('header1')}|header2|
41
+ +-------+-------+
42
+ |#{color.green.on_blue('a1')} |a2 |
43
+ |b1 |#{color.red.on_yellow('b2')} |
44
+ +-------+-------+
45
+ EOS
46
+ end
47
+
48
+ it "colors multiline content" do
49
+ header = [color.yellow("Multi\nHeader"), 'header2']
50
+ table = TTY::Table.new header: header
51
+ table << [color.green.on_blue("Multi\nLine\nContent"), 'a2']
52
+ table << ['b1', color.red.on_yellow("Multi\nLine\nContent")]
53
+ renderer = described_class.new(table, multiline: true)
54
+
55
+ expect(renderer.render).to eq unindent(<<-EOS)
56
+ +-------+-------+
57
+ |#{color.yellow('Multi ')}|header2|
58
+ |#{color.yellow('Header')} | |
59
+ +-------+-------+
60
+ |#{color.green.on_blue('Multi ')}|a2 |
61
+ |#{color.green.on_blue('Line ')}| |
62
+ |#{color.green.on_blue('Content')}| |
63
+ |b1 |#{color.red.on_yellow("Multi ")}|
64
+ | |#{color.red.on_yellow("Line ")}|
65
+ | |#{color.red.on_yellow("Content")}|
66
+ +-------+-------+
67
+ EOS
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,101 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::Table::Renderer::ASCII, '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
+ +------------------+-+
13
+ |First |1|
14
+ |Multiline\\nContent|2|
15
+ |Third |3|
16
+ +------------------+-+
17
+ EOS
18
+ end
19
+
20
+ it "truncates multiline content" do
21
+ rows = [["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']]
22
+ table = TTY::Table.new rows
23
+ renderer = described_class.new(table, multiline: false, column_widths: [8,1])
24
+ expect(renderer.render).to eq unindent(<<-EOS)
25
+ +--------+-+
26
+ |First |1|
27
+ |Multil… |2|
28
+ |Third |3|
29
+ +--------+-+
30
+ EOS
31
+ end
32
+
33
+ it "renders correctly multiline header as single line" do
34
+ header = ["Multi\nHeader", "header2"]
35
+ rows = [["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']]
36
+ table = TTY::Table.new header, rows
37
+ renderer = described_class.new(table, multiline: false)
38
+ expect(renderer.render).to eq unindent(<<-EOS)
39
+ +------------------+-------+
40
+ |Multi\\nHeader |header2|
41
+ +------------------+-------+
42
+ |First |1 |
43
+ |Multiline\\nContent|2 |
44
+ |Third |3 |
45
+ +------------------+-------+
46
+ EOS
47
+ end
48
+ end
49
+
50
+ context 'without escaping' do
51
+ it "renders multiline" do
52
+ rows = [["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']]
53
+ table = TTY::Table.new rows
54
+ renderer = described_class.new(table, multiline: true)
55
+ expect(renderer.render).to eq unindent(<<-EOS)
56
+ +-------+-+
57
+ |First |1|
58
+ |Multi |2|
59
+ |Line | |
60
+ |Content| |
61
+ |Third |3|
62
+ +-------+-+
63
+ EOS
64
+ end
65
+
66
+ it "wraps multiline" do
67
+ rows = [["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']]
68
+ table = TTY::Table.new rows
69
+ renderer = described_class.new(table, multiline: true, column_widths: [5,1])
70
+ expect(renderer.render).to eq unindent(<<-EOS)
71
+ +-----+-+
72
+ |First|1|
73
+ |Multi|2|
74
+ |Line | |
75
+ |Conte| |
76
+ |nt | |
77
+ |Third|3|
78
+ +-----+-+
79
+ EOS
80
+ end
81
+
82
+ it "renders multilne header" do
83
+ header = ["Multi\nHeader", "header2"]
84
+ rows = [["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']]
85
+ table = TTY::Table.new header, rows
86
+ renderer = described_class.new(table, multiline: true)
87
+ expect(renderer.render).to eq unindent(<<-EOS)
88
+ +-------+-------+
89
+ |Multi |header2|
90
+ |Header | |
91
+ +-------+-------+
92
+ |First |1 |
93
+ |Multi |2 |
94
+ |Line | |
95
+ |Content| |
96
+ |Third |3 |
97
+ +-------+-------+
98
+ EOS
99
+ end
100
+ end
101
+ end