tty-table 0.7.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +57 -0
- data/LICENSE.txt +1 -1
- data/README.md +165 -94
- data/lib/tty-table.rb +1 -5
- data/lib/tty/table.rb +102 -42
- data/lib/tty/table/alignment_set.rb +3 -6
- data/lib/tty/table/border.rb +57 -68
- data/lib/tty/table/border/ascii.rb +17 -17
- data/lib/tty/table/border/null.rb +20 -22
- data/lib/tty/table/border/row_line.rb +4 -3
- data/lib/tty/table/border/unicode.rb +17 -17
- data/lib/tty/table/border_dsl.rb +28 -25
- data/lib/tty/table/border_options.rb +50 -25
- data/lib/tty/table/column_constraint.rb +29 -17
- data/lib/tty/table/{column_set.rb → columns.rb} +44 -69
- data/lib/tty/table/empty.rb +2 -0
- data/lib/tty/table/error.rb +1 -1
- data/lib/tty/table/field.rb +43 -35
- data/lib/tty/table/header.rb +7 -5
- data/lib/tty/table/indentation.rb +16 -25
- data/lib/tty/table/operation/alignment.rb +10 -8
- data/lib/tty/table/operation/escape.rb +2 -3
- data/lib/tty/table/operation/filter.rb +1 -1
- data/lib/tty/table/operation/padding.rb +4 -12
- data/lib/tty/table/operation/truncation.rb +4 -4
- data/lib/tty/table/operation/wrapped.rb +4 -4
- data/lib/tty/table/operations.rb +4 -15
- data/lib/tty/table/options.rb +2 -4
- data/lib/tty/table/orientation.rb +5 -5
- data/lib/tty/table/orientation/horizontal.rb +1 -1
- data/lib/tty/table/orientation/vertical.rb +1 -1
- data/lib/tty/table/renderer.rb +40 -35
- data/lib/tty/table/renderer/ascii.rb +4 -4
- data/lib/tty/table/renderer/basic.rb +85 -88
- data/lib/tty/table/renderer/unicode.rb +3 -3
- data/lib/tty/table/row.rb +10 -8
- data/lib/tty/table/transformation.rb +2 -2
- data/lib/tty/table/validatable.rb +25 -7
- data/lib/tty/table/version.rb +3 -3
- metadata +33 -283
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -24
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -18
- data/Rakefile +0 -8
- data/benchmarks/speed.rb +0 -41
- data/spec/spec_helper.rb +0 -50
- data/spec/unit/access_spec.rb +0 -86
- data/spec/unit/add_row_spec.rb +0 -28
- data/spec/unit/alignment_set/each_spec.rb +0 -17
- data/spec/unit/alignment_set/new_spec.rb +0 -27
- data/spec/unit/alignment_set/to_ary_spec.rb +0 -14
- data/spec/unit/alignment_spec.rb +0 -71
- data/spec/unit/border/ascii/rendering_spec.rb +0 -90
- data/spec/unit/border/new_spec.rb +0 -27
- data/spec/unit/border/null/rendering_spec.rb +0 -130
- data/spec/unit/border/options/from_spec.rb +0 -38
- data/spec/unit/border/options/new_spec.rb +0 -14
- data/spec/unit/border/unicode/rendering_spec.rb +0 -63
- data/spec/unit/border_options/new_spec.rb +0 -20
- data/spec/unit/border_options/update_spec.rb +0 -18
- data/spec/unit/column_constraint/enforce_spec.rb +0 -70
- data/spec/unit/column_constraint/widths_spec.rb +0 -35
- data/spec/unit/column_set/extract_widths_spec.rb +0 -48
- data/spec/unit/column_set/total_width_spec.rb +0 -15
- data/spec/unit/column_set/widths_from_spec.rb +0 -51
- data/spec/unit/data_spec.rb +0 -12
- data/spec/unit/each_spec.rb +0 -26
- data/spec/unit/each_with_index_spec.rb +0 -51
- data/spec/unit/empty_spec.rb +0 -23
- data/spec/unit/eql_spec.rb +0 -34
- data/spec/unit/field/equality_spec.rb +0 -51
- data/spec/unit/field/length_spec.rb +0 -35
- data/spec/unit/field/lines_spec.rb +0 -21
- data/spec/unit/field/new_spec.rb +0 -29
- data/spec/unit/field/width_spec.rb +0 -23
- data/spec/unit/filter_spec.rb +0 -22
- data/spec/unit/header/call_spec.rb +0 -30
- data/spec/unit/header/color_spec.rb +0 -19
- data/spec/unit/header/equality_spec.rb +0 -51
- data/spec/unit/header/height_spec.rb +0 -27
- data/spec/unit/header/new_spec.rb +0 -16
- data/spec/unit/header/set_spec.rb +0 -20
- data/spec/unit/header/to_ary_spec.rb +0 -14
- data/spec/unit/header_spec.rb +0 -13
- data/spec/unit/indentation/indent_spec.rb +0 -21
- data/spec/unit/new_spec.rb +0 -73
- data/spec/unit/operation/alignment/call_spec.rb +0 -39
- data/spec/unit/operation/escape/call_spec.rb +0 -15
- data/spec/unit/operation/filter/call_spec.rb +0 -16
- data/spec/unit/operation/truncation/call_spec.rb +0 -30
- data/spec/unit/operation/wrapped/call_spec.rb +0 -40
- data/spec/unit/operations/new_spec.rb +0 -30
- data/spec/unit/options/access_spec.rb +0 -14
- data/spec/unit/options_spec.rb +0 -25
- data/spec/unit/orientation_spec.rb +0 -145
- data/spec/unit/padding_spec.rb +0 -117
- data/spec/unit/properties_spec.rb +0 -25
- data/spec/unit/render_repeat_spec.rb +0 -42
- data/spec/unit/render_spec.rb +0 -63
- data/spec/unit/render_with_spec.rb +0 -106
- data/spec/unit/renderer/ascii/coloring_spec.rb +0 -70
- data/spec/unit/renderer/ascii/indentation_spec.rb +0 -41
- data/spec/unit/renderer/ascii/multiline_spec.rb +0 -101
- data/spec/unit/renderer/ascii/padding_spec.rb +0 -88
- data/spec/unit/renderer/ascii/render_spec.rb +0 -68
- data/spec/unit/renderer/ascii/resizing_spec.rb +0 -114
- data/spec/unit/renderer/ascii/separator_spec.rb +0 -28
- data/spec/unit/renderer/basic/alignment_spec.rb +0 -88
- data/spec/unit/renderer/basic/coloring_spec.rb +0 -61
- data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -28
- data/spec/unit/renderer/basic/filter_spec.rb +0 -53
- data/spec/unit/renderer/basic/indentation_spec.rb +0 -48
- data/spec/unit/renderer/basic/multiline_spec.rb +0 -74
- data/spec/unit/renderer/basic/new_spec.rb +0 -26
- data/spec/unit/renderer/basic/options_spec.rb +0 -52
- data/spec/unit/renderer/basic/padding_spec.rb +0 -76
- data/spec/unit/renderer/basic/render_spec.rb +0 -57
- data/spec/unit/renderer/basic/resizing_spec.rb +0 -96
- data/spec/unit/renderer/basic/separator_spec.rb +0 -43
- data/spec/unit/renderer/basic/truncation_spec.rb +0 -35
- data/spec/unit/renderer/basic/wrapping_spec.rb +0 -40
- data/spec/unit/renderer/border_spec.rb +0 -104
- data/spec/unit/renderer/render_spec.rb +0 -36
- data/spec/unit/renderer/select_spec.rb +0 -22
- data/spec/unit/renderer/unicode/coloring_spec.rb +0 -70
- data/spec/unit/renderer/unicode/indentation_spec.rb +0 -41
- data/spec/unit/renderer/unicode/padding_spec.rb +0 -61
- data/spec/unit/renderer/unicode/render_spec.rb +0 -68
- data/spec/unit/renderer/unicode/separator_spec.rb +0 -26
- data/spec/unit/renderer_spec.rb +0 -19
- data/spec/unit/rotate_spec.rb +0 -86
- data/spec/unit/row/access_spec.rb +0 -25
- data/spec/unit/row/call_spec.rb +0 -45
- data/spec/unit/row/data_spec.rb +0 -26
- data/spec/unit/row/each_spec.rb +0 -31
- data/spec/unit/row/equality_spec.rb +0 -73
- data/spec/unit/row/height_spec.rb +0 -27
- data/spec/unit/row/new_spec.rb +0 -41
- data/spec/unit/row/to_ary_spec.rb +0 -14
- data/spec/unit/to_s_spec.rb +0 -56
- data/spec/unit/transformation/extract_tuples_spec.rb +0 -35
- data/spec/unit/utf_spec.rb +0 -33
- data/spec/unit/validatable/validate_options_spec.rb +0 -33
- data/spec/unit/validatable_spec.rb +0 -32
- data/tasks/console.rake +0 -10
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-table.gemspec +0 -30
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
cache: bundler
|
5
|
-
bundler_args: --without yard benchmarks
|
6
|
-
script: "bundle exec rake ci"
|
7
|
-
rvm:
|
8
|
-
- 2.0.0
|
9
|
-
- 2.1.10
|
10
|
-
- 2.2.6
|
11
|
-
- 2.3.3
|
12
|
-
- 2.4.0
|
13
|
-
- ruby-head
|
14
|
-
- jruby-9.1.1.0
|
15
|
-
- jruby-head
|
16
|
-
matrix:
|
17
|
-
allow_failures:
|
18
|
-
- rvm: ruby-head
|
19
|
-
- rvm: jruby-head
|
20
|
-
fast_finish: true
|
21
|
-
branches:
|
22
|
-
only: master
|
23
|
-
notifications:
|
24
|
-
email: false
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
7
|
-
|
8
|
-
We are committed to making participation in this project a harassment-free
|
9
|
-
experience for everyone, regardless of level of experience, gender, gender
|
10
|
-
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
-
body size, race, ethnicity, age, religion, or nationality.
|
12
|
-
|
13
|
-
Examples of unacceptable behavior by participants include:
|
14
|
-
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
* Personal attacks
|
17
|
-
* Trolling or insulting/derogatory comments
|
18
|
-
* Public or private harassment
|
19
|
-
* Publishing other's private information, such as physical or electronic
|
20
|
-
addresses, without explicit permission
|
21
|
-
* Other unethical or unprofessional conduct
|
22
|
-
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
-
threatening, offensive, or harmful.
|
28
|
-
|
29
|
-
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
-
Conduct may be permanently removed from the project team.
|
33
|
-
|
34
|
-
This code of conduct applies both within project spaces and in public spaces
|
35
|
-
when an individual is representing the project or its community.
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at [email]. All
|
39
|
-
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
incident.
|
43
|
-
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version 1.3.0, available at
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
-
|
48
|
-
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
group :tools do
|
6
|
-
gem 'rspec', '~> 3.5.0'
|
7
|
-
gem 'yard', '~> 0.8.7'
|
8
|
-
end
|
9
|
-
|
10
|
-
group :metrics do
|
11
|
-
gem 'coveralls', '~> 0.8.2'
|
12
|
-
gem 'simplecov', '~> 0.10.0'
|
13
|
-
gem 'yardstick', '~> 0.9.9'
|
14
|
-
end
|
15
|
-
|
16
|
-
group :benchmarks do
|
17
|
-
gem 'benchmark_suite', '~> 1.0.0'
|
18
|
-
end
|
data/Rakefile
DELETED
data/benchmarks/speed.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
# Benchmark speed of table operations
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
6
|
-
|
7
|
-
require 'tty-table'
|
8
|
-
require 'benchmark'
|
9
|
-
require 'benchmark/ips'
|
10
|
-
|
11
|
-
header = [:name, :color]
|
12
|
-
rows = (1..100).map { |n| ["row#{n}", "red"] }
|
13
|
-
table = TTY::Table.new(header, rows)
|
14
|
-
|
15
|
-
Benchmark.ips do |r|
|
16
|
-
r.report("Ruby #to_s") do
|
17
|
-
rows.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
r.report("TTY #render") do
|
21
|
-
table.render
|
22
|
-
end
|
23
|
-
|
24
|
-
r.report("TTY #render ASCII") do
|
25
|
-
table.render(:ascii)
|
26
|
-
end
|
27
|
-
|
28
|
-
r.report("TTY #render Unicode") do
|
29
|
-
table.render(:unicode)
|
30
|
-
end
|
31
|
-
|
32
|
-
r.report("TTY #render Color") do
|
33
|
-
table.render(:ascii, border: {style: :red})
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Ruby #to_s 2588.6 (±12.2%) i/s - 12948 in 5.084883s
|
38
|
-
# TTY #render 20.8 (±9.6%) i/s - 104 in 5.030159s
|
39
|
-
# TTY #render ASCII 18.1 (±16.5%) i/s - 89 in 5.041230s
|
40
|
-
# TTY #render Unicode 18.0 (±16.7%) i/s - 88 in 5.029868s
|
41
|
-
# TTY #render Color 11.7 (±17.1%) i/s - 58 in 5.071654s
|
data/spec/spec_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
]
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name 'spec'
|
14
|
-
add_filter 'spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'tty-table'
|
19
|
-
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.expect_with :rspec do |expectations|
|
22
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
-
end
|
24
|
-
|
25
|
-
config.mock_with :rspec do |mocks|
|
26
|
-
mocks.verify_partial_doubles = true
|
27
|
-
end
|
28
|
-
|
29
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
30
|
-
config.disable_monkey_patching!
|
31
|
-
|
32
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
33
|
-
# be too noisy due to issues in dependencies.
|
34
|
-
config.warnings = true
|
35
|
-
|
36
|
-
if config.files_to_run.one?
|
37
|
-
config.default_formatter = 'doc'
|
38
|
-
end
|
39
|
-
|
40
|
-
config.profile_examples = 2
|
41
|
-
|
42
|
-
config.order = :random
|
43
|
-
|
44
|
-
Kernel.srand config.seed
|
45
|
-
end
|
46
|
-
|
47
|
-
def unindent(string)
|
48
|
-
prefix = string.scan(/^[ \t]+(?=\S)/).min
|
49
|
-
string.gsub(/^#{prefix}/, '').chomp
|
50
|
-
end
|
data/spec/unit/access_spec.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table, 'access' do
|
6
|
-
let(:header) { [:head1, :head2] }
|
7
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
8
|
-
|
9
|
-
subject(:table) { TTY::Table.new rows: rows, header: header }
|
10
|
-
|
11
|
-
it { is_expected.to respond_to(:element) }
|
12
|
-
|
13
|
-
it { is_expected.to respond_to(:component) }
|
14
|
-
|
15
|
-
it { is_expected.to respond_to(:at) }
|
16
|
-
|
17
|
-
context 'when array like access' do
|
18
|
-
it { expect(table[0,0]).to eq('a1') }
|
19
|
-
|
20
|
-
it { expect(table[0]).to eq(['a1','a2']) }
|
21
|
-
|
22
|
-
it { expect(table[5]).to eq(nil) }
|
23
|
-
|
24
|
-
it { expect(table[-1]).to eq(['b1','b2']) }
|
25
|
-
|
26
|
-
it { expect(table[5,5]).to eq(nil) }
|
27
|
-
|
28
|
-
it 'raises error for negative indices' do
|
29
|
-
expect { table[-5,-5] }.to raise_error(IndexError)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context '#row' do
|
34
|
-
it 'returns nil for wrong index' do
|
35
|
-
expect(table.row(11)).to be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'gets row at index' do
|
39
|
-
expect(table.row(1)).to eq(rows[1])
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'yields self for wrong index' do
|
43
|
-
block = lambda { |el| [] << el }
|
44
|
-
expect(table.row(11, &block)).to eq(table)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'yields row at index' do
|
48
|
-
yields = []
|
49
|
-
expect {
|
50
|
-
table.row(1).each { |el| yields << el }
|
51
|
-
}.to change { yields }.from( [] ).to( rows[1] )
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context '#column' do
|
56
|
-
it "gets based on header name" do
|
57
|
-
expect(table.column(:head1)).to eq(['a1', 'b1'])
|
58
|
-
end
|
59
|
-
|
60
|
-
it "yields based on header name" do
|
61
|
-
yielded = []
|
62
|
-
table.column(:head1) { |el| yielded << el }
|
63
|
-
expect(yielded).to eql(['a1', 'b1'])
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'returns nil for wrong index' do
|
67
|
-
expect(table.column(11)).to be_nil
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'gets column at index' do
|
71
|
-
expect(table.column(0)).to eq(['a1', 'b1'])
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'yields self for wrong index' do
|
75
|
-
block = lambda { |el| [] << el }
|
76
|
-
expect(table.column(11, &block)).to eq(table)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'yields column at index' do
|
80
|
-
yields = []
|
81
|
-
expect {
|
82
|
-
table.column(1).each { |el| yields << el }
|
83
|
-
}.to change { yields }.from( [] ).to( ['a2', 'b2'])
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
data/spec/unit/add_row_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table, '#<<' do
|
6
|
-
let(:rows) { ['a', 'b', 'c'] }
|
7
|
-
let(:object) { described_class }
|
8
|
-
|
9
|
-
subject(:table) { object[rows] }
|
10
|
-
|
11
|
-
context 'with primitive values' do
|
12
|
-
let(:row) { [1, 2, 3] }
|
13
|
-
|
14
|
-
it 'extracts values correctly' do
|
15
|
-
table << row
|
16
|
-
expect(table.to_a.last).to eql(row)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with complex values' do
|
21
|
-
let(:row) { [1, { value: 2 }, 3] }
|
22
|
-
|
23
|
-
it 'extracts values correctly' do
|
24
|
-
table << row
|
25
|
-
expect(table.to_a.last).to eql([1,2,3])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::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
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::AlignmentSet, '#new' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject(:alignment_set) { 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(alignment_set.to_a).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(alignment_set.to_a).to eq(argument) }
|
26
|
-
end
|
27
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table::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
|
data/spec/unit/alignment_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Table, 'alignment' do
|
6
|
-
it "aligns table columns when rendering" do
|
7
|
-
table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
|
8
|
-
expect(table.render(alignments: [:right, :center])).to eql([
|
9
|
-
"header1 header2",
|
10
|
-
" a1 a2 ",
|
11
|
-
" b1 b2 "
|
12
|
-
].join("\n"))
|
13
|
-
end
|
14
|
-
|
15
|
-
it "uses default alignment when too few alignments provided" do
|
16
|
-
table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
|
17
|
-
expect(table.render(alignments: [:right])).to eql([
|
18
|
-
"header1 header2",
|
19
|
-
" a1 a2 ",
|
20
|
-
" b1 b2 "
|
21
|
-
].join("\n"))
|
22
|
-
end
|
23
|
-
|
24
|
-
it "aligns table columns without header when rendering" do
|
25
|
-
table = TTY::Table.new [['aaaaa1','a2'],['b1','bbbbb2']]
|
26
|
-
expect(table.render(alignments: [:right, :center])).to eql([
|
27
|
-
"aaaaa1 a2 ",
|
28
|
-
" b1 bbbbb2"
|
29
|
-
].join("\n"))
|
30
|
-
end
|
31
|
-
|
32
|
-
it "aligns individual fields when rendering" do
|
33
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
34
|
-
table << ['a1', {value: 'a2', alignment: :center}]
|
35
|
-
table << [{value: 'b1', alignment: :right}, 'b2']
|
36
|
-
expect(table.render).to eql([
|
37
|
-
"header1 header2",
|
38
|
-
"a1 a2 ",
|
39
|
-
" b1 b2 "
|
40
|
-
].join("\n"))
|
41
|
-
end
|
42
|
-
|
43
|
-
it "prioritizes individual field options over table rendering options" do
|
44
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
45
|
-
table << [{value: 'a1', alignment: :center},'a2']
|
46
|
-
table << ['b1','b2']
|
47
|
-
expect(table.render(alignments: [:right, :center])).to eql([
|
48
|
-
"header1 header2",
|
49
|
-
" a1 a2 ",
|
50
|
-
" b1 b2 "
|
51
|
-
].join("\n"))
|
52
|
-
end
|
53
|
-
|
54
|
-
it "allows to align all columns at once" do
|
55
|
-
table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
|
56
|
-
expect(table.render(alignment: [:center])).to eql([
|
57
|
-
"header1 header2",
|
58
|
-
" a1 a2 ",
|
59
|
-
" b1 b2 "
|
60
|
-
].join("\n"))
|
61
|
-
end
|
62
|
-
|
63
|
-
xit "aligns specific column" do
|
64
|
-
table = TTY::Table.new ['header1', 'header2'], [['a1','a2'],['b1','b2']]
|
65
|
-
expect(table.render(column_alignment: [1, :center])).to eql([
|
66
|
-
"header1 header2",
|
67
|
-
"a1 a2 ",
|
68
|
-
"b1 b2 "
|
69
|
-
].join("\n"))
|
70
|
-
end
|
71
|
-
end
|