columnize 0.3.6 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,78 +3,41 @@ require 'test/unit'
3
3
 
4
4
  # Test of Columnize module
5
5
  class TestHashFormat < Test::Unit::TestCase
6
- TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)),
7
- '..', 'lib')
6
+ TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
8
7
  require File.join(TOP_SRC_DIR, 'columnize.rb')
9
- include Columnize
8
+
10
9
  def test_parse_columnize_options
11
- list, default_opts = parse_columnize_options([[], {}])
12
- assert list.kind_of?(Array)
13
- assert default_opts.kind_of?(Hash)
14
- list, opts = parse_columnize_options([[], 90])
15
- assert_equal 90, opts[:displaywidth]
16
- list, opts = parse_columnize_options([[], 70, '|'])
10
+ assert Columnize.parse_columnize_options([{}]).kind_of?(Hash)
11
+ assert_equal 90, Columnize.parse_columnize_options([90])[:displaywidth]
12
+ opts = Columnize.parse_columnize_options([70, '|'])
17
13
  assert_equal 70, opts[:displaywidth]
18
14
  assert_equal '|', opts[:colsep]
19
15
  end
20
16
 
21
- def test_parse_columnize_ljust
22
- list, opts = parse_columnize_options([[1.5, 2, 3], {:ljust => :auto}])
23
- assert_equal false, opts[:ljust]
24
- list, opts = parse_columnize_options([[1.5, 2, 3], {:ljust => false}])
25
- assert_equal false, opts[:ljust]
26
- list, opts = parse_columnize_options([[1.5, 2, 3], {:ljust => true}])
27
- assert_equal true, opts[:ljust]
28
- list, opts = parse_columnize_options([[1, 2, 'b'], {:ljust => :auto}])
29
- assert_equal true, opts[:ljust]
30
- end
31
-
32
17
  def test_new_hash
33
- list, opts = parse_columnize_options([[], {:displaywidth => 40,
34
- :colsep => ', ',
35
- :term_adjust => true,
36
- }])
37
- [[:displaywidth, 40], [:colsep, ', '], [:term_adjust, true]].each do
38
- |field, value|
39
- assert_equal(value , opts[field])
40
- end
41
- list, opts = parse_columnize_options([[], {:displaywidth => 40,
42
- :colsep => ', ',
43
- }])
44
- assert_equal(false , opts[:term_adjust])
45
- opts = {:colsep => ', '}
46
- assert_equal("1, 2, 3\n",
47
- Columnize::columnize([1, 2, 3], opts))
18
+ hash = {:displaywidth => 40, :colsep => ', ', :term_adjust => true,}
19
+ assert_equal(hash, Columnize.parse_columnize_options([hash]), "parse_columnize_options returns same hash it was passed")
48
20
  end
49
-
21
+
50
22
  def test_array
51
23
  data = (0..54).to_a
52
- assert_equal(
53
- "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n" +
54
- " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19\n" +
55
- " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29\n" +
56
- " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39\n" +
57
- " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49\n" +
58
- " 50, 51, 52, 53, 54\n" +
59
- "]\n",
60
- columnize(data,
61
- :arrange_array => true, :ljust => false,
62
- :displaywidth => 39))
24
+ expected = "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,\n" +
25
+ " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,\n" +
26
+ " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,\n" +
27
+ " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\n" +
28
+ " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,\n" +
29
+ " 50, 51, 52, 53, 54]"
30
+ assert_equal(expected, Columnize.columnize(data, :arrange_array => true, :ljust => false, :displaywidth => 39))
63
31
  end
64
32
 
65
33
  def test_justify
66
34
  data = (0..54).to_a
67
- assert_equal(
68
- "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n" +
69
- " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19\n" +
70
- " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29\n" +
71
- " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39\n" +
72
- " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49\n" +
73
- " 50, 51, 52, 53, 54\n" +
74
- "]\n",
75
- columnize(data,
76
- :arrange_array => true,
77
- :displaywidth => 39))
35
+ expected = "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,\n" +
36
+ " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,\n" +
37
+ " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,\n" +
38
+ " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\n" +
39
+ " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,\n" +
40
+ " 50, 51, 52, 53, 54]"
41
+ assert_equal(expected, Columnize.columnize(data, :arrange_array => true, :displaywidth => 39))
78
42
  end
79
-
80
43
  end
@@ -1,37 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'test/unit'
3
3
 
4
- # Test of Columnize module
4
+ # Test of Columnize module for github issue #3
5
5
  class TestIssue3 < Test::Unit::TestCase
