2019-05-02 18:33:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-01-09 18:16:14 -05:00
|
|
|
describe 'Formatting Table' do
|
|
|
|
it 'knows about colorized fitting' do
|
2019-03-02 06:22:03 -05:00
|
|
|
t = Pry::Helpers::Table.new %w[hihi], column_count: 1
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.fits_on_line?(4)).to eq true
|
2013-01-09 18:16:14 -05:00
|
|
|
t.items = []
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.fits_on_line?(4)).to eq true
|
2013-01-09 18:16:14 -05:00
|
|
|
|
2019-03-02 06:22:03 -05:00
|
|
|
t.items = %w[hi hi]
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.fits_on_line?(4)).to eq true
|
2013-01-09 18:16:14 -05:00
|
|
|
t.column_count = 2
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.fits_on_line?(4)).to eq false
|
2013-01-09 18:16:14 -05:00
|
|
|
|
2019-02-25 17:44:52 -05:00
|
|
|
t.items = %w[a ccc bb dddd].sort
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.fits_on_line?(8)).to eq true
|
|
|
|
expect(t.fits_on_line?(7)).to eq false
|
2013-01-09 18:16:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'formatting - should order downward and wrap to columns' do
|
|
|
|
FAKE_COLUMNS = 62
|
|
|
|
def try_round_trip(expected)
|
|
|
|
things = expected.split(/\s+/).sort
|
|
|
|
actual = Pry::Helpers.tablify(things, FAKE_COLUMNS).to_s.strip
|
2019-05-07 17:13:29 -04:00
|
|
|
expected = expected.gsub(/\s+$/, '')
|
|
|
|
actual = actual.gsub(/\s+$/, '')
|
2013-01-09 18:16:14 -05:00
|
|
|
if actual != expected
|
2018-11-04 04:34:24 -05:00
|
|
|
bar = '-' * 25
|
2013-01-09 18:16:14 -05:00
|
|
|
puts \
|
2018-11-04 04:34:24 -05:00
|
|
|
bar + 'expected' + bar,
|
2013-01-09 18:16:14 -05:00
|
|
|
expected,
|
2018-11-04 04:34:24 -05:00
|
|
|
bar + 'actual' + bar,
|
2013-01-09 18:16:14 -05:00
|
|
|
actual
|
|
|
|
end
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(actual).to eq expected
|
2013-01-09 18:16:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should handle a tiny case' do
|
2019-03-24 12:14:20 -04:00
|
|
|
try_round_trip(<<-TABLE)
|
2013-01-09 18:16:14 -05:00
|
|
|
asdf asfddd fdass
|
2019-03-24 12:14:20 -04:00
|
|
|
TABLE
|
2013-01-09 18:16:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should handle the basic case' do
|
2019-03-24 12:14:20 -04:00
|
|
|
try_round_trip(<<-TABLE)
|
2013-01-09 18:16:14 -05:00
|
|
|
aadd ddasffssdad sdsaadaasd ssfasaafssd
|
|
|
|
adassdfffaasds f sdsfasddasfds ssssdaa
|
|
|
|
assfsafsfsds fsasa ssdsssafsdasdf
|
2019-03-24 12:14:20 -04:00
|
|
|
TABLE
|
2013-01-09 18:16:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should handle... another basic case' do
|
2019-03-24 09:36:06 -04:00
|
|
|
try_round_trip(<<-TABLE)
|
2013-01-09 18:16:14 -05:00
|
|
|
aaad dasaasffaasf fdasfdfss safdfdddsasd
|
|
|
|
aaadfasassdfff ddadadassasdf fddsasadfssdss sasf
|
|
|
|
aaddaafaf dddasaaaaaa fdsasad sddsa
|
|
|
|
aas dfsddffdddsdfd ff sddsfsaa
|
|
|
|
adasadfaaffds dsfafdsfdfssda ffadsfafsaafa ss
|
|
|
|
asddaadaaadfdd dssdss ffssfsfafaadss ssas
|
|
|
|
asdsdaa faadf fsddfff ssdfssff
|
|
|
|
asfadsssaaad fasfaafdssd s
|
2019-03-24 09:36:06 -04:00
|
|
|
TABLE
|
2013-01-09 18:16:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should handle colors' do
|
2019-03-24 09:36:06 -04:00
|
|
|
try_round_trip(<<-TABLE)
|
2013-01-09 18:16:14 -05:00
|
|
|
\e[31maaaaaaaaaa\e[0m \e[31mccccccccccccccccccccccccccccc\e[0m
|
|
|
|
\e[31mbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\e[0m \e[31mddddddddddddd\e[0m
|
2019-03-24 09:36:06 -04:00
|
|
|
TABLE
|
2013-01-09 18:16:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should handle empty input' do
|
|
|
|
try_round_trip('')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should handle one-token input' do
|
|
|
|
try_round_trip('asdf')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-26 23:12:35 -05:00
|
|
|
describe 'line length is smaller than the length of the longest word' do
|
|
|
|
before do
|
|
|
|
element = 'swizzle'
|
|
|
|
@elem_len = element.length
|
|
|
|
@out = [element, 'crime', 'fun']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not raise error' do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { Pry::Helpers.tablify(@out, @elem_len - 1) }.not_to raise_error
|
2013-01-26 23:12:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should format output as one column' do
|
|
|
|
table = Pry::Helpers.tablify(@out, @elem_len - 1).to_s
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(table).to eq "swizzle\ncrime \nfun "
|
2013-01-26 23:12:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-12 11:09:18 -04:00
|
|
|
specify 'decide between one-line or indented output' do
|
2019-03-02 06:22:03 -05:00
|
|
|
expect(Pry::Helpers.tablify_or_one_line('head', %w[ing])).to eq "head: ing\n"
|
2013-01-17 00:29:32 -05:00
|
|
|
end
|
2013-01-09 18:16:14 -05:00
|
|
|
end
|