tty 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -7
- data/CHANGELOG.md +6 -0
- data/Gemfile +18 -1
- data/README.md +55 -28
- data/Rakefile +5 -9
- data/images/tty.png +0 -0
- data/lib/tty.rb +7 -1
- data/lib/tty/coercer/boolean.rb +6 -9
- data/lib/tty/coercer/float.rb +14 -17
- data/lib/tty/coercer/integer.rb +14 -17
- data/lib/tty/coercer/range.rb +6 -7
- data/lib/tty/logger.rb +23 -9
- data/lib/tty/plugins.rb +3 -6
- data/lib/tty/plugins/plugin.rb +4 -7
- data/lib/tty/shell.rb +20 -12
- data/lib/tty/shell/question.rb +41 -48
- data/lib/tty/shell/question/modifier.rb +5 -8
- data/lib/tty/shell/question/validation.rb +8 -7
- data/lib/tty/shell/reader.rb +28 -19
- data/lib/tty/shell/response.rb +26 -22
- data/lib/tty/shell/statement.rb +13 -9
- data/lib/tty/shell/suggestion.rb +17 -13
- data/lib/tty/support/coercion.rb +5 -6
- data/lib/tty/support/conversion.rb +7 -6
- data/lib/tty/support/delegatable.rb +5 -5
- data/lib/tty/support/unicode.rb +3 -4
- data/lib/tty/support/utils.rb +1 -2
- data/lib/tty/system.rb +13 -6
- data/lib/tty/system/editor.rb +21 -18
- data/lib/tty/system/which.rb +3 -5
- data/lib/tty/table.rb +18 -22
- data/lib/tty/table/border.rb +2 -4
- data/lib/tty/table/border/ascii.rb +3 -2
- data/lib/tty/table/border/null.rb +1 -3
- data/lib/tty/table/border/row_line.rb +1 -4
- data/lib/tty/table/border/unicode.rb +3 -2
- data/lib/tty/table/border_dsl.rb +21 -17
- data/lib/tty/table/border_options.rb +6 -5
- data/lib/tty/table/column_set.rb +11 -7
- data/lib/tty/table/columns.rb +19 -16
- data/lib/tty/table/error.rb +1 -3
- data/lib/tty/table/field.rb +30 -12
- data/lib/tty/table/header.rb +18 -9
- data/lib/tty/table/indentation.rb +1 -3
- data/lib/tty/table/operation/alignment.rb +8 -9
- data/lib/tty/table/operation/alignment_set.rb +6 -5
- data/lib/tty/table/operation/escape.rb +3 -3
- data/lib/tty/table/operation/filter.rb +3 -4
- data/lib/tty/table/operation/truncation.rb +3 -3
- data/lib/tty/table/operation/wrapped.rb +3 -4
- data/lib/tty/table/operations.rb +19 -22
- data/lib/tty/table/orientation.rb +5 -5
- data/lib/tty/table/orientation/horizontal.rb +9 -6
- data/lib/tty/table/orientation/vertical.rb +10 -7
- data/lib/tty/table/padder.rb +46 -8
- data/lib/tty/table/renderer.rb +21 -14
- data/lib/tty/table/renderer/ascii.rb +6 -5
- data/lib/tty/table/renderer/basic.rb +18 -19
- data/lib/tty/table/renderer/unicode.rb +11 -5
- data/lib/tty/table/row.rb +36 -20
- data/lib/tty/table/transformation.rb +6 -5
- data/lib/tty/table/validatable.rb +32 -17
- data/lib/tty/terminal.rb +26 -42
- data/lib/tty/terminal/color.rb +10 -12
- data/lib/tty/terminal/echo.rb +4 -7
- data/lib/tty/terminal/home.rb +3 -10
- data/lib/tty/terminal/pager.rb +11 -10
- data/lib/tty/terminal/pager/basic.rb +3 -6
- data/lib/tty/terminal/pager/system.rb +2 -5
- data/lib/tty/text.rb +7 -10
- data/lib/tty/text/distance.rb +2 -4
- data/lib/tty/text/truncation.rb +1 -3
- data/lib/tty/text/wrapping.rb +1 -3
- data/lib/tty/vector.rb +3 -5
- data/lib/tty/version.rb +2 -2
- data/spec/spec_helper.rb +4 -11
- data/spec/tty/coercer/boolean/coerce_spec.rb +19 -16
- data/spec/tty/coercer/float/coerce_spec.rb +6 -4
- data/spec/tty/coercer/integer/coerce_spec.rb +5 -4
- data/spec/tty/coercer/range/coerce_spec.rb +12 -11
- data/spec/tty/logger/log_spec.rb +23 -0
- data/spec/tty/logger/new_spec.rb +14 -14
- data/spec/tty/logger/valid_level_spec.rb +6 -6
- data/spec/tty/plugins/find_spec.rb +4 -4
- data/spec/tty/plugins/load_spec.rb +4 -5
- data/spec/tty/plugins/plugin/load_spec.rb +10 -8
- data/spec/tty/plugins/plugin/new_spec.rb +7 -7
- data/spec/tty/shell/ask_spec.rb +6 -7
- data/spec/tty/shell/error_spec.rb +1 -2
- data/spec/tty/shell/print_table_spec.rb +1 -2
- data/spec/tty/shell/question/argument_spec.rb +1 -1
- data/spec/tty/shell/question/character_spec.rb +11 -3
- data/spec/tty/shell/question/default_spec.rb +3 -3
- data/spec/tty/shell/question/in_spec.rb +1 -1
- data/spec/tty/shell/question/initialize_spec.rb +8 -11
- data/spec/tty/shell/question/modifier/apply_to_spec.rb +8 -4
- data/spec/tty/shell/question/modifier/letter_case_spec.rb +4 -4
- data/spec/tty/shell/question/modifier/whitespace_spec.rb +5 -5
- data/spec/tty/shell/question/modify_spec.rb +1 -1
- data/spec/tty/shell/question/valid_spec.rb +4 -4
- data/spec/tty/shell/question/validate_spec.rb +4 -4
- data/spec/tty/shell/question/validation/coerce_spec.rb +2 -3
- data/spec/tty/shell/question/validation/valid_value_spec.rb +3 -3
- data/spec/tty/shell/reader/getc_spec.rb +16 -14
- data/spec/tty/shell/response/read_bool_spec.rb +1 -1
- data/spec/tty/shell/response/read_char_spec.rb +1 -2
- data/spec/tty/shell/response/read_date_spec.rb +1 -1
- data/spec/tty/shell/response/read_email_spec.rb +1 -1
- data/spec/tty/shell/response/read_multiple_spec.rb +3 -4
- data/spec/tty/shell/response/read_number_spec.rb +1 -2
- data/spec/tty/shell/response/read_range_spec.rb +2 -2
- data/spec/tty/shell/response/read_spec.rb +7 -7
- data/spec/tty/shell/response/read_string_spec.rb +2 -2
- data/spec/tty/shell/say_spec.rb +1 -1
- data/spec/tty/shell/statement/initialize_spec.rb +3 -3
- data/spec/tty/shell/suggest_spec.rb +1 -1
- data/spec/tty/shell/warn_spec.rb +1 -2
- data/spec/tty/support/coercion_spec.rb +10 -10
- data/spec/tty/support/conversion_spec.rb +9 -9
- data/spec/tty/support/delegatable_spec.rb +7 -5
- data/spec/tty/support/equatable_spec.rb +32 -34
- data/spec/tty/support/fixtures/classes.rb +4 -2
- data/spec/tty/system/editor/available_spec.rb +12 -12
- data/spec/tty/system/editor/build_spec.rb +8 -16
- data/spec/tty/system/editor/command_spec.rb +3 -2
- data/spec/tty/system/editor/executables_spec.rb +3 -3
- data/spec/tty/system/editor/invoke_spec.rb +10 -14
- data/spec/tty/system/editor/open_spec.rb +9 -7
- data/spec/tty/system/platform_spec.rb +32 -13
- data/spec/tty/system/which/which_spec.rb +9 -9
- data/spec/tty/system/which_spec.rb +4 -4
- data/spec/tty/table/access_spec.rb +24 -21
- data/spec/tty/table/add_row_spec.rb +2 -2
- data/spec/tty/table/border/ascii/rendering_spec.rb +13 -13
- data/spec/tty/table/border/new_spec.rb +5 -4
- data/spec/tty/table/border/null/rendering_spec.rb +12 -12
- data/spec/tty/table/border/options/from_spec.rb +2 -3
- data/spec/tty/table/border/options/new_spec.rb +4 -5
- data/spec/tty/table/border/unicode/rendering_spec.rb +10 -10
- data/spec/tty/table/border_options/new_spec.rb +20 -0
- data/spec/tty/table/border_options/update_spec.rb +18 -0
- data/spec/tty/table/column_set/extract_widths_spec.rb +1 -1
- data/spec/tty/table/column_set/total_width_spec.rb +2 -2
- data/spec/tty/table/column_set/widths_from_spec.rb +1 -2
- data/spec/tty/table/columns/enforce_spec.rb +2 -2
- data/spec/tty/table/columns/widths_spec.rb +2 -0
- data/spec/tty/table/data_spec.rb +3 -3
- data/spec/tty/table/each_spec.rb +9 -11
- data/spec/tty/table/each_with_index_spec.rb +8 -9
- data/spec/tty/table/empty_spec.rb +3 -3
- data/spec/tty/table/eql_spec.rb +6 -6
- data/spec/tty/table/field/equality_spec.rb +11 -11
- data/spec/tty/table/field/length_spec.rb +4 -4
- data/spec/tty/table/field/lines_spec.rb +3 -3
- data/spec/tty/table/field/new_spec.rb +7 -7
- data/spec/tty/table/field/width_spec.rb +6 -4
- data/spec/tty/table/filter_spec.rb +3 -3
- data/spec/tty/table/header/call_spec.rb +3 -3
- data/spec/tty/table/header/height_spec.rb +1 -1
- data/spec/tty/table/header/new_spec.rb +5 -5
- data/spec/tty/table/header/set_spec.rb +9 -4
- data/spec/tty/table/header/to_ary_spec.rb +4 -4
- data/spec/tty/table/header_spec.rb +3 -4
- data/spec/tty/table/indentation/insert_indent_spec.rb +1 -1
- data/spec/tty/table/initialize_spec.rb +13 -13
- data/spec/tty/table/operation/alignment/format_spec.rb +5 -5
- data/spec/tty/table/operation/alignment/new_spec.rb +4 -4
- data/spec/tty/table/operation/alignment_set/call_spec.rb +11 -11
- data/spec/tty/table/operation/alignment_set/each_spec.rb +3 -3
- data/spec/tty/table/operation/alignment_set/new_spec.rb +6 -6
- data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +4 -4
- data/spec/tty/table/operation/escape/call_spec.rb +1 -1
- data/spec/tty/table/operation/filter/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/truncate_spec.rb +4 -4
- data/spec/tty/table/operation/wrapped/call_spec.rb +1 -1
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +3 -3
- data/spec/tty/table/operations/new_spec.rb +1 -1
- data/spec/tty/table/options_spec.rb +8 -8
- data/spec/tty/table/orientation_spec.rb +15 -13
- data/spec/tty/table/padder/parse_spec.rb +1 -1
- data/spec/tty/table/padder/to_s_spec.rb +14 -0
- data/spec/tty/table/padding_spec.rb +1 -1
- data/spec/tty/table/properties_spec.rb +9 -8
- data/spec/tty/table/render_spec.rb +8 -5
- data/spec/tty/table/render_with_spec.rb +5 -4
- data/spec/tty/table/renderer/ascii/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/render_spec.rb +7 -7
- data/spec/tty/table/renderer/ascii/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/alignment_spec.rb +5 -5
- data/spec/tty/table/renderer/basic/coloring_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +6 -6
- data/spec/tty/table/renderer/basic/filter_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/indentation_spec.rb +5 -3
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +10 -10
- data/spec/tty/table/renderer/basic/new_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/options_spec.rb +9 -9
- data/spec/tty/table/renderer/basic/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/render_spec.rb +8 -8
- data/spec/tty/table/renderer/basic/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/truncation_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +4 -4
- data/spec/tty/table/renderer/border_spec.rb +21 -21
- data/spec/tty/table/renderer/render_spec.rb +7 -7
- data/spec/tty/table/renderer/select_spec.rb +4 -4
- data/spec/tty/table/renderer/style_spec.rb +19 -19
- data/spec/tty/table/renderer/unicode/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/render_spec.rb +6 -6
- data/spec/tty/table/renderer/unicode/separator_spec.rb +2 -2
- data/spec/tty/table/renderer_spec.rb +1 -1
- data/spec/tty/table/rotate_spec.rb +27 -27
- data/spec/tty/table/row/access_spec.rb +3 -3
- data/spec/tty/table/row/call_spec.rb +4 -4
- data/spec/tty/table/row/data_spec.rb +5 -5
- data/spec/tty/table/row/each_spec.rb +1 -1
- data/spec/tty/table/row/equality_spec.rb +16 -16
- data/spec/tty/table/row/height_spec.rb +1 -1
- data/spec/tty/table/row/new_spec.rb +11 -11
- data/spec/tty/table/row/to_ary_spec.rb +3 -3
- data/spec/tty/table/to_s_spec.rb +8 -8
- data/spec/tty/table/validatable/validate_options_spec.rb +5 -5
- data/spec/tty/table/validatable_spec.rb +14 -1
- data/spec/tty/terminal/color/code_spec.rb +3 -3
- data/spec/tty/terminal/color/remove_spec.rb +8 -9
- data/spec/tty/terminal/color/set_spec.rb +5 -6
- data/spec/tty/terminal/color_spec.rb +3 -5
- data/spec/tty/terminal/echo_spec.rb +3 -4
- data/spec/tty/terminal/home_spec.rb +12 -14
- data/spec/tty/terminal/page_spec.rb +5 -4
- data/spec/tty/terminal/pager/available_spec.rb +11 -11
- data/spec/tty/terminal/pager/basic/page_spec.rb +8 -8
- data/spec/tty/terminal/pager/command_spec.rb +2 -2
- data/spec/tty/terminal/pager/executables_spec.rb +3 -3
- data/spec/tty/terminal/pager/page_spec.rb +8 -10
- data/spec/tty/terminal/pager/system/page_spec.rb +8 -8
- data/spec/tty/terminal/size_spec.rb +39 -36
- data/spec/tty/text/distance/distance_spec.rb +13 -13
- data/spec/tty/text/distance/initialize_spec.rb +4 -4
- data/spec/tty/text/distance_spec.rb +2 -2
- data/spec/tty/text/truncate_spec.rb +2 -3
- data/spec/tty/text/truncation/initialize_spec.rb +9 -9
- data/spec/tty/text/truncation/truncate_spec.rb +14 -14
- data/spec/tty/text/wrap_spec.rb +2 -3
- data/spec/tty/text/wrapping/initialize_spec.rb +7 -7
- data/spec/tty/text/wrapping/wrap_spec.rb +11 -11
- data/spec/tty/tty_spec.rb +22 -0
- data/spec/tty/vector/new_spec.rb +7 -7
- data/tasks/console.rake +10 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/metrics/cane.rake +2 -0
- data/tasks/metrics/flog.rake +2 -0
- data/tasks/metrics/heckle.rake +15 -0
- data/tasks/metrics/reek.rake +2 -0
- data/tasks/spec.rake +29 -0
- data/tty.gemspec +5 -12
- metadata +34 -91
- data/.rvmrc +0 -34
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -11,7 +11,7 @@ describe TTY::Table, '#render' do
|
|
11
11
|
|
12
12
|
subject(:table) { object.new header, rows }
|
13
13
|
|
14
|
-
it {
|
14
|
+
it { is_expected.to respond_to(:render) }
|
15
15
|
|
16
16
|
context 'with block' do
|
17
17
|
it 'allows to modify renderer in a block' do
|
@@ -32,7 +32,7 @@ describe TTY::Table, '#render' do
|
|
32
32
|
result = table.render :ascii do |renderer|
|
33
33
|
renderer.border.style = :red
|
34
34
|
end
|
35
|
-
result.
|
35
|
+
expect(result).to eq <<-EOS.normalize
|
36
36
|
\e[31m+--+--+\e[0m
|
37
37
|
\e[31m|\e[0mh1\e[31m|\e[0mh2\e[31m|\e[0m
|
38
38
|
\e[31m+--+--+\e[0m
|
@@ -45,13 +45,16 @@ describe TTY::Table, '#render' do
|
|
45
45
|
|
46
46
|
context 'with params' do
|
47
47
|
it 'sets params without renderer' do
|
48
|
-
TTY::Table::Renderer.
|
48
|
+
allow(TTY::Table::Renderer).to receive(:render)
|
49
49
|
table.render(:basic)
|
50
|
+
expect(TTY::Table::Renderer).to have_received(:render).
|
51
|
+
with(table, {renderer: :basic})
|
50
52
|
end
|
51
53
|
|
52
54
|
it 'sets params with renderer' do
|
53
|
-
TTY::Table::Renderer.
|
55
|
+
allow(TTY::Table::Renderer).to receive(:render)
|
54
56
|
table.render
|
57
|
+
expect(TTY::Table::Renderer).to have_received(:render).with(table, {})
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
@@ -14,7 +14,8 @@ describe TTY::Table, '#render_with' do
|
|
14
14
|
|
15
15
|
it "doesn't implement def_border" do
|
16
16
|
klass = Class.new(TTY::Table::Border)
|
17
|
-
expect { table.render_with klass }.
|
17
|
+
expect { table.render_with klass }.
|
18
|
+
to raise_error(TTY::NoImplementationError)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
@@ -42,7 +43,7 @@ describe TTY::Table, '#render_with' do
|
|
42
43
|
}
|
43
44
|
|
44
45
|
it 'displays custom border' do
|
45
|
-
table.render_with(MyBorder).
|
46
|
+
expect(table.render_with(MyBorder)).to eq <<-EOS.normalize
|
46
47
|
*==*==*==*
|
47
48
|
$h1$h2$h3$
|
48
49
|
*==*==*==*
|
@@ -69,7 +70,7 @@ describe TTY::Table, '#render_with' do
|
|
69
70
|
}
|
70
71
|
|
71
72
|
it 'displays border' do
|
72
|
-
table.render_with(MyBorder).
|
73
|
+
expect(table.render_with(MyBorder)).to eq <<-EOS.normalize
|
73
74
|
$h1$h2$h3$
|
74
75
|
$a1$a2$a3$
|
75
76
|
$b1$b2$b3$
|
@@ -92,7 +93,7 @@ describe TTY::Table, '#render_with' do
|
|
92
93
|
result = table.render_with MyBorder do |renderer|
|
93
94
|
renderer.border.style = :red
|
94
95
|
end
|
95
|
-
result.
|
96
|
+
expect(result).to eq <<-EOS.normalize
|
96
97
|
\e[31m|\e[0mh1\e[31m\e[0mh2\e[31m\e[0mh3\e[31m|\e[0m
|
97
98
|
\e[31m|\e[0ma1\e[31m\e[0ma2\e[31m\e[0ma3\e[31m|\e[0m
|
98
99
|
\e[31m|\e[0mb1\e[31m\e[0mb2\e[31m\e[0mb3\e[31m|\e[0m
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -7,13 +7,13 @@ describe TTY::Table::Renderer::ASCII, '#render' do
|
|
7
7
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
8
|
let(:table) { TTY::Table.new header, rows }
|
9
9
|
|
10
|
-
subject { described_class.new(table) }
|
10
|
+
subject(:renderer) { described_class.new(table) }
|
11
11
|
|
12
12
|
context 'only rows' do
|
13
13
|
let(:table) { TTY::Table.new rows }
|
14
14
|
|
15
15
|
it 'display table rows' do
|
16
|
-
|
16
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
17
17
|
+--+--+--+
|
18
18
|
|a1|a2|a3|
|
19
19
|
|b1|b2|b3|
|
@@ -24,7 +24,7 @@ describe TTY::Table::Renderer::ASCII, '#render' do
|
|
24
24
|
|
25
25
|
context 'with header' do
|
26
26
|
it 'displays table with header' do
|
27
|
-
|
27
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
28
28
|
+--+--+--+
|
29
29
|
|h1|h2|h3|
|
30
30
|
+--+--+--+
|
@@ -37,10 +37,10 @@ describe TTY::Table::Renderer::ASCII, '#render' do
|
|
37
37
|
|
38
38
|
context 'with short header' do
|
39
39
|
let(:header) { ['h1', 'h2'] }
|
40
|
-
let(:rows)
|
40
|
+
let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
|
41
41
|
|
42
42
|
it 'displays table according to widths' do
|
43
|
-
|
43
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
44
44
|
+----+---+
|
45
45
|
|h1 |h2 |
|
46
46
|
+----+---+
|
@@ -55,7 +55,7 @@ describe TTY::Table::Renderer::ASCII, '#render' do
|
|
55
55
|
let(:header) { ['header1', 'header2', 'header3'] }
|
56
56
|
|
57
57
|
it 'header greater than row sizes' do
|
58
|
-
|
58
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
59
59
|
+-------+-------+-------+
|
60
60
|
|header1|header2|header3|
|
61
61
|
+-------+-------+-------+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -14,7 +14,7 @@ describe TTY::Table::Renderer::ASCII, 'with separator' do
|
|
14
14
|
context 'when ascii' do
|
15
15
|
it "renders each row" do
|
16
16
|
renderer.border.separator= :each_row
|
17
|
-
renderer.render.
|
17
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
18
18
|
+--+--+--+
|
19
19
|
|h1|h2|h3|
|
20
20
|
+--+--+--+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -57,13 +57,13 @@ describe TTY::Table::Renderer::Basic, 'alignment' do
|
|
57
57
|
let(:table) {
|
58
58
|
TTY::Table.new header: header do |t|
|
59
59
|
t << ['a1', 'a2', 'a3']
|
60
|
-
t << ['b1', {:
|
61
|
-
t << ['c1', 'c2', {:
|
60
|
+
t << ['b1', {value: 'b2', align: :right}, 'b3']
|
61
|
+
t << ['c1', 'c2', {value: 'c3', align: :center}]
|
62
62
|
end
|
63
63
|
}
|
64
64
|
|
65
65
|
it "takes individual fields over global aligns" do
|
66
|
-
renderer.render.
|
66
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
67
67
|
header1 header2 header3
|
68
68
|
a1 a2 a3
|
69
69
|
b1 b2 b3
|
@@ -78,7 +78,7 @@ describe TTY::Table::Renderer::Basic, 'alignment' do
|
|
78
78
|
let(:options) { { renderer: :basic } }
|
79
79
|
|
80
80
|
it "aligns headres" do
|
81
|
-
renderer.render.
|
81
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
82
82
|
h1 h2 h3
|
83
83
|
aaaaa1 a2 aaa3
|
84
84
|
b1 bbbb2 bb3
|
@@ -1,19 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe TTY::Table::Renderer::Basic, '#
|
5
|
+
describe TTY::Table::Renderer::Basic, '#column_widths' do
|
6
6
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
7
|
-
let(:
|
7
|
+
let(:renderer) { described_class.new(table) }
|
8
8
|
|
9
|
-
subject {
|
9
|
+
subject { renderer.render }
|
10
10
|
|
11
11
|
context 'with rows only' do
|
12
12
|
let(:rows) { [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']] }
|
13
13
|
let(:table) { TTY::Table.new rows }
|
14
14
|
|
15
15
|
it 'calculates column widths' do
|
16
|
-
|
16
|
+
expect(renderer.column_widths).to eq([5,6])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,7 +22,7 @@ describe TTY::Table::Renderer::Basic, '#extract_column_widths' do
|
|
22
22
|
let(:table) { TTY::Table.new header, rows }
|
23
23
|
|
24
24
|
it 'calcualtes column widths with header' do
|
25
|
-
|
25
|
+
expect(renderer.column_widths).to eq([7,5,2])
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -17,7 +17,7 @@ describe TTY::Table::Renderer::Basic, 'filter' do
|
|
17
17
|
}
|
18
18
|
|
19
19
|
it 'filters only rows' do
|
20
|
-
|
20
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
21
21
|
h1 h2 h3
|
22
22
|
a1 A2 a3
|
23
23
|
b1 B2 b3
|
@@ -29,7 +29,7 @@ describe TTY::Table::Renderer::Basic, 'filter' do
|
|
29
29
|
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val }}
|
30
30
|
|
31
31
|
it 'filters only rows' do
|
32
|
-
|
32
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
33
33
|
h1 H2 h3
|
34
34
|
a1 A2 a3
|
35
35
|
b1 B2 b3
|
@@ -44,7 +44,7 @@ describe TTY::Table::Renderer::Basic, 'filter' do
|
|
44
44
|
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val } }
|
45
45
|
|
46
46
|
it 'filters only rows' do
|
47
|
-
|
47
|
+
expect(renderer.render).to eq <<-EOS.normalize
|
48
48
|
a1 A2 a3
|
49
49
|
b1 B2 b3
|
50
50
|
EOS
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,13 +6,12 @@ describe TTY::Table::Renderer::Basic, 'indentation' do
|
|
6
6
|
let(:header) { ['h1', 'h2', 'h3'] }
|
7
7
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
8
|
let(:table) { TTY::Table.new(header, rows) }
|
9
|
-
let(:indent) { 2 }
|
10
9
|
let(:options) { {indent: indent } }
|
11
10
|
|
12
11
|
subject(:renderer) { described_class.new(table, options)}
|
13
12
|
|
14
13
|
context 'when default' do
|
15
|
-
let(:
|
14
|
+
let(:indent) { 0 }
|
16
15
|
|
17
16
|
it 'indents by value' do
|
18
17
|
expect(renderer.render).to eql <<-EOS.chomp
|
@@ -24,6 +23,8 @@ b1 b2 b3
|
|
24
23
|
end
|
25
24
|
|
26
25
|
context 'when custom' do
|
26
|
+
let(:indent) { 2 }
|
27
|
+
|
27
28
|
it 'indents by value' do
|
28
29
|
expect(renderer.render).to eql <<-EOS.chomp
|
29
30
|
h1 h2 h3
|
@@ -34,6 +35,7 @@ b1 b2 b3
|
|
34
35
|
end
|
35
36
|
|
36
37
|
context 'when changed' do
|
38
|
+
let(:indent) { 2 }
|
37
39
|
let(:header) { ['h1', 'h2'] }
|
38
40
|
let(:rows) { [['a1', 'a2']] }
|
39
41
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -14,7 +14,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
14
14
|
|
15
15
|
context 'without border' do
|
16
16
|
it "renders single line" do
|
17
|
-
table.render(multiline: false).
|
17
|
+
expect(table.render(multiline: false)).to eq <<-EOS.normalize
|
18
18
|
First 1
|
19
19
|
Multiline\\nContent 2
|
20
20
|
Third 3
|
@@ -24,7 +24,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
24
24
|
|
25
25
|
context 'with column widths' do
|
26
26
|
it "renders single line" do
|
27
|
-
table.render(multiline: false, column_widths: [8,1]).
|
27
|
+
expect(table.render(multiline: false, column_widths: [8,1])).to eq <<-EOS.normalize
|
28
28
|
First 1
|
29
29
|
Multili… 2
|
30
30
|
Third 3
|
@@ -34,7 +34,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
34
34
|
|
35
35
|
context 'with border' do
|
36
36
|
it "renders single line" do
|
37
|
-
table.render(:ascii, multiline: false).
|
37
|
+
expect(table.render(:ascii, multiline: false)).to eq <<-EOS.normalize
|
38
38
|
+------------------+-+
|
39
39
|
|First |1|
|
40
40
|
|Multiline\\nContent|2|
|
@@ -48,7 +48,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
48
48
|
let(:header) { ["Multi\nHeader", "header2"] }
|
49
49
|
|
50
50
|
it "renders header" do
|
51
|
-
table.render(:ascii, multiline: false).
|
51
|
+
expect(table.render(:ascii, multiline: false)).to eq <<-EOS.normalize
|
52
52
|
+------------------+-------+
|
53
53
|
|Multi\\nHeader |header2|
|
54
54
|
+------------------+-------+
|
@@ -66,7 +66,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
66
66
|
|
67
67
|
context 'without border' do
|
68
68
|
it "renders every line" do
|
69
|
-
table.render(multiline: true).
|
69
|
+
expect(table.render(multiline: true)).to eq <<-EOS.normalize
|
70
70
|
First 1
|
71
71
|
Multi 2
|
72
72
|
Line
|
@@ -78,7 +78,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
78
78
|
|
79
79
|
context 'with column widths' do
|
80
80
|
it "renders multiline" do
|
81
|
-
table.render(multiline: true, column_widths: [8,1]).
|
81
|
+
expect(table.render(multiline: true, column_widths: [8,1])).to eq <<-EOS.normalize
|
82
82
|
First 1
|
83
83
|
Multi 2
|
84
84
|
Line
|
@@ -88,7 +88,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'wraps multi line' do
|
91
|
-
table.render(multiline: true, column_widths: [5,1]).
|
91
|
+
expect(table.render(multiline: true, column_widths: [5,1])).to eq <<-EOS.normalize
|
92
92
|
First 1
|
93
93
|
Multi 2
|
94
94
|
Line
|
@@ -101,7 +101,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
101
101
|
|
102
102
|
context 'with border' do
|
103
103
|
it "renders every line" do
|
104
|
-
table.render(:ascii, multiline: true).
|
104
|
+
expect(table.render(:ascii, multiline: true)).to eq <<-EOS.normalize
|
105
105
|
+-------+-+
|
106
106
|
|First |1|
|
107
107
|
|Multi |2|
|
@@ -117,7 +117,7 @@ describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
|
117
117
|
let(:header) { ["Multi\nHeader", "header2"] }
|
118
118
|
|
119
119
|
it "renders header" do
|
120
|
-
table.render(:ascii, multiline: true).
|
120
|
+
expect(table.render(:ascii, multiline: true)).to eq <<-EOS.normalize
|
121
121
|
+-------+-------+
|
122
122
|
|Multi |header2|
|
123
123
|
|Header | |
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -16,33 +16,33 @@ describe TTY::Table::Renderer::Basic, 'options' do
|
|
16
16
|
}
|
17
17
|
}
|
18
18
|
|
19
|
-
subject { object.new table, options }
|
19
|
+
subject(:renderer) { object.new table, options }
|
20
20
|
|
21
|
-
|
21
|
+
it { expect(renderer.border).to be_kind_of(TTY::Table::BorderOptions) }
|
22
22
|
|
23
|
-
|
23
|
+
it { expect(renderer.column_widths).to eql([2,2]) }
|
24
24
|
|
25
|
-
|
25
|
+
it { expect(renderer.column_aligns).to eql(aligns) }
|
26
26
|
|
27
|
-
it {
|
27
|
+
it { expect(renderer.column_aligns.to_a).to be_empty }
|
28
28
|
|
29
29
|
context '#column_widths' do
|
30
30
|
let(:widths) { [10, 10] }
|
31
31
|
|
32
|
-
|
32
|
+
it { expect(renderer.column_widths).to eq(widths) }
|
33
33
|
end
|
34
34
|
|
35
35
|
context '#column_widths empty' do
|
36
36
|
let(:widths) { [] }
|
37
37
|
|
38
|
-
it { expect {
|
38
|
+
it { expect { renderer.column_widths }.to raise_error(TTY::InvalidArgument) }
|
39
39
|
end
|
40
40
|
|
41
41
|
context '#column_aligns' do
|
42
42
|
let(:aligns) { [:center, :center] }
|
43
43
|
|
44
44
|
it 'unwraps original array' do
|
45
|
-
|
45
|
+
expect(renderer.column_aligns.to_a).to eq(aligns)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|