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,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::BorderOptions do
6
-
7
- subject { described_class.new(options) }
8
-
9
- context 'with characters' do
10
- let(:options) { {top: '**'} }
11
-
12
- it { expect(subject.characters).to eq({top:'**'}) }
13
- end
14
-
15
- context 'without characters' do
16
- let(:options) { nil }
17
-
18
- it { expect(subject.characters).to eq({}) }
19
- end
20
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::BorderOptions, '.update' do
6
-
7
- let(:object) { described_class.new }
8
-
9
- let(:params) { {characters: {top: '*'}, separator: '|', style: :red} }
10
-
11
- subject { object.update(params) }
12
-
13
- it 'sets properties from hash object' do
14
- expect(subject.characters).to eq({top: '*'})
15
- expect(subject.separator).to eq('|')
16
- expect(subject.style).to eq(:red)
17
- end
18
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::ColumnSet, '#extract_widths' 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 { described_class.new table }
11
-
12
- it 'extract widths' do
13
- expect(subject.extract_widths).to eql([2,2,2])
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::ColumnSet, '#extract_widths!' 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 { described_class.new table }
11
-
12
- it 'extract widths' do
13
- expect(subject.total_width).to eql(6)
14
- end
15
- end
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::ColumnSet, '#widths_from' 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 { described_class.widths_from(table, column_widths) }
11
-
12
- context 'when empty array' do
13
- let(:column_widths) { [] }
14
-
15
- it 'raises an error' do
16
- expect { subject }.to raise_error(TTY::InvalidArgument)
17
- end
18
- end
19
-
20
- context 'when invalid size array' do
21
- let(:column_widths) { [3,3] }
22
-
23
- it 'raises an error' do
24
- expect { subject }.to raise_error(TTY::InvalidArgument)
25
- end
26
- end
27
-
28
- context 'when valid array' do
29
- let(:column_widths) { [3,3,3] }
30
-
31
- it 'converts into numbers' do
32
- expect(subject).to eql(column_widths)
33
- end
34
- end
35
-
36
- context 'when nil' do
37
- let(:column_widths) { nil }
38
-
39
- it 'extracts widths' do
40
- expect(subject).to eql([2,2,2])
41
- end
42
- end
43
-
44
- context 'when numeric' do
45
- let(:column_widths) { 5 }
46
-
47
- it 'generates widths' do
48
- expect(subject).to eql([5,5,5])
49
- end
50
- end
51
- end
@@ -1,68 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Columns, '#enforce' do
6
- let(:header) { ['h1', 'h2', 'h3', 'h4'] }
7
- let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
8
- let(:table) { TTY::Table.new(header, rows) }
9
- let(:object) { described_class.new(renderer) }
10
-
11
- subject { object.enforce }
12
-
13
- context 'with width contraint' do
14
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
15
- let(:options) { { width: 5 }}
16
-
17
- it 'raises error when table width is too small' do
18
- expect { subject }.to raise_error(TTY::ResizeError)
19
- end
20
- end
21
-
22
- context 'with width contraint matching natural width' do
23
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
24
- let(:options) { { width: 11, resize: true }}
25
-
26
- it 'raises error when table width is too small' do
27
- expect(object).to receive(:expand)
28
- subject
29
- end
30
- end
31
-
32
- context 'with table larger than allowed width' do
33
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
34
-
35
- context 'with resize' do
36
- let(:options) { { width: 8, resize: true } }
37
-
38
- it 'calls shrink' do
39
- expect(object).to receive(:shrink)
40
- subject
41
- end
42
- end
43
-
44
- context 'without resize' do
45
- let(:options) { { width: 8, resize: false }}
46
-
47
- it 'changes table orientation to vertical' do
48
- allow(TTY.shell).to receive(:warn)
49
- expect(renderer.column_widths).to eql([2,2,2,2])
50
- expect(renderer.table.orientation.name).to eql(:horizontal)
51
- subject
52
- expect(renderer.column_widths).to eq([2,2])
53
- expect(renderer.table.orientation.name).to eql(:vertical)
54
- end
55
- end
56
- end
57
-
58
- context 'with table less than allowed width' do
59
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
60
- let(:options) { { width: 15 }}
61
-
62
- before { allow(TTY.shell).to receive(:warn) }
63
-
64
- it "doesn't change original widths" do
65
- expect(renderer.column_widths).to eq([2,2,2,2])
66
- end
67
- end
68
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Columns, 'column widths' do
6
- let(:header) { ['h1', 'h2', 'h3', 'h4'] }
7
- let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
8
- let(:table) { TTY::Table.new(header, rows) }
9
-
10
- subject { described_class.new(renderer) }
11
-
12
- context 'with basic renderer' do
13
- let(:renderer) { TTY::Table::Renderer::Basic.new(table) }
14
-
15
- it 'calculates columns natural width' do
16
- expect(subject.natural_width).to eq(11)
17
- end
18
-
19
- it 'calculates miminimum columns width' do
20
- expect(subject.minimum_width).to eq(7)
21
- end
22
- end
23
-
24
- context 'with ascii renderer' do
25
- let(:renderer) { TTY::Table::Renderer::ASCII.new(table) }
26
-
27
- it 'calculates columns natural width' do
28
- expect(subject.natural_width).to eq(13)
29
- end
30
-
31
- it 'calculates miminimum columns width' do
32
- expect(subject.minimum_width).to eq(9)
33
- end
34
- end
35
- end
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '#data' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
-
9
- subject(:table) { described_class.new header, rows }
10
-
11
- it 'gets all table data' do
12
- expect(table.data).to eql([header] + rows)
13
- end
14
- end
@@ -1,41 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '#each' do
6
- let(:table) { described_class.new header, rows }
7
- let(:header) { ['Header1'] }
8
- let(:rows) { [['a1'], ['b1']] }
9
- let(:field) { TTY::Table::Field }
10
-
11
- context 'with no block' do
12
- subject { table.each }
13
-
14
- it { is_expected.to be_instance_of(to_enum.class) }
15
-
16
- it 'yields the expected values' do
17
- expect(subject.to_a).to eql(table.to_a)
18
- end
19
- end
20
-
21
- context 'with block' do
22
- let(:yields) { [] }
23
-
24
- subject { table.each { |row| yields << row } }
25
-
26
- it 'yields header and rows' do
27
- subject
28
- expect(yields.first).to be_instance_of(TTY::Table::Header)
29
- expect(yields.last).to be_instance_of(TTY::Table::Row)
30
- end
31
-
32
- it 'yields header and rows with expected attributes' do
33
- subject
34
- expect(yields).to eql(table.data)
35
- end
36
-
37
- xit 'yields each row' do
38
- expect { subject }.to change { yields }.from([]).to(table.data)
39
- end
40
- end
41
- end
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '.each_with_index' do
6
- let(:header) { ['Header1', 'Header2'] }
7
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
8
- let(:field) { TTY::Table::Field }
9
-
10
- let(:object) { described_class.new header, rows }
11
-
12
- context 'with no block' do
13
- subject { object.each_with_index }
14
-
15
- it { is_expected.to be_instance_of(to_enum.class) }
16
-
17
- it 'yields the expected values' do
18
- expect(subject.to_a).to eql(object.to_a)
19
- end
20
- end
21
-
22
- context 'with block' do
23
- let(:yields) { [] }
24
-
25
- subject { object.each_with_index { |el, row, col| yields << [el, row, col]}}
26
-
27
- context 'without header' do
28
- let(:header) { nil }
29
-
30
- let(:expected) {
31
- [ [field.new('a1'), 0, 0], [field.new('a2'), 0, 1],
32
- [field.new('b1'), 1, 0], [field.new('b2'), 1, 1] ]
33
- }
34
-
35
- it "yields rows with expected data" do
36
- expect { subject }.to change { yields }.
37
- from( [] ).
38
- to( expected )
39
- end
40
- end
41
-
42
- context 'with header' do
43
-
44
- let(:expected) {
45
- [ [field.new('Header1'), 0, 0], [field.new('Header2'), 0, 1],
46
- [field.new('a1'), 1, 0], [field.new('a2'), 1, 1],
47
- [field.new('b1'), 2, 0], [field.new('b2'), 2, 1] ]
48
- }
49
-
50
- it "yields header and rows with expected data" do
51
- expect { subject }.to change { yields }.
52
- from( [] ).
53
- to( expected )
54
- end
55
- end
56
- end
57
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '#empty?' do
6
- let(:header) { ['Header1', 'Header2'] }
7
- let(:object) { described_class.new header, rows }
8
-
9
- subject { object.empty? }
10
-
11
- context 'with rows containing no entries' do
12
- let(:rows) { [] }
13
-
14
- it { is_expected.to eq(true) }
15
- end
16
-
17
- context 'with rows containing an entry' do
18
- let(:rows) { [['a1']] }
19
-
20
- it { is_expected.to eq(false) }
21
- end
22
- end
23
-
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '#eql?' do
6
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
7
- let(:object) { described_class.new rows }
8
-
9
- subject { object.eql?(other) }
10
-
11
- describe '#inspect' do
12
- it { expect(object.inspect).to match /#<TTY::Table/ }
13
- end
14
-
15
- context 'with the same object' do
16
- let(:other) { object }
17
-
18
- it { is_expected.to eql(true) }
19
-
20
- it 'is symmetric' do
21
- is_expected.to eql(other.eql?(object))
22
- end
23
- end
24
-
25
- context 'with an equivalent object' do
26
- let(:other) { object.dup }
27
-
28
- it { is_expected.to eql(true) }
29
-
30
- it 'is symmetric' do
31
- is_expected.to eql(other.eql?(object))
32
- end
33
- end
34
- end
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Field, '#==' do
6
- let(:value) { '1' }
7
- let(:object) { described_class.new(value) }
8
-
9
- subject { object == other }
10
-
11
- context 'with the same object' do
12
- let(:other) { object }
13
-
14
- it { is_expected.to eql(true) }
15
-
16
- it 'is symmetric' do
17
- is_expected.to eql(other == object)
18
- end
19
- end
20
-
21
- context 'with an equivalent object' do
22
- let(:other) { object.dup }
23
-
24
- it { is_expected.to eql(true) }
25
-
26
- it 'is symmetric' do
27
- is_expected.to eql(other == object)
28
- end
29
- end
30
-
31
- context 'with an equivalent object of subclass' do
32
- let(:other) { Class.new(described_class).new(value) }
33
-
34
- it { is_expected.to eq(true) }
35
-
36
- it 'is symmetric' do
37
- is_expected.not_to eql(other == object)
38
- end
39
- end
40
-
41
- context 'with an object having a different value' do
42
- let(:other_value) { '2' }
43
- let(:other) { described_class.new(other_value) }
44
-
45
- it { is_expected.to eql(false) }
46
-
47
- it 'is symmetric' do
48
- is_expected.to eql(other == object)
49
- end
50
- end
51
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Field, '#length' do
6
- let(:object) { described_class.new value }
7
-
8
- subject { object.length }
9
-
10
- context 'with escaped value' do
11
- let(:value) { "Multi\nLine" }
12
-
13
- it { is_expected.to eql(5) }
14
- end
15
-
16
- context 'with unescaped value' do
17
- let(:value) { "Multi\\nLine" }
18
-
19
- it { is_expected.to eql(11) }
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Field, '#lines' do
6
- let(:object) { described_class.new value }
7
-
8
- subject { object.lines }
9
-
10
- context 'with escaped value' do
11
- let(:value) { "Multi\nLine" }
12
-
13
- it { is_expected.to eql(["Multi", "Line"]) }
14
- end
15
-
16
- context 'with unescaped value' do
17
- let(:value) { "Multi\\nLine" }
18
-
19
- it { is_expected.to eql(["Multi\\nLine"]) }
20
- end
21
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Field, '#new' do
6
- let(:object) { described_class }
7
-
8
- subject { object.new value }
9
-
10
- context 'with only value' do
11
- let(:value) { 'foo' }
12
-
13
- it { is_expected.to be_instance_of(object) }
14
-
15
- it { expect(subject.value).to eql(value) }
16
-
17
- it { expect(subject.height).to eql(1) }
18
- end
19
-
20
- context 'with hash value' do
21
- let(:value) { { :value => 'foo' } }
22
-
23
- it { is_expected.to be_instance_of(object) }
24
-
25
- it { expect(subject.value).to eql('foo') }
26
-
27
- it { expect(subject.height).to eql(1) }
28
- end
29
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Field, '#width' do
6
- let(:object) { described_class }
7
-
8
- let(:instance) { object.new(value) }
9
-
10
- subject { instance.width }
11
-
12
- context 'with only value' do
13
- let(:value) { 'foo' }
14
-
15
- it { is_expected.to eql(3) }
16
- end
17
-
18
- context 'with hash value' do
19
- let(:value) { "foo\nbaar" }
20
-
21
- it { is_expected.to eql(8) }
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '#filter' 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(:filter) { Proc.new { |val, row, col|
10
- (col == 1 and row > 0) ? val.capitalize : val
11
- }
12
- }
13
-
14
- it 'filters rows' do
15
- expect(table.render do |renderer|
16
- renderer.filter = filter
17
- end).to eq <<-EOS.normalize
18
- h1 h2 h3
19
- a1 A2 a3
20
- b1 B2 b3
21
- EOS
22
- end
23
- end
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Header, '#call' do
6
- let(:object) { described_class.new(attributes) }
7
- let(:attributes) { [:id, :name, :age] }
8
-
9
- subject { object[attribute] }
10
-
11
- context 'with a known attribute' do
12
- context 'when symbol' do
13
- let(:attribute) { :age }
14
-
15
- it { is_expected.to eq(2) }
16
- end
17
-
18
- context 'when integer' do
19
- let(:attribute) { 1 }
20
-
21
- it { is_expected.to eq(:name) }
22
- end
23
- end
24
-
25
- context 'with an unknown attribute' do
26
- let(:attribute) { :mine }
27
-
28
- specify { expect { subject }.to raise_error(TTY::UnknownAttributeError, "the header 'mine' is unknown")}
29
- end
30
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Header, '#height' do
6
- let(:object) { described_class.new header }
7
-
8
- subject { object.height }
9
-
10
- context 'single row' do
11
- let(:header) { ['h1', 'h1'] }
12
-
13
- it { expect(subject).to eql(1) }
14
- end
15
-
16
- context 'non escaped multiline' do
17
- let(:header) { ["h1\nh1\nh1", 'h2'] }
18
-
19
- it { expect(subject).to eql(3)}
20
- end
21
-
22
- context 'escaped multiline' do
23
- let(:header) { ["h1\\h1\\h1", 'h2'] }
24
-
25
- it { expect(subject).to eql(1) }
26
- end
27
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Header, '#new' do
6
- let(:object) { described_class }
7
-
8
- context 'with no arguments' do
9
- subject { object.new }
10
-
11
- it { is_expected.to be_instance_of(object) }
12
-
13
- it { is_expected.to be_empty }
14
- end
15
-
16
- context 'with attributes' do
17
- subject { object.new(attributes) }
18
-
19
- let(:attributes) { ['id', 'name', 'age'] }
20
-
21
- it { is_expected.to be_instance_of(object) }
22
-
23
- it { is_expected == attributes }
24
- end
25
- end
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Header, '#set' do
6
- let(:object) { described_class }
7
- let(:attributes) { [:id, :name, :age] }
8
-
9
- subject(:header) { object.new }
10
-
11
- it 'sets the value' do
12
- header[0] = :id
13
- expect(header[0]).to eql(:id)
14
- end
15
-
16
- it 'gets the value' do
17
- head = object.new [{value: :id}]
18
- expect(head[0]).to eq(:id)
19
- end
20
- end