tty-table 0.7.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +57 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +165 -94
  5. data/lib/tty-table.rb +1 -5
  6. data/lib/tty/table.rb +102 -42
  7. data/lib/tty/table/alignment_set.rb +3 -6
  8. data/lib/tty/table/border.rb +57 -68
  9. data/lib/tty/table/border/ascii.rb +17 -17
  10. data/lib/tty/table/border/null.rb +20 -22
  11. data/lib/tty/table/border/row_line.rb +4 -3
  12. data/lib/tty/table/border/unicode.rb +17 -17
  13. data/lib/tty/table/border_dsl.rb +28 -25
  14. data/lib/tty/table/border_options.rb +50 -25
  15. data/lib/tty/table/column_constraint.rb +29 -17
  16. data/lib/tty/table/{column_set.rb → columns.rb} +44 -69
  17. data/lib/tty/table/empty.rb +2 -0
  18. data/lib/tty/table/error.rb +1 -1
  19. data/lib/tty/table/field.rb +43 -35
  20. data/lib/tty/table/header.rb +7 -5
  21. data/lib/tty/table/indentation.rb +16 -25
  22. data/lib/tty/table/operation/alignment.rb +10 -8
  23. data/lib/tty/table/operation/escape.rb +2 -3
  24. data/lib/tty/table/operation/filter.rb +1 -1
  25. data/lib/tty/table/operation/padding.rb +4 -12
  26. data/lib/tty/table/operation/truncation.rb +4 -4
  27. data/lib/tty/table/operation/wrapped.rb +4 -4
  28. data/lib/tty/table/operations.rb +4 -15
  29. data/lib/tty/table/options.rb +2 -4
  30. data/lib/tty/table/orientation.rb +5 -5
  31. data/lib/tty/table/orientation/horizontal.rb +1 -1
  32. data/lib/tty/table/orientation/vertical.rb +1 -1
  33. data/lib/tty/table/renderer.rb +40 -35
  34. data/lib/tty/table/renderer/ascii.rb +4 -4
  35. data/lib/tty/table/renderer/basic.rb +85 -88
  36. data/lib/tty/table/renderer/unicode.rb +3 -3
  37. data/lib/tty/table/row.rb +10 -8
  38. data/lib/tty/table/transformation.rb +2 -2
  39. data/lib/tty/table/validatable.rb +25 -7
  40. data/lib/tty/table/version.rb +3 -3
  41. metadata +33 -283
  42. data/.gitignore +0 -14
  43. data/.rspec +0 -3
  44. data/.travis.yml +0 -24
  45. data/CODE_OF_CONDUCT.md +0 -49
  46. data/Gemfile +0 -18
  47. data/Rakefile +0 -8
  48. data/benchmarks/speed.rb +0 -41
  49. data/spec/spec_helper.rb +0 -50
  50. data/spec/unit/access_spec.rb +0 -86
  51. data/spec/unit/add_row_spec.rb +0 -28
  52. data/spec/unit/alignment_set/each_spec.rb +0 -17
  53. data/spec/unit/alignment_set/new_spec.rb +0 -27
  54. data/spec/unit/alignment_set/to_ary_spec.rb +0 -14
  55. data/spec/unit/alignment_spec.rb +0 -71
  56. data/spec/unit/border/ascii/rendering_spec.rb +0 -90
  57. data/spec/unit/border/new_spec.rb +0 -27
  58. data/spec/unit/border/null/rendering_spec.rb +0 -130
  59. data/spec/unit/border/options/from_spec.rb +0 -38
  60. data/spec/unit/border/options/new_spec.rb +0 -14
  61. data/spec/unit/border/unicode/rendering_spec.rb +0 -63
  62. data/spec/unit/border_options/new_spec.rb +0 -20
  63. data/spec/unit/border_options/update_spec.rb +0 -18
  64. data/spec/unit/column_constraint/enforce_spec.rb +0 -70
  65. data/spec/unit/column_constraint/widths_spec.rb +0 -35
  66. data/spec/unit/column_set/extract_widths_spec.rb +0 -48
  67. data/spec/unit/column_set/total_width_spec.rb +0 -15
  68. data/spec/unit/column_set/widths_from_spec.rb +0 -51
  69. data/spec/unit/data_spec.rb +0 -12
  70. data/spec/unit/each_spec.rb +0 -26
  71. data/spec/unit/each_with_index_spec.rb +0 -51
  72. data/spec/unit/empty_spec.rb +0 -23
  73. data/spec/unit/eql_spec.rb +0 -34
  74. data/spec/unit/field/equality_spec.rb +0 -51
  75. data/spec/unit/field/length_spec.rb +0 -35
  76. data/spec/unit/field/lines_spec.rb +0 -21
  77. data/spec/unit/field/new_spec.rb +0 -29
  78. data/spec/unit/field/width_spec.rb +0 -23
  79. data/spec/unit/filter_spec.rb +0 -22
  80. data/spec/unit/header/call_spec.rb +0 -30
  81. data/spec/unit/header/color_spec.rb +0 -19
  82. data/spec/unit/header/equality_spec.rb +0 -51
  83. data/spec/unit/header/height_spec.rb +0 -27
  84. data/spec/unit/header/new_spec.rb +0 -16
  85. data/spec/unit/header/set_spec.rb +0 -20
  86. data/spec/unit/header/to_ary_spec.rb +0 -14
  87. data/spec/unit/header_spec.rb +0 -13
  88. data/spec/unit/indentation/indent_spec.rb +0 -21
  89. data/spec/unit/new_spec.rb +0 -73
  90. data/spec/unit/operation/alignment/call_spec.rb +0 -39
  91. data/spec/unit/operation/escape/call_spec.rb +0 -15
  92. data/spec/unit/operation/filter/call_spec.rb +0 -16
  93. data/spec/unit/operation/truncation/call_spec.rb +0 -30
  94. data/spec/unit/operation/wrapped/call_spec.rb +0 -40
  95. data/spec/unit/operations/new_spec.rb +0 -30
  96. data/spec/unit/options/access_spec.rb +0 -14
  97. data/spec/unit/options_spec.rb +0 -25
  98. data/spec/unit/orientation_spec.rb +0 -145
  99. data/spec/unit/padding_spec.rb +0 -117
  100. data/spec/unit/properties_spec.rb +0 -25
  101. data/spec/unit/render_repeat_spec.rb +0 -42
  102. data/spec/unit/render_spec.rb +0 -63
  103. data/spec/unit/render_with_spec.rb +0 -106
  104. data/spec/unit/renderer/ascii/coloring_spec.rb +0 -70
  105. data/spec/unit/renderer/ascii/indentation_spec.rb +0 -41
  106. data/spec/unit/renderer/ascii/multiline_spec.rb +0 -101
  107. data/spec/unit/renderer/ascii/padding_spec.rb +0 -88
  108. data/spec/unit/renderer/ascii/render_spec.rb +0 -68
  109. data/spec/unit/renderer/ascii/resizing_spec.rb +0 -114
  110. data/spec/unit/renderer/ascii/separator_spec.rb +0 -28
  111. data/spec/unit/renderer/basic/alignment_spec.rb +0 -88
  112. data/spec/unit/renderer/basic/coloring_spec.rb +0 -61
  113. data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -28
  114. data/spec/unit/renderer/basic/filter_spec.rb +0 -53
  115. data/spec/unit/renderer/basic/indentation_spec.rb +0 -48
  116. data/spec/unit/renderer/basic/multiline_spec.rb +0 -74
  117. data/spec/unit/renderer/basic/new_spec.rb +0 -26
  118. data/spec/unit/renderer/basic/options_spec.rb +0 -52
  119. data/spec/unit/renderer/basic/padding_spec.rb +0 -76
  120. data/spec/unit/renderer/basic/render_spec.rb +0 -57
  121. data/spec/unit/renderer/basic/resizing_spec.rb +0 -96
  122. data/spec/unit/renderer/basic/separator_spec.rb +0 -43
  123. data/spec/unit/renderer/basic/truncation_spec.rb +0 -35
  124. data/spec/unit/renderer/basic/wrapping_spec.rb +0 -40
  125. data/spec/unit/renderer/border_spec.rb +0 -104
  126. data/spec/unit/renderer/render_spec.rb +0 -36
  127. data/spec/unit/renderer/select_spec.rb +0 -22
  128. data/spec/unit/renderer/unicode/coloring_spec.rb +0 -70
  129. data/spec/unit/renderer/unicode/indentation_spec.rb +0 -41
  130. data/spec/unit/renderer/unicode/padding_spec.rb +0 -61
  131. data/spec/unit/renderer/unicode/render_spec.rb +0 -68
  132. data/spec/unit/renderer/unicode/separator_spec.rb +0 -26
  133. data/spec/unit/renderer_spec.rb +0 -19
  134. data/spec/unit/rotate_spec.rb +0 -86
  135. data/spec/unit/row/access_spec.rb +0 -25
  136. data/spec/unit/row/call_spec.rb +0 -45
  137. data/spec/unit/row/data_spec.rb +0 -26
  138. data/spec/unit/row/each_spec.rb +0 -31
  139. data/spec/unit/row/equality_spec.rb +0 -73
  140. data/spec/unit/row/height_spec.rb +0 -27
  141. data/spec/unit/row/new_spec.rb +0 -41
  142. data/spec/unit/row/to_ary_spec.rb +0 -14
  143. data/spec/unit/to_s_spec.rb +0 -56
  144. data/spec/unit/transformation/extract_tuples_spec.rb +0 -35
  145. data/spec/unit/utf_spec.rb +0 -33
  146. data/spec/unit/validatable/validate_options_spec.rb +0 -33
  147. data/spec/unit/validatable_spec.rb +0 -32
  148. data/tasks/console.rake +0 -10
  149. data/tasks/coverage.rake +0 -11
  150. data/tasks/spec.rake +0 -29
  151. data/tty-table.gemspec +0 -30