6
- @@TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)),
7
- '..', 'lib')
6
+ @@TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
8
7
  require File.join(@@TOP_SRC_DIR, 'columnize.rb')
9
- include Columnize
8
+
10
9
  # test columnize
11
10
  def test_long_column
12
11
  data = ["what's", "upppppppppppppppppp"]
13
- # Try at least one test where we give the module name explicitely.
14
- assert_equal("what's\nupppppppppppppppppp\n",
15
- Columnize::columnize(data, :arrange_vertical => false,
16
- :displaywidth => 7))
17
- assert_equal("what's\nupppppppppppppppppp\n",
18
- Columnize::columnize(data, :arrange_vertical => true,
19
- :displaywidth => 7))
12
+ data.columnize_opts = Columnize::DEFAULT_OPTS.merge :displaywidth => 7, :arrange_vertical => false
13
+ assert_equal("what's\nupppppppppppppppppp", data.columnize)
14
+ assert_equal("what's\nupppppppppppppppppp", data.columnize(:arrange_vertical => true))
15
+ end
16
+
17
+ def test_long_column_with_ljust
20
18
  data = ["whaaaaaat's", "up"]
21
- assert_equal("whaaaaaat's\n up\n",
22
- Columnize::columnize(data,
23
- :arrange_vertical => false,
24
- :ljust => false,
25
- :displaywidth => 7))
26
- assert_equal("whaaaaaat's\nup\n",
27
- Columnize::columnize(data,
28
- :arrange_vertical => false,
29
- :ljust => true,
30
- :displaywidth => 7))
31
- assert_equal("whaaaaaat's\nup\n",
32
- Columnize::columnize(data,
33
- :arrange_vertical => true,
34
- :ljust => true,
35
- :displaywidth => 7))
19
+ data.columnize_opts = Columnize::DEFAULT_OPTS.merge :displaywidth => 7, :arrange_vertical => false, :ljust => true
20
+ assert_equal("whaaaaaat's\nup", data.columnize)
21
+ assert_equal("whaaaaaat's\n up", data.columnize(:ljust => false))
22
+ assert_equal("whaaaaaat's\nup", data.columnize(:arrange_vertical => true))
36
23
  end
37
24
  end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+
4
+ # Test of Columnize#min_rows_and_colwidths
5
+ class TestComputeRowsAndColwidths < Test::Unit::TestCase
6
+ # Ruby 1.8 form of require_relative
7
+ TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
8
+ require File.join(TOP_SRC_DIR, 'columnize.rb')
9
+
10
+ VOPTS = Columnize::DEFAULT_OPTS.merge(:displaywidth => 80)
11
+ HOPTS = VOPTS.merge(:arrange_vertical => false)
12
+
13
+ def min_rows_and_colwidths(list, opts)
14
+ Columnize::Columnizer.new(list, opts).min_rows_and_colwidths
15
+ end
16
+
17
+ def test_colwidths
18
+ data = ["one", "two", "three",
19
+ "four", "five", "six",
20
+ "seven", "eight", "nine",
21
+ "ten", "eleven", "twelve",
22
+ "thirteen", "fourteen", "fifteen",
23
+ "sixteen", "seventeen", "eightteen",
24
+ "nineteen", "twenty", "twentyone",
25
+ "twentytwo", "twentythree", "twentyfour",
26
+ "twentyfive","twentysix", "twentyseven"]
27
+
28
+ [['horizontal', HOPTS, [10, 9, 11, 9, 11, 10], 5, 6],
29
+ ['vertical' , VOPTS, [5, 5, 6, 8, 9, 11, 11], 4, 7]].each do
30
+ |direction, opts, expect_colwidths, expect_rows, expect_cols|
31
+ rows, colwidths = min_rows_and_colwidths(data, opts)
32
+ assert_equal(expect_colwidths, colwidths, "colwidths - #{direction}")
33
+ assert_equal(expect_rows, rows.length,
34
+ "number of rows - #{direction}")
35
+ assert_equal(expect_cols, rows.first.length,
36
+ "number of cols - #{direction}")
37
+ end
38
+ end
39
+
40
+ def test_horizontal_vs_vertical
41
+ data = (0..54).map{|i| i.to_s}
42
+
43
+ [['horizontal', HOPTS.merge(:displaywidth => 39), [2,2,2,2,2,2,2,2,2,2]],
44
+ ['vertical' , VOPTS.merge(:displaywidth => 39), [1,2,2,2,2,2,2,2,2,2]]].each do
45
+ |direction, opts, expect|
46
+ rows, colwidths = min_rows_and_colwidths(data, opts)
47
+ assert_equal(expect, colwidths, "colwidths #{direction}")
48
+ assert_equal(6, rows.length, "number of rows - #{direction}")
49
+ assert_equal(10, rows.first.length, "number of cols - #{direction}")
50
+ end
51
+ end
52
+
53
+ def test_displaywidth_smaller_than_largest_atom
54
+ data = ['a' * 100, 'b', 'c', 'd', 'e']
55
+
56
+ [['horizontal', HOPTS],
57
+ ['vertical' , VOPTS]].each do
58
+ |direction, opts|
59
+ rows, colwidths = min_rows_and_colwidths(data, opts)
60
+ assert_equal([100], colwidths, "colwidths #{direction}")
61
+ assert_equal(5, rows.length, "number of rows - #{direction}")
62
+ assert_equal(1, rows.first.length, "number of cols - #{direction}")
63
+ end
64
+ end
65
+ end
metadata CHANGED
@@ -1,91 +1,121 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: columnize
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 6
9
- version: 0.3.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.9
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
12
- - R. Bernstein
7
+ authors:
8
+ - Rocky Bernstein
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
12
+ date: 2014-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! '
47
+
48
+ In showing a long lists, sometimes one would prefer to see the value
49
+
50
+ arranged aligned in columns. Some examples include listing methods
16
51
 
