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,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Header, '#height' do
|
4
|
-
let(:object) { described_class.new header }
|
5
|
-
|
6
|
-
subject { object.height }
|
7
|
-
|
8
|
-
context 'single row' do
|
9
|
-
let(:header) { ['h1', 'h1'] }
|
10
|
-
|
11
|
-
it { expect(subject).to eql(1) }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'non escaped multiline' do
|
15
|
-
let(:header) { ["h1\nh1\nh1", 'h2'] }
|
16
|
-
|
17
|
-
it { expect(subject).to eql(3)}
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'escaped multiline' do
|
21
|
-
let(:header) { ["h1\\h1\\h1", 'h2'] }
|
22
|
-
|
23
|
-
it { expect(subject).to eql(1) }
|
24
|
-
end
|
25
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Header, '#new' do
|
4
|
-
it "is empty without arguments" do
|
5
|
-
header = TTY::Table::Header.new
|
6
|
-
expect(header).to be_empty
|
7
|
-
end
|
8
|
-
|
9
|
-
it "isn't empty with attributes" do
|
10
|
-
header = TTY::Table::Header.new [:id, :name, :age]
|
11
|
-
expect(header.to_a).to eq([:id, :name, :age])
|
12
|
-
end
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Header, '#set' do
|
4
|
-
let(:object) { described_class }
|
5
|
-
let(:attributes) { [:id, :name, :age] }
|
6
|
-
|
7
|
-
subject(:header) { object.new }
|
8
|
-
|
9
|
-
it 'sets the value' do
|
10
|
-
header[0] = :id
|
11
|
-
expect(header[0]).to eql(:id)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'gets the value' do
|
15
|
-
head = object.new [{value: :id}]
|
16
|
-
expect(head[0]).to eq(:id)
|
17
|
-
end
|
18
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Header, '#to_ary' do
|
4
|
-
let(:object) { described_class.new(attributes) }
|
5
|
-
let(:attributes) { [:id, :name, :age] }
|
6
|
-
|
7
|
-
subject { object.to_ary }
|
8
|
-
|
9
|
-
it { is_expected.to be_instance_of(Array) }
|
10
|
-
|
11
|
-
it { is_expected.to eq(attributes) }
|
12
|
-
end
|
data/spec/unit/header_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, '#header' do
|
4
|
-
let(:header) { [:header1, :header2] }
|
5
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject(:table) { object.new header, rows }
|
9
|
-
|
10
|
-
it { expect(table.header).to be_instance_of(TTY::Table::Header) }
|
11
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Indentation, '.indent' do
|
4
|
-
context 'when enumerable' do
|
5
|
-
it 'inserts indentation for each element' do
|
6
|
-
expect(described_class.indent(['line1'], 2)).to eql([' line1'])
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'when string' do
|
11
|
-
it 'inserts indentation' do
|
12
|
-
expect(described_class.indent('line1', 2)).to eql(' line1')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/spec/unit/new_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, '#new' do
|
4
|
-
it { is_expected.to be_kind_of(Enumerable) }
|
5
|
-
|
6
|
-
it { is_expected.to be_kind_of(Comparable) }
|
7
|
-
|
8
|
-
context 'with rows only' do
|
9
|
-
it 'allows hash like syntax for rows' do
|
10
|
-
table = TTY::Table[['a1','a2'], ['b1', 'b2']]
|
11
|
-
expect(table.to_a).to eql([['a1','a2'], ['b1', 'b2']])
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'allows for array' do
|
15
|
-
table = TTY::Table.new [['a1','a2'], ['b1','b2']]
|
16
|
-
expect(table.to_a).to eql([['a1','a2'], ['b1','b2']])
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'allows for :rows key' do
|
20
|
-
table = TTY::Table.new rows: [['a1','a2'], ['b1','b2']]
|
21
|
-
expect(table.to_a).to eql([['a1','a2'], ['b1','b2']])
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'allows for rows in a block' do
|
25
|
-
table = TTY::Table.new do |t|
|
26
|
-
t << ['a1', 'a2']
|
27
|
-
t << ['b1', 'b2']
|
28
|
-
end
|
29
|
-
expect(table.to_a).to eql([['a1','a2'],['b1','b2']])
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'allows to add rows after initialization' do
|
33
|
-
table = TTY::Table.new
|
34
|
-
table << ['a1','a2']
|
35
|
-
table << ['b1','b2']
|
36
|
-
expect(table.to_a).to eql([['a1','a2'],['b1','b2']])
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'allows for chaining rows' do
|
40
|
-
table = TTY::Table.new
|
41
|
-
table << ['a1','a2'] << ['b1','b2']
|
42
|
-
expect(table.to_a).to eql([['a1','a2'],['b1','b2']])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'with header and rows' do
|
47
|
-
it 'permits header and rows' do
|
48
|
-
table = TTY::Table.new ['h1','h2'], [['a1','a2'],['b1','b2']]
|
49
|
-
expect(table.to_a).to eql([['h1','h2'], ['a1','a2'], ['b1','b2']])
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'permits only header with :header key' do
|
53
|
-
table = TTY::Table.new header: ['h1','h2']
|
54
|
-
expect(table.to_a).to eql([['h1','h2']])
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'with header and rows as hash' do
|
59
|
-
it 'permits header as key and rows as hash values' do
|
60
|
-
table = TTY::Table.new [{'h1' => ['a1','a2'], 'h2' => ['b1','b2']}]
|
61
|
-
expect(table.to_a).to eql([['h1','h2'], ['a1','a2'], ['b1','b2']])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'coercion' do
|
66
|
-
it 'converts row arguments from hash to array' do
|
67
|
-
table = TTY::Table.new rows: {a: 1, b: 2}
|
68
|
-
expect(table.to_a).to eql([[:a,1],[:b,2]])
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Operation::Alignment, '#call' do
|
4
|
-
let(:object) { described_class.new alignments, widths }
|
5
|
-
let(:value) { 'a1' }
|
6
|
-
let(:field) { TTY::Table::Field.new(value)}
|
7
|
-
|
8
|
-
subject { object.call(field, 0, 0) }
|
9
|
-
|
10
|
-
context 'aligned with column widths and no alignments' do
|
11
|
-
let(:alignments) { [] }
|
12
|
-
let(:widths) { [4, 4] }
|
13
|
-
|
14
|
-
it { is_expected.to eq("#{value} ") }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'aligned with column widths and alignments' do
|
18
|
-
let(:alignments) { [:right, :left] }
|
19
|
-
let(:widths) { [4, 4] }
|
20
|
-
|
21
|
-
it { is_expected.to eq(" #{value}") }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'aligned with no column widths and no alignments' do
|
25
|
-
let(:alignments) { [] }
|
26
|
-
let(:widths) { [] }
|
27
|
-
|
28
|
-
it { is_expected.to eq("#{value}") }
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'aligned with no column widths and alignments' do
|
32
|
-
let(:alignments) { [:right, :left] }
|
33
|
-
let(:widths) { [] }
|
34
|
-
|
35
|
-
it { is_expected.to eq("#{value}") }
|
36
|
-
end
|
37
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Operation::Escape, '#call' do
|
4
|
-
let(:object) { described_class }
|
5
|
-
let(:text) { "太丸\nゴシ\tック体\r" }
|
6
|
-
let(:field) { TTY::Table::Field.new(text) }
|
7
|
-
|
8
|
-
subject(:operation) { object.new }
|
9
|
-
|
10
|
-
it 'changes field value' do
|
11
|
-
expect(operation.call(field, 0, 0)).to eql("太丸\\nゴシ\\tック体\\r")
|
12
|
-
end
|
13
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Operation::Filter, '#call' do
|
4
|
-
let(:object) { described_class }
|
5
|
-
let(:field) { TTY::Table::Field.new('a1') }
|
6
|
-
let(:filter) { Proc.new { |val, row, col| 'new' } }
|
7
|
-
let(:value) { 'new' }
|
8
|
-
|
9
|
-
subject(:operation) { object.new(filter) }
|
10
|
-
|
11
|
-
it 'changes field value' do
|
12
|
-
expect(operation.call(field, 0, 0)).to eql(value)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Operation::Truncation, '#call' do
|
4
|
-
let(:text) { '太丸ゴシック体' }
|
5
|
-
let(:field) { TTY::Table::Field.new(text) }
|
6
|
-
|
7
|
-
subject(:operation) { described_class.new(column_widths) }
|
8
|
-
|
9
|
-
context 'without column width' do
|
10
|
-
let(:column_widths) { [] }
|
11
|
-
|
12
|
-
it "truncates string" do
|
13
|
-
expect(operation.call(field, 0, 0)).to eql(text)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with column width ' do
|
18
|
-
let(:column_widths) { [6, 8] }
|
19
|
-
|
20
|
-
it "truncates string for 0 column" do
|
21
|
-
expect(operation.call(field, 0, 0)).to eql('太丸…')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "truncates string for 1 column" do
|
25
|
-
expect(operation.call(field, 0, 1)).to eql('太丸ゴ…')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Operation::Wrapped, '#call' do
|
4
|
-
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
5
|
-
let(:field) { TTY::Table::Field.new(text) }
|
6
|
-
|
7
|
-
subject(:operation) { described_class.new(column_widths) }
|
8
|
-
|
9
|
-
context 'without column width' do
|
10
|
-
let(:column_widths) { [] }
|
11
|
-
|
12
|
-
it "doesn't wrap string" do
|
13
|
-
expect(operation.call(field, 0, 0)).to eql(text)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with column width' do
|
18
|
-
let(:column_widths) { [12, 14] }
|
19
|
-
|
20
|
-
it "wraps string for 0 column" do
|
21
|
-
expect(operation.call(field, 0, 0)).to eql([
|
22
|
-
"ラドクリフ、",
|
23
|
-
"マラソン五輪",
|
24
|
-
"代表に1万m出",
|
25
|
-
"場にも含み"
|
26
|
-
].join("\n"))
|
27
|
-
end
|
28
|
-
|
29
|
-
it "wraps string for 1 column" do
|
30
|
-
expect(operation.call(field, 0, 1)).to eql([
|
31
|
-
"ラドクリフ、マ",
|
32
|
-
"ラソン五輪代表",
|
33
|
-
"に1万m出場にも",
|
34
|
-
"含み"
|
35
|
-
].join("\n"))
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Operations, '#new' do
|
4
|
-
let(:object) { described_class }
|
5
|
-
let(:row) { [1,2,3] }
|
6
|
-
let(:table) { TTY::Table.new :rows => [row] }
|
7
|
-
let(:callable) {
|
8
|
-
Class.new do
|
9
|
-
def call(val, row, col)
|
10
|
-
val.value= val.value + 1
|
11
|
-
end
|
12
|
-
end
|
13
|
-
}
|
14
|
-
let(:instance) { callable.new }
|
15
|
-
|
16
|
-
subject { object.new }
|
17
|
-
|
18
|
-
before { subject.add(:alignment, instance) }
|
19
|
-
|
20
|
-
it 'stores away operations' do
|
21
|
-
expect(subject[:alignment]).to include(instance)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'applies selected operations' do
|
25
|
-
subject.apply_to(table, :alignment)
|
26
|
-
expect(table.data[0]).to eql([2,3,4])
|
27
|
-
end
|
28
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# describe TTY::Table::Options, 'options' do
|
4
|
-
# let(:object) { described_class }
|
5
|
-
#
|
6
|
-
# subject { described_class.new({'a' => 1, :b => 2}) }
|
7
|
-
#
|
8
|
-
# it '' do
|
9
|
-
# pending
|
10
|
-
# expect(subject[:a]).to eql(1)
|
11
|
-
# end
|
12
|
-
# end
|
data/spec/unit/options_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, 'options' do
|
4
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
5
|
-
let(:widths) { nil }
|
6
|
-
let(:aligns) { [] }
|
7
|
-
let(:object) { described_class }
|
8
|
-
let(:options) {
|
9
|
-
{
|
10
|
-
column_widths: widths,
|
11
|
-
column_aligns: aligns,
|
12
|
-
renderer: :basic
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
subject(:table) { object.new rows, options }
|
17
|
-
|
18
|
-
it { expect(table.header).to be_nil }
|
19
|
-
|
20
|
-
it { expect(table.rows).to eq(rows) }
|
21
|
-
|
22
|
-
it { expect(table.orientation).to be_kind_of TTY::Table::Orientation::Horizontal }
|
23
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, 'orientation' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:options) { { :orientation => orientation } }
|
7
|
-
|
8
|
-
subject { described_class.new(header, rows, options) }
|
9
|
-
|
10
|
-
context 'when illegal option' do
|
11
|
-
let(:orientation) { :accross }
|
12
|
-
|
13
|
-
it { expect { subject }.to raise_error(TTY::Table::InvalidOrientationError) }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when horizontal' do
|
17
|
-
let(:orientation) { :horizontal }
|
18
|
-
|
19
|
-
it { expect(subject.orientation).to be_kind_of TTY::Table::Orientation }
|
20
|
-
|
21
|
-
it { expect(subject.orientation.name).to eql(:horizontal) }
|
22
|
-
|
23
|
-
it { expect(subject.header).to eql(header) }
|
24
|
-
|
25
|
-
it 'preserves original rows' do
|
26
|
-
expect(subject.to_a).to eql(subject.data)
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'without border' do
|
30
|
-
it 'displays table' do
|
31
|
-
expect(subject.to_s).to eq unindent(<<-EOS)
|
32
|
-
h1 h2 h3
|
33
|
-
a1 a2 a3
|
34
|
-
b1 b2 b3
|
35
|
-
EOS
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with border' do
|
40
|
-
let(:renderer) { :ascii }
|
41
|
-
|
42
|
-
it 'diplays table' do
|
43
|
-
expect(subject.render(renderer)).to eq unindent(<<-EOS)
|
44
|
-
+--+--+--+
|
45
|
-
|h1|h2|h3|
|
46
|
-
+--+--+--+
|
47
|
-
|a1|a2|a3|
|
48
|
-
|b1|b2|b3|
|
49
|
-
+--+--+--+
|
50
|
-
EOS
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when vertical' do
|
56
|
-
let(:orientation) { :vertical }
|
57
|
-
|
58
|
-
it { expect(subject.orientation).to be_kind_of TTY::Table::Orientation }
|
59
|
-
|
60
|
-
it { expect(subject.orientation.name).to eql :vertical }
|
61
|
-
|
62
|
-
it { expect(subject.header).to be_empty }
|
63
|
-
|
64
|
-
context 'with header' do
|
65
|
-
it 'rotates original rows' do
|
66
|
-
rotated_rows = [['h1','a1'],['h2','a2'],['h3','a3'], ['h1','b1'],['h2','b2'],['h3','b3']]
|
67
|
-
expect(subject.to_a).to eql rotated_rows
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'without border' do
|
71
|
-
it 'displays table' do
|
72
|
-
expect(subject.to_s).to eq unindent(<<-EOS)
|
73
|
-
h1 a1
|
74
|
-
h2 a2
|
75
|
-
h3 a3
|
76
|
-
h1 b1
|
77
|
-
h2 b2
|
78
|
-
h3 b3
|
79
|
-
EOS
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'with border' do
|
84
|
-
let(:renderer) { :ascii }
|
85
|
-
|
86
|
-
it 'diplays table' do
|
87
|
-
expect(subject.render(renderer)).to eq unindent(<<-EOS)
|
88
|
-
+--+--+
|
89
|
-
|h1|a1|
|
90
|
-
|h2|a2|
|
91
|
-
|h3|a3|
|
92
|
-
|h1|b1|
|
93
|
-
|h2|b2|
|
94
|
-
|h3|b3|
|
95
|
-
+--+--+
|
96
|
-
EOS
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'without header' do
|
102
|
-
let(:header) { nil }
|
103
|
-
|
104
|
-
it 'rotates original rows' do
|
105
|
-
rotated_rows = [
|
106
|
-
['1','a1'],['2','a2'],['3','a3'],
|
107
|
-
['1','b1'],['2','b2'],['3','b3']
|
108
|
-
]
|
109
|
-
expect(subject.to_a).to eql rotated_rows
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'without border' do
|
113
|
-
it 'displays table' do
|
114
|
-
expect(subject.to_s).to eq unindent(<<-EOS)
|
115
|
-
1 a1
|
116
|
-
2 a2
|
117
|
-
3 a3
|
118
|
-
1 b1
|
119
|
-
2 b2
|
120
|
-
3 b3
|
121
|
-
EOS
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'with border' do
|
126
|
-
let(:renderer) { :ascii }
|
127
|
-
|
128
|
-
it 'diplays table' do
|
129
|
-
expect(subject.render(renderer)).to eq unindent(<<-EOS)
|
130
|
-
+-+--+
|
131
|
-
|1|a1|
|
132
|
-
|2|a2|
|
133
|
-
|3|a3|
|
134
|
-
|1|b1|
|
135
|
-
|2|b2|
|
136
|
-
|3|b3|
|
137
|
-
+-+--+
|
138
|
-
EOS
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end # orientation
|