@@ -1,35 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Basic, 'truncation' do
6
- let(:header) { ['header1', 'head2', 'h3'] }
7
- let(:rows) { [['a1111111', 'a222', 'a3333333'], ['b111', 'b2222222', 'b333333']]}
8
- let(:table) { TTY::Table.new header, rows }
9
-
10
- subject(:renderer) { described_class.new(table, options) }
11
-
12
- context 'without column widths' do
13
- let(:options) { {} }
14
-
15
- it "doesn't shorten the fields" do
16
- expect(renderer.render).to eq unindent(<<-EOS)
17
- header1 head2 h3
18
- a1111111 a222 a3333333
19
- b111 b2222222 b333333
20
- EOS
21
- end
22
- end
23
-
24
- context 'with column widths' do
25
- let(:options) { { column_widths: [4, 5, 7] } }
26
-
27
- it 'shortens the fields' do
28
- expect(renderer.render).to eq unindent(<<-EOS)
29
- he… head2 h3
30
- a1… a222 a3333…
31
- b111 b22… b333333
32
- EOS
33
- end
34
- end
35
- end
@@ -1,40 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Basic, 'wrapping' do
6
- let(:header) { ['header1', 'head2', 'h3'] }
7
- let(:rows) { [['a1111111', 'a222', 'a3333333'], ['b111', 'b2222222', 'b333333']]}
8
- let(:table) { TTY::Table.new header, rows }
9
-
10
- subject(:renderer) { described_class.new(table, options) }
11
-
12
- context 'without column widths' do
13
- let(:options) { {multiline: true} }
14
-
15
- it "doesn't wrap the fields" do
16
- expect(renderer.render).to eq unindent(<<-EOS)
17
- header1 head2 h3
18
- a1111111 a222 a3333333
19
- b111 b2222222 b333333
20
- EOS
21
- end
22
- end
23
-
24
- context 'with column widths' do
25
- let(:options) { { column_widths: [3, 5, 7], multiline: true} }
26
-
27
- it 'wraps the fields' do
28
- expect(renderer.render).to eq unindent(<<-EOS)
29
- hea head2 h3
30
- der
31
- 1
32
- a11 a222 a333333
33
- 111 3
34
- 11
35
- b11 b2222 b333333
36
- 1 222
37
- EOS
38
- end
39
- end
40
- end
@@ -1,104 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer, '#border' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:border) { nil }
9
-
10
- let(:table) { TTY::Table.new(header, rows) }
11
-
12
- subject(:renderer) { described_class.select(type).new(table) }
13
-
14
- context 'when basic renderer' do
15
- let(:type) { :basic }
16
- let(:border) { {characters: {'top' => '-'}, style: :red} }
17
-
18
- it 'specifies border in hash' do
19
- renderer.border(border)
20
- expect(renderer.border.characters['top']).to eql('-')
21
- end
22
-
23
- it 'specifies border in characters attribute' do
24
- renderer.border.characters = {'top' => '*'}
25
- expect(renderer.border.characters['top']).to eql('*')
26
- end
27
-
28
- it 'specifies border in block' do
29
- renderer.border do
30
- mid '='
31
- mid_mid ' '
32
- end
33
-
34
- expect(renderer.render).to eq unindent(<<-EOS)
35
- h1 h2 h3
36
- == == ==
37
- a1 a2 a3
38
- b1 b2 b3
39
- EOS
40
- end
41
- end
42
-
43
- context 'when ascii renderer' do
44
- let(:type) { :ascii }
45
-
46
- it 'specifies border in block' do
47
- renderer.border do
48
- mid '='
49
- mid_mid '='
50
- mid_left '='
51
- mid_right '='
52
- end
53
-
54
- expect(renderer.render).to eq unindent(<<-EOS)
55
- +--+--+--+
56
- |h1|h2|h3|
57
- ==========
58
- |a1|a2|a3|
59
- |b1|b2|b3|
60
- +--+--+--+
61
- EOS
62
- end
63
-
64
- it 'specifies border as hash' do
65
- renderer.border({characters: {
66
- 'mid' => '=',
67
- 'mid_mid' => '=',
68
- 'mid_left' => '=',
69
- 'mid_right' => '=',
70
- }})
71
-
72
- expect(renderer.render).to eq unindent(<<-EOS)
73
- +--+--+--+
74
- |h1|h2|h3|
75
- ==========
76
- |a1|a2|a3|
77
- |b1|b2|b3|
78
- +--+--+--+
79
- EOS
80
- end
81
- end
82
-
83
- context 'when unicode renderer' do
84
- let(:type) { :unicode }
85
-
86
- it 'specifies border in block' do
87
- renderer.border do
88
- mid '='
89
- mid_mid '='
90
- mid_left '='
91
- mid_right '='
92
- end
93
-
94
- expect(renderer.render).to eq unindent(<<-EOS)
95
- ┌──┬──┬──┐
96
- │h1│h2│h3│
97
- ==========
98
- │a1│a2│a3│
99
- │b1│b2│b3│
100
- └──┴──┴──┘
101
- EOS
102
- end
103
- end
104
- end # border
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer, '#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 { described_class.render(table, {}, &block) }
11
-
12
- context 'when default' do
13
- let(:renderer) { double(:renderer).as_null_object }
14
- let(:renderer_class) { double(:renderer_class).as_null_object }
15
- let(:yielded) { [] }
16
- let(:block) { proc { |render| yielded << render } }
17
-
18
- before { allow(described_class).to receive(:select).and_return(renderer_class) }
19
-
20
- it 'creates renderer' do
21
- subject
22
- expect(renderer_class).to have_received(:new).with(table, {})
23
- end
24
-
25
- it 'yields renderer' do
26
- allow(renderer_class).to receive(:new).and_return(renderer)
27
- expect { subject }.to change { yielded}.from([]).to([renderer])
28
- end
29
-
30
- it 'calls render' do
31
- allow(renderer_class).to receive(:new).and_return(renderer)
32
- subject
33
- expect(renderer).to have_received(:render)
34
- end
35
- end
36
- end
@@ -1,22 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer, '#select' do
6
- let(:klass) { ::Class.new }
7
- let(:instance) { described_class }
8
-
9
- subject { instance.select(renderer) }
10
-
11
- context 'with basic' do
12
- let(:renderer) { :basic }
13
-
14
- it { is_expected.to be(TTY::Table::Renderer::Basic) }
15
- end
16
-
17
- context 'with unicode' do
18
- let(:renderer) { :unicode }
19
-
20
- it { is_expected.to be(TTY::Table::Renderer::Unicode) }
21
- end
22
- end
@@ -1,70 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Unicode, '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
@@ -1,41 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Unicode, '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(:indent) { 2 }
10
- let(:options) { {indent: indent } }
11
-
12
- subject(:renderer) { described_class.new(table, options)}
13
-
14
- context 'when default' do
15
- it 'indents by value' do
16
- expect(renderer.render).to eq <<-EOS.chomp
17
- ┌──┬──┬──┐
18
- │h1│h2│h3│
19
- ├──┼──┼──┤
20
- │a1│a2│a3│
21
- │b1│b2│b3│
22
- └──┴──┴──┘
23
- EOS
24
- end
25
- end
26
-
27
- context 'when each row' do
28
- it 'indents by value' do
29
- renderer.border.separator = :each_row
30
- expect(renderer.render).to eql <<-EOS.chomp
31
- ┌──┬──┬──┐
32
- │h1│h2│h3│
33
- ├──┼──┼──┤
34
- │a1│a2│a3│
35
- ├──┼──┼──┤
36
- │b1│b2│b3│
37
- └──┴──┴──┘
38
- EOS
39
- end
40
- end
41
- end
@@ -1,61 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Unicode, '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 unindent(<<-EOS)
17
- ┌───────┬─────────┬──────┬─────┬─────────┬───────┐
18
- │ Field │ Type │ Null │ Key │ Default │ Extra │
19
- ├───────┼─────────┼──────┼─────┼─────────┼───────┤
20
- │ id │ int(11) │ YES │ nil │ NULL │ │
21
- └───────┴─────────┴──────┴─────┴─────────┴───────┘
22
- EOS
23
- end
24
- end
25
-
26
- context 'with top & bottom padding' do
27
- let(:options) { {padding: [1,0,1,0], multiline: true} }
28
-
29
- it 'pads each field' do
30
- expect(renderer.render).to eql unindent(<<-EOS)
31
- ┌─────┬───────┬────┬───┬───────┬─────┐
32
- │ │ │ │ │ │ │
33
- │Field│Type │Null│Key│Default│Extra│
34
- │ │ │ │ │ │ │
35
- ├─────┼───────┼────┼───┼───────┼─────┤
36
- │ │ │ │ │ │ │
37
- │id │int(11)│YES │nil│NULL │ │
38
- │ │ │ │ │ │ │
39
- └─────┴───────┴────┴───┴───────┴─────┘
40
- EOS
41
- end
42
- end
43
-
44
- context 'with full padding' do
45
- let(:options) { {padding: [1,1,1,1], multiline: true} }
46
-
47
- it 'pads each field' do
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
- end
@@ -1,68 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Unicode, '#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 only' do
13
- let(:table) { TTY::Table.new rows }
14
-
15
- it 'display table rows' do
16
- expect(renderer.render).to eq unindent(<<-EOS)
17
- ┌──┬──┬──┐
18
- │a1│a2│a3│
19
- │b1│b2│b3│
20
- └──┴──┴──┘
21
- EOS
22
- end
23
- end
24
-
25
- context 'with header' do
26
- it 'displays table with header' do
27
- expect(renderer.render).to eq unindent(<<-EOS)
28
- ┌──┬──┬──┐
29
- │h1│h2│h3│
30
- ├──┼──┼──┤
31
- │a1│a2│a3│
32
- │b1│b2│b3│
33
- └──┴──┴──┘
34
- EOS
35
- end
36
- end
37
-
38
- context 'with short header' do
39
- let(:header) { ['h1', 'h2'] }
40
- let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
41
-
42
- it 'displays table according to widths' do
43
- expect(renderer.render).to eq unindent(<<-EOS)
44
- ┌────┬───┐
45
- │h1 │h2 │
46
- ├────┼───┤
47
- │aaa1│a2 │
48
- │b1 │bb1│
49
- └────┴───┘
50
- EOS
51
- end
52
- end
53
-
54
- context 'with long header' do
55
- let(:header) { ['header1', 'header2', 'header3'] }
56
-
57
- it 'header greater than row sizes' do
58
- expect(renderer.render).to eq unindent(<<-EOS)
59
- ┌───────┬───────┬───────┐
60
- │header1│header2│header3│
61
- ├───────┼───────┼───────┤
62
- │a1 │a2 │a3 │
63
- │b1 │b2 │b3 │
64
- └───────┴───────┴───────┘
65
- EOS
66
- end
67
- end
68
- end