17
- date: 2011-12-17 00:00:00 -05:00
18
- default_executable:
19
- dependencies: []
52
+ of an object or debugger commands.
20
53
 
21
- description: "\n\
22
- In showing a long lists, sometimes one would prefer to see the value\n\
23
- arranged aligned in columns. Some examples include listing methods\n\
24
- of an object or debugger commands. \n\
25
- See Examples in the rdoc documentation for examples.\n"
54
+ See Examples in the rdoc documentation for examples.
55
+
56
+ '
26
57
  email: rockyb@rubyforge.net
27
58
  executables: []
28
-
29
59
  extensions: []
30
-
31
- extra_rdoc_files:
60
+ extra_rdoc_files:
32
61
  - README.md
33
62
  - lib/columnize.rb
34
63
  - COPYING
35
- files:
64
+ - THANKS
65
+ files:
36
66
  - .gitignore
67
+ - .travis.yml
37
68
  - AUTHORS
38
69
  - COPYING
39
70
  - ChangeLog
71
+ - Gemfile
72
+ - Gemfile.lock
40
73
  - Makefile
41
74
  - NEWS
42
75
  - README.md
43
76
  - Rakefile
77
+ - THANKS
44
78
  - columnize.gemspec
45
79
  - lib/Makefile
46
80
  - lib/columnize.rb
47
81
  - lib/columnize/Makefile
82
+ - lib/columnize/columnize.rb
83
+ - lib/columnize/opts.rb
48
84
  - lib/columnize/version.rb
85
+ - test/test-columnize-array.rb
49
86
  - test/test-columnize.rb
87
+ - test/test-columnizer.rb
50
88
  - test/test-hashparm.rb
51
89
  - test/test-issue3.rb
52
- has_rdoc: true
90
+ - test/test-min_rows_and_colwidths.rb
53
91
  homepage: https://github.com/rocky/columnize
54
- licenses:
92
+ licenses:
55
93
  - Ruby
56
94
  - GPL2
57
95
  post_install_message:
58
- rdoc_options:
96
+ rdoc_options:
59
97
  - --main
60
98
  - README
61
99
  - --title
62
- - Columnize 0.3.6 Documentation
63
- require_paths:
100
+ - Columnize 0.8.9 Documentation
101
+ require_paths:
64
102
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
103
+ required_ruby_version: !ruby/object:Gem::Requirement
66
104
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- segments:
71
- - 1
72
- - 8
73
- - 2
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
74
108
  version: 1.8.2
75
- required_rubygems_version: !ruby/object:Gem::Requirement
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
110
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- segments:
81
- - 0
82
- version: "0"
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
83
115
  requirements: []
84
-
85
116
  rubyforge_project: columnize
86
- rubygems_version: 1.3.7
117
+ rubygems_version: 1.8.23
87
118
  signing_key:
88
119
  specification_version: 3
89
120
  summary: Module to format an Array as an Array of String aligned in columns
90
121
  test_files: []
91
-