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,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Unicode, 'coloring' do
|
4
|
-
|
5
|
-
let(:color) { Pastel.new(enabled: true) }
|
6
|
-
|
7
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
8
|
-
|
9
|
-
context 'when border' do
|
10
|
-
it "colors border" do
|
11
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
12
|
-
table << ['a1', 'a2']
|
13
|
-
table << ['b1', 'b2']
|
14
|
-
renderer = described_class.new(table)
|
15
|
-
renderer.border = {style: :green }
|
16
|
-
|
17
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
18
|
-
#{color.green('┌───────┬───────┐')}
|
19
|
-
#{color.green('│')}header1#{color.green('│')}header2#{color.green('│')}
|
20
|
-
#{color.green('├───────┼───────┤')}
|
21
|
-
#{color.green('│')}a1 #{color.green('│')}a2 #{color.green('│')}
|
22
|
-
#{color.green('│')}b1 #{color.green('│')}b2 #{color.green('│')}
|
23
|
-
#{color.green('└───────┴───────┘')}
|
24
|
-
EOS
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when content' do
|
29
|
-
it "colors individual field" do
|
30
|
-
header = [color.yellow('header1'), 'header2']
|
31
|
-
table = TTY::Table.new header: header
|
32
|
-
table << [color.green.on_blue('a1'), 'a2']
|
33
|
-
table << ['b1', color.red.on_yellow('b2')]
|
34
|
-
renderer = described_class.new(table)
|
35
|
-
|
36
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
37
|
-
┌───────┬───────┐
|
38
|
-
│#{color.yellow('header1')}│header2│
|
39
|
-
├───────┼───────┤
|
40
|
-
│#{color.green.on_blue('a1')} │a2 │
|
41
|
-
│b1 │#{color.red.on_yellow('b2')} │
|
42
|
-
└───────┴───────┘
|
43
|
-
EOS
|
44
|
-
end
|
45
|
-
|
46
|
-
it "colors multiline content" do
|
47
|
-
header = [color.yellow("Multi\nHeader"), 'header2']
|
48
|
-
table = TTY::Table.new header: header
|
49
|
-
table << [color.green.on_blue("Multi\nLine\nContent"), 'a2']
|
50
|
-
table << ['b1', color.red.on_yellow("Multi\nLine\nContent")]
|
51
|
-
renderer = described_class.new(table, multiline: true)
|
52
|
-
|
53
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
54
|
-
┌───────┬───────┐
|
55
|
-
│#{color.yellow('Multi ')}│header2│
|
56
|
-
│#{color.yellow('Header')} │ │
|
57
|
-
├───────┼───────┤
|
58
|
-
│#{color.green.on_blue('Multi ')}│a2 │
|
59
|
-
│#{color.green.on_blue('Line ')}│ │
|
60
|
-
│#{color.green.on_blue('Content')}│ │
|
61
|
-
│b1 │#{color.red.on_yellow("Multi ")}│
|
62
|
-
│ │#{color.red.on_yellow("Line ")}│
|
63
|
-
│ │#{color.red.on_yellow("Content")}│
|
64
|
-
└───────┴───────┘
|
65
|
-
EOS
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Unicode, 'indentation' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
let(:indent) { 2 }
|
8
|
-
let(:options) { {indent: indent } }
|
9
|
-
|
10
|
-
subject(:renderer) { described_class.new(table, options)}
|
11
|
-
|
12
|
-
context 'when default' do
|
13
|
-
it 'indents by value' do
|
14
|
-
expect(renderer.render).to eq <<-EOS.chomp
|
15
|
-
┌──┬──┬──┐
|
16
|
-
│h1│h2│h3│
|
17
|
-
├──┼──┼──┤
|
18
|
-
│a1│a2│a3│
|
19
|
-
│b1│b2│b3│
|
20
|
-
└──┴──┴──┘
|
21
|
-
EOS
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when each row' do
|
26
|
-
it 'indents by value' do
|
27
|
-
renderer.border.separator = :each_row
|
28
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
29
|
-
┌──┬──┬──┐
|
30
|
-
│h1│h2│h3│
|
31
|
-
├──┼──┼──┤
|
32
|
-
│a1│a2│a3│
|
33
|
-
├──┼──┼──┤
|
34
|
-
│b1│b2│b3│
|
35
|
-
└──┴──┴──┘
|
36
|
-
EOS
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Unicode, 'padding' do
|
4
|
-
let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
|
5
|
-
let(:rows) { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
|
8
|
-
subject(:renderer) { described_class.new(table, options) }
|
9
|
-
|
10
|
-
context 'with left & right padding' do
|
11
|
-
let(:options) { {padding: [0,1,0,1]} }
|
12
|
-
|
13
|
-
it 'pads each field' do
|
14
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
15
|
-
┌───────┬─────────┬──────┬─────┬─────────┬───────┐
|
16
|
-
│ Field │ Type │ Null │ Key │ Default │ Extra │
|
17
|
-
├───────┼─────────┼──────┼─────┼─────────┼───────┤
|
18
|
-
│ id │ int(11) │ YES │ nil │ NULL │ │
|
19
|
-
└───────┴─────────┴──────┴─────┴─────────┴───────┘
|
20
|
-
EOS
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with top & bottom padding' do
|
25
|
-
let(:options) { {padding: [1,0,1,0], multiline: true} }
|
26
|
-
|
27
|
-
it 'pads each field' do
|
28
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
29
|
-
┌─────┬───────┬────┬───┬───────┬─────┐
|
30
|
-
│ │ │ │ │ │ │
|
31
|
-
│Field│Type │Null│Key│Default│Extra│
|
32
|
-
│ │ │ │ │ │ │
|
33
|
-
├─────┼───────┼────┼───┼───────┼─────┤
|
34
|
-
│ │ │ │ │ │ │
|
35
|
-
│id │int(11)│YES │nil│NULL │ │
|
36
|
-
│ │ │ │ │ │ │
|
37
|
-
└─────┴───────┴────┴───┴───────┴─────┘
|
38
|
-
EOS
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with full padding' do
|
43
|
-
let(:options) { {padding: [1,1,1,1], multiline: true} }
|
44
|
-
|
45
|
-
it 'pads each field' do
|
46
|
-
expect(renderer.render).to eql unindent(<<-EOS)
|
47
|
-
┌───────┬─────────┬──────┬─────┬─────────┬───────┐
|
48
|
-
│ │ │ │ │ │ │
|
49
|
-
│ Field │ Type │ Null │ Key │ Default │ Extra │
|
50
|
-
│ │ │ │ │ │ │
|
51
|
-
├───────┼─────────┼──────┼─────┼─────────┼───────┤
|
52
|
-
│ │ │ │ │ │ │
|
53
|
-
│ id │ int(11) │ YES │ nil │ NULL │ │
|
54
|
-
│ │ │ │ │ │ │
|
55
|
-
└───────┴─────────┴──────┴─────┴─────────┴───────┘
|
56
|
-
EOS
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Unicode, '#render' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new header, rows }
|
7
|
-
|
8
|
-
subject(:renderer) { described_class.new(table) }
|
9
|
-
|
10
|
-
context 'with rows only' do
|
11
|
-
let(:table) { TTY::Table.new rows }
|
12
|
-
|
13
|
-
it 'display table rows' do
|
14
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
15
|
-
┌──┬──┬──┐
|
16
|
-
│a1│a2│a3│
|
17
|
-
│b1│b2│b3│
|
18
|
-
└──┴──┴──┘
|
19
|
-
EOS
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'with header' do
|
24
|
-
it 'displays table with header' do
|
25
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
26
|
-
┌──┬──┬──┐
|
27
|
-
│h1│h2│h3│
|
28
|
-
├──┼──┼──┤
|
29
|
-
│a1│a2│a3│
|
30
|
-
│b1│b2│b3│
|
31
|
-
└──┴──┴──┘
|
32
|
-
EOS
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with short header' do
|
37
|
-
let(:header) { ['h1', 'h2'] }
|
38
|
-
let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
|
39
|
-
|
40
|
-
it 'displays table according to widths' do
|
41
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
42
|
-
┌────┬───┐
|
43
|
-
│h1 │h2 │
|
44
|
-
├────┼───┤
|
45
|
-
│aaa1│a2 │
|
46
|
-
│b1 │bb1│
|
47
|
-
└────┴───┘
|
48
|
-
EOS
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'with long header' do
|
53
|
-
let(:header) { ['header1', 'header2', 'header3'] }
|
54
|
-
|
55
|
-
it 'header greater than row sizes' do
|
56
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
57
|
-
┌───────┬───────┬───────┐
|
58
|
-
│header1│header2│header3│
|
59
|
-
├───────┼───────┼───────┤
|
60
|
-
│a1 │a2 │a3 │
|
61
|
-
│b1 │b2 │b3 │
|
62
|
-
└───────┴───────┴───────┘
|
63
|
-
EOS
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::Unicode, 'with separator' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
|
8
|
-
let(:object) { described_class.new table }
|
9
|
-
|
10
|
-
subject(:renderer) { object }
|
11
|
-
|
12
|
-
it "renders each row" do
|
13
|
-
renderer.border.separator= :each_row
|
14
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
15
|
-
┌──┬──┬──┐
|
16
|
-
│h1│h2│h3│
|
17
|
-
├──┼──┼──┤
|
18
|
-
│a1│a2│a3│
|
19
|
-
├──┼──┼──┤
|
20
|
-
│b1│b2│b3│
|
21
|
-
└──┴──┴──┘
|
22
|
-
EOS
|
23
|
-
end
|
24
|
-
|
25
|
-
it "will not the default separator if individual separators are specified" do
|
26
|
-
renderer.border.separator = [1]
|
27
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
28
|
-
┌──┬──┬──┐
|
29
|
-
│h1│h2│h3│
|
30
|
-
│a1│a2│a3│
|
31
|
-
├──┼──┼──┤
|
32
|
-
│b1│b2│b3│
|
33
|
-
└──┴──┴──┘
|
34
|
-
EOS
|
35
|
-
end
|
36
|
-
end
|
data/spec/unit/renderer_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, '#renderer' do
|
4
|
-
let(:object) { described_class }
|
5
|
-
let(:header) { ['h1', 'h2'] }
|
6
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
7
|
-
|
8
|
-
subject(:table) { object.new(header, rows).renderer }
|
9
|
-
|
10
|
-
it 'creates new renderer' do
|
11
|
-
expect(subject).to be_kind_of(TTY::Table::Renderer::Basic)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'chains calls on renderer' do
|
15
|
-
expect(subject.render).to eql("h1 h2\na1 a2\nb1 b2")
|
16
|
-
end
|
17
|
-
end
|
data/spec/unit/rotate_spec.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, '#rotate' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
|
7
|
-
subject(:table) { described_class.new(header, rows) }
|
8
|
-
|
9
|
-
before { table.orientation = :horizontal }
|
10
|
-
|
11
|
-
context 'with default' do
|
12
|
-
context 'without header' do
|
13
|
-
let(:header) { nil }
|
14
|
-
|
15
|
-
it 'preserves orientation' do
|
16
|
-
expect(table.header).to be_nil
|
17
|
-
expect(table.rotate.to_a).to eql rows
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with header' do
|
22
|
-
it 'preserves orientation' do
|
23
|
-
expect(table.rotate.to_a).to eql [header] + rows
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'with no header' do
|
29
|
-
let(:header) { nil }
|
30
|
-
|
31
|
-
it 'rotates the rows' do
|
32
|
-
table.orientation = :vertical
|
33
|
-
expect(table.rotate.to_a).to eql [
|
34
|
-
['1', 'a1'],
|
35
|
-
['2', 'a2'],
|
36
|
-
['3', 'a3'],
|
37
|
-
['1', 'b1'],
|
38
|
-
['2', 'b2'],
|
39
|
-
['3', 'b3'],
|
40
|
-
]
|
41
|
-
expect(table.header).to be_nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'rotates the rows back' do
|
45
|
-
table.orientation = :vertical
|
46
|
-
table.rotate
|
47
|
-
table.orientation = :horizontal
|
48
|
-
expect(table.rotate.to_a).to eql rows
|
49
|
-
expect(table.header).to eql header
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'roates the output' do
|
53
|
-
expect(table.to_s).to eq("a1 a2 a3\nb1 b2 b3")
|
54
|
-
table.orientation = :vertical
|
55
|
-
table.rotate
|
56
|
-
expect(table.to_s).to eq("1 a1\n2 a2\n3 a3\n1 b1\n2 b2\n3 b3")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'with header' do
|
61
|
-
it 'rotates the rows and merges header' do
|
62
|
-
table.orientation = :vertical
|
63
|
-
expect(table.rotate.to_a).to eql [
|
64
|
-
['h1', 'a1'],
|
65
|
-
['h2', 'a2'],
|
66
|
-
['h3', 'a3'],
|
67
|
-
['h1', 'b1'],
|
68
|
-
['h2', 'b2'],
|
69
|
-
['h3', 'b3'],
|
70
|
-
]
|
71
|
-
expect(table.header).to be_empty
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'rotates the rows and header back' do
|
75
|
-
table.orientation = :vertical
|
76
|
-
table.rotate
|
77
|
-
expect(table.orientation).to be_a TTY::Table::Orientation::Vertical
|
78
|
-
|
79
|
-
table.orientation = :horizontal
|
80
|
-
expect(table.rotate.to_a).to eql [header] + rows
|
81
|
-
expect(table.header).to eql header
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Row, '#access' do
|
4
|
-
let(:object) { described_class.new [] }
|
5
|
-
|
6
|
-
before { object[attribute] = value}
|
7
|
-
|
8
|
-
subject { object[attribute] }
|
9
|
-
|
10
|
-
context 'when integer' do
|
11
|
-
let(:attribute) { 0 }
|
12
|
-
let(:value) { 1 }
|
13
|
-
|
14
|
-
it { is_expected.to eq(1) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'when symbol' do
|
18
|
-
let(:attribute) { :id }
|
19
|
-
let(:value) { 1 }
|
20
|
-
|
21
|
-
it { is_expected.to eq(1) }
|
22
|
-
end
|
23
|
-
end
|
data/spec/unit/row/call_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Row, '#call' do
|
4
|
-
let(:object) { described_class.new(data) }
|
5
|
-
|
6
|
-
subject { object[attribute] }
|
7
|
-
|
8
|
-
context 'when integer' do
|
9
|
-
let(:data) { ['a', 'b'] }
|
10
|
-
|
11
|
-
let(:attribute) { 1 }
|
12
|
-
|
13
|
-
it { is_expected.to eql('b') }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when symbol' do
|
17
|
-
let(:data) { {:id => 1} }
|
18
|
-
|
19
|
-
context 'when hash access' do
|
20
|
-
let(:attribute) { :id }
|
21
|
-
|
22
|
-
it { is_expected.to eql(1) }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when array access' do
|
26
|
-
let(:attribute) { 0 }
|
27
|
-
|
28
|
-
it { is_expected.to eql(1) }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when unkown attribute' do
|
33
|
-
let(:data) { {:id => 1} }
|
34
|
-
|
35
|
-
let(:attribute) { :other }
|
36
|
-
|
37
|
-
specify {
|
38
|
-
expect {
|
39
|
-
subject
|
40
|
-
}.to raise_error(TTY::Table::UnknownAttributeError)
|
41
|
-
}
|
42
|
-
end
|
43
|
-
end
|
data/spec/unit/row/data_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Row, '#data' do
|
4
|
-
let(:object) { described_class.new data, header }
|
5
|
-
let(:data) { ['a'] }
|
6
|
-
|
7
|
-
subject { object.to_hash }
|
8
|
-
|
9
|
-
context 'without attributes' do
|
10
|
-
let(:header) { nil }
|
11
|
-
|
12
|
-
it { is_expected.to be_instance_of(Hash) }
|
13
|
-
|
14
|
-
it { is_expected.to eql(0 => 'a') }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with attributes' do
|
18
|
-
let(:header) { [:id] }
|
19
|
-
|
20
|
-
it { is_expected.to be_instance_of(Hash) }
|
21
|
-
|
22
|
-
it { is_expected.to eql(id: 'a') }
|
23
|
-
end
|
24
|
-
end
|