tty 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -3
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +42 -306
  5. data/lib/tty/{text → shell}/distance.rb +5 -27
  6. data/lib/tty/shell/suggestion.rb +42 -22
  7. data/lib/tty/version.rb +1 -1
  8. data/lib/tty.rb +2 -42
  9. data/spec/tty/{text → shell}/distance/distance_spec.rb +4 -4
  10. data/spec/tty/shell/distance/initialize_spec.rb +14 -0
  11. data/tty.gemspec +4 -3
  12. metadata +37 -269
  13. data/benchmarks/table.rb +0 -40
  14. data/lib/tty/table/border/ascii.rb +0 -32
  15. data/lib/tty/table/border/null.rb +0 -37
  16. data/lib/tty/table/border/row_line.rb +0 -18
  17. data/lib/tty/table/border/unicode.rb +0 -32
  18. data/lib/tty/table/border.rb +0 -222
  19. data/lib/tty/table/border_dsl.rb +0 -251
  20. data/lib/tty/table/border_options.rb +0 -53
  21. data/lib/tty/table/column_set.rb +0 -121
  22. data/lib/tty/table/columns.rb +0 -170
  23. data/lib/tty/table/error.rb +0 -18
  24. data/lib/tty/table/field.rb +0 -139
  25. data/lib/tty/table/header.rb +0 -133
  26. data/lib/tty/table/indentation.rb +0 -52
  27. data/lib/tty/table/operation/alignment.rb +0 -107
  28. data/lib/tty/table/operation/alignment_set.rb +0 -77
  29. data/lib/tty/table/operation/escape.rb +0 -30
  30. data/lib/tty/table/operation/filter.rb +0 -34
  31. data/lib/tty/table/operation/padding.rb +0 -95
  32. data/lib/tty/table/operation/truncation.rb +0 -55
  33. data/lib/tty/table/operation/wrapped.rb +0 -58
  34. data/lib/tty/table/operations.rb +0 -69
  35. data/lib/tty/table/orientation/horizontal.rb +0 -48
  36. data/lib/tty/table/orientation/vertical.rb +0 -38
  37. data/lib/tty/table/orientation.rb +0 -57
  38. data/lib/tty/table/padder.rb +0 -180
  39. data/lib/tty/table/renderer/ascii.rb +0 -16
  40. data/lib/tty/table/renderer/basic.rb +0 -294
  41. data/lib/tty/table/renderer/color.rb +0 -12
  42. data/lib/tty/table/renderer/unicode.rb +0 -21
  43. data/lib/tty/table/renderer.rb +0 -101
  44. data/lib/tty/table/row.rb +0 -217
  45. data/lib/tty/table/transformation.rb +0 -39
  46. data/lib/tty/table/validatable.rb +0 -64
  47. data/lib/tty/table.rb +0 -476
  48. data/lib/tty/text/truncation.rb +0 -99
  49. data/lib/tty/text/wrapping.rb +0 -118
  50. data/lib/tty/text.rb +0 -98
  51. data/spec/tty/table/access_spec.rb +0 -86
  52. data/spec/tty/table/add_row_spec.rb +0 -28
  53. data/spec/tty/table/border/ascii/rendering_spec.rb +0 -90
  54. data/spec/tty/table/border/new_spec.rb +0 -27
  55. data/spec/tty/table/border/null/rendering_spec.rb +0 -130
  56. data/spec/tty/table/border/options/from_spec.rb +0 -38
  57. data/spec/tty/table/border/options/new_spec.rb +0 -14
  58. data/spec/tty/table/border/unicode/rendering_spec.rb +0 -63
  59. data/spec/tty/table/border_options/new_spec.rb +0 -20
  60. data/spec/tty/table/border_options/update_spec.rb +0 -18
  61. data/spec/tty/table/column_set/extract_widths_spec.rb +0 -15
  62. data/spec/tty/table/column_set/total_width_spec.rb +0 -15
  63. data/spec/tty/table/column_set/widths_from_spec.rb +0 -51
  64. data/spec/tty/table/columns/enforce_spec.rb +0 -68
  65. data/spec/tty/table/columns/widths_spec.rb +0 -35
  66. data/spec/tty/table/data_spec.rb +0 -14
  67. data/spec/tty/table/each_spec.rb +0 -41
  68. data/spec/tty/table/each_with_index_spec.rb +0 -57
  69. data/spec/tty/table/empty_spec.rb +0 -23
  70. data/spec/tty/table/eql_spec.rb +0 -34
  71. data/spec/tty/table/field/equality_spec.rb +0 -51
  72. data/spec/tty/table/field/length_spec.rb +0 -21
  73. data/spec/tty/table/field/lines_spec.rb +0 -21
  74. data/spec/tty/table/field/new_spec.rb +0 -29
  75. data/spec/tty/table/field/width_spec.rb +0 -23
  76. data/spec/tty/table/filter_spec.rb +0 -23
  77. data/spec/tty/table/header/call_spec.rb +0 -30
  78. data/spec/tty/table/header/height_spec.rb +0 -27
  79. data/spec/tty/table/header/new_spec.rb +0 -25
  80. data/spec/tty/table/header/set_spec.rb +0 -20
  81. data/spec/tty/table/header/to_ary_spec.rb +0 -14
  82. data/spec/tty/table/header_spec.rb +0 -13
  83. data/spec/tty/table/indentation/insert_indent_spec.rb +0 -27
  84. data/spec/tty/table/initialize_spec.rb +0 -88
  85. data/spec/tty/table/operation/alignment/format_spec.rb +0 -47
  86. data/spec/tty/table/operation/alignment/new_spec.rb +0 -31
  87. data/spec/tty/table/operation/alignment_set/call_spec.rb +0 -39
  88. data/spec/tty/table/operation/alignment_set/each_spec.rb +0 -17
  89. data/spec/tty/table/operation/alignment_set/new_spec.rb +0 -27
  90. data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +0 -14
  91. data/spec/tty/table/operation/escape/call_spec.rb +0 -16
  92. data/spec/tty/table/operation/filter/call_spec.rb +0 -17
  93. data/spec/tty/table/operation/truncation/call_spec.rb +0 -32
  94. data/spec/tty/table/operation/truncation/truncate_spec.rb +0 -22
  95. data/spec/tty/table/operation/wrapped/call_spec.rb +0 -33
  96. data/spec/tty/table/operation/wrapped/wrap_spec.rb +0 -23
  97. data/spec/tty/table/operations/new_spec.rb +0 -30
  98. data/spec/tty/table/options_spec.rb +0 -25
  99. data/spec/tty/table/orientation_spec.rb +0 -145
  100. data/spec/tty/table/padder/parse_spec.rb +0 -45
  101. data/spec/tty/table/padder/to_s_spec.rb +0 -14
  102. data/spec/tty/table/padding_spec.rb +0 -120
  103. data/spec/tty/table/properties_spec.rb +0 -25
  104. data/spec/tty/table/render_spec.rb +0 -63
  105. data/spec/tty/table/render_with_spec.rb +0 -106
  106. data/spec/tty/table/renderer/ascii/indentation_spec.rb +0 -41
  107. data/spec/tty/table/renderer/ascii/padding_spec.rb +0 -61
  108. data/spec/tty/table/renderer/ascii/render_spec.rb +0 -68
  109. data/spec/tty/table/renderer/ascii/resizing_spec.rb +0 -114
  110. data/spec/tty/table/renderer/ascii/separator_spec.rb +0 -28
  111. data/spec/tty/table/renderer/basic/alignment_spec.rb +0 -88
  112. data/spec/tty/table/renderer/basic/coloring_spec.rb +0 -46
  113. data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +0 -28
  114. data/spec/tty/table/renderer/basic/filter_spec.rb +0 -53
  115. data/spec/tty/table/renderer/basic/indentation_spec.rb +0 -48
  116. data/spec/tty/table/renderer/basic/multiline_content_spec.rb +0 -135
  117. data/spec/tty/table/renderer/basic/new_spec.rb +0 -22
  118. data/spec/tty/table/renderer/basic/options_spec.rb +0 -48
  119. data/spec/tty/table/renderer/basic/padding_spec.rb +0 -52
  120. data/spec/tty/table/renderer/basic/render_spec.rb +0 -57
  121. data/spec/tty/table/renderer/basic/resizing_spec.rb +0 -96
  122. data/spec/tty/table/renderer/basic/separator_spec.rb +0 -43
  123. data/spec/tty/table/renderer/basic/truncation_spec.rb +0 -35
  124. data/spec/tty/table/renderer/basic/wrapping_spec.rb +0 -40
  125. data/spec/tty/table/renderer/basic_spec.rb +0 -0
  126. data/spec/tty/table/renderer/border_spec.rb +0 -104
  127. data/spec/tty/table/renderer/render_spec.rb +0 -36
  128. data/spec/tty/table/renderer/select_spec.rb +0 -22
  129. data/spec/tty/table/renderer/style_spec.rb +0 -72
  130. data/spec/tty/table/renderer/unicode/indentation_spec.rb +0 -41
  131. data/spec/tty/table/renderer/unicode/padding_spec.rb +0 -61
  132. data/spec/tty/table/renderer/unicode/render_spec.rb +0 -68
  133. data/spec/tty/table/renderer/unicode/separator_spec.rb +0 -26
  134. data/spec/tty/table/renderer_spec.rb +0 -19
  135. data/spec/tty/table/rotate_spec.rb +0 -86
  136. data/spec/tty/table/row/access_spec.rb +0 -25
  137. data/spec/tty/table/row/call_spec.rb +0 -41
  138. data/spec/tty/table/row/data_spec.rb +0 -26
  139. data/spec/tty/table/row/each_spec.rb +0 -31
  140. data/spec/tty/table/row/equality_spec.rb +0 -73
  141. data/spec/tty/table/row/height_spec.rb +0 -27
  142. data/spec/tty/table/row/new_spec.rb +0 -41
  143. data/spec/tty/table/row/to_ary_spec.rb +0 -14
  144. data/spec/tty/table/to_s_spec.rb +0 -63
  145. data/spec/tty/table/transformation/extract_tuples_spec.rb +0 -35
  146. data/spec/tty/table/validatable/validate_options_spec.rb +0 -33
  147. data/spec/tty/table/validatable_spec.rb +0 -32
  148. data/spec/tty/text/distance/initialize_spec.rb +0 -14
  149. data/spec/tty/text/distance_spec.rb +0 -11
  150. data/spec/tty/text/truncate_spec.rb +0 -12
  151. data/spec/tty/text/truncation/initialize_spec.rb +0 -29
  152. data/spec/tty/text/truncation/truncate_spec.rb +0 -94
  153. data/spec/tty/text/wrap_spec.rb +0 -13
  154. data/spec/tty/text/wrapping/initialize_spec.rb +0 -25
  155. data/spec/tty/text/wrapping/wrap_spec.rb +0 -97
