console_table 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 319bf461a967b3098c88d16ed370e6b32cfe0a11
4
- data.tar.gz: 82ac42a1dcc1680f982ddafa7a9613a28a7a0d42
3
+ metadata.gz: 2f72bfb44646e954c27cf46a4b3b3f4d50c629b0
4
+ data.tar.gz: 23402eb6500112776e41f43a988c0340552c1b65
5
5
  SHA512:
6
- metadata.gz: 1c0bdfbc856c1f7e04a7b9a3adfc3d259472947293a8812637395d233f1bc14ce68bc0e1730312012c4fd87765cb66e07ace95a74c7d27ab2c0f790ce552802b
7
- data.tar.gz: 64a60d6b7571dcabee14970cc6b9bef3768c2bbcf9663c7d03378ea26085c8b466f7e28a0e56d666b709f92a2d9c562ef844fc6be7e1bb9b33871d99a4cfd6ad
6
+ metadata.gz: 3fb568ca9cac5df83ac89909b4988f56b464345ca938600926c84f747d734799ea64967d472420d0a30cc6be66b39afa0a9040d6eb63fd08be6d4a22573526a4
7
+ data.tar.gz: d2bdf4a87fe2dbf1a6f62a5a1a9bbfbf60250b28c36d96a480575e76fbe36597b71b275a60a9c700e2edff0bac2d7ff2b683b02f17a83d7cf4cfc8d24c55e5c2
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "console_table"
7
- spec.version = "0.0.3"
7
+ spec.version = "0.0.4"
8
8
  spec.authors = ["Rod Hilton"]
9
9
  spec.email = ["consoletable@rodhilton.com"]
10
10
  spec.summary = %q{Simplifies printing tables of information to commandline consoles}
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency "bundler", "~> 1.5"
20
20
  spec.add_development_dependency 'rake', '~> 0'
21
21
  spec.add_development_dependency 'simplecov', '~> 0.9'
22
+ spec.add_development_dependency 'minitest', '~> 5.5'
22
23
 
23
24
  spec.add_runtime_dependency 'colorize', '~> 0.7'
24
25
  end
@@ -101,7 +101,10 @@ class ConsoleTable
101
101
  justify = to_print[:justify] || :left
102
102
  mode = to_print[:mode] || :default
103
103
 
104
- formatted=format(@working_width, text, ellipsize, justify).colorize(:color => color, :background => background, :mode => mode)
104
+ formatted=format(@working_width, text, ellipsize, justify)
105
+ if text != :default or background != :default or mode != :default
106
+ formatted = formatted.colorize(:color => color, :background => background, :mode => mode)
107
+ end
105
108
  @out.print formatted
106
109
  end
107
110
 
@@ -127,7 +130,11 @@ class ConsoleTable
127
130
  justify = to_print[:justify] || justify #can override
128
131
  mode = to_print[:mode] || :default
129
132
 
130
- formatted=format(column[:size], text, ellipsize, justify).colorize(:color => color, :background => background, :mode => mode)
133
+ formatted=format(column[:size], text, ellipsize, justify)
134
+
135
+ if color != :default or background != :default or mode != :default
136
+ formatted = formatted.colorize(:color => color, :background => background, :mode => mode)
137
+ end
131
138
 
132
139
  unless (to_print[:highlight].nil?)
133
140
  highlight_regex = to_print[:highlight][:regex] || /wontbefoundbecauseit'sgobbledygookblahblahblahbah/
@@ -167,6 +174,11 @@ class ConsoleTable
167
174
  total_width = ENV["COLUMNS"].to_i || 150
168
175
  end
169
176
 
177
+ keys = @original_column_layout.collect { |d| d[:key] }.uniq
178
+ if keys.length < @original_column_layout.length
179
+ raise("ConsoleTable configuration invalid, same key defined more than once")
180
+ end
181
+
170
182
  num_spacers = @original_column_layout.length - 1
171
183
  set_sizes = @original_column_layout.collect { |x| x[:size] }.find_all { |x| x.is_a? Integer }
172
184
  used_up = set_sizes.inject(:+) || 0
@@ -1,7 +1,7 @@
1
- require 'test/unit'
2
- require '../lib/console_table'
1
+ require 'minitest/autorun'
2
+ require 'console_table'
3
3
 
4
- class ConsoleTableTest < Test::Unit::TestCase
4
+ class ConsoleTableTest < Minitest::Test
5
5
 
6
6
  def setup
7
7
  @mock_out = StringIO.new
@@ -196,10 +196,10 @@ Row 2, Column 1 Row 2, Column 2 Row Row 2, Column 4
196
196
 
197
197
  commit_table_config = [
198
198
  {:key=>:col1, :size=>20, :title=>"Column 1"},
199
- {:key=>:col1, :size=>20, :title=>"Column 2"},
199
+ {:key=>:col2, :size=>20, :title=>"Column 2"},
200
200
  ]
201
201
 
202
- assert_raise(RuntimeError) { ConsoleTable.define(commit_table_config) }
202
+ assert_raises(RuntimeError) { ConsoleTable.define(commit_table_config) }
203
203
  end
204
204
 
205
205
  def test_wont_create_layout_with_more_than_100_percent
@@ -207,10 +207,10 @@ Row 2, Column 1 Row 2, Column 2 Row Row 2, Column 4
207
207
 
208
208
  commit_table_config = [
209
209
  {:key=>:col1, :size=>0.8, :title=>"Column 1"},
210
- {:key=>:col1, :size=>0.3, :title=>"Column 2"},
210
+ {:key=>:col2, :size=>0.3, :title=>"Column 2"},
211
211
  ]
212
212
 
213
- assert_raise(RuntimeError) { ConsoleTable.define(commit_table_config) }
213
+ assert_raises(RuntimeError) { ConsoleTable.define(commit_table_config) }
214
214
  end
215
215
 
216
216
  def test_wont_create_layout_with_invalid_size
@@ -218,10 +218,97 @@ Row 2, Column 1 Row 2, Column 2 Row Row 2, Column 4
218
218
 
219
219
  commit_table_config = [
220
220
  {:key=>:col1, :size=>0.8, :title=>"Column 1"},
221
- {:key=>:col1, :size=>"hello!", :title=>"Column 2"},
221
+ {:key=>:col2, :size=>"hello!", :title=>"Column 2"},
222
+ ]
223
+
224
+ assert_raises(RuntimeError) { ConsoleTable.define(commit_table_config) }
225
+ end
226
+
227
+ def test_wont_allow_repeats_of_key_names
228
+ ENV["COLUMNS"] = "50"
229
+
230
+ commit_table_config = [
231
+ {:key=>:col1, :size=>20, :title=>"Column 1"},
232
+ {:key=>:col1, :size=>20, :title=>"Column 2"},
233
+ ]
234
+
235
+ assert_raises(RuntimeError) { ConsoleTable.define(commit_table_config) }
236
+ end
237
+
238
+ def test_can_truncate_output
239
+ ENV["COLUMNS"] = "100"
240
+
241
+ commit_table_config = [
242
+ {:key=>:col1, :size=>20, :title=>"Column 1"}
243
+ ]
244
+
245
+ ConsoleTable.define(commit_table_config, :output=>@mock_out) do |table|
246
+ table.print({
247
+ :col1 => "This is short"
248
+ })
249
+
250
+ table.print({
251
+ :col1 => "This is way too long and it needs to get cut off"
252
+ })
253
+
254
+ table.print({
255
+ :col1 => {:text=>"This is way too long and it needs to get cut off", :ellipsize=>true}
256
+ })
257
+ end
258
+
259
+ expected=<<-END
260
+ ====================
261
+ Column 1
262
+ --------------------
263
+ This is short
264
+ This is way too long
265
+ This is way too l...
266
+ ====================
267
+ END
268
+
269
+ assert_output_equal expected, @mock_out.string
270
+ end
271
+
272
+ def test_can_justify_columns_and_override_in_rows
273
+ ENV["COLUMNS"] = "100"
274
+
275
+ commit_table_config = [
276
+ {:key=>:col1, :size=>20, :title=>"Column 1"},
277
+ {:key=>:col2, :size=>20, :title=>"Column 2", :justify=>:center},
278
+ {:key=>:col3, :size=>20, :title=>"Column 3", :justify=>:right}
222
279
  ]
223
280
 
224
- assert_raise(RuntimeError) { ConsoleTable.define(commit_table_config) }
281
+ ConsoleTable.define(commit_table_config, :output=>@mock_out) do |table|
282
+ table.print({
283
+ :col1 => "Short1",
284
+ :col2 => "Short2",
285
+ :col3 => "Short3"
286
+ })
287
+
288
+ table.print({
289
+ :col1 => {text: "Short1"},
290
+ :col2 => {text: "Short2"},
291
+ :col3 => {text: "Short3"}
292
+ })
293
+
294
+ table.print({
295
+ :col1 => {text: "Short1", :justify=>:center},
296
+ :col2 => {text: "Short2", :justify=>:right},
297
+ :col3 => {text: "Short3", :justify=>:left}
298
+ })
299
+ end
300
+
301
+ expected=<<-END
302
+ ==============================================================
303
+ Column 1 Column 2 Column 3
304
+ --------------------------------------------------------------
305
+ Short1 Short2 Short3
306
+ Short1 Short2 Short3
307
+ Short1 Short2 Short3
308
+ ==============================================================
309
+ END
310
+
311
+ assert_output_equal expected, @mock_out.string
225
312
  end
226
313
 
227
314
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rod Hilton
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.5'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: colorize
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +96,7 @@ files:
82
96
  - Rakefile
83
97
  - console_table.gemspec
84
98
  - lib/console_table.rb
85
- - test/console_table_test.rb
99
+ - test/test_console_table.rb
86
100
  - todo.txt
87
101
  homepage: https://github.com/rodhilton/console_table
88
102
  licenses:
@@ -109,4 +123,4 @@ signing_key:
109
123
  specification_version: 4
110
124
  summary: Simplifies printing tables of information to commandline consoles
111
125
  test_files:
112
- - test/console_table_test.rb
126
+ - test/test_console_table.rb