source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/unicode/padding_spec.rb | Ruby | mit | 204 | master | 3,216 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Unicode, 'padding' do
let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
let(:rows) { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
let(:table) { TTY::Table.new(header, rows) }
subject(:renderer) { described_class.new(t... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/truncation_spec.rb | Ruby | mit | 204 | master | 903 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'truncation' do
let(:header) { ['header1', 'head2', 'h3'] }
let(:rows) { [['a1111111', 'a222', 'a3333333'], ['b111', 'b2222222', 'b333333']]}
let(:table) { TTY::Table.new header, rows }
subject(:renderer) { described_class.new(table, op... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/alignment_spec.rb | Ruby | mit | 204 | master | 2,448 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'alignment' do
let(:header) { ['h1', 'h2', 'h3'] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
let(:options) { { alignments: alignments } }
let(:table) { TTY::Table.new(header, rows) }
subject(:renderer) { described_... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/extract_column_widths_spec.rb | Ruby | mit | 204 | master | 711 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, '#column_widths' do
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
let(:renderer) { described_class.new(table) }
subject { renderer.render }
context 'with rows only' do
let(:rows) { [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/render_spec.rb | Ruby | mit | 204 | master | 1,317 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, '#render' do
let(:header) { ['h1', 'h2', 'h3'] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
let(:table) { TTY::Table.new header, rows }
subject(:renderer) { described_class.new(table) }
context 'with rows' do
let(... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/coloring_spec.rb | Ruby | mit | 204 | master | 1,953 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'coloring' do
let(:clear) { "\e[0m" }
let(:color) { Pastel.new(enabled: true) }
before { allow(Pastel).to receive(:new).and_return(color) }
context 'when border ' do
it "doesn't color" do
table = TTY::Table.new header: ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/separator_spec.rb | Ruby | mit | 204 | master | 1,217 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, "with separator" do
let(:header) { ["h1", "h2", "h3"] }
let(:rows) { [%w[a1 a2 a3], %w[b1 b2 b3], %w[c1 c2 c3]] }
let(:table) { TTY::Table.new(header, rows) }
let(:object) { described_class.new table }
subject(:renderer) { object ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/multiline_spec.rb | Ruby | mit | 204 | master | 2,162 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'multiline content' do
context 'with escaping' do
it "renders multiline as single line" do
rows = [ ["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']]
table = TTY::Table.new rows
renderer = described_class.new(t... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/single_row_separator_spec.rb | Ruby | mit | 204 | master | 2,198 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'individual row separators' do
context 'using the separator option' do
let(:header) { %w[h1 h2 h3] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']] }
let(:table) { TTY::Table.new(header, rows) }
l... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/filter_spec.rb | Ruby | mit | 204 | master | 1,260 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'filter' do
let(:header) { ['h1', 'h2', 'h3'] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
let(:table) { TTY::Table.new(header, rows) }
subject(:renderer) { described_class.new(table, {filter: filter}) }
context 'with... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/padding_spec.rb | Ruby | mit | 204 | master | 2,186 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'padding' do
let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
let(:rows) { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
let(:table) { TTY::Table.new(header, rows) }
subject(:renderer) { described_class.new(tab... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/indentation_spec.rb | Ruby | mit | 204 | master | 1,040 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'indentation' do
let(:header) { ['h1', 'h2', 'h3'] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
let(:table) { TTY::Table.new(header, rows) }
let(:options) { {indent: indent } }
subject(:renderer) { described_class.n... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/new_spec.rb | Ruby | mit | 204 | master | 502 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, '.new' do
let(:header) { ['h1'] }
let(:rows) { [['a1']] }
subject(:renderer) { described_class }
context 'without table' do
let(:table) { nil }
it {
expect {
renderer.new(table)
}.to raise_error(TTY::Tabl... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/options_spec.rb | Ruby | mit | 204 | master | 1,163 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'options' do
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
let(:object) { described_class }
let(:table) { TTY::Table.new(rows) }
let(:widths) { nil }
let(:alignments) { [] }
let(:options) {
{
column_widths: widths,
a... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/wrapping_spec.rb | Ruby | mit | 204 | master | 1,045 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'wrapping' do
let(:header) { ['header1', 'head2', 'h3'] }
let(:rows) { [['a1111111', 'a222', 'a3333333'], ['b111', 'b2222222', 'b333333']]}
let(:table) { TTY::Table.new header, rows }
subject(:renderer) { described_class.new(table, opti... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/renderer/basic/resizing_spec.rb | Ruby | mit | 204 | master | 2,623 | # frozen_string_literal: true
RSpec.describe TTY::Table::Renderer::Basic, 'resizing' do
let(:header) { ['h1', 'h2', 'h3'] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
let(:table) { TTY::Table.new(header, rows) }
subject(:renderer) { described_class.new(table, options) }
context 'when exp... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/indentation/indent_spec.rb | Ruby | mit | 204 | master | 394 | # frozen_string_literal: true
RSpec.describe TTY::Table::Indentation, '.indent' do
context 'when enumerable' do
it 'inserts indentation for each element' do
expect(described_class.indent(['line1'], 2)).to eql([' line1'])
end
end
context 'when string' do
it 'inserts indentation' do
expec... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/operation/filter/call_spec.rb | Ruby | mit | 204 | master | 390 | # frozen_string_literal: true
RSpec.describe TTY::Table::Operation::Filter, '#call' do
let(:object) { described_class }
let(:field) { TTY::Table::Field.new('a1') }
let(:filter) { Proc.new { |val, row, col| 'new' } }
let(:value) { 'new' }
subject(:operation) { object.new(filter) }
it 'changes field valu... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/operation/alignment/call_spec.rb | Ruby | mit | 204 | master | 958 | # frozen_string_literal: true
RSpec.describe TTY::Table::Operation::Alignment, '#call' do
let(:object) { described_class.new alignments, widths }
let(:value) { 'a1' }
let(:field) { TTY::Table::Field.new(value)}
subject { object.call(field, 0, 0) }
context 'aligned with column widths and no alignments' do... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/operation/escape/call_spec.rb | Ruby | mit | 204 | master | 379 | # frozen_string_literal: true
RSpec.describe TTY::Table::Operation::Escape, '#call' do
let(:object) { described_class }
let(:text) { "太丸\nゴシ\tック体\r" }
let(:field) { TTY::Table::Field.new(text) }
subject(:operation) { object.new }
it 'changes field value' do
expect(operation.call(field, 0, 0)).to eql... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/operation/truncation/call_spec.rb | Ruby | mit | 204 | master | 720 | # frozen_string_literal: true
RSpec.describe TTY::Table::Operation::Truncation, '#call' do
let(:text) { '太丸ゴシック体' }
let(:field) { TTY::Table::Field.new(text) }
subject(:operation) { described_class.new(column_widths) }
context 'without column width' do
let(:column_widths) { [] }
it "truncates str... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/operation/wrapped/call_spec.rb | Ruby | mit | 204 | master | 1,005 | # frozen_string_literal: true
RSpec.describe TTY::Table::Operation::Wrapped, '#call' do
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
let(:field) { TTY::Table::Field.new(text) }
subject(:operation) { described_class.new(column_widths) }
context 'without column width' do
let(:column_widths) { [] }
it ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/column_constraint/widths_spec.rb | Ruby | mit | 204 | master | 935 | # frozen_string_literal: true
RSpec.describe TTY::Table::ColumnConstraint, 'column widths' do
let(:header) { ['h1', 'h2', 'h3', 'h4'] }
let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
let(:table) { TTY::Table.new(header, rows) }
subject(:columns) { described_class.new(table, renderer) }... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/column_constraint/enforce_spec.rb | Ruby | mit | 204 | master | 2,141 | # frozen_string_literal: true
RSpec.describe TTY::Table::ColumnConstraint, '#enforce' do
let(:header) { ['h1', 'h2', 'h3', 'h4'] }
let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
let(:table) { TTY::Table.new(header, rows) }
subject(:columns) { described_class.new(table, renderer) }
c... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/options/access_spec.rb | Ruby | mit | 204 | master | 253 | # frozen_string_literal: true
# describe TTY::Table::Options, 'options' do
# let(:object) { described_class }
#
# subject { described_class.new({'a' => 1, :b => 2}) }
#
# it '' do
# pending
# expect(subject[:a]).to eql(1)
# end
# end |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/operations/new_spec.rb | Ruby | mit | 204 | master | 644 | # frozen_string_literal: true
RSpec.describe TTY::Table::Operations, '#new' do
let(:object) { described_class }
let(:row) { [1,2,3] }
let(:table) { TTY::Table.new :rows => [row] }
let(:callable) {
Class.new do
def call(val, row, col)
val.value= val.value + 1
end
end
}
let(:i... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/equality_spec.rb | Ruby | mit | 204 | master | 1,630 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#==' do
let(:attributes) { [:id] }
let(:data) { ['1'] }
let(:object) { described_class.new(data, attributes) }
subject { object == other }
context 'with the same object' do
let(:other) { object }
it { is_expected.to eql(true) }
it... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/call_spec.rb | Ruby | mit | 204 | master | 781 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#call' do
let(:object) { described_class.new(data) }
subject { object[attribute] }
context 'when integer' do
let(:data) { ['a', 'b'] }
let(:attribute) { 1 }
it { is_expected.to eql('b') }
end
context 'when symbol' do
let(:dat... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/access_spec.rb | Ruby | mit | 204 | master | 427 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#access' do
let(:object) { described_class.new [] }
before { object[attribute] = value}
subject { object[attribute] }
context 'when integer' do
let(:attribute) { 0 }
let(:value) { 1 }
it { is_expected.to eq(1) }
end
context 'wh... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/to_ary_spec.rb | Ruby | mit | 204 | master | 262 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#to_ary' do
let(:object) { described_class.new data }
let(:data) { ['a', 'b'] }
subject { object.to_ary }
it { is_expected.to be_instance_of(Array) }
it { is_expected.to eq(data) }
end |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/data_spec.rb | Ruby | mit | 204 | master | 491 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#data' do
let(:object) { described_class.new data, header }
let(:data) { ['a'] }
subject { object.to_hash }
context 'without attributes' do
let(:header) { nil }
it { is_expected.to be_instance_of(Hash) }
it { is_expected.to eql(0 =>... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/height_spec.rb | Ruby | mit | 204 | master | 493 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#height' do
let(:object) { described_class.new row }
subject { object.height }
context 'single row' do
let(:row) { ['a1', 'b1'] }
it { expect(subject).to eql(1) }
end
context 'non escaped multiline' do
let(:row) { ["a1\na2\na3", '... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/each_spec.rb | Ruby | mit | 204 | master | 706 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#new' do
let(:yields) { [] }
let(:value) { 'a1' }
let(:header) { ['Header1']}
let(:row) { [ value ] }
let(:object) { described_class.new row, header }
context 'with block' do
subject { object.each { |field| yields << field } }
it ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/row/new_spec.rb | Ruby | mit | 204 | master | 824 | # frozen_string_literal: true
RSpec.describe TTY::Table::Row, '#new' do
let(:object) { described_class }
subject { object.new data }
context 'with no arguments' do
let(:data) { [] }
it { is_expected.to be_instance_of(object) }
it { is_expected.to be_empty }
it { expect(subject.attributes).to... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/validatable/validate_options_spec.rb | Ruby | mit | 204 | master | 816 | # frozen_string_literal: true
RSpec.describe TTY::Table::Validatable, '#validate_options!' do
let(:described_class) { Class.new { include TTY::Table::Validatable } }
subject { described_class.new.validate_options! options }
context 'with empty rows' do
let(:options) { {rows: []} }
it { expect { subjec... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/field/width_spec.rb | Ruby | mit | 204 | master | 388 | # frozen_string_literal: true
RSpec.describe TTY::Table::Field, '#width' do
let(:object) { described_class }
let(:instance) { object.new(value) }
subject { instance.width }
context 'with only value' do
let(:value) { 'foo' }
it { is_expected.to eql(3) }
end
context 'with hash value' do
let(... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/field/lines_spec.rb | Ruby | mit | 204 | master | 406 | # frozen_string_literal: true
RSpec.describe TTY::Table::Field, '#lines' do
let(:object) { described_class.new value }
subject { object.lines }
context 'with escaped value' do
let(:value) { "Multi\nLine" }
it { is_expected.to eql(["Multi", "Line"]) }
end
context 'with unescaped value' do
let(... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/field/equality_spec.rb | Ruby | mit | 204 | master | 1,495 | # frozen_string_literal: true
RSpec.describe TTY::Table::Field, "equality" do
let(:value) { "1" }
let(:object) { described_class.new(value) }
describe "#==" do
it "is equal with the same object" do
expect(object).to eq(object)
end
it "is equal with an quivalent object" do
expect(object)... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/field/length_spec.rb | Ruby | mit | 204 | master | 906 | # frozen_string_literal: true
RSpec.describe TTY::Table::Field, '.length' do
it "calculates length for nil string" do
field = described_class.new(nil)
expect(field.length).to eq(0)
end
it "calculates length for empty string" do
field = described_class.new('')
expect(field.length).to eq(0)
end
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/field/new_spec.rb | Ruby | mit | 204 | master | 575 | # frozen_string_literal: true
RSpec.describe TTY::Table::Field, '#new' do
let(:object) { described_class }
subject { object.new value }
context 'with only value' do
let(:value) { 'foo' }
it { is_expected.to be_instance_of(object) }
it { expect(subject.value).to eql(value) }
it { expect(subj... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/border/new_spec.rb | Ruby | mit | 204 | master | 522 | # frozen_string_literal: true
RSpec.describe TTY::Table::Border, '#new' do
let(:row) { [] }
subject(:instance) { klass.new row, [0,0,0,0] }
context 'when abstract' do
let(:klass) { described_class }
it { expect { instance }.to raise_error(NotImplementedError) }
end
context 'when concrete' do
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/border/ascii/rendering_spec.rb | Ruby | mit | 204 | master | 2,014 | # frozen_string_literal: true
RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
subject(:border) { described_class.new(column_widths) }
context 'with empty row' do
let(:row) { TTY::Table::Row.new([]) }
let(:column_widths) { [] }
it 'draws top line' do
expect(border.top_line).to eq("++"... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/border/unicode/rendering_spec.rb | Ruby | mit | 204 | master | 1,488 | # frozen_string_literal: true
RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
subject(:border) { described_class.new(column_widths) }
context 'with empty row' do
let(:row) { TTY::Table::Row.new([]) }
let(:column_widths) { [] }
it 'draws top line' do
expect(border.top_line).to eq("┌... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/border/options/from_spec.rb | Ruby | mit | 204 | master | 907 | # frozen_string_literal: true
RSpec.describe TTY::Table::BorderOptions, "#from" do
subject(:options) { described_class.from object }
context "when empty hash" do
let(:object) { {} }
it { expect(options.style).to be_nil }
it { expect(options.separator).to be_nil }
end
context "when hash" do
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/border/options/new_spec.rb | Ruby | mit | 204 | master | 853 | # frozen_string_literal: true
RSpec.describe TTY::Table::BorderOptions, "#new" do
it "defaults characters to an empty hash" do
expect(described_class.new.characters).to eq({})
end
it "sets characters option" do
border_options = described_class.new(characters: {top: "**"})
expect(border_options.chara... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/border/null/rendering_spec.rb | Ruby | mit | 204 | master | 2,901 | # frozen_string_literal: true
RSpec.describe TTY::Table::Border::Null, '#rendering' do
let(:border) { nil }
subject { described_class.new column_widths, border }
context 'with empty row' do
let(:row) { TTY::Table::Row.new([]) }
let(:column_widths) { [] }
it 'draws top line' do
expect(subject... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/columns/total_width_spec.rb | Ruby | mit | 204 | master | 326 | # frozen_string_literal: true
RSpec.describe TTY::Table::Columns, '#extract_widths!' do
let(:header) { ['h1', 'h2', 'h3'] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
it 'extract widths' do
table = TTY::Table.new(header, rows)
expect(described_class.total_width(table.data)).to eql(6)
en... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/columns/widths_from_spec.rb | Ruby | mit | 204 | master | 1,102 | # frozen_string_literal: true
RSpec.describe TTY::Table::Columns, '#widths_from' do
let(:header) { ['h1', 'h2', 'h3'] }
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
let(:table) { TTY::Table.new header, rows }
subject { described_class.widths_from(table, column_widths) }
context 'when empty ar... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/columns/extract_widths_spec.rb | Ruby | mit | 204 | master | 1,415 | # frozen_string_literal: true
RSpec.describe TTY::Table::Columns, '#extract_widths' do
let(:color) { Pastel.new(enabled: true) }
it 'extract widths' do
header = ['h1', 'h2', 'h3']
rows = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
table = TTY::Table.new(header, rows)
expect(described_class.extract_... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/alignment_set/each_spec.rb | Ruby | mit | 204 | master | 403 | # frozen_string_literal: true
RSpec.describe TTY::Table::AlignmentSet, '#each' do
let(:alignments) { [:left, :center, :right] }
let(:yields) { [] }
let(:object) { described_class.new alignments }
subject { object.each { |alignment| yields << alignment } }
it 'yields each alignment' do
expect { ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/alignment_set/new_spec.rb | Ruby | mit | 204 | master | 568 | # frozen_string_literal: true
RSpec.describe TTY::Table::AlignmentSet, '#new' do
let(:object) { described_class }
subject(:alignment_set) { object.new(argument) }
context 'with no argument' do
let(:argument) { [] }
it { is_expected.to be_kind_of(Enumerable) }
it { is_expected.to be_instance_of(ob... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/alignment_set/to_ary_spec.rb | Ruby | mit | 204 | master | 291 | # frozen_string_literal: true
RSpec.describe TTY::Table::AlignmentSet, '#to_ary' do
let(:argument) { [:center, :left] }
let(:object) { described_class.new argument }
subject { object.to_ary }
it { is_expected.to be_instance_of(Array) }
it { is_expected.to eq(argument) }
end |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/header/height_spec.rb | Ruby | mit | 204 | master | 506 | # frozen_string_literal: true
RSpec.describe TTY::Table::Header, '#height' do
let(:object) { described_class.new header }
subject { object.height }
context 'single row' do
let(:header) { ['h1', 'h1'] }
it { expect(subject).to eql(1) }
end
context 'non escaped multiline' do
let(:header) { ["h1... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/header/equality_spec.rb | Ruby | mit | 204 | master | 1,084 | # frozen_string_literal: true
RSpec.describe TTY::Table::Header, '#==' do
let(:attributes) { [:id, :name] }
let(:object) { described_class.new(attributes) }
subject { object == other }
context 'with the same object' do
let(:other) { object }
it { is_expected.to eql(true) }
it 'is symmetric' do
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/header/call_spec.rb | Ruby | mit | 204 | master | 651 | # frozen_string_literal: true
RSpec.describe TTY::Table::Header, '#call' do
let(:object) { described_class.new(attributes) }
let(:attributes) { [:id, :name, :age] }
subject { object[attribute] }
context 'with a known attribute' do
context 'when symbol' do
let(:attribute) { :age }
it { is_exp... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/header/new_spec.rb | Ruby | mit | 204 | master | 340 | # frozen_string_literal: true
RSpec.describe TTY::Table::Header, '#new' do
it "is empty without arguments" do
header = TTY::Table::Header.new
expect(header).to be_empty
end
it "isn't empty with attributes" do
header = TTY::Table::Header.new [:id, :name, :age]
expect(header.to_a).to eq([:id, :nam... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/header/to_ary_spec.rb | Ruby | mit | 204 | master | 296 | # frozen_string_literal: true
RSpec.describe TTY::Table::Header, '#to_ary' do
let(:object) { described_class.new(attributes) }
let(:attributes) { [:id, :name, :age] }
subject { object.to_ary }
it { is_expected.to be_instance_of(Array) }
it { is_expected.to eq(attributes) }
end |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/header/color_spec.rb | Ruby | mit | 204 | master | 300 | # frozen_string_literal: true
RSpec.describe TTY::Table::Header, 'color' do
context 'when default' do
end
context 'when ascii' do
let(:renderer) { :ascii }
let(:red) { "\e[31m" }
let(:clear) { "\e[0m" }
xit 'renders header background in color' do
end
end
end |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/header/set_spec.rb | Ruby | mit | 204 | master | 378 | # frozen_string_literal: true
RSpec.describe TTY::Table::Header, '#set' do
let(:object) { described_class }
let(:attributes) { [:id, :name, :age] }
subject(:header) { object.new }
it 'sets the value' do
header[0] = :id
expect(header[0]).to eql(:id)
end
it 'gets the value' do
head = object.ne... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/unit/transformation/extract_tuples_spec.rb | Ruby | mit | 204 | master | 810 | # frozen_string_literal: true
RSpec.describe TTY::Table::Transformation, '#extract_tuples' do
let(:object) { described_class }
let(:header) { ['Header1', 'Header2'] }
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
subject { object.extract_tuples(value) }
context 'when rows' do
let(:value) { [rows] }
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | spec/perf/add_row_spec.rb | Ruby | mit | 204 | master | 416 | # frozen_string_literal: true
require "rspec-benchmark"
RSpec.describe TTY::Table, "#<<" do
include RSpec::Benchmark::Matchers
let(:array) { [] }
let(:table) { described_class.new }
let(:row) { %w[YYYY-MM-DD Something 123.456] }
it "performs slower than adding elements to an array" do
expect {
t... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | examples/orientation.rb | Ruby | mit | 204 | master | 311 | # frozen_string_literal: true
require_relative "../lib/tty-table"
table = TTY::Table.new(header: ["Column 1", "Column 2", "Column 3"]) do |t|
t << ["r1 c1", "r1 c2", "r1 c3"]
t << ["r2 c1", "r2 c2", "r2 c3"]
t << ["r3 c1", "r3 c2", "r3 c3"]
end
table.orientation = :vertical
puts table.render(:ascii) |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | examples/padding.rb | Ruby | mit | 204 | master | 368 | # frozen_string_literal: true
require "pastel"
require_relative "../lib/tty-table"
pastel = Pastel.new
yellow = pastel.yellow.detach
header = [yellow.("Column 1"), yellow.("Column 2"), yellow.("Column 3")]
table = TTY::Table.new(header: header) do |t|
t << %w[11 12 13]
t << %w[21 22 23]
t << %w[31 32 33]
end
p... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | examples/resize.rb | Ruby | mit | 204 | master | 382 | # frozen_string_literal: true
require 'pastel'
require_relative "../lib/tty-table"
pastel = Pastel.new
yellow = pastel.yellow.detach
header = [yellow.("Column 1"), yellow.("Column 2"), yellow.("Column 3")]
table = TTY::Table.new(header: header) do |t|
t << %w[11 12 13]
t << %w[21 22 23]
t << %w[31 32 33]
end
p... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | examples/alignment.rb | Ruby | mit | 204 | master | 273 | # frozen_string_literal: true
require_relative "../lib/tty-table"
table = TTY::Table.new header: ["Right align", "Center align", "Left align"]
table << %w[a1 a2 a3]
table << %w[b1 b2 b3]
table << %w[c1 c2 c3]
puts table.render(:ascii, alignments: %i[right center left]) |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | examples/basic.rb | Ruby | mit | 204 | master | 254 | # frozen_string_literal: true
require_relative "../lib/tty-table"
table = TTY::Table.new(%w[header1 header2],
[%w[a1 a2], %w[b1 b2], %w[c1 c2]])
puts table.render(:ascii) do |renderer|
renderer.border.separator = :each_row
end |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | tasks/console.rake | Ruby | mit | 204 | master | 230 | # frozen_string_literal: true
desc "Load gem inside irb console"
task :console do
require "irb"
require "irb/completion"
require File.join(__FILE__, "../../lib/tty-table")
ARGV.clear
IRB.start
end
task c: %w[ console ] |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | tasks/spec.rake | Ruby | mit | 204 | master | 830 | # frozen_string_literal: true
begin
require "rspec/core/rake_task"
desc "Run all specs"
RSpec::Core::RakeTask.new(:spec) do |task|
task.pattern = "spec/{unit,integration}{,/*/**}/*_spec.rb"
end
namespace :spec do
desc "Run unit specs"
RSpec::Core::RakeTask.new(:unit) do |task|
task.patter... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table.rb | Ruby | mit | 204 | master | 12,964 | # frozen_string_literal: true
require "forwardable"
require_relative "table/columns"
require_relative "table/header"
require_relative "table/orientation"
require_relative "table/row"
require_relative "table/renderer"
require_relative "table/transformation"
require_relative "table/validatable"
require_relative "table/... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/empty.rb | Ruby | mit | 204 | master | 396 | # frozen_string_literal: true
module TTY
class Table
class Empty < TTY::Table
ZERO_ROW = [].freeze
def self.new(header, rows = ZERO_ROW)
super.new(header, rows)
end
def each
return to_enum unless block_given?
self
end
def size
0
end
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/border_options.rb | Ruby | mit | 204 | master | 1,730 | # frozen_string_literal: true
module TTY
class Table
# A class that represents table border options
#
# Used internally by {Table::Border} to manage options such as style
#
# @api private
class BorderOptions
# Create options instance from hash
#
# @api public
def self.... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/renderer.rb | Ruby | mit | 204 | master | 3,024 | # frozen_string_literal: true
require_relative "error"
require_relative "renderer/basic"
require_relative "renderer/ascii"
require_relative "renderer/unicode"
module TTY
class Table
# A module responsible for selecting tabule data renderer
#
# Used internally by {Table} to render table content out.
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/row.rb | Ruby | mit | 204 | master | 5,441 | # frozen_string_literal: true
require "forwardable"
require_relative "error"
require_relative "field"
module TTY
class Table
# Convert an Array row into Row
#
# @return [TTY::Table::Row]
#
# @api private
def to_row(row, header = nil)
Row.new(row, header)
end
# A class that re... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/orientation.rb | Ruby | mit | 204 | master | 1,258 | # frozen_string_literal: true
require_relative "orientation/horizontal"
require_relative "orientation/vertical"
module TTY
class Table
# A class representing table orientation
#
# @api private
class Orientation
# The name for the orientation
#
# @api public
attr_reader :name
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/columns.rb | Ruby | mit | 204 | master | 2,706 | # frozen_string_literal: true
require_relative "error"
module TTY
class Table
# A module for calculating table data column widths
#
# Used by {Table} to manage column sizing.
#
# @api private
module Columns
# Calculate total table width
#
# @return [Integer]
#
#... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/column_constraint.rb | Ruby | mit | 204 | master | 5,018 | # frozen_string_literal: true
require_relative "border/null"
require_relative "columns"
require_relative "error"
module TTY
class Table
# A class responsible for enforcing column constraints.
#
# Used internally by {Renderer::Basic} to enforce correct column widths.
#
# @api private
class Co... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/field.rb | Ruby | mit | 204 | master | 3,937 | # frozen_string_literal: true
require "strings"
module TTY
class Table
# A class that represents a unique element in a table.
#
# Used internally by {Table::Header} and {Table::Row} to
# define internal structure.
#
# @api private
class Field
# The value inside the field
#
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/header.rb | Ruby | mit | 204 | master | 3,606 | # frozen_string_literal: true
require "forwardable"
require_relative "error"
require_relative "field"
module TTY
class Table
# Convert an Array row into Header
#
# @return [TTY::Table::Header]
#
# @api private
def to_header(row)
Header.new(row)
end
# A set of header elements ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/options.rb | Ruby | mit | 204 | master | 540 | # frozen_string_literal: true
require "delegate"
module TTY
class Table
# Structure for holding table options with indifferent access
class Options < DelegateClass(Hash)
def initialize(hash={}, &block)
super(&block)
hash.each do |key, value|
self[convert_key(key)] = valu
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/operations.rb | Ruby | mit | 204 | master | 1,677 | # frozen_string_literal: true
module TTY
class Table
# A class holding table field operations.
#
# @api private
class Operations
# Initialize Operations
#
# @api public
def initialize
@operations = Hash.new { |hash, key| hash[key] = [] }
end
# Add operatio... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/alignment_set.rb | Ruby | mit | 204 | master | 1,456 | # frozen_string_literal: true
module TTY
class Table
# A class responsible for column alignments
#
# Used internally by {TTY::Table::Operation::Alignment}
class AlignmentSet
include Enumerable
DEFAULT = :left
# Initialize an AlignmentSet
#
# @param [AlignmentSet, Array... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/transformation.rb | Ruby | mit | 204 | master | 965 | # frozen_string_literal: true
module TTY
class Table
# A class for transforming table values
#
# Used internally by {Table}
#
# @api private
class Transformation
# Extract the header and row tuples from the value
#
# @param [Array] args
#
# @return [Object]
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/border_dsl.rb | Ruby | mit | 204 | master | 5,421 | # frozen_string_literal: true
require "forwardable"
require_relative "border_options"
module TTY
class Table
# A class responsible for bulding and modifying border
#
# Used internally by {Table::Border} to allow for building custom border
# through DSL
# @api private
class BorderDSL
e... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/border.rb | Ruby | mit | 204 | master | 5,705 | # frozen_string_literal: true
require "pastel"
require "strings"
require_relative "border_dsl"
require_relative "border/row_line"
require_relative "error"
module TTY
class Table
# Abstract base class that is responsible for building the table border.
class Border
EMPTY_CHAR = ""
SPACE_CHAR = "... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/error.rb | Ruby | mit | 204 | master | 1,144 | # frozen_string_literal: true
module TTY
class Table
# Raised when inserting into table with a mismatching row(s)
class DimensionMismatchError < ArgumentError; end
# Raised when reading non-existent element from a table
class TupleMissing < IndexError
attr_reader :i, :j
def initialize(i... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/validatable.rb | Ruby | mit | 204 | master | 2,142 | # frozen_string_literal: true
require_relative "error"
module TTY
class Table
# Mixin to provide validation for {Table}.
#
# Include this mixin to add validation for options.
#
# @api private
module Validatable
# Check if table rows are the equal size
#
# @raise [DimensionM... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/indentation.rb | Ruby | mit | 204 | master | 1,041 | # frozen_string_literal: true
module TTY
class Table
# A module responsible for indenting table representation
module Indentation
# Return a table part with indentation inserted
#
# @param [#map, #to_s] part
# the rendered table part
#
# @api public
def indent(part... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/border/ascii.rb | Ruby | mit | 204 | master | 723 | # frozen_string_literal: true
require_relative "../border"
module TTY
class Table
class Border
# A class that represents an ascii border.
#
# @api private
class ASCII < Border
def_border do
top "-"
top_mid "+"
top_left "+"
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/border/row_line.rb | Ruby | mit | 204 | master | 538 | # frozen_string_literal: true
module TTY
class Table
class Border
# A class for a table row line chars manipulation
class RowLine < Struct.new(:left, :center, :right)
# Colorize characters with a given style
#
# @api public
def colorize(border, style)
self.ri... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/border/null.rb | Ruby | mit | 204 | master | 936 | # frozen_string_literal: true
require_relative "../border"
module TTY
class Table
class Border
# A class that represents no border.
class Null < Border
def_border do
top EMPTY_CHAR
top_mid EMPTY_CHAR
top_left EMPTY_CHAR
top_right ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/border/unicode.rb | Ruby | mit | 204 | master | 743 | # frozen_string_literal: true
require_relative "../border"
module TTY
class Table
class Border
# A class that represents a unicode border.
#
# @api private
class Unicode < Border
def_border do
top "─"
top_mid "┬"
top_left "┌"
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/renderer/unicode.rb | Ruby | mit | 204 | master | 528 | # frozen_string_literal: true
require_relative "../border/unicode"
module TTY
class Table
module Renderer
# Unicode representation of table renderer
#
# @api private
class Unicode < Basic
# Create Unicode renderer
#
# @param [Table] table
#
# @api ... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/renderer/ascii.rb | Ruby | mit | 204 | master | 436 | # frozen_string_literal: true
require_relative "../border/ascii"
require_relative "../renderer/basic"
module TTY
class Table
module Renderer
class ASCII < Basic
# Create ASCII renderer
#
# @api private
def initialize(table, options = {})
super(table, options.merge... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/renderer/basic.rb | Ruby | mit | 204 | master | 9,646 | # frozen_string_literal: true
require "strings"
require "tty-screen"
require_relative "../alignment_set"
require_relative "../border_dsl"
require_relative "../border/null"
require_relative "../column_constraint"
require_relative "../columns"
require_relative "../header"
require_relative "../indentation"
require_relat... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/orientation/horizontal.rb | Ruby | mit | 204 | master | 1,260 | # frozen_string_literal: true
module TTY
class Table
# A class representing table orientation
class Orientation
# A class responsible for horizontal table transformation
class Horizontal < Orientation
# Rotate table horizontally
#
# @param [Table] table
#
#... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/orientation/vertical.rb | Ruby | mit | 204 | master | 963 | # frozen_string_literal: true
module TTY
class Table
# A class representing table orientation
class Orientation
# A class responsible for vertical table transformation
class Vertical < Orientation
# Rotate table vertically
#
# @param [Table] table
#
# @retu... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/operation/truncation.rb | Ruby | mit | 204 | master | 933 | # frozen_string_literal: true
require "strings"
module TTY
class Table
module Operation
# A class responsible for shortening text.
#
# @api private
class Truncation
attr_reader :widths
# Initialize a Truncation
#
# @api public
def initialize(widt... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/operation/filter.rb | Ruby | mit | 204 | master | 756 | # frozen_string_literal: true
module TTY
class Table
module Operation
# A class responsible for transforming table field
#
# @api private
class Filter
# Initialize a Filter
#
# @api public
def initialize(filter)
@filter = filter
end
... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/operation/padding.rb | Ruby | mit | 204 | master | 825 | # frozen_string_literal: true
require "strings"
module TTY
class Table
module Operation
# A class responsible for padding field with whitespace
#
# Used internally by {Table::Renderer}
class Padding
# Initialize a Padding operation
#
# @param [Strings::Padder] pad... |
github | piotrmurach/tty-table | https://github.com/piotrmurach/tty-table | lib/tty/table/operation/alignment.rb | Ruby | mit | 204 | master | 1,502 | # frozen_string_literal: true
require "strings"
module TTY
class Table
module Operation
# A class which responsiblity is to align table rows and header.
class Alignment
DEFAULT = :left
# Initialize an Alignment operation
#
# @api private
def initialize(alignm... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.