@@ -1,88 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, 'alignment' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:options) { { column_aligns: column_aligns } }
9
- let(:table) { TTY::Table.new(header, rows) }
10
-
11
- subject(:renderer) { described_class.new table, options }
12
-
13
- context 'with default' do
14
- let(:header) { ['h1', 'h2'] }
15
- let(:rows) { [['aaaaa', 'a'], ['b', 'bbbbb']] }
16
- let(:column_aligns) { nil }
17
-
18
- it 'aligns left by default' do
19
- expect(renderer.render).to eql <<-EOS.normalize
20
- h1 h2
21
- aaaaa a
22
- b bbbbb
23
- EOS
24
- end
25
- end
26
-
27
- context 'with different headers' do
28
- let(:header) { ['header1', 'head2', 'h3'] }
29
- let(:column_aligns) { [:left, :center, :right] }
30
-
31
- it 'aligns headers' do
32
- expect(renderer.render).to eql <<-EOS.normalize
33
- header1 head2 h3
34
- a1 a2 a3
35
- b1 b2 b3
36
- EOS
37
- end
38
- end
39
-
40
- context 'with different aligns' do
41
- let(:header) { nil }
42
- let(:rows) { [['aaaaa', 'a'], ['b', 'bbbbb']] }
43
- let(:column_aligns) { [:left, :right] }
44
-
45
- it 'aligns table rows' do
46
- expect(renderer.render.to_s).to eql <<-EOS.normalize
47
- aaaaa a
48
- b bbbbb
49
- EOS
50
- end
51
- end
52
-
53
- context 'with individual field aligns' do
54
- let(:header) { ['header1', 'header2', 'header3'] }
55
- let(:column_aligns) { [:left, :center, :right] }
56
- let(:options) { {column_aligns: column_aligns} }
57
- let(:table) {
58
- TTY::Table.new header: header do |t|
59
- t << ['a1', 'a2', 'a3']
60
- t << ['b1', {value: 'b2', align: :right}, 'b3']
61
- t << ['c1', 'c2', {value: 'c3', align: :center}]
62
- end
63
- }
64
-
65
- it "takes individual fields over global aligns" do
66
- expect(renderer.render).to eq <<-EOS.normalize
67
- header1 header2 header3
68
- a1 a2 a3
69
- b1 b2 b3
70
- c1 c2 c3
71
- EOS
72
- end
73
- end
74
-
75
- context 'with aligned header' do
76
- let(:rows) { [['aaaaa1', 'a2', 'aaa3'], ['b1', 'bbbb2', 'bb3']] }
77
- let(:header) {['h1', {:value => 'h2', :align => :right}, {:value => 'h3', :align => :center}] }
78
- let(:options) { { renderer: :basic } }
79
-
80
- it "aligns headres" do
81
- expect(renderer.render).to eq <<-EOS.normalize
82
- h1 h2 h3
83
- aaaaa1 a2 aaa3
84
- b1 bbbb2 bb3
85
- EOS
86
- end
87
- end
88
- end
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Basic, 'coloring' do
6
- let(:header) { ['h1', 'h2'] }
7
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
8
- let(:clear) { "\e[0m" }
9
- let(:options) { {filter: filter } }
10
- let(:table) { TTY::Table.new(header, rows) }
11
- let(:color) { Pastel.new(enabled: true) }
12
-
13
- subject(:renderer) { described_class.new(table, options) }
14
-
15
- before { allow(Pastel).to receive(:new).and_return(color) }
16
-
17
- context 'with filter on all fields' do
18
- let(:filter) {
19
- proc { |val, row, col| color.decorate val, :blue, :on_green }
20
- }
21
-
22
- it 'colors all elements' do
23
- expect(renderer.render).to eql <<-EOS.normalize
24
- \e[34;42mh1#{clear} \e[34;42mh2#{clear}
25
- \e[34;42ma1#{clear} \e[34;42ma2#{clear}
26
- \e[34;42mb1#{clear} \e[34;42mb2#{clear}
27
- EOS
28
- end
29
- end
30
-
31
- context 'with filter only on header' do
32
- let(:filter) {
33
- proc { |val, row, col|
34
- row.zero? ? color.decorate(val, :blue, :on_green) : val
35
- }
36
- }
37
-
38
- it 'colors only header' do
39
- expect(renderer.render).to eql <<-EOS.normalize
40
- \e[34;42mh1#{clear} \e[34;42mh2#{clear}
41
- a1 a2
42
- b1 b2
43
- EOS
44
- end
45
- end
46
- end
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, '#column_widths' do
6
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
7
- let(:renderer) { described_class.new(table) }
8
-
9
- subject { renderer.render }
10
-
11
- context 'with rows only' do
12
- let(:rows) { [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']] }
13
- let(:table) { TTY::Table.new rows }
14
-
15
- it 'calculates column widths' do
16
- expect(renderer.column_widths).to eq([5,6])
17
- end
18
- end
19
-
20
- context 'with header' do
21
- let(:header) { ['header1', 'head2', 'h3'] }
22
- let(:table) { TTY::Table.new header, rows }
23
-
24
- it 'calcualtes column widths with header' do
25
- expect(renderer.column_widths).to eq([7,5,2])
26
- end
27
- end
28
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, 'filter' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { TTY::Table.new(header, rows) }
9
-
10
- subject(:renderer) { described_class.new(table, {filter: filter}) }
11
-
12
- context 'with header' do
13
- context 'filtering only rows' do
14
- let(:filter) { Proc.new { |val, row, col|
15
- (col == 1 and row > 0) ? val.capitalize : val
16
- }
17
- }
18
-
19
- it 'filters only rows' do
20
- expect(renderer.render).to eq <<-EOS.normalize
21
- h1 h2 h3
22
- a1 A2 a3
23
- b1 B2 b3
24
- EOS
25
- end
26
- end
27
-
28
- context 'filtering header and rows' do
29
- let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val }}
30
-
31
- it 'filters only rows' do
32
- expect(renderer.render).to eq <<-EOS.normalize
33
- h1 H2 h3
34
- a1 A2 a3
35
- b1 B2 b3
36
- EOS
37
- end
38
- end
39
- end
40
-
41
- context 'without header' do
42
- let(:header) { nil }
43
-
44
- let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val } }
45
-
46
- it 'filters only rows' do
47
- expect(renderer.render).to eq <<-EOS.normalize
48
- a1 A2 a3
49
- b1 B2 b3
50
- EOS
51
- end
52
- end
53
- end
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, 'indentation' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { TTY::Table.new(header, rows) }
9
- let(:options) { {indent: indent } }
10
-
11
- subject(:renderer) { described_class.new(table, options)}
12
-
13
- context 'when default' do
14
- let(:indent) { 0 }
15
-
16
- it 'indents by value' do
17
- expect(renderer.render).to eql <<-EOS.chomp
18
- h1 h2 h3
19
- a1 a2 a3
20
- b1 b2 b3
21
- EOS
22
- end
23
- end
24
-
25
- context 'when custom' do
26
- let(:indent) { 2 }
27
-
28
- it 'indents by value' do
29
- expect(renderer.render).to eql <<-EOS.chomp
30
- h1 h2 h3
31
- a1 a2 a3
32
- b1 b2 b3
33
- EOS
34
- end
35
- end
36
-
37
- context 'when changed' do
38
- let(:indent) { 2 }
39
- let(:header) { ['h1', 'h2'] }
40
- let(:rows) { [['a1', 'a2']] }
41
-
42
- it 'changes indentation and reuses renderer' do
43
- expect(renderer.render).to eq(" h1 h2\n a1 a2")
44
- renderer.indent = 1
45
- expect(renderer.render).to eq(" h1 h2\n a1 a2")
46
- end
47
- end
48
- end
@@ -1,135 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, 'with multiline content' do
6
- let(:header) { nil }
7
- let(:object) { described_class }
8
- let(:table) { TTY::Table.new header, rows }
9
-
10
- subject(:renderer) { object.new table }
11
-
12
- context 'with escaping' do
13
- let(:rows) { [ ["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']] }
14
-
15
- context 'without border' do
16
- it "renders single line" do
17
- expect(table.render(multiline: false)).to eq <<-EOS.normalize
18
- First 1
19
- Multiline\\nContent 2
20
- Third 3
21
- EOS
22
- end
23
- end
24
-
25
- context 'with column widths' do
26
- it "renders single line" do
27
- expect(table.render(multiline: false, column_widths: [8,1])).to eq <<-EOS.normalize
28
- First 1
29
- Multili… 2
30
- Third 3
31
- EOS
32
- end
33
- end
34
-
35
- context 'with border' do
36
- it "renders single line" do
37
- expect(table.render(:ascii, multiline: false)).to eq <<-EOS.normalize
38
- +------------------+-+
39
- |First |1|
40
- |Multiline\\nContent|2|
41
- |Third |3|
42
- +------------------+-+
43
- EOS
44
- end
45
- end
46
-
47
- context 'with header' do
48
- let(:header) { ["Multi\nHeader", "header2"] }
49
-
50
- it "renders header" do
51
- expect(table.render(:ascii, multiline: false)).to eq <<-EOS.normalize
52
- +------------------+-------+
53
- |Multi\\nHeader |header2|
54
- +------------------+-------+
55
- |First |1 |
56
- |Multiline\\nContent|2 |
57
- |Third |3 |
58
- +------------------+-------+
59
- EOS
60
- end
61
- end
62
- end
63
-
64
- context 'without escaping' do
65
- let(:rows) { [ ["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']] }
66
-
67
- context 'without border' do
68
- it "renders every line" do
69
- expect(table.render(multiline: true)).to eq <<-EOS.normalize
70
- First 1
71
- Multi 2
72
- Line
73
- Content
74
- Third 3
75
- EOS
76
- end
77
- end
78
-
79
- context 'with column widths' do
80
- it "renders multiline" do
81
- expect(table.render(multiline: true, column_widths: [8,1])).to eq <<-EOS.normalize
82
- First 1
83
- Multi 2
84
- Line
85
- Content
86
- Third 3
87
- EOS
88
- end
89
-
90
- it 'wraps multi line' do
91
- expect(table.render(multiline: true, column_widths: [5,1])).to eq <<-EOS.normalize
92
- First 1
93
- Multi 2
94
- Line
95
- Conte
96
- nt
97
- Third 3
98
- EOS
99
- end
100
- end
101
-
102
- context 'with border' do
103
- it "renders every line" do
104
- expect(table.render(:ascii, multiline: true)).to eq <<-EOS.normalize
105
- +-------+-+
106
- |First |1|
107
- |Multi |2|
108
- |Line | |
109
- |Content| |
110
- |Third |3|
111
- +-------+-+
112
- EOS
113
- end
114
- end
115
-
116
- context 'with header' do
117
- let(:header) { ["Multi\nHeader", "header2"] }
118
-
119
- it "renders header" do
120
- expect(table.render(:ascii, multiline: true)).to eq <<-EOS.normalize
121
- +-------+-------+
122
- |Multi |header2|
123
- |Header | |
124
- +-------+-------+
125
- |First |1 |
126
- |Multi |2 |
127
- |Line | |
128
- |Content| |
129
- |Third |3 |
130
- +-------+-------+
131
- EOS
132
- end
133
- end
134
- end
135
- end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, '.new' do
6
- let(:header) { ['h1'] }
7
- let(:rows) { [['a1']] }
8
-
9
- subject(:renderer) { described_class }
10
-
11
- context 'without table' do
12
- let(:table) { nil }
13
-
14
- it { expect { renderer.new(table) }.to raise_error(TTY::ArgumentRequired) }
15
- end
16
-
17
- context 'with table' do
18
- let(:table) { TTY::Table.new(header, rows) }
19
-
20
- it { expect { renderer.new(table) }.not_to raise_error }
21
- end
22
- end
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, 'options' do
6
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
7
- let(:object) { described_class }
8
- let(:table) { TTY::Table.new(rows) }
9
- let(:widths) { nil }
10
- let(:aligns) { [] }
11
- let(:options) {
12
- {
13
- :column_widths => widths,
14
- :column_aligns => aligns,
15
- :renderer => :basic
16
- }
17
- }
18
-
19
- subject(:renderer) { object.new table, options }
20
-
21
- it { expect(renderer.border).to be_kind_of(TTY::Table::BorderOptions) }
22
-
23
- it { expect(renderer.column_widths).to eql([2,2]) }
24
-
25
- it { expect(renderer.column_aligns).to eql(aligns) }
26
-
27
- it { expect(renderer.column_aligns.to_a).to be_empty }
28
-
29
- context '#column_widths' do
30
- let(:widths) { [10, 10] }
31
-
32
- it { expect(renderer.column_widths).to eq(widths) }
33
- end
34
-
35
- context '#column_widths empty' do
36
- let(:widths) { [] }
37
-
38
- it { expect { renderer.column_widths }.to raise_error(TTY::InvalidArgument) }
39
- end
40
-
41
- context '#column_aligns' do
42
- let(:aligns) { [:center, :center] }
43
-
44
- it 'unwraps original array' do
45
- expect(renderer.column_aligns.to_a).to eq(aligns)
46
- end
47
- end
48
- end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, 'padding' do
6
- let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
7
- let(:rows) { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
8
- let(:table) { TTY::Table.new(header, rows) }
9
-
10
- subject(:renderer) { described_class.new(table, options) }
11
-
12
- context 'with left & right padding' do
13
- let(:options) { {padding: [0,1,0,1]} }
14
-
15
- it 'pads each field' do
16
- expect(renderer.render).to eql <<-EOS.chomp
17
- Field Type Null Key Default Extra
18
- id int(11) YES nil NULL
19
- EOS
20
- end
21
- end
22
-
23
- context 'with top & bottom padding' do
24
- let(:options) { {padding: [1,0,1,0], multiline: true} }
25
-
26
- it 'pads each field' do
27
- expect(renderer.render).to eql <<-EOS.chomp
28
-
29
- Field Type Null Key Default Extra
30
-
31
-
32
- id int(11) YES nil NULL
33
-
34
- EOS
35
- end
36
- end
37
-
38
- context 'with full padding' do
39
- let(:options) { {padding: [1,1,1,1], multiline: true} }
40
-
41
- it 'pads each field' do
42
- expect(renderer.render).to eql <<-EOS.chomp
43
-
44
- Field Type Null Key Default Extra
45
-
46
-
47
- id int(11) YES nil NULL
48
-
49
- EOS
50
- end
51
- end
52
- end
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, '#render' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { TTY::Table.new header, rows }
9
-
10
- subject(:renderer) { described_class.new(table) }
11
-
12
- context 'with rows' do
13
- let(:table) { TTY::Table.new rows }
14
-
15
- it 'displays table without styling' do
16
- expect(renderer.render).to eq <<-EOS.normalize
17
- a1 a2 a3
18
- b1 b2 b3
19
- EOS
20
- end
21
- end
22
-
23
- context 'with header and rows' do
24
- it 'displays table with header' do
25
- expect(renderer.render).to eq <<-EOS.normalize
26
- h1 h2 h3
27
- a1 a2 a3
28
- b1 b2 b3
29
- EOS
30
- end
31
- end
32
-
33
- context 'with short header' do
34
- let(:header) { ['h1', 'h2'] }
35
- let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
36
-
37
- it 'displays table according to widths' do
38
- expect(renderer.render).to eq <<-EOS.normalize
39
- h1 h2
40
- aaa1 a2
41
- b1 bb1
42
- EOS
43
- end
44
- end
45
-
46
- context 'with long header' do
47
- let(:header) { ['header1', 'header2', 'header3'] }
48
-
49
- it 'header greater than row sizes' do
50
- expect(renderer.render).to eq <<-EOS.normalize
51
- header1 header2 header3
52
- a1 a2 a3
53
- b1 b2 b3
54
- EOS
55
- end
56
- end
57
- end
@@ -1,96 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::Basic, 'resizing' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { TTY::Table.new(header, rows) }
9
-
10
- subject(:renderer) { described_class.new(table, options) }
11
-
12
- context 'when expanding' do
13
- context 'even columns' do
14
- let(:options) { {width: 16, resize: true} }
15
-
16
- it 'resizes each column' do
17
- expect(renderer.render).to eql <<-EOS.normalize
18
- h1 h2 h3
19
- a1 a2 a3
20
- b1 b2 b3
21
- EOS
22
- end
23
- end
24
-
25
- context 'even columns with extra width' do
26
- let(:header) { ['h1', 'h2', 'h3', 'h4'] }
27
- let(:rows) { [['a1','a2','a3','a4'], ['b1','b2','b3','b4']] }
28
- let(:options) { {width: 21, resize: true} }
29
-
30
- it 'resizes each column' do
31
- expect(renderer.render).to eql <<-EOS.normalize
32
- h1 h2 h3 h4
33
- a1 a2 a3 a4
34
- b1 b2 b3 b4
35
- EOS
36
- end
37
- end
38
-
39
- context 'uneven columns' do
40
- let(:header) { ['h1', 'h2', 'h3'] }
41
- let(:rows) { [['aaa1', 'aa2', 'aaaaaaa3'], ['b1', 'b2', 'b3']] }
42
- let(:options) { {width: 32, resize: true} }
43
-
44
- it 'resizes each column' do
45
- expect(renderer.render).to eql <<-EOS.normalize
46
- h1 h2 h3
47
- aaa1 aa2 aaaaaaa3
48
- b1 b2 b3
49
- EOS
50
- end
51
- end
52
- end
53
-
54
- context 'when shrinking' do
55
- let(:header) { ['head1', 'head2'] }
56
- let(:rows) { [['aaaa1','aaaa2',], ['bbbb1','bbbb2']] }
57
-
58
- context 'even columns' do
59
- let(:options) { {width: 7, resize: true} }
60
-
61
- it 'resizes each column' do
62
- expect(renderer.render).to eql <<-EOS.normalize
63
- he… he…
64
- aa… aa…
65
- bb… bb…
66
- EOS
67
- end
68
- end
69
-
70
- context 'even columns with extra width' do
71
- let(:options) { {width: 8, resize: true} }
72
-
73
- it 'resizes each column' do
74
- expect(renderer.render).to eql <<-EOS.normalize
75
- hea… he…
76
- aaa… aa…
77
- bbb… bb…
78
- EOS
79
- end
80
- end
81
-
82
- context 'uneven columns' do
83
- let(:header) { ['head1', 'head2', 'head3'] }
84
- let(:rows) { [['aaa1', 'aa2', 'aaaaaaa3'], ['b1', 'b2', 'b3']] }
85
- let(:options) { {width: 15, resize: true} }
86
-
87
- it 'resizes each column' do
88
- expect(renderer.render).to eql <<-EOS.normalize
89
- hea… he… head3
90
- aaa1 aa2 aaaaa…
91
- b1 b2 b3
92
- EOS
93
- end
94
- end
95
- end
96
- end