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,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Padder, '#parse' do
6
- let(:object) { described_class }
7
-
8
- subject { object.parse(value).padding }
9
-
10
- context 'when self' do
11
- let(:value) { described_class.new([]) }
12
-
13
- it { expect(subject).to eq([]) }
14
- end
15
-
16
- context 'when number' do
17
- let(:value) { 5 }
18
-
19
- it { expect(subject).to eq([5,5,5,5]) }
20
- end
21
-
22
- context 'when nil' do
23
- let(:value) { nil }
24
-
25
- it { expect(subject).to eq([]) }
26
- end
27
-
28
- context 'when 2-element array' do
29
- let(:value) { [2,3] }
30
-
31
- it { expect(subject).to eq([2,3,2,3]) }
32
- end
33
-
34
- context 'when 4-element array' do
35
- let(:value) { [1,2,3,4] }
36
-
37
- it { expect(subject).to eq([1,2,3,4]) }
38
- end
39
-
40
- context 'when unkown' do
41
- let(:value) { :unkown }
42
-
43
- it { expect { subject }.to raise_error }
44
- end
45
- end
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Padder, '.to_s' do
6
- let(:object) { described_class }
7
- let(:value) { [1,2,3,4] }
8
-
9
- subject { object.parse(value) }
10
-
11
- it 'prints string representation' do
12
- expect(subject.to_s).to eq('#<TTY::Table::Padder padding=[1, 2, 3, 4]>')
13
- end
14
- end
@@ -1,120 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, 'padding' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { described_class.new(header, rows) }
9
-
10
- it 'sets specific padding' do
11
- expect(table.render(:ascii) { |renderer|
12
- renderer.multiline = true
13
- renderer.padding.right = 2
14
- renderer.padding.top = 1
15
- }).to eq <<-EOS.normalize
16
- +----+----+----+
17
- | | | |
18
- |h1 |h2 |h3 |
19
- +----+----+----+
20
- | | | |
21
- |a1 |a2 |a3 |
22
- | | | |
23
- |b1 |b2 |b3 |
24
- +----+----+----+
25
- EOS
26
- end
27
-
28
- it 'sets padding for all' do
29
- expect(table.render(:ascii) { |renderer|
30
- renderer.multiline = true
31
- renderer.padding= [1,2,1,2]
32
- }).to eq <<-EOS.normalize
33
- +------+------+------+
34
- | | | |
35
- | h1 | h2 | h3 |
36
- | | | |
37
- +------+------+------+
38
- | | | |
39
- | a1 | a2 | a3 |
40
- | | | |
41
- | | | |
42
- | b1 | b2 | b3 |
43
- | | | |
44
- +------+------+------+
45
- EOS
46
- end
47
-
48
- context 'with column width' do
49
- let(:column_widths) { [4,4,4] }
50
-
51
- it 'sets padding for all' do
52
- expect(table.render(:ascii) { |renderer|
53
- renderer.column_widths = column_widths
54
- renderer.multiline = true
55
- renderer.padding= [1,2,1,2]
56
- }).to eq <<-EOS.normalize
57
- +--------+--------+--------+
58
- | | | |
59
- | h1 | h2 | h3 |
60
- | | | |
61
- +--------+--------+--------+
62
- | | | |
63
- | a1 | a2 | a3 |
64
- | | | |
65
- | | | |
66
- | b1 | b2 | b3 |
67
- | | | |
68
- +--------+--------+--------+
69
- EOS
70
- end
71
- end
72
-
73
- context 'with multi line text' do
74
- let(:header) { ['head1', 'head2'] }
75
- let(:rows) { [["Multi\nLine\nContent", "Text\nthat\nwraps",],
76
- ["Some\nother\ntext", 'Simple']] }
77
-
78
- context 'when wrapped' do
79
- it 'sets padding for all' do
80
- expect(table.render(:ascii) { |renderer|
81
- renderer.multiline = true
82
- renderer.padding= [1,2,1,2]
83
- }).to eq <<-EOS.normalize
84
- +-----------+----------+
85
- | | |
86
- | head1 | head2 |
87
- | | |
88
- +-----------+----------+
89
- | | |
90
- | Multi | Text |
91
- | Line | that |
92
- | Content | wraps |
93
- | | |
94
- | | |
95
- | Some | Simple |
96
- | other | |
97
- | text | |
98
- | | |
99
- +-----------+----------+
100
- EOS
101
- end
102
- end
103
-
104
- context 'when escaped' do
105
- it 'sets padding for all' do
106
- expect(table.render(:ascii) { |renderer|
107
- renderer.multiline = false
108
- renderer.padding= [0,2,0,2]
109
- }).to eq <<-EOS.normalize
110
- +------------------------+---------------------+
111
- | head1 | head2 |
112
- +------------------------+---------------------+
113
- | Multi\\nLine\\nContent | Text\\nthat\\nwraps |
114
- | Some\\nother\\ntext | Simple |
115
- +------------------------+---------------------+
116
- EOS
117
- end
118
- end
119
- end
120
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, 'properties' do
6
- let(:rows) {[['a1', 'a2', 'a3'], ['b1', 'b2', 'c3']] }
7
-
8
- subject(:table) { described_class.new rows }
9
-
10
- it { expect(table.width).to eq(6) }
11
-
12
- it { expect(table.row_size).to eq(2) }
13
-
14
- it { expect(table.column_size).to eq(3) }
15
-
16
- it { expect(table.size).to eq([2,3]) }
17
-
18
- context 'no size' do
19
- let(:rows) { [] }
20
-
21
- it { expect(table.row_size).to eq(0) }
22
-
23
- it { expect(table.column_size).to eq(0) }
24
- end
25
- end
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '#render' do
6
- let(:object) { described_class }
7
- let(:header) { ['h1', 'h2'] }
8
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
9
- let(:color) { Pastel.new(enabled: true) }
10
- let(:basic_renderer) { TTY::Table::Renderer::Basic }
11
- let(:ascii_renderer) { TTY::Table::Renderer::ASCII }
12
-
13
- subject(:table) { object.new header, rows }
14
-
15
- before { allow(Pastel).to receive(:new).and_return(color) }
16
-
17
- it { is_expected.to respond_to(:render) }
18
-
19
- context 'with block' do
20
- it 'allows to modify renderer in a block' do
21
- expected = nil
22
- block = lambda { |renderer| expected = renderer }
23
- table.render(&block)
24
- expect(expected).to be_kind_of(basic_renderer)
25
- end
26
-
27
- it 'sets renderer as block parameter' do
28
- expected = nil
29
- block = lambda { |renderer| expected = renderer }
30
- table.render(:ascii, &block)
31
- expect(expected).to be_kind_of(ascii_renderer)
32
- end
33
-
34
- it 'sets parameter on renderer' do
35
- result = table.render :ascii do |renderer|
36
- renderer.border.style = :red
37
- end
38
- expect(result).to eq <<-EOS.normalize
39
- \e[31m+--+--+\e[0m
40
- \e[31m|\e[0mh1\e[31m|\e[0mh2\e[31m|\e[0m
41
- \e[31m+--+--+\e[0m
42
- \e[31m|\e[0ma1\e[31m|\e[0ma2\e[31m|\e[0m
43
- \e[31m|\e[0mb1\e[31m|\e[0mb2\e[31m|\e[0m
44
- \e[31m+--+--+\e[0m
45
- EOS
46
- end
47
- end
48
-
49
- context 'with params' do
50
- it 'sets params without renderer' do
51
- allow(TTY::Table::Renderer).to receive(:render)
52
- table.render(:basic)
53
- expect(TTY::Table::Renderer).to have_received(:render).
54
- with(table, {renderer: :basic})
55
- end
56
-
57
- it 'sets params with renderer' do
58
- allow(TTY::Table::Renderer).to receive(:render)
59
- table.render
60
- expect(TTY::Table::Renderer).to have_received(:render).with(table, {})
61
- end
62
- end
63
- end
@@ -1,106 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '#render_with' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { described_class.new header, rows }
9
- let(:color) { Pastel.new(enabled: true) }
10
-
11
- before { allow(Pastel).to receive(:new).and_return(color) }
12
-
13
- context 'with invalid border class' do
14
- it "doesn't inherit from TTY::Table::Border" do
15
- expect { table.render_with String }.to raise_error(TTY::TypeError)
16
- end
17
-
18
- it "doesn't implement def_border" do
19
- klass = Class.new(TTY::Table::Border)
20
- expect { table.render_with klass }.
21
- to raise_error(TTY::NoImplementationError)
22
- end
23
- end
24
-
25
- context 'with complete border' do
26
- before {
27
- class MyBorder < TTY::Table::Border
28
- def_border do
29
- top '='
30
- top_mid '*'
31
- top_left '*'
32
- top_right '*'
33
- bottom '='
34
- bottom_mid '*'
35
- bottom_left '*'
36
- bottom_right '*'
37
- mid '='
38
- mid_mid '*'
39
- mid_left '*'
40
- mid_right '*'
41
- left '$'
42
- center '$'
43
- right '$'
44
- end
45
- end
46
- }
47
-
48
- it 'displays custom border' do
49
- expect(table.render_with(MyBorder)).to eq <<-EOS.normalize
50
- *==*==*==*
51
- $h1$h2$h3$
52
- *==*==*==*
53
- $a1$a2$a3$
54
- $b1$b2$b3$
55
- *==*==*==*
56
- EOS
57
- end
58
- end
59
-
60
- context 'with incomplete border' do
61
- before {
62
- class MyBorder < TTY::Table::Border
63
- def_border do
64
- bottom ' '
65
- bottom_mid '*'
66
- bottom_left '*'
67
- bottom_right '*'
68
- left '$'
69
- center '$'
70
- right '$'
71
- end
72
- end
73
- }
74
-
75
- it 'displays border' do
76
- expect(table.render_with(MyBorder)).to eq <<-EOS.normalize
77
- $h1$h2$h3$
78
- $a1$a2$a3$
79
- $b1$b2$b3$
80
- * * * *
81
- EOS
82
- end
83
- end
84
-
85
- context 'with renderer' do
86
- before {
87
- class MyBorder < TTY::Table::Border
88
- def_border do
89
- left '|'
90
- right '|'
91
- end
92
- end
93
- }
94
-
95
- it 'displays border' do
96
- result = table.render_with MyBorder do |renderer|
97
- renderer.border.style = :red
98
- end
99
- expect(result).to eq <<-EOS.normalize
100
- \e[31m|\e[0mh1h2h3\e[31m|\e[0m
101
- \e[31m|\e[0ma1a2a3\e[31m|\e[0m
102
- \e[31m|\e[0mb1b2b3\e[31m|\e[0m
103
- EOS
104
- end
105
- end
106
- end # render_with
@@ -1,41 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::ASCII, '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(:indent) { 2 }
10
- let(:options) { {indent: indent } }
11
-
12
- subject(:renderer) { described_class.new(table, options)}
13
-
14
- context 'when default' do
15
- it 'indents by value' do
16
- expect(renderer.render).to eql <<-EOS.chomp
17
- +--+--+--+
18
- |h1|h2|h3|
19
- +--+--+--+
20
- |a1|a2|a3|
21
- |b1|b2|b3|
22
- +--+--+--+
23
- EOS
24
- end
25
- end
26
-
27
- context 'when each row' do
28
- it 'indents by value' do
29
- renderer.border.separator = :each_row
30
- expect(renderer.render).to eql <<-EOS.chomp
31
- +--+--+--+
32
- |h1|h2|h3|
33
- +--+--+--+
34
- |a1|a2|a3|
35
- +--+--+--+
36
- |b1|b2|b3|
37
- +--+--+--+
38
- EOS
39
- end
40
- end
41
- end
@@ -1,61 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::ASCII, '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
- +-------+---------+------+-----+---------+-------+
18
- | Field | Type | Null | Key | Default | Extra |
19
- +-------+---------+------+-----+---------+-------+
20
- | id | int(11) | YES | nil | NULL | |
21
- +-------+---------+------+-----+---------+-------+
22
- EOS
23
- end
24
- end
25
-
26
- context 'with top & bottom padding' do
27
- let(:options) { {padding: [1,0,1,0], multiline: true} }
28
-
29
- it 'pads each field' do
30
- expect(renderer.render).to eql <<-EOS.chomp
31
- +-----+-------+----+---+-------+-----+
32
- | | | | | | |
33
- |Field|Type |Null|Key|Default|Extra|
34
- | | | | | | |
35
- +-----+-------+----+---+-------+-----+
36
- | | | | | | |
37
- |id |int(11)|YES |nil|NULL | |
38
- | | | | | | |
39
- +-----+-------+----+---+-------+-----+
40
- EOS
41
- end
42
- end
43
-
44
- context 'with full padding' do
45
- let(:options) { {padding: [1,1,1,1], multiline: true} }
46
-
47
- it 'pads each field' do
48
- expect(renderer.render).to eql <<-EOS.chomp
49
- +-------+---------+------+-----+---------+-------+
50
- | | | | | | |
51
- | Field | Type | Null | Key | Default | Extra |
52
- | | | | | | |
53
- +-------+---------+------+-----+---------+-------+
54
- | | | | | | |
55
- | id | int(11) | YES | nil | NULL | |
56
- | | | | | | |
57
- +-------+---------+------+-----+---------+-------+
58
- EOS
59
- end
60
- end
61
- end
@@ -1,68 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::ASCII, '#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 'only rows' do
13
- let(:table) { TTY::Table.new rows }
14
-
15
- it 'display table rows' do
16
- expect(renderer.render).to eq <<-EOS.normalize
17
- +--+--+--+
18
- |a1|a2|a3|
19
- |b1|b2|b3|
20
- +--+--+--+
21
- EOS
22
- end
23
- end
24
-
25
- context 'with header' do
26
- it 'displays table with header' do
27
- expect(renderer.render).to eq <<-EOS.normalize
28
- +--+--+--+
29
- |h1|h2|h3|
30
- +--+--+--+
31
- |a1|a2|a3|
32
- |b1|b2|b3|
33
- +--+--+--+
34
- EOS
35
- end
36
- end
37
-
38
- context 'with short header' do
39
- let(:header) { ['h1', 'h2'] }
40
- let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
41
-
42
- it 'displays table according to widths' do
43
- expect(renderer.render).to eq <<-EOS.normalize
44
- +----+---+
45
- |h1 |h2 |
46
- +----+---+
47
- |aaa1|a2 |
48
- |b1 |bb1|
49
- +----+---+
50
- EOS
51
- end
52
- end
53
-
54
- context 'with long header' do
55
- let(:header) { ['header1', 'header2', 'header3'] }
56
-
57
- it 'header greater than row sizes' do
58
- expect(renderer.render).to eq <<-EOS.normalize
59
- +-------+-------+-------+
60
- |header1|header2|header3|
61
- +-------+-------+-------+
62
- |a1 |a2 |a3 |
63
- |b1 |b2 |b3 |
64
- +-------+-------+-------+
65
- EOS
66
- end
67
- end
68
- end
@@ -1,114 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::ASCII, '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
- +----+----+----+
19
- |h1 |h2 |h3 |
20
- +----+----+----+
21
- |a1 |a2 |a3 |
22
- |b1 |b2 |b3 |
23
- +----+----+----+
24
- EOS
25
- end
26
- end
27
-
28
- context 'even columns with extra width' do
29
- let(:header) { ['h1', 'h2', 'h3', 'h4'] }
30
- let(:rows) { [['a1','a2','a3','a4'], ['b1','b2','b3','b4']] }
31
- let(:options) { {width: 21, resize: true} }
32
-
33
- it 'resizes each column' do
34
- expect(renderer.render).to eql <<-EOS.normalize
35
- +----+----+----+----+
36
- |h1 |h2 |h3 |h4 |
37
- +----+----+----+----+
38
- |a1 |a2 |a3 |a4 |
39
- |b1 |b2 |b3 |b4 |
40
- +----+----+----+----+
41
- EOS
42
- end
43
- end
44
-
45
- context 'uneven columns' do
46
- let(:header) { ['h1', 'h2', 'h3'] }
47
- let(:rows) { [['aaa1', 'aa2', 'aaaaaaa3'], ['b1', 'b2', 'b3']] }
48
- let(:options) { {width: 32, resize: true} }
49
-
50
- it 'resizes each column' do
51
- expect(renderer.render).to eql <<-EOS.normalize
52
- +---------+-------+------------+
53
- |h1 |h2 |h3 |
54
- +---------+-------+------------+
55
- |aaa1 |aa2 |aaaaaaa3 |
56
- |b1 |b2 |b3 |
57
- +---------+-------+------------+
58
- EOS
59
- end
60
- end
61
- end
62
-
63
- context 'when shrinking' do
64
- let(:header) { ['head1', 'head2'] }
65
- let(:rows) { [['aaaa1','aaaa2',], ['bbbb1','bbbb2']] }
66
-
67
- context 'even columns' do
68
- let(:options) { {width: 7, resize: true} }
69
-
70
- it 'resizes each column' do
71
- expect(renderer.render).to eql <<-EOS.normalize
72
- +--+--+
73
- |h…|h…|
74
- +--+--+
75
- |a…|a…|
76
- |b…|b…|
77
- +--+--+
78
- EOS
79
- end
80
- end
81
-
82
- context 'even columns with extra width' do
83
- let(:options) { {width: 8, resize: true} }
84
-
85
- it 'resizes each column' do
86
- expect(renderer.render).to eql <<-EOS.normalize
87
- +---+--+
88
- |he…|h…|
89
- +---+--+
90
- |aa…|a…|
91
- |bb…|b…|
92
- +---+--+
93
- EOS
94
- end
95
- end
96
-
97
- context 'uneven columns' do
98
- let(:header) { ['head1', 'head2', 'head3'] }
99
- let(:rows) { [['aaa1', 'aa2', 'aaaaaaa3'], ['b1', 'b2', 'b3']] }
100
- let(:options) { {width: 15, resize: true} }
101
-
102
- it 'resizes each column' do
103
- expect(renderer.render).to eql <<-EOS.normalize
104
- +---+---+-----+
105
- |he…|he…|head3|
106
- +---+---+-----+
107
- |aa…|aa2|aaaa…|
108
- |b1 |b2 |b3 |
109
- +---+---+-----+
110
- EOS
111
- end
112
- end
113
- end
114
- end
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Renderer::ASCII, 'with separator' 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
- let(:object) { described_class.new table }
11
-
12
- subject(:renderer) { object }
13
-
14
- context 'when ascii' do
15
- it "renders each row" do
16
- renderer.border.separator= :each_row
17
- expect(renderer.render).to eq <<-EOS.normalize
18
- +--+--+--+
19
- |h1|h2|h3|
20
- +--+--+--+
21
- |a1|a2|a3|
22
- +--+--+--+
23
- |b1|b2|b3|
24
- +--+--+--+
25
- EOS
26
- end
27
- end
28
- end