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,118 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module TTY
4
- class Text
5
- # A class responsible for text wrapping operations
6
- class Wrapping
7
- include Unicode
8
-
9
- attr_reader :text
10
-
11
- attr_reader :length
12
-
13
- attr_reader :indent
14
-
15
- attr_reader :padding
16
-
17
- attr_reader :color
18
-
19
- # Initialize a Wrapping
20
- #
21
- # @param [String] text
22
- # the text to be wrapped
23
- #
24
- # @overload new(text, value)
25
- # wraps text at given value
26
- #
27
- # @param [Integer] value
28
- #
29
- # @overload new(text, value, options)
30
- # @param [Integer] value
31
- # @param [Hash] options
32
- # @option options [Symbol] :indent the indentation
33
- # @option options [Symbol] :length the desired length
34
- #
35
- # @api private
36
- def initialize(text, *args)
37
- options = Utils.extract_options!(args)
38
- @text = text
39
- @length = options.fetch(:length) { DEFAULT_WIDTH }
40
- @indent = options.fetch(:indent) { 0 }
41
- @padding = options.fetch(:padding) { [] }
42
- @length = args[0] unless args.empty?
43
- @color = Pastel.new
44
- end
45
-
46
- # Wrap a text into lines no longer than length
47
- #
48
- # @see TTY::Text#wrap
49
- #
50
- # @api private
51
- def wrap
52
- return text unless length && length > 0
53
-
54
- as_unicode do
55
- text.split(NEWLINE, -1).map do |line|
56
- pad_line(indent_line(wrap_line(line)))
57
- end * NEWLINE
58
- end
59
- end
60
-
61
- private
62
-
63
- # Calculate string length without color escapes
64
- #
65
- # @param [String] string
66
- #
67
- # @api private
68
- def actual_length(string)
69
- length + (string.length - color.strip(string).length)
70
- end
71
-
72
- # Wrap line at given length
73
- #
74
- # @param [String] line
75
- #
76
- # @return [String]
77
- #
78
- # @api private
79
- def wrap_line(line)
80
- wrap_at = actual_length line
81
- line.strip.gsub(/\n/, ' ').squeeze(' ')
82
- .gsub(/(.{1,#{wrap_at}})(?:\s+|$\n?)|(.{1,#{wrap_at}})/, "\\1\\2\n")
83
- .strip
84
- end
85
-
86
- # Indent string by given value
87
- #
88
- # @param [String] text
89
- #
90
- # @return [String]
91
- #
92
- # @api private
93
- def indent_line(text)
94
- text.split(NEWLINE).each do |line|
95
- line.insert(0, SPACE * indent)
96
- end
97
- end
98
-
99
- # Add padding to each line in wrapped text
100
- #
101
- # @param [String] text
102
- # the wrapped text
103
- #
104
- # @return [String]
105
- #
106
- # @api private
107
- def pad_line(text)
108
- return text if text.empty? || padding.empty?
109
-
110
- padding_left = ' ' * padding[3].to_i
111
- padding_right = ' ' * padding[1].to_i
112
- text.map! do |part|
113
- part.insert(0, padding_left).insert(-1, padding_right)
114
- end
115
- end
116
- end # Wrapping
117
- end # Text
118
- end # TTY
data/lib/tty/text.rb DELETED
@@ -1,98 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module TTY
4
- # A class responsible for text manipulations
5
- class Text
6
- SPACE = ' '
7
-
8
- NEWLINE = "\n"
9
-
10
- DEFAULT_WIDTH = 80.freeze
11
-
12
- # Specifies the split mode for words
13
- def split_mode
14
- end
15
-
16
- # Calculate the distance between strings
17
- #
18
- # @param [String] first
19
- # the first string for comparison
20
- #
21
- # @param [String] second
22
- # the second string for comparison
23
- #
24
- # @example
25
- # distance("which", "witch") # => 2
26
- #
27
- # @api public
28
- def self.distance(first, second, *args)
29
- Distance.new(first, second, *args).distance
30
- end
31
-
32
- # Wrap a text into lines no longer than provided length
33
- #
34
- # @param [String] text
35
- # the text to be wrapped
36
- #
37
- # @overload wrap(text, value)
38
- # wraps text at given value
39
- #
40
- # @param [Integer] value
41
- #
42
- # @overload wrap(text, value, options)
43
- # @param [Integer] value
44
- # @param [Hash] options
45
- # @option options [Symbol] :indent the indentation
46
- #
47
- # @example
48
- # wrap("Some longish text", 8)
49
- # # => "Some\nlongish\ntext"
50
- #
51
- # wrap("Some longish text", length: 8)
52
- # # => "Some\nlongish\ntext"
53
- #
54
- # wrap("Some longish text", 8, indent: 4)
55
- # # => > Some
56
- # > longish
57
- # > text
58
- #
59
- # @api public
60
- def self.wrap(text, *args)
61
- Wrapping.new(text, *args).wrap
62
- end
63
-
64
- # Truncate a text at a given length (defaults to 30)
65
- #
66
- # @param [String] text
67
- # the text to be truncated
68
- #
69
- # @overload truncate(text, value)
70
- # truncates text at given value
71
- #
72
- # @param [Integer] value
73
- #
74
- # @overload truncate(text, value, options)
75
- # @param [Integer] value
76
- # @param [Hash] options
77
- # @option options [Symbol] :separator the separation character
78
- # @option options [Symbol] :trailing the trailing characters
79
- #
80
- # @example
81
- # truncate("The sovereignest thing on earth is parmacetti for an inward bruise.")
82
- # # => "The sovereignest thing on ear…"
83
- #
84
- # truncate("The sovereignest thing on earth is parmacetti for an inward bruise.", length: 20)
85
- # # => "The sovereignest th…"
86
- #
87
- # truncate("The sovereignest thing on earth is parmacetti for an inward bruise.", length: 20, separator: ' ' )
88
- # # => "The sovereignest…"
89
- #
90
- # truncate("The sovereignest thing on earth is parmacetti for an inward bruise.", length: 40, trailing: '... (see more)' )
91
- # # => "The sovereignest thing on... (see more)"
92
- #
93
- # @api public
94
- def self.truncate(text, *args)
95
- Truncation.new(text, *args).truncate
96
- end
97
- end # Text
98
- end # TTY
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, 'access' do
6
- let(:header) { [:head1, :head2] }
7
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
8
-
9
- subject(:table) { TTY::Table.new rows: rows, header: header }
10
-
11
- it { is_expected.to respond_to(:element) }
12
-
13
- it { should respond_to(:component) }
14
-
15
- it { should respond_to(:at) }
16
-
17
- context 'when array like access' do
18
- it { expect(table[0,0]).to eq('a1') }
19
-
20
- it { expect(table[0]).to eq(rows[0]) }
21
-
22
- it { expect(table[5]).to eq(nil) }
23
-
24
- it { expect(table[-1]).to eq(rows[-1]) }
25
-
26
- it { expect(table[5,5]).to eq(nil) }
27
-
28
- it 'raises error for negative indices' do
29
- expect { table[-5,-5] }.to raise_error(IndexError)
30
- end
31
- end
32
-
33
- context '#row' do
34
- it 'returns nil for wrong index' do
35
- expect(table.row(11)).to be_nil
36
- end
37
-
38
- it 'gets row at index' do
39
- expect(table.row(1)).to eq(rows[1])
40
- end
41
-
42
- it 'yields self for wrong index' do
43
- block = lambda { |el| [] << el }
44
- expect(table.row(11, &block)).to eq(table)
45
- end
46
-
47
- it 'yields row at index' do
48
- yields = []
49
- expect { table.row(1).each { |el| yields << el } }.to change { yields }.
50
- from( [] ).
51
- to( rows[1] )
52
- end
53
- end
54
-
55
- context '#column' do
56
- it "gets based on header name" do
57
- expect(table.column(:head1)).to eq(['a1', 'b1'])
58
- end
59
-
60
- it "yields based on header name" do
61
- yielded = []
62
- table.column(:head1) { |el| yielded << el }
63
- expect(yielded).to eql(['a1', 'b1'])
64
- end
65
-
66
- it 'returns nil for wrong index' do
67
- expect(table.column(11)).to be_nil
68
- end
69
-
70
- it 'gets column at index' do
71
- expect(table.column(0)).to eq(['a1', 'b1'])
72
- end
73
-
74
- it 'yields self for wrong index' do
75
- block = lambda { |el| [] << el }
76
- expect(table.column(11, &block)).to eq(table)
77
- end
78
-
79
- it 'yields column at index' do
80
- yields = []
81
- expect { table.column(1).each { |el| yields << el } }.to change { yields }.
82
- from( [] ).
83
- to( ['a2', 'b2'])
84
- end
85
- end
86
- end
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table, '#<<' do
6
- let(:rows) { ['a', 'b', 'c'] }
7
- let(:object) { described_class }
8
-
9
- subject(:table) { object[rows] }
10
-
11
- context 'with primitive values' do
12
- let(:row) { [1, 2, 3] }
13
-
14
- it 'extracts values correctly' do
15
- table << row
16
- expect(table.to_a.last).to eql(row)
17
- end
18
- end
19
-
20
- context 'with complex values' do
21
- let(:row) { [1, { value: 2 }, 3] }
22
-
23
- it 'extracts values correctly' do
24
- table << row
25
- expect(table.to_a.last).to eql([1,2,3])
26
- end
27
- end
28
- end
@@ -1,90 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Border::ASCII, '#rendering' do
6
-
7
- subject { described_class.new(column_widths) }
8
-
9
- context 'with empty row' do
10
- let(:row) { TTY::Table::Row.new([]) }
11
- let(:column_widths) { [] }
12
-
13
- it 'draws top line' do
14
- expect(subject.top_line).to eq("++")
15
- end
16
-
17
- it 'draws middle line' do
18
- expect(subject.separator).to eq("++")
19
- end
20
-
21
- it 'draw bottom line' do
22
- expect(subject.bottom_line).to eq("++")
23
- end
24
-
25
- it 'draws row line' do
26
- expect(subject.row_line(row)).to eq("||")
27
- end
28
- end
29
-
30
- context 'with row' do
31
- let(:column_widths) { [2,2,2] }
32
- let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
33
-
34
- it 'draws top line' do
35
- expect(subject.top_line).to eq("+--+--+--+")
36
- end
37
-
38
- it 'draw middle line' do
39
- expect(subject.separator).to eq("+--+--+--+")
40
- end
41
-
42
- it 'draw bottom line' do
43
- expect(subject.bottom_line).to eq("+--+--+--+")
44
- end
45
-
46
- it 'draws row line' do
47
- expect(subject.row_line(row)).to eq("|a1|a2|a3|")
48
- end
49
- end
50
-
51
- context 'with multiline row' do
52
- let(:column_widths) { [2,2,2]}
53
-
54
- context 'with mixed data' do
55
- let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
56
-
57
- it 'draws row line' do
58
- expect(subject.row_line(row)).to eq <<-EOS.normalize
59
- |a1|a2|a3|
60
- |b1| | |
61
- |c1| | |
62
- EOS
63
- end
64
- end
65
-
66
- context 'with sparse data' do
67
- let(:row) { TTY::Table::Row.new(["a1\n\n", "\na2\n", "\n\na3"]) }
68
-
69
- it 'draws row line' do
70
- expect(subject.row_line(row)).to eq <<-EOS.normalize
71
- |a1| | |
72
- | |a2| |
73
- | | |a3|
74
- EOS
75
- end
76
- end
77
-
78
- context 'with empty data' do
79
- let(:row) { TTY::Table::Row.new(["\na1\n", "\na2\n", "\na3\n"]) }
80
-
81
- it 'draws row line' do
82
- expect(subject.row_line(row)).to eq <<-EOS.normalize
83
- | | | |
84
- |a1|a2|a3|
85
- | | | |
86
- EOS
87
- end
88
- end
89
- end
90
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Border, '#new' do
6
- let(:row) { [] }
7
-
8
- subject(:instance) { klass.new row }
9
-
10
- context 'when abstract' do
11
- let(:klass) { described_class }
12
-
13
- it { expect { instance }.to raise_error(NotImplementedError) }
14
- end
15
-
16
- context 'when concrete' do
17
- let(:klass) {
18
- Class.new do
19
- def initialize(row); end
20
- end
21
- }
22
-
23
- it { expect { instance }.to_not raise_error() }
24
-
25
- it { is_expected.to be_instance_of klass }
26
- end
27
- end
@@ -1,130 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Border::Null, '#rendering' do
6
- let(:border) { nil }
7
-
8
- subject { described_class.new column_widths, border }
9
-
10
- context 'with empty row' do
11
- let(:row) { TTY::Table::Row.new([]) }
12
- let(:column_widths) { [] }
13
-
14
- it 'draws top line' do
15
- expect(subject.top_line).to be_nil
16
- end
17
-
18
- it 'draws middle line' do
19
- expect(subject.separator).to be_nil
20
- end
21
-
22
- it 'draw bottom line' do
23
- expect(subject.bottom_line).to be_nil
24
- end
25
-
26
- it 'draws row line' do
27
- expect(subject.row_line(row)).to eq('')
28
- end
29
- end
30
-
31
- context 'with row' do
32
- let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
33
- let(:column_widths) { [2,2,2] }
34
-
35
- it 'draws top line' do
36
- expect(subject.top_line).to be_nil
37
- end
38
-
39
- it 'draw middle line' do
40
- expect(subject.separator).to be_nil
41
- end
42
-
43
- it 'draw bottom line' do
44
- expect(subject.bottom_line).to be_nil
45
- end
46
-
47
- it 'draws row line' do
48
- expect(subject.row_line(row)).to eq('a1 a2 a3')
49
- end
50
- end
51
-
52
- context 'with multiline row' do
53
- let(:column_widths) { [2,2,2] }
54
-
55
- context 'with mixed data' do
56
- let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
57
-
58
- it 'draws row line' do
59
- expect(subject.row_line(row)).to eq <<-EOS.normalize
60
- a1 a2 a3
61
- b1
62
- c1
63
- EOS
64
- end
65
- end
66
-
67
- context 'with sparse data' do
68
- let(:row) { TTY::Table::Row.new(["a1\n\n", "\na2\n", "\n\na3"]) }
69
-
70
- it 'draws row line' do
71
- expect(subject.row_line(row)).to eq <<-EOS.chomp
72
- a1
73
- a2
74
- a3
75
- EOS
76
- end
77
- end
78
-
79
- context 'with empty data' do
80
- let(:row) { TTY::Table::Row.new(["\na1\n", "\na2\n", "\na3\n"]) }
81
-
82
- it 'draws row line' do
83
- expect(subject.row_line(row)).to eq <<-EOS.chomp
84
-
85
- a1 a2 a3
86
-
87
- EOS
88
- end
89
- end
90
- end
91
-
92
- context 'with border' do
93
- let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
94
- let(:column_widths) { [2,2,2] }
95
- let(:border) { { :characters => {
96
- 'top' => '=',
97
- 'top_mid' => '=',
98
- 'top_left' => '=',
99
- 'top_right' => '=',
100
- 'bottom' => '=',
101
- 'bottom_mid' => '=',
102
- 'bottom_left' => '=',
103
- 'bottom_right' => '=',
104
- 'mid' => '=',
105
- 'mid_mid' => '=',
106
- 'mid_left' => '=',
107
- 'mid_right' => '=',
108
- 'left' => '=',
109
- 'center' => '=',
110
- 'right' => '='
111
- } } }
112
-
113
-
114
- it 'draws top line' do
115
- expect(subject.top_line).to eql '=========='
116
- end
117
-
118
- it 'draws separator line' do
119
- expect(subject.separator).to eql '=========='
120
- end
121
-
122
- it 'draws bottom line' do
123
- expect(subject.bottom_line).to eql '=========='
124
- end
125
-
126
- it 'draws row line' do
127
- expect(subject.row_line(row)).to eql '=a1=a2=a3='
128
- end
129
- end
130
- end
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::BorderOptions, '#from' do
6
-
7
- subject(:options) { described_class.from object }
8
-
9
- context 'when empty hash' do
10
- let(:object) { {} }
11
-
12
- it { expect(options.style).to be_nil }
13
-
14
- it { expect(options.separator).to be_nil }
15
- end
16
-
17
- context 'when hash' do
18
- let(:object) { { style: :red, separator: :none } }
19
-
20
- it { expect(options).to be_kind_of(described_class) }
21
-
22
- it { expect(options.style).to eql :red }
23
-
24
- it { expect(options.separator).to eql :none }
25
-
26
- it { expect(options.characters).to eql({}) }
27
- end
28
-
29
- context 'when other BorderOptions' do
30
- let(:object) { described_class.new(nil, nil, :blue) }
31
-
32
- it { expect(options).to eql object }
33
-
34
- it { expect(options.characters).to eql({}) }
35
-
36
- it { expect(options.style).to eql :blue }
37
- end
38
- end # from
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::BorderOptions, '.new' do
6
-
7
- subject(:options) { described_class.new }
8
-
9
- it { expect(subject.characters).to eql({}) }
10
-
11
- it { expect(subject.separator).to be_nil }
12
-
13
- it { expect(subject.style).to be_nil }
14
- end # new
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Table::Border::Unicode, '#rendering' do
6
-
7
- subject { described_class.new(column_widths) }
8
-
9
- context 'with empty row' do
10
- let(:row) { TTY::Table::Row.new([]) }
11
- let(:column_widths) { [] }
12
-
13
- it 'draws top line' do
14
- expect(subject.top_line).to eq("┌┐")
15
- end
16
-
17
- it 'draws middle line' do
18
- expect(subject.separator).to eq("├┤")
19
- end
20
-
21
- it 'draw bottom line' do
22
- expect(subject.bottom_line).to eq("└┘")
23
- end
24
-
25
- it 'draws row line' do
26
- expect(subject.row_line(row)).to eq("││")
27
- end
28
- end
29
-
30
- context 'with row' do
31
- let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
32
- let(:column_widths) { [2,2,2] }
33
-
34
- it 'draws top line' do
35
- expect(subject.top_line).to eq("┌──┬──┬──┐")
36
- end
37
-
38
- it 'draw middle line' do
39
- expect(subject.separator).to eq("├──┼──┼──┤")
40
- end
41
-
42
- it 'draw bottom line' do
43
- expect(subject.bottom_line).to eq("└──┴──┴──┘")
44
- end
45
-
46
- it 'draws row line' do
47
- expect(subject.row_line(row)).to eq("│a1│a2│a3│")
48
- end
49
- end
50
-
51
- context 'with multiline row' do
52
- let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
53
- let(:column_widths) { [2,2,2] }
54
-
55
- it 'draws row line' do
56
- expect(subject.row_line(row)).to eq <<-EOS.normalize
57
- │a1│a2│a3│
58
- │b1│ │ │
59
- │c1│ │ │
60
- EOS
61
- end
62
- end
63
- end