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,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Row, '#call' do
|
6
|
-
let(:object) { described_class.new(data) }
|
7
|
-
|
8
|
-
subject { object[attribute] }
|
9
|
-
|
10
|
-
context 'when integer' do
|
11
|
-
let(:data) { ['a', 'b'] }
|
12
|
-
|
13
|
-
let(:attribute) { 1 }
|
14
|
-
|
15
|
-
it { is_expected.to eql('b') }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when symbol' do
|
19
|
-
let(:data) { {:id => 1} }
|
20
|
-
|
21
|
-
context 'when hash access' do
|
22
|
-
let(:attribute) { :id }
|
23
|
-
|
24
|
-
it { is_expected.to eql(1) }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when array access' do
|
28
|
-
let(:attribute) { 0 }
|
29
|
-
|
30
|
-
it { is_expected.to eql(1) }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when unkown attribute' do
|
35
|
-
let(:data) { {:id => 1} }
|
36
|
-
|
37
|
-
let(:attribute) { :other }
|
38
|
-
|
39
|
-
specify { expect { subject }.to raise_error(TTY::UnknownAttributeError) }
|
40
|
-
end
|
41
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Row, '#data' do
|
6
|
-
let(:object) { described_class.new data, header }
|
7
|
-
let(:data) { ['a'] }
|
8
|
-
|
9
|
-
subject { object.to_hash }
|
10
|
-
|
11
|
-
context 'without attributes' do
|
12
|
-
let(:header) { nil }
|
13
|
-
|
14
|
-
it { is_expected.to be_instance_of(Hash) }
|
15
|
-
|
16
|
-
it { is_expected.to eql(0 => 'a') }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with attributes' do
|
20
|
-
let(:header) { [:id] }
|
21
|
-
|
22
|
-
it { is_expected.to be_instance_of(Hash) }
|
23
|
-
|
24
|
-
it { is_expected.to eql(id: 'a') }
|
25
|
-
end
|
26
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Row, '#new' do
|
6
|
-
let(:yields) { [] }
|
7
|
-
let(:value) { 'a1' }
|
8
|
-
let(:header) { ['Header1']}
|
9
|
-
let(:row) { [ value ] }
|
10
|
-
let(:object) { described_class.new row, header }
|
11
|
-
|
12
|
-
context 'with block' do
|
13
|
-
subject { object.each { |field| yields << field } }
|
14
|
-
|
15
|
-
it 'yields only fields' do
|
16
|
-
subject
|
17
|
-
yields.each { |field| expect(field).to be_instance_of(value.class) }
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'yields rows with expected attributes' do
|
21
|
-
subject
|
22
|
-
yields.each { |field| expect(field).to eql(value) }
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'yields each row' do
|
26
|
-
expect { subject }.to change { yields }.
|
27
|
-
from( [] ).
|
28
|
-
to( yields )
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Row, '#==' do
|
6
|
-
let(:attributes) { [:id] }
|
7
|
-
let(:data) { ['1'] }
|
8
|
-
let(:object) { described_class.new(data, attributes) }
|
9
|
-
|
10
|
-
subject { object == other }
|
11
|
-
|
12
|
-
context 'with the same object' do
|
13
|
-
let(:other) { object }
|
14
|
-
|
15
|
-
it { is_expected.to eql(true) }
|
16
|
-
|
17
|
-
it 'is symmetric' do
|
18
|
-
is_expected.to eql(other == object)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with an equivalent object' do
|
23
|
-
let(:other) { object.dup }
|
24
|
-
|
25
|
-
it { is_expected.to eql(true) }
|
26
|
-
|
27
|
-
it 'is symmetric' do
|
28
|
-
is_expected.to eql(other == object)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with an equivalent object of subclass' do
|
33
|
-
let(:other) { Class.new(described_class).new(data, attributes: attributes) }
|
34
|
-
|
35
|
-
it { is_expected.to eql(true) }
|
36
|
-
|
37
|
-
it 'is symmetric' do
|
38
|
-
is_expected.to eql(other == object)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with an object having a different attributes' do
|
43
|
-
let(:other_attributes) { [:text] }
|
44
|
-
let(:other) { described_class.new(data, attributes: other_attributes) }
|
45
|
-
|
46
|
-
it { is_expected.to eql(true) }
|
47
|
-
|
48
|
-
it 'is symmetric' do
|
49
|
-
is_expected.to eql(other == object)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with an object having a different attributes' do
|
54
|
-
let(:other_data) { [2] }
|
55
|
-
let(:other) { described_class.new(other_data, attributes: attributes) }
|
56
|
-
|
57
|
-
it { is_expected.to eql(false) }
|
58
|
-
|
59
|
-
it 'is symmetric' do
|
60
|
-
is_expected.to eql(other == object)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'with an equivalent object responding to_ary' do
|
65
|
-
let(:other) { data }
|
66
|
-
|
67
|
-
it { is_expected.to eql(true) }
|
68
|
-
|
69
|
-
it 'is symmetric' do
|
70
|
-
is_expected.to eql(other == object)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Row, '#height' do
|
6
|
-
let(:object) { described_class.new row }
|
7
|
-
|
8
|
-
subject { object.height }
|
9
|
-
|
10
|
-
context 'single row' do
|
11
|
-
let(:row) { ['a1', 'b1'] }
|
12
|
-
|
13
|
-
it { expect(subject).to eql(1) }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'non escaped multiline' do
|
17
|
-
let(:row) { ["a1\na2\na3", 'b1'] }
|
18
|
-
|
19
|
-
it { expect(subject).to eql(3)}
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'escaped multiline' do
|
23
|
-
let(:row) { ["a1\\na2\\na3", 'b1'] }
|
24
|
-
|
25
|
-
it { expect(subject).to eql(1) }
|
26
|
-
end
|
27
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Row, '#new' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject { object.new data }
|
9
|
-
|
10
|
-
context 'with no arguments' do
|
11
|
-
let(:data) { [] }
|
12
|
-
|
13
|
-
it { is_expected.to be_instance_of(object) }
|
14
|
-
|
15
|
-
it { is_expected.to be_empty }
|
16
|
-
|
17
|
-
it { expect(subject.attributes).to eq([]) }
|
18
|
-
|
19
|
-
it { expect(subject.data).to eq({}) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with Array argument' do
|
23
|
-
let(:data) { ['a'] }
|
24
|
-
|
25
|
-
it { is_expected.to be_instance_of(object) }
|
26
|
-
|
27
|
-
it { expect(subject.attributes).to eq([0]) }
|
28
|
-
|
29
|
-
it { expect(subject.to_hash).to eq({0 => "a"}) }
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with Hash argument' do
|
33
|
-
let(:data) { {id: 'a'} }
|
34
|
-
|
35
|
-
it { should be_instance_of(object) }
|
36
|
-
|
37
|
-
it { expect(subject.attributes).to eq([:id]) }
|
38
|
-
|
39
|
-
it { expect(subject.to_hash).to eq({:id => 'a'}) }
|
40
|
-
end
|
41
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Row, '#to_ary' do
|
6
|
-
let(:object) { described_class.new data }
|
7
|
-
let(:data) { ['a', 'b'] }
|
8
|
-
|
9
|
-
subject { object.to_ary }
|
10
|
-
|
11
|
-
it { is_expected.to be_instance_of(Array) }
|
12
|
-
|
13
|
-
it { is_expected.to eq(data) }
|
14
|
-
end
|
data/spec/tty/table/to_s_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table, '#to_s' do
|
6
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:renderer) { :basic }
|
9
|
-
|
10
|
-
subject(:table) { described_class.new(header, rows) }
|
11
|
-
|
12
|
-
context 'without renderer' do
|
13
|
-
let(:renderer) { nil }
|
14
|
-
|
15
|
-
it 'displayes basic table' do
|
16
|
-
expect(table.to_s).to eq <<-EOS.normalize
|
17
|
-
h1 h2 h3
|
18
|
-
a1 a2 a3
|
19
|
-
b1 b2 b3
|
20
|
-
EOS
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'without border' do
|
25
|
-
it 'displays table' do
|
26
|
-
expect(table.to_s).to eq <<-EOS.normalize
|
27
|
-
h1 h2 h3
|
28
|
-
a1 a2 a3
|
29
|
-
b1 b2 b3
|
30
|
-
EOS
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with ascii border' do
|
35
|
-
let(:renderer) { :ascii }
|
36
|
-
|
37
|
-
it 'displays table' do
|
38
|
-
expect(table.render(renderer)).to eq <<-EOS.normalize
|
39
|
-
+--+--+--+
|
40
|
-
|h1|h2|h3|
|
41
|
-
+--+--+--+
|
42
|
-
|a1|a2|a3|
|
43
|
-
|b1|b2|b3|
|
44
|
-
+--+--+--+
|
45
|
-
EOS
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'with unicode border' do
|
50
|
-
let(:renderer) { :unicode}
|
51
|
-
|
52
|
-
it 'displays table' do
|
53
|
-
expect(table.render(renderer)).to eq <<-EOS.normalize
|
54
|
-
┌──┬──┬──┐
|
55
|
-
│h1│h2│h3│
|
56
|
-
├──┼──┼──┤
|
57
|
-
│a1│a2│a3│
|
58
|
-
│b1│b2│b3│
|
59
|
-
└──┴──┴──┘
|
60
|
-
EOS
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end # to_s
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Transformation, '#extract_tuples' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
let(:header) { ['Header1', 'Header2'] }
|
8
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
9
|
-
|
10
|
-
subject { object.extract_tuples(value) }
|
11
|
-
|
12
|
-
context 'when rows' do
|
13
|
-
let(:value) { [rows] }
|
14
|
-
|
15
|
-
it { expect(subject[:header]).to be_nil }
|
16
|
-
|
17
|
-
it { expect(subject[:rows]).to eql(rows) }
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when header and rows' do
|
21
|
-
let(:value) { [header, rows] }
|
22
|
-
|
23
|
-
it { expect(subject[:header]).to eql(header) }
|
24
|
-
|
25
|
-
it { expect(subject[:rows]).to eql(rows) }
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when hash' do
|
29
|
-
let(:value) { [[{'Header1' => ['a1', 'a2'], 'Header2' => ['b1', 'b2'] }]] }
|
30
|
-
|
31
|
-
it { expect(subject[:header]).to eql(header) }
|
32
|
-
|
33
|
-
it { expect(subject[:rows]).to eql(rows) }
|
34
|
-
end
|
35
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Validatable, '#validate_options!' do
|
6
|
-
let(:described_class) { Class.new { include TTY::Table::Validatable } }
|
7
|
-
|
8
|
-
subject { described_class.new.validate_options! options }
|
9
|
-
|
10
|
-
context 'with empty rows' do
|
11
|
-
let(:options) { {rows: []} }
|
12
|
-
|
13
|
-
it { expect { subject }.not_to raise_error() }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'with invalid rows type' do
|
17
|
-
let(:options) { {rows: 1 } }
|
18
|
-
|
19
|
-
it { expect { subject }.to raise_error(TTY::InvalidArgument) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with empty header' do
|
23
|
-
let(:options) { {header: []} }
|
24
|
-
|
25
|
-
it { expect { subject }.to raise_error(TTY::InvalidArgument) }
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'with invalid header type' do
|
29
|
-
let(:options) { {header: 1} }
|
30
|
-
|
31
|
-
it { expect { subject }.to raise_error(TTY::InvalidArgument) }
|
32
|
-
end
|
33
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Validatable do
|
6
|
-
let(:described_class) { Class.new { include TTY::Table::Validatable } }
|
7
|
-
let(:rows) { [['a1', 'a2'], ['b1']] }
|
8
|
-
|
9
|
-
subject { described_class.new }
|
10
|
-
|
11
|
-
it 'raises no exception' do
|
12
|
-
rows[1] << ['b2']
|
13
|
-
expect { subject.assert_row_sizes(rows) }.not_to raise_error
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'raises exception for mismatched rows' do
|
17
|
-
expect { subject.assert_row_sizes(rows) }.
|
18
|
-
to raise_error(TTY::Table::DimensionMismatchError)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "raises exception when :header key has wrong data type" do
|
22
|
-
options = {header: 'h1'}
|
23
|
-
expect { subject.validate_options!(options) }.
|
24
|
-
to raise_error(TTY::InvalidArgument)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "raises exception when :rows key has wrong data type" do
|
28
|
-
options = {rows: 'a1'}
|
29
|
-
expect { subject.validate_options!(options) }.
|
30
|
-
to raise_error(TTY::InvalidArgument)
|
31
|
-
end
|
32
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Text::Distance, '#initialize' do
|
6
|
-
let(:strings) { ['abc', 'acb'] }
|
7
|
-
|
8
|
-
subject(:distance) { described_class.new(*strings) }
|
9
|
-
|
10
|
-
it { expect(distance.first).to eq(strings.first) }
|
11
|
-
|
12
|
-
it { expect(distance.second).to eq(strings.last) }
|
13
|
-
|
14
|
-
end # initialize
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Text, '#truncate' do
|
6
|
-
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
7
|
-
let(:length) { 12 }
|
8
|
-
|
9
|
-
subject { described_class.truncate(text, :length => length) }
|
10
|
-
|
11
|
-
it { is_expected.to eq("ラドクリフ、マラソン五…") }
|
12
|
-
end # truncate
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Text::Truncation, '#initialize' do
|
6
|
-
let(:text) { "There go the ships; there is that Leviathan whom thou hast made to play therein."}
|
7
|
-
|
8
|
-
let(:args) { [] }
|
9
|
-
|
10
|
-
subject { described_class.new text, *args }
|
11
|
-
|
12
|
-
it { expect(subject.text).to eq(text) }
|
13
|
-
|
14
|
-
it { expect(subject.length).to eq(30) }
|
15
|
-
|
16
|
-
it { expect(subject.separator).to be_nil }
|
17
|
-
|
18
|
-
it { expect(subject.trailing).to eq('…') }
|
19
|
-
|
20
|
-
context 'custom values' do
|
21
|
-
let(:args) { [45, { separator: ' ', trailing: '...' }] }
|
22
|
-
|
23
|
-
it { expect(subject.length).to eq(45) }
|
24
|
-
|
25
|
-
it { expect(subject.separator).to eq(' ') }
|
26
|
-
|
27
|
-
it { expect(subject.trailing).to eq('...') }
|
28
|
-
end
|
29
|
-
end # initialize
|
@@ -1,94 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Text::Truncation, '#truncate' do
|
6
|
-
let(:separator) { nil }
|
7
|
-
let(:options) { { length: length, separator: separator, trailing: trailing } }
|
8
|
-
let(:trailing) { '…' }
|
9
|
-
let(:object) { described_class.new(text, options) }
|
10
|
-
|
11
|
-
subject { object.truncate }
|
12
|
-
|
13
|
-
context 'unicode support' do
|
14
|
-
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
15
|
-
|
16
|
-
context 'with zero length' do
|
17
|
-
let(:length) { 0 }
|
18
|
-
|
19
|
-
it { is_expected.to eq(text) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with nil length' do
|
23
|
-
let(:length) { nil }
|
24
|
-
|
25
|
-
it { is_expected.to eq(text) }
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'with equal length' do
|
29
|
-
let(:length) { text.length }
|
30
|
-
|
31
|
-
it { is_expected.to eq(text) }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with truncation' do
|
35
|
-
let(:length) { 12 }
|
36
|
-
|
37
|
-
it { is_expected.to eq("ラドクリフ、マラソン五#{trailing}") }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'without truncation' do
|
41
|
-
let(:length) { 100 }
|
42
|
-
|
43
|
-
it { is_expected.to eq(text) }
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'with separator' do
|
47
|
-
let(:length) { 12 }
|
48
|
-
let(:separator) { ' ' }
|
49
|
-
|
50
|
-
it { is_expected.to eq("ラドクリフ、マラソン五#{trailing}") }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'with custom trailing' do
|
55
|
-
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
56
|
-
let(:length) { 20 }
|
57
|
-
let(:trailing) { '... (see more)' }
|
58
|
-
|
59
|
-
it { is_expected.to eq("ラドクリフ、#{trailing}") }
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'with separator' do
|
63
|
-
let(:length) { 25 }
|
64
|
-
let(:text) { "Immense as whales, the motion of whose vast bodies can in a peaceful calm trouble the ocean til it boil." }
|
65
|
-
|
66
|
-
context 'blank' do
|
67
|
-
let(:separator) { '' }
|
68
|
-
|
69
|
-
it { is_expected.to eq("Immense as whales, the m#{trailing}") }
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'space' do
|
73
|
-
let(:separator) { ' ' }
|
74
|
-
|
75
|
-
it { is_expected.to eq("Immense as whales, the…") }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'with excape' do
|
80
|
-
let(:text) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
81
|
-
|
82
|
-
context 'removes ansi chars' do
|
83
|
-
let(:options) { {escape: true} }
|
84
|
-
|
85
|
-
it { expect(subject).to eq 'This is a bold blue text' }
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'preserves ansi chars' do
|
89
|
-
let(:options) { {escape: false, length: -1} }
|
90
|
-
|
91
|
-
it { expect(subject).to eq text }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end # truncate
|
data/spec/tty/text/wrap_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Text, '#wrap' do
|
6
|
-
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
7
|
-
let(:length) { 8 }
|
8
|
-
let(:indent) { 4 }
|
9
|
-
|
10
|
-
subject { described_class.wrap(text, :length => length, :indent => indent) }
|
11
|
-
|
12
|
-
it { is_expected.to eq(" ラドクリフ、マラ\n ソン五輪代表に1\n 万m出場にも含み") }
|
13
|
-
end # wrap
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Text::Wrapping, '#initialize' do
|
6
|
-
let(:text) { "There go the ships; there is that Leviathan whom thou hast made to play therein."}
|
7
|
-
|
8
|
-
let(:args) { [] }
|
9
|
-
|
10
|
-
subject(:wrapping) { described_class.new text, *args }
|
11
|
-
|
12
|
-
it { expect(wrapping.text).to eq(text) }
|
13
|
-
|
14
|
-
it { expect(wrapping.length).to eq(80) }
|
15
|
-
|
16
|
-
it { expect(wrapping.indent).to eq(0) }
|
17
|
-
|
18
|
-
context 'custom values' do
|
19
|
-
let(:args) { [45, { :indent => 5 }]}
|
20
|
-
|
21
|
-
it { expect(wrapping.length).to eq(45) }
|
22
|
-
|
23
|
-
it { expect(wrapping.indent).to eq(5) }
|
24
|
-
end
|
25
|
-
end # initialize
|