tty 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/CHANGELOG.md +5 -0
- data/README.md +42 -306
- data/lib/tty/{text → shell}/distance.rb +5 -27
- data/lib/tty/shell/suggestion.rb +42 -22
- data/lib/tty/version.rb +1 -1
- data/lib/tty.rb +2 -42
- data/spec/tty/{text → shell}/distance/distance_spec.rb +4 -4
- data/spec/tty/shell/distance/initialize_spec.rb +14 -0
- data/tty.gemspec +4 -3
- metadata +37 -269
- data/benchmarks/table.rb +0 -40
- data/lib/tty/table/border/ascii.rb +0 -32
- data/lib/tty/table/border/null.rb +0 -37
- data/lib/tty/table/border/row_line.rb +0 -18
- data/lib/tty/table/border/unicode.rb +0 -32
- data/lib/tty/table/border.rb +0 -222
- data/lib/tty/table/border_dsl.rb +0 -251
- data/lib/tty/table/border_options.rb +0 -53
- data/lib/tty/table/column_set.rb +0 -121
- data/lib/tty/table/columns.rb +0 -170
- data/lib/tty/table/error.rb +0 -18
- data/lib/tty/table/field.rb +0 -139
- data/lib/tty/table/header.rb +0 -133
- data/lib/tty/table/indentation.rb +0 -52
- data/lib/tty/table/operation/alignment.rb +0 -107
- data/lib/tty/table/operation/alignment_set.rb +0 -77
- data/lib/tty/table/operation/escape.rb +0 -30
- data/lib/tty/table/operation/filter.rb +0 -34
- data/lib/tty/table/operation/padding.rb +0 -95
- data/lib/tty/table/operation/truncation.rb +0 -55
- data/lib/tty/table/operation/wrapped.rb +0 -58
- data/lib/tty/table/operations.rb +0 -69
- data/lib/tty/table/orientation/horizontal.rb +0 -48
- data/lib/tty/table/orientation/vertical.rb +0 -38
- data/lib/tty/table/orientation.rb +0 -57
- data/lib/tty/table/padder.rb +0 -180
- data/lib/tty/table/renderer/ascii.rb +0 -16
- data/lib/tty/table/renderer/basic.rb +0 -294
- data/lib/tty/table/renderer/color.rb +0 -12
- data/lib/tty/table/renderer/unicode.rb +0 -21
- data/lib/tty/table/renderer.rb +0 -101
- data/lib/tty/table/row.rb +0 -217
- data/lib/tty/table/transformation.rb +0 -39
- data/lib/tty/table/validatable.rb +0 -64
- data/lib/tty/table.rb +0 -476
- data/lib/tty/text/truncation.rb +0 -99
- data/lib/tty/text/wrapping.rb +0 -118
- data/lib/tty/text.rb +0 -98
- data/spec/tty/table/access_spec.rb +0 -86
- data/spec/tty/table/add_row_spec.rb +0 -28
- data/spec/tty/table/border/ascii/rendering_spec.rb +0 -90
- data/spec/tty/table/border/new_spec.rb +0 -27
- data/spec/tty/table/border/null/rendering_spec.rb +0 -130
- data/spec/tty/table/border/options/from_spec.rb +0 -38
- data/spec/tty/table/border/options/new_spec.rb +0 -14
- data/spec/tty/table/border/unicode/rendering_spec.rb +0 -63
- data/spec/tty/table/border_options/new_spec.rb +0 -20
- data/spec/tty/table/border_options/update_spec.rb +0 -18
- data/spec/tty/table/column_set/extract_widths_spec.rb +0 -15
- data/spec/tty/table/column_set/total_width_spec.rb +0 -15
- data/spec/tty/table/column_set/widths_from_spec.rb +0 -51
- data/spec/tty/table/columns/enforce_spec.rb +0 -68
- data/spec/tty/table/columns/widths_spec.rb +0 -35
- data/spec/tty/table/data_spec.rb +0 -14
- data/spec/tty/table/each_spec.rb +0 -41
- data/spec/tty/table/each_with_index_spec.rb +0 -57
- data/spec/tty/table/empty_spec.rb +0 -23
- data/spec/tty/table/eql_spec.rb +0 -34
- data/spec/tty/table/field/equality_spec.rb +0 -51
- data/spec/tty/table/field/length_spec.rb +0 -21
- data/spec/tty/table/field/lines_spec.rb +0 -21
- data/spec/tty/table/field/new_spec.rb +0 -29
- data/spec/tty/table/field/width_spec.rb +0 -23
- data/spec/tty/table/filter_spec.rb +0 -23
- data/spec/tty/table/header/call_spec.rb +0 -30
- data/spec/tty/table/header/height_spec.rb +0 -27
- data/spec/tty/table/header/new_spec.rb +0 -25
- data/spec/tty/table/header/set_spec.rb +0 -20
- data/spec/tty/table/header/to_ary_spec.rb +0 -14
- data/spec/tty/table/header_spec.rb +0 -13
- data/spec/tty/table/indentation/insert_indent_spec.rb +0 -27
- data/spec/tty/table/initialize_spec.rb +0 -88
- data/spec/tty/table/operation/alignment/format_spec.rb +0 -47
- data/spec/tty/table/operation/alignment/new_spec.rb +0 -31
- data/spec/tty/table/operation/alignment_set/call_spec.rb +0 -39
- data/spec/tty/table/operation/alignment_set/each_spec.rb +0 -17
- data/spec/tty/table/operation/alignment_set/new_spec.rb +0 -27
- data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +0 -14
- data/spec/tty/table/operation/escape/call_spec.rb +0 -16
- data/spec/tty/table/operation/filter/call_spec.rb +0 -17
- data/spec/tty/table/operation/truncation/call_spec.rb +0 -32
- data/spec/tty/table/operation/truncation/truncate_spec.rb +0 -22
- data/spec/tty/table/operation/wrapped/call_spec.rb +0 -33
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +0 -23
- data/spec/tty/table/operations/new_spec.rb +0 -30
- data/spec/tty/table/options_spec.rb +0 -25
- data/spec/tty/table/orientation_spec.rb +0 -145
- data/spec/tty/table/padder/parse_spec.rb +0 -45
- data/spec/tty/table/padder/to_s_spec.rb +0 -14
- data/spec/tty/table/padding_spec.rb +0 -120
- data/spec/tty/table/properties_spec.rb +0 -25
- data/spec/tty/table/render_spec.rb +0 -63
- data/spec/tty/table/render_with_spec.rb +0 -106
- data/spec/tty/table/renderer/ascii/indentation_spec.rb +0 -41
- data/spec/tty/table/renderer/ascii/padding_spec.rb +0 -61
- data/spec/tty/table/renderer/ascii/render_spec.rb +0 -68
- data/spec/tty/table/renderer/ascii/resizing_spec.rb +0 -114
- data/spec/tty/table/renderer/ascii/separator_spec.rb +0 -28
- data/spec/tty/table/renderer/basic/alignment_spec.rb +0 -88
- data/spec/tty/table/renderer/basic/coloring_spec.rb +0 -46
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +0 -28
- data/spec/tty/table/renderer/basic/filter_spec.rb +0 -53
- data/spec/tty/table/renderer/basic/indentation_spec.rb +0 -48
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +0 -135
- data/spec/tty/table/renderer/basic/new_spec.rb +0 -22
- data/spec/tty/table/renderer/basic/options_spec.rb +0 -48
- data/spec/tty/table/renderer/basic/padding_spec.rb +0 -52
- data/spec/tty/table/renderer/basic/render_spec.rb +0 -57
- data/spec/tty/table/renderer/basic/resizing_spec.rb +0 -96
- data/spec/tty/table/renderer/basic/separator_spec.rb +0 -43
- data/spec/tty/table/renderer/basic/truncation_spec.rb +0 -35
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +0 -40
- data/spec/tty/table/renderer/basic_spec.rb +0 -0
- data/spec/tty/table/renderer/border_spec.rb +0 -104
- data/spec/tty/table/renderer/render_spec.rb +0 -36
- data/spec/tty/table/renderer/select_spec.rb +0 -22
- data/spec/tty/table/renderer/style_spec.rb +0 -72
- data/spec/tty/table/renderer/unicode/indentation_spec.rb +0 -41
- data/spec/tty/table/renderer/unicode/padding_spec.rb +0 -61
- data/spec/tty/table/renderer/unicode/render_spec.rb +0 -68
- data/spec/tty/table/renderer/unicode/separator_spec.rb +0 -26
- data/spec/tty/table/renderer_spec.rb +0 -19
- data/spec/tty/table/rotate_spec.rb +0 -86
- data/spec/tty/table/row/access_spec.rb +0 -25
- data/spec/tty/table/row/call_spec.rb +0 -41
- data/spec/tty/table/row/data_spec.rb +0 -26
- data/spec/tty/table/row/each_spec.rb +0 -31
- data/spec/tty/table/row/equality_spec.rb +0 -73
- data/spec/tty/table/row/height_spec.rb +0 -27
- data/spec/tty/table/row/new_spec.rb +0 -41
- data/spec/tty/table/row/to_ary_spec.rb +0 -14
- data/spec/tty/table/to_s_spec.rb +0 -63
- data/spec/tty/table/transformation/extract_tuples_spec.rb +0 -35
- data/spec/tty/table/validatable/validate_options_spec.rb +0 -33
- data/spec/tty/table/validatable_spec.rb +0 -32
- data/spec/tty/text/distance/initialize_spec.rb +0 -14
- data/spec/tty/text/distance_spec.rb +0 -11
- data/spec/tty/text/truncate_spec.rb +0 -12
- data/spec/tty/text/truncation/initialize_spec.rb +0 -29
- data/spec/tty/text/truncation/truncate_spec.rb +0 -94
- data/spec/tty/text/wrap_spec.rb +0 -13
- data/spec/tty/text/wrapping/initialize_spec.rb +0 -25
- data/spec/tty/text/wrapping/wrap_spec.rb +0 -97
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Header, '#to_ary' do
|
6
|
-
let(:object) { described_class.new(attributes) }
|
7
|
-
let(:attributes) { [:id, :name, :age] }
|
8
|
-
|
9
|
-
subject { object.to_ary }
|
10
|
-
|
11
|
-
it { is_expected.to be_instance_of(Array) }
|
12
|
-
|
13
|
-
it { is_expected.to eq(attributes) }
|
14
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table, '#header' do
|
6
|
-
let(:header) { [:header1, :header2] }
|
7
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
8
|
-
let(:object) { described_class }
|
9
|
-
|
10
|
-
subject(:table) { object.new header, rows }
|
11
|
-
|
12
|
-
it { expect(table.header).to be_instance_of(TTY::Table::Header) }
|
13
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Indentation, '#insert_indent' do
|
6
|
-
let(:indent) { 2 }
|
7
|
-
let(:renderer) { double(:renderer, indent: indent) }
|
8
|
-
let(:object) { described_class.new(renderer) }
|
9
|
-
|
10
|
-
subject { object.insert_indent(part) }
|
11
|
-
|
12
|
-
context 'when enumerable' do
|
13
|
-
let(:part) { ['line1'] }
|
14
|
-
|
15
|
-
it 'inserts indentation for each element' do
|
16
|
-
expect(subject[0]).to eql(' line1')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when string' do
|
21
|
-
let(:part) { 'line1' }
|
22
|
-
|
23
|
-
it 'inserts indentation' do
|
24
|
-
expect(subject).to eql(' line1')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table, '#initialize' do
|
6
|
-
let(:header) { ['Header1', 'Header2'] }
|
7
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
8
|
-
|
9
|
-
it { is_expected.to be_kind_of(Enumerable) }
|
10
|
-
|
11
|
-
it { is_expected.to be_kind_of(Comparable) }
|
12
|
-
|
13
|
-
it { expect(Enumerable === subject).to eq(true) }
|
14
|
-
|
15
|
-
context 'with rows only' do
|
16
|
-
it 'initializes with rows as arguments' do
|
17
|
-
table = TTY::Table[*rows]
|
18
|
-
expect(table.to_a).to eql(rows)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'initializes with rows' do
|
22
|
-
table = TTY::Table.new rows
|
23
|
-
expect(table.to_a).to eql(rows)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'initializes table rows as an option' do
|
27
|
-
table = TTY::Table.new rows: rows
|
28
|
-
expect(table.to_a).to eq(rows)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'initializes table rows in a block with param' do
|
32
|
-
table = TTY::Table.new do |t|
|
33
|
-
t << rows[0]
|
34
|
-
t << rows[1]
|
35
|
-
end
|
36
|
-
expect(table.to_a).to eq(rows)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'initializes table and adds rows' do
|
40
|
-
table = TTY::Table.new
|
41
|
-
table << rows[0]
|
42
|
-
table << rows[1]
|
43
|
-
expect(table.to_a).to eq(rows)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'chains rows' do
|
47
|
-
table = TTY::Table.new
|
48
|
-
table << rows[0] << rows[1]
|
49
|
-
expect(table.to_a).to eq(rows)
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'with data as hash' do
|
53
|
-
let(:data) { [ {'Header1' => ['a1','a2'], 'Header2' => ['b1', 'b2'] }] }
|
54
|
-
|
55
|
-
it 'extracts rows' do
|
56
|
-
table = TTY::Table.new data
|
57
|
-
expect(table.to_a).to include rows[0]
|
58
|
-
expect(table.to_a).to include rows[1]
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'extracts header' do
|
62
|
-
table = TTY::Table.new data
|
63
|
-
expect(table.header).to include header[0]
|
64
|
-
expect(table.header).to include header[1]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'with header and rows' do
|
70
|
-
it 'initializes header as an option' do
|
71
|
-
table = TTY::Table.new header: header
|
72
|
-
expect(table.header).to eql(header)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'initializes table rows as an argument' do
|
76
|
-
table = TTY::Table.new header, rows
|
77
|
-
expect(table.header).to eql(header)
|
78
|
-
expect(table.rows).to eql(rows)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'coercion' do
|
83
|
-
it 'converts row arguments from hash to array' do
|
84
|
-
table = TTY::Table.new rows: {a: 1, b: 2}
|
85
|
-
expect(table.to_a).to include [:a, 1 ]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Alignment, '#new' do
|
6
|
-
let(:object) { described_class.new alignment }
|
7
|
-
let(:field) { "aaaa"}
|
8
|
-
let(:space) { '' }
|
9
|
-
let(:column_width) { 8 }
|
10
|
-
|
11
|
-
subject { object.format field, column_width, space }
|
12
|
-
|
13
|
-
shared_examples_for 'lower column width' do
|
14
|
-
let(:column_width) { 2 }
|
15
|
-
|
16
|
-
it { is_expected.to eql(field) }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'left aligend' do
|
20
|
-
let(:alignment) { :left }
|
21
|
-
|
22
|
-
it { is_expected.to eq(field + ' ') }
|
23
|
-
|
24
|
-
it_should_behave_like 'lower column width'
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'center aligned' do
|
28
|
-
let(:alignment) { :center }
|
29
|
-
|
30
|
-
it { is_expected.to eql(' ' + field + ' ') }
|
31
|
-
|
32
|
-
it_should_behave_like 'lower column width'
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'right aligned' do
|
36
|
-
let(:alignment) { :right }
|
37
|
-
|
38
|
-
it_should_behave_like 'lower column width'
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'with space' do
|
42
|
-
let(:alignment) { :center }
|
43
|
-
let(:space) { ' '}
|
44
|
-
|
45
|
-
it { is_expected.to eql(' ' + field + ' ') }
|
46
|
-
end
|
47
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Alignment, '#new' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject { object.new(type) }
|
9
|
-
|
10
|
-
context 'with no type' do
|
11
|
-
let(:type) { nil }
|
12
|
-
|
13
|
-
it { is_expected.to be_instance_of(object) }
|
14
|
-
|
15
|
-
it { expect(subject.type).to eql(:left) }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with unrecognized type' do
|
19
|
-
let(:type) { :unknown }
|
20
|
-
|
21
|
-
it 'raises exception' do
|
22
|
-
expect { subject }.to raise_error(TTY::TypeError)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with coerced type' do
|
27
|
-
let(:type) { 'center' }
|
28
|
-
|
29
|
-
it { expect(subject.type).to eql(:center) }
|
30
|
-
end
|
31
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::AlignmentSet, '#call' do
|
6
|
-
let(:object) { described_class.new alignments, widths }
|
7
|
-
let(:value) { 'a1' }
|
8
|
-
let(:field) { TTY::Table::Field.new(value)}
|
9
|
-
|
10
|
-
subject { object.call(field, 0, 0) }
|
11
|
-
|
12
|
-
context 'aligned with column widths and no alignments' do
|
13
|
-
let(:alignments) { [] }
|
14
|
-
let(:widths) { [4, 4] }
|
15
|
-
|
16
|
-
it { is_expected.to eq("#{value} ") }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'aligned with column widths and alignments' do
|
20
|
-
let(:alignments) { [:right, :left] }
|
21
|
-
let(:widths) { [4, 4] }
|
22
|
-
|
23
|
-
it { is_expected.to eq(" #{value}") }
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'aligned with no column widths and no alignments' do
|
27
|
-
let(:alignments) { [] }
|
28
|
-
let(:widths) { [] }
|
29
|
-
|
30
|
-
it { is_expected.to eq("#{value}") }
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'aligned with no column widths and alignments' do
|
34
|
-
let(:alignments) { [:right, :left] }
|
35
|
-
let(:widths) { [] }
|
36
|
-
|
37
|
-
it { is_expected.to eq("#{value}") }
|
38
|
-
end
|
39
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::AlignmentSet, '#each' do
|
6
|
-
let(:alignments) { [:left, :center, :right] }
|
7
|
-
let(:yields) { [] }
|
8
|
-
let(:object) { described_class.new alignments }
|
9
|
-
|
10
|
-
subject { object.each { |alignment| yields << alignment } }
|
11
|
-
|
12
|
-
it 'yields each alignment' do
|
13
|
-
expect { subject }.to change { yields.dup }.
|
14
|
-
from([]).
|
15
|
-
to(alignments)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::AlignmentSet, '#new' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject { object.new(argument) }
|
9
|
-
|
10
|
-
context 'with no argument' do
|
11
|
-
let(:argument) { [] }
|
12
|
-
|
13
|
-
it { is_expected.to be_kind_of(Enumerable) }
|
14
|
-
|
15
|
-
it { is_expected.to be_instance_of(object) }
|
16
|
-
|
17
|
-
it { expect(subject.alignments).to eq([]) }
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with argument' do
|
21
|
-
let(:argument) { [:center, :left] }
|
22
|
-
|
23
|
-
it { is_expected.to be_instance_of(object) }
|
24
|
-
|
25
|
-
it { expect(subject.alignments).to eq(argument) }
|
26
|
-
end
|
27
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::AlignmentSet, '#to_ary' do
|
6
|
-
let(:argument) { [:center, :left] }
|
7
|
-
let(:object) { described_class.new argument }
|
8
|
-
|
9
|
-
subject { object.to_ary }
|
10
|
-
|
11
|
-
it { is_expected.to be_instance_of(Array) }
|
12
|
-
|
13
|
-
it { is_expected.to eq(argument) }
|
14
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Escape, '#call' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
let(:text) { "太丸\nゴシ\tック体\r" }
|
8
|
-
let(:field) { TTY::Table::Field.new(text) }
|
9
|
-
|
10
|
-
subject { object.new }
|
11
|
-
|
12
|
-
it 'changes field value' do
|
13
|
-
subject.call(field, 0, 0)
|
14
|
-
expect(field.value).to eql("太丸\\nゴシ\\tック体\\r")
|
15
|
-
end
|
16
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Filter, '#call' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
let(:field) { TTY::Table::Field.new('a1') }
|
8
|
-
let(:filter) { Proc.new { |val, row, col| 'new' } }
|
9
|
-
let(:value) { 'new' }
|
10
|
-
|
11
|
-
subject { object.new(filter) }
|
12
|
-
|
13
|
-
it 'changes field value' do
|
14
|
-
subject.call(field, 0, 0)
|
15
|
-
expect(field.value).to eql(value)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Truncation, '#call' do
|
6
|
-
let(:object) { described_class.new column_widths }
|
7
|
-
let(:text) { '太丸ゴシック体' }
|
8
|
-
let(:field) { TTY::Table::Field.new(text) }
|
9
|
-
|
10
|
-
context 'without column width' do
|
11
|
-
let(:column_widths) { [] }
|
12
|
-
|
13
|
-
it "truncates string" do
|
14
|
-
object.call(field, 0, 0)
|
15
|
-
expect(field.value).to eql(text)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with column width ' do
|
20
|
-
let(:column_widths) { [3, 6] }
|
21
|
-
|
22
|
-
it "truncates string for 0 column" do
|
23
|
-
object.call(field, 0, 0)
|
24
|
-
expect(field.value).to eql('太丸…')
|
25
|
-
end
|
26
|
-
|
27
|
-
it "truncates string for 1 column" do
|
28
|
-
object.call(field, 0, 1)
|
29
|
-
expect(field.value).to eql('太丸ゴシッ…')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Truncation, '#truncate' do
|
6
|
-
let(:instance) { described_class.new [] }
|
7
|
-
let(:text) { '太丸ゴシック体' }
|
8
|
-
|
9
|
-
subject { instance.truncate(text, width) }
|
10
|
-
|
11
|
-
context 'without shortening' do
|
12
|
-
let(:width) { 8 }
|
13
|
-
|
14
|
-
it { is_expected.to eq(text) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with shortening' do
|
18
|
-
let(:width) { 5 }
|
19
|
-
|
20
|
-
it { is_expected.to eq('太丸ゴシ…') }
|
21
|
-
end
|
22
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Wrapped, '#call' do
|
6
|
-
let(:padding) { TTY::Table::Padder.parse }
|
7
|
-
let(:object) { described_class.new(column_widths, padding) }
|
8
|
-
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
9
|
-
let(:field) { TTY::Table::Field.new(text) }
|
10
|
-
|
11
|
-
context 'without column width' do
|
12
|
-
let(:column_widths) { [] }
|
13
|
-
|
14
|
-
it "doesn't wrap string" do
|
15
|
-
object.call(field, 0, 0)
|
16
|
-
expect(field.value).to eql(text)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with column width' do
|
21
|
-
let(:column_widths) { [12, 14] }
|
22
|
-
|
23
|
-
it "wraps string for 0 column" do
|
24
|
-
object.call(field, 0, 0)
|
25
|
-
expect(field.value).to eql("ラドクリフ、マラソン五輪\n代表に1万m出場にも含み")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "wraps string for 1 column" do
|
29
|
-
object.call(field, 0, 1)
|
30
|
-
expect(field.value).to eql("ラドクリフ、マラソン五輪代表\nに1万m出場にも含み")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operation::Wrapped, '#wrap' do
|
6
|
-
let(:padding) { TTY::Table::Padder.parse }
|
7
|
-
let(:instance) { described_class.new([], padding) }
|
8
|
-
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
9
|
-
|
10
|
-
subject { instance.wrap(text, width) }
|
11
|
-
|
12
|
-
context 'without wrapping' do
|
13
|
-
let(:width) { 8 }
|
14
|
-
|
15
|
-
it { is_expected.to eq("ラドクリフ、マラ\nソン五輪代表に1\n万m出場にも含み") }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with wrapping' do
|
19
|
-
let(:width) { 100 }
|
20
|
-
|
21
|
-
it { is_expected.to eq(text) }
|
22
|
-
end
|
23
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Operations, '#new' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
let(:row) { [1,2,3] }
|
8
|
-
let(:table) { TTY::Table.new :rows => [row] }
|
9
|
-
let(:callable) {
|
10
|
-
Class.new do
|
11
|
-
def call(val, row, col)
|
12
|
-
val.value= val.value + 1
|
13
|
-
end
|
14
|
-
end
|
15
|
-
}
|
16
|
-
let(:instance) { callable.new }
|
17
|
-
|
18
|
-
subject { object.new table }
|
19
|
-
|
20
|
-
before { subject.add(:alignment, instance) }
|
21
|
-
|
22
|
-
it 'stores away operations' do
|
23
|
-
expect(subject.operations[:alignment]).to include(instance)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'runs selected operations' do
|
27
|
-
subject.run_operations(:alignment)
|
28
|
-
expect(table.data[0]).to eql([2,3,4])
|
29
|
-
end
|
30
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table, 'options' do
|
6
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
7
|
-
let(:widths) { nil }
|
8
|
-
let(:aligns) { [] }
|
9
|
-
let(:object) { described_class }
|
10
|
-
let(:options) {
|
11
|
-
{
|
12
|
-
column_widths: widths,
|
13
|
-
column_aligns: aligns,
|
14
|
-
renderer: :basic
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
subject(:table) { object.new rows, options }
|
19
|
-
|
20
|
-
it { expect(table.header).to be_nil }
|
21
|
-
|
22
|
-
it { expect(table.rows).to eq(rows) }
|
23
|
-
|
24
|
-
it { expect(table.orientation).to be_kind_of TTY::Table::Orientation::Horizontal }
|
25
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table, 'orientation' do
|
6
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:options) { { :orientation => orientation } }
|
9
|
-
|
10
|
-
subject { described_class.new(header, rows, options) }
|
11
|
-
|
12
|
-
context 'when illegal option' do
|
13
|
-
let(:orientation) { :accross }
|
14
|
-
|
15
|
-
it { expect { subject }.to raise_error(TTY::InvalidOrientationError) }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when horizontal' do
|
19
|
-
let(:orientation) { :horizontal }
|
20
|
-
|
21
|
-
it { expect(subject.orientation).to be_kind_of TTY::Table::Orientation }
|
22
|
-
|
23
|
-
it { expect(subject.orientation.name).to eql(:horizontal) }
|
24
|
-
|
25
|
-
it { expect(subject.header).to eql(header) }
|
26
|
-
|
27
|
-
it 'preserves original rows' do
|
28
|
-
expect(subject.to_a).to eql(subject.data)
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'without border' do
|
32
|
-
it 'displays table' do
|
33
|
-
expect(subject.to_s).to eq <<-EOS.normalize
|
34
|
-
h1 h2 h3
|
35
|
-
a1 a2 a3
|
36
|
-
b1 b2 b3
|
37
|
-
EOS
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'with border' do
|
42
|
-
let(:renderer) { :ascii }
|
43
|
-
|
44
|
-
it 'diplays table' do
|
45
|
-
expect(subject.render(renderer)).to eq <<-EOS.normalize
|
46
|
-
+--+--+--+
|
47
|
-
|h1|h2|h3|
|
48
|
-
+--+--+--+
|
49
|
-
|a1|a2|a3|
|
50
|
-
|b1|b2|b3|
|
51
|
-
+--+--+--+
|
52
|
-
EOS
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when vertical' do
|
58
|
-
let(:orientation) { :vertical }
|
59
|
-
|
60
|
-
it { expect(subject.orientation).to be_kind_of TTY::Table::Orientation }
|
61
|
-
|
62
|
-
it { expect(subject.orientation.name).to eql :vertical }
|
63
|
-
|
64
|
-
it { expect(subject.header).to be_empty }
|
65
|
-
|
66
|
-
context 'with header' do
|
67
|
-
it 'rotates original rows' do
|
68
|
-
rotated_rows = [['h1','a1'],['h2','a2'],['h3','a3'], ['h1','b1'],['h2','b2'],['h3','b3']]
|
69
|
-
expect(subject.to_a).to eql rotated_rows
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'without border' do
|
73
|
-
it 'displays table' do
|
74
|
-
expect(subject.to_s).to eq <<-EOS.normalize
|
75
|
-
h1 a1
|
76
|
-
h2 a2
|
77
|
-
h3 a3
|
78
|
-
h1 b1
|
79
|
-
h2 b2
|
80
|
-
h3 b3
|
81
|
-
EOS
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'with border' do
|
86
|
-
let(:renderer) { :ascii }
|
87
|
-
|
88
|
-
it 'diplays table' do
|
89
|
-
expect(subject.render(renderer)).to eq <<-EOS.normalize
|
90
|
-
+--+--+
|
91
|
-
|h1|a1|
|
92
|
-
|h2|a2|
|
93
|
-
|h3|a3|
|
94
|
-
|h1|b1|
|
95
|
-
|h2|b2|
|
96
|
-
|h3|b3|
|
97
|
-
+--+--+
|
98
|
-
EOS
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'without header' do
|
104
|
-
let(:header) { nil }
|
105
|
-
|
106
|
-
it 'rotates original rows' do
|
107
|
-
rotated_rows = [
|
108
|
-
['1','a1'],['2','a2'],['3','a3'],
|
109
|
-
['1','b1'],['2','b2'],['3','b3']
|
110
|
-
]
|
111
|
-
expect(subject.to_a).to eql rotated_rows
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'without border' do
|
115
|
-
it 'displays table' do
|
116
|
-
expect(subject.to_s).to eq <<-EOS.normalize
|
117
|
-
1 a1
|
118
|
-
2 a2
|
119
|
-
3 a3
|
120
|
-
1 b1
|
121
|
-
2 b2
|
122
|
-
3 b3
|
123
|
-
EOS
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context 'with border' do
|
128
|
-
let(:renderer) { :ascii }
|
129
|
-
|
130
|
-
it 'diplays table' do
|
131
|
-
expect(subject.render(renderer)).to eq <<-EOS.normalize
|
132
|
-
+-+--+
|
133
|
-
|1|a1|
|
134
|
-
|2|a2|
|
135
|
-
|3|a3|
|
136
|
-
|1|b1|
|
137
|
-
|2|b2|
|
138
|
-
|3|b3|
|
139
|
-
+-+--+
|
140
|
-
EOS
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end # orientation
|