facets 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/AUTHORS +3 -3
  2. data/README +6 -7
  3. data/lib/core/facets.rb +1 -46
  4. data/lib/core/facets/array.rb +3 -0
  5. data/lib/core/facets/array/indexable.rb +6 -1
  6. data/lib/core/facets/array/only.rb +20 -0
  7. data/lib/core/facets/dir/multiglob.rb +12 -1
  8. data/lib/core/facets/enumerable.rb +0 -1
  9. data/lib/core/facets/enumerable/collect.rb +1 -0
  10. data/lib/core/facets/enumerable/combination.rb +44 -90
  11. data/lib/core/facets/facets.rb +46 -0
  12. data/lib/core/facets/file/write.rb +46 -58
  13. data/lib/core/facets/hash.rb +2 -0
  14. data/lib/core/facets/hash/select.rb +14 -0
  15. data/lib/core/facets/integer/multiples.rb +12 -55
  16. data/lib/core/facets/kernel/val.rb +14 -0
  17. data/lib/core/facets/module/alias.rb +28 -9
  18. data/lib/core/facets/module/methods.rb +18 -0
  19. data/lib/core/facets/module/traits.rb +65 -70
  20. data/lib/core/facets/proc/compose.rb +15 -12
  21. data/lib/core/facets/stackable.rb +3 -2
  22. data/lib/core/facets/string/format.rb +4 -6
  23. data/lib/core/facets/string/tabs.rb +34 -0
  24. data/lib/core/facets/symbol.rb +1 -0
  25. data/lib/core/facets/symbol/succ.rb +1 -42
  26. data/lib/core/facets/symbol/to_proc.rb +34 -0
  27. data/lib/methods/facets/array/contains.rb +1 -0
  28. data/lib/methods/facets/facets/require_core.rb +1 -0
  29. data/lib/methods/facets/file/writelines.rb +1 -0
  30. data/lib/methods/facets/io/writelines.rb +1 -0
  31. data/lib/methods/facets/kernel/not_nil.rb +1 -0
  32. data/lib/methods/facets/module/conflict.rb +1 -0
  33. data/lib/methods/facets/module/instance_method_defined.rb +1 -0
  34. data/lib/methods/facets/module/module_method_defined.rb +1 -0
  35. data/lib/methods/facets/module/private_conflict.rb +1 -0
  36. data/lib/methods/facets/module/protected_conflict.rb +1 -0
  37. data/lib/methods/facets/module/public_conflict.rb +1 -0
  38. data/lib/methods/facets/string/expand_tabs.rb +1 -0
  39. data/lib/methods/facets/string/outdent.rb +1 -0
  40. data/lib/methods/facets/string/taballto.rb +1 -0
  41. data/lib/more/facets/arguments.rb +1 -1
  42. data/lib/more/facets/association.rb +0 -46
  43. data/lib/more/facets/autoarray.rb +0 -28
  44. data/lib/more/facets/command.rb +341 -8
  45. data/lib/more/facets/dictionary.rb +25 -131
  46. data/lib/more/facets/downloader.rb +1 -1
  47. data/lib/more/facets/infinity.rb +3 -3
  48. data/lib/more/facets/interval.rb +0 -161
  49. data/lib/more/facets/multiton.rb +16 -12
  50. data/lib/more/facets/namespace.rb +1 -1
  51. data/lib/more/facets/ostruct.rb +46 -10
  52. data/lib/more/facets/overload.rb +0 -51
  53. data/lib/more/facets/paramix.rb +0 -97
  54. data/lib/more/facets/pp_s.rb +30 -0
  55. data/lib/more/facets/progressbar.rb +18 -10
  56. data/lib/more/facets/prototype.rb +1 -40
  57. data/lib/more/facets/random.rb +1 -0
  58. data/lib/more/facets/rbsystem.rb +4 -1
  59. data/lib/more/facets/snapshot.rb +8 -1
  60. data/lib/more/facets/stylize.rb +2 -0
  61. data/meta/{project.yaml → facets-2.0.3.roll} +22 -14
  62. data/meta/manifest.txt +38 -8
  63. data/task/{config.yaml → config/general.yaml} +7 -2
  64. data/task/{rdoc.yaml → config/rdoc.yaml} +1 -1
  65. data/task/crosstest +309 -0
  66. data/task/isotest +293 -0
  67. data/task/loadtest +28 -0
  68. data/task/methods +4 -4
  69. data/task/prepare +5 -0
  70. data/task/publish +2 -2
  71. data/task/rdoc +1 -0
  72. data/task/syntax +29 -0
  73. data/task/test +0 -1
  74. data/task/testeach +42 -0
  75. data/task/testpairs +50 -0
  76. data/test/lib/rq.rb +15 -0
  77. data/test/unit/array/test_merge.rb +21 -43
  78. data/test/unit/array/test_only.rb +21 -0
  79. data/test/unit/enumerable/test_collect.rb +1 -21
  80. data/test/unit/enumerable/test_combination.rb +50 -44
  81. data/test/unit/file/test_topath.rb +48 -57
  82. data/test/unit/file/test_write.rb +82 -0
  83. data/test/unit/hash/test_select.rb +43 -0
  84. data/test/unit/integer/test_multiples.rb +28 -32
  85. data/test/unit/kernel/test_report.rb +9 -12
  86. data/test/unit/kernel/test_val.rb +50 -45
  87. data/test/unit/module/test_include.rb +56 -57
  88. data/test/unit/module/test_name.rb +42 -55
  89. data/test/unit/module/test_traits.rb +46 -47
  90. data/test/unit/string/test_filter.rb +19 -34
  91. data/test/unit/string/test_format.rb +87 -96
  92. data/test/unit/string/test_regesc.rb +18 -26
  93. data/test/unit/string/test_tabs.rb +226 -119
  94. data/test/unit/symbol/test_succ.rb +14 -23
  95. data/test/unit/symbol/test_to_proc.rb +41 -0
  96. data/test/unit/test_association.rb +38 -47
  97. data/test/unit/test_attributes.rb +24 -33
  98. data/test/unit/test_autoarray.rb +23 -32
  99. data/test/unit/test_command.rb +26 -0
  100. data/test/unit/test_dictionary.rb +123 -117
  101. data/test/unit/test_infinity.rb +41 -47
  102. data/test/unit/test_inheritor.rb +133 -142
  103. data/test/unit/test_interval.rb +129 -93
  104. data/test/unit/test_ostruct.rb +148 -101
  105. data/test/unit/test_overload.rb +8 -15
  106. data/test/unit/test_paramix.rb +67 -73
  107. data/test/unit/test_pp_s.rb +23 -0
  108. data/test/unit/test_prototype.rb +28 -38
  109. metadata +47 -11
  110. data/lib/core/facets/enumerable/instance_map.rb +0 -0
  111. data/lib/more/facets/command_options.rb +0 -328
  112. data/meta/version.txt +0 -1
  113. data/task/load +0 -39
  114. data/test/unit/test_command_options.rb +0 -29
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ratch
2
+
3
+ # cross-run unit tests
4
+ #
5
+ # This tool runs all tests against each other in pairs
6
+ # to ensure across the board compatibility.
7
+
8
+ abort "Not working correctly. Fix me."
9
+
10
+ require "./lib/more/facets/progressbar"
11
+
12
+ main :test do
13
+ output = "doc/log/crosstest.txt"
14
+
15
+ live = ARGV.delete('--live')
16
+
17
+ find = 'test/**/test_*.rb'
18
+
19
+ tests = Dir.glob(find).reject{ |f| dir?(f) }.sort
20
+ tests = tests.sort{ |a,b| File.basename(a) <=> File.basename(b) }
21
+
22
+ File.open(output, 'w'){ |f|
23
+ f << "= CROSS TESTING\n#{Time.now}"
24
+ }
25
+
26
+ total = tests.size * tests.size
27
+
28
+ pbar = Console::ProgressBar.new("CrossTest", total+1)
29
+ pbar.inc
30
+
31
+ tests.each do |file1|
32
+ tests.each do |file2|
33
+ next if file1 == file2
34
+
35
+ sh %{echo "\n\n#{file1} & #{file2}" >> #{output}}
36
+
37
+ pbar.title = File.basename(file1)
38
+ pbar.inc
39
+ pbar.flush
40
+
41
+ if live
42
+ sh %{ruby -r#{file2} #{file1} >> #{output}}
43
+ else
44
+ sh %{ruby -Ilib/more -Ilib/core -Ilib/methods -r#{file2} #{file1} >> #{output}}
45
+ end
46
+ end
47
+ end
48
+
49
+ pbar.finish
50
+ end
@@ -0,0 +1,15 @@
1
+ BEGIN {
2
+
3
+ module Kernel
4
+ h = Hash.new
5
+ define_method(:requiree) do
6
+ h
7
+ end
8
+
9
+ r = method :require
10
+ define_method(:require) do |a|
11
+ r.call a
12
+ h[a] = caller
13
+ end
14
+ end
15
+ }
@@ -1,51 +1,29 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/array/merge.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for facets/array/merge.rb
12
8
 
13
- require 'facets/array/merge.rb'
9
+ require 'facets/array/merge.rb'
14
10
 
11
+ require 'test/unit'
15
12
 
13
+ class TestArray < Test::Unit::TestCase
16
14
 
17
- require 'test/unit'
18
-
19
- class TestArray < Test::Unit::TestCase
20
-
21
- def test_merge
22
- a = [1,2,3]
23
- b = [3,4,5]
24
- assert_equal( [1,2,3,4,5], a.merge(b) )
25
- end
26
-
27
- def test_merge!
28
- a = [1,2,3]
29
- b = [3,4,5]
30
- a.merge!(b)
31
- assert_equal( [1,2,3,4,5], a )
32
- end
33
-
34
- def test_rotate
35
- a = [1,2,3]
36
- assert_equal( [3,1,2], a.rotate, 'clockwise' )
37
- assert_equal( [2,3,1], a.rotate(-1), 'counter-clockwise' )
38
- end
39
-
40
- def test_rotate!
41
- a = [1,2,3]
42
- a.rotate!
43
- assert_equal( [3,1,2], a, 'clockwise' )
44
- a.rotate!(-1)
45
- assert_equal( [1,2,3], a, 'counter-clockwise' )
46
- end
47
-
15
+ def test_merge
16
+ a = [1,2,3]
17
+ b = [3,4,5]
18
+ assert_equal( [1,2,3,4,5], a.merge(b) )
48
19
  end
49
20
 
21
+ def test_merge!
22
+ a = [1,2,3]
23
+ b = [3,4,5]
24
+ a.merge!(b)
25
+ assert_equal( [1,2,3,4,5], a )
26
+ end
50
27
 
28
+ end
51
29
 
@@ -0,0 +1,21 @@
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ require 'facets/array/only.rb'
8
+
9
+ require 'test/unit'
10
+
11
+ class TestArrayOnly < Test::Unit::TestCase
12
+
13
+ def test_only
14
+ assert_equal(5, [5].only)
15
+ assert_equal(nil, [nil].only)
16
+ assert_raise(IndexError) { [].only }
17
+ assert_raise(IndexError) { [1,2,3].only }
18
+ end
19
+
20
+ end
21
+
@@ -4,14 +4,9 @@
4
4
  # | | __/\__ \ |
5
5
  # |_|\___||___/\__|
6
6
  #
7
- # for lib/facets/enumerable/partition.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
7
+ # for facets/enumerable/collect.rb
12
8
 
13
9
  require 'facets/enumerable/collect.rb'
14
-
15
10
  require 'test/unit'
16
11
  require 'set'
17
12
 
@@ -140,13 +135,6 @@ class TestEnumerable < Test::Unit::TestCase
140
135
  assert_equal( [[1,2],[3,4]], r )
141
136
  end
142
137
 
143
- def test_each_unique_pair
144
- r = []
145
- a = [1,2,3,4]
146
- a.each_unique_pair{ |a,b| r << [a,b] }
147
- assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
148
- end
149
-
150
138
  def test_eachn
151
139
  x = []
152
140
  [1,2,3,4].eachn{ |a,b| x << [a,b] }
@@ -159,14 +147,6 @@ class TestEnumerable < Test::Unit::TestCase
159
147
  assert_equal( o, x )
160
148
  end
161
149
 
162
- def test_each_combination
163
- r = []
164
- a = [1,2,3,4]
165
- a.each_combination(2){ |a,b| r << [a,b] }
166
- assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
167
- end
168
-
169
-
170
150
  def test_collect_with_index
171
151
  a = [1,2,3].collect_with_index{ |e,i| e*i }
172
152
  assert_equal( [0,2,6], a )
@@ -1,49 +1,55 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/enumerable/combination.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
12
-
13
- require 'facets/enumerable/combination.rb'
14
-
15
-
16
-
17
- require 'test/unit'
18
- require 'set'
19
-
20
- class TestEnumerableCombination < Test::Unit::TestCase
21
-
22
- def test_combinations_01
23
- a = [1,2]
24
- b = [3,4]
25
- z = Enumerable.combinations(a,b)
26
- r = [[1,3],[1,4],[2,3],[2,4]]
27
- assert_equal( r, z )
28
- end
29
-
30
- def test_combinations_02
31
- a = %w|a b|
32
- b = %w|a x|
33
- c = %w|x y|
34
- z = Enumerable.combinations(a, b, c)
35
- r = [ ["a", "a", "x"],
36
- ["a", "a", "y"],
37
- ["a", "x", "x"],
38
- ["a", "x", "y"],
39
- ["b", "a", "x"],
40
- ["b", "a", "y"],
41
- ["b", "x", "x"],
42
- ["b", "x", "y"] ]
43
- assert_equal( r, z )
44
- end
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for lib/facets/enumerable/combination.rb
8
+
9
+ require 'facets/enumerable/combination.rb'
10
+ require 'test/unit'
11
+ require 'set'
12
+
13
+ class TestEnumerableCombination < Test::Unit::TestCase
14
+
15
+ def test_combinations
16
+ a = [1,2]
17
+ b = [3,4]
18
+ z = Enumerable.combinations(a,b)
19
+ r = [[1,3],[1,4],[2,3],[2,4]]
20
+ assert_equal( r, z )
21
+ end
22
+
23
+ def test_combinations_of_three
24
+ a = %w|a b|
25
+ b = %w|a x|
26
+ c = %w|x y|
27
+ z = Enumerable.combinations(a, b, c)
28
+ r = [ ["a", "a", "x"],
29
+ ["a", "a", "y"],
30
+ ["a", "x", "x"],
31
+ ["a", "x", "y"],
32
+ ["b", "a", "x"],
33
+ ["b", "a", "y"],
34
+ ["b", "x", "x"],
35
+ ["b", "x", "y"] ]
36
+ assert_equal( r, z )
37
+ end
45
38
 
39
+ def test_each_combination
40
+ r = []
41
+ a = [1,2,3,4]
42
+ a.each_combination(2){ |a,b| r << [a,b] }
43
+ assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
46
44
  end
47
45
 
46
+ # DEPRECATED
47
+ # def test_each_unique_pair
48
+ # r = []
49
+ # a = [1,2,3,4]
50
+ # a.each_unique_pair{ |a,b| r << [a,b] }
51
+ # assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
52
+ # end
48
53
 
54
+ end
49
55
 
@@ -1,74 +1,65 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/file/topath.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for facets/file/topath.rb
12
8
 
13
- require 'facets/file/topath.rb'
9
+ require 'facets/file/topath.rb'
14
10
 
11
+ require 'test/unit'
15
12
 
13
+ # mock file
16
14
 
17
- require 'test/unit'
18
-
19
- # mock file
20
-
21
- class File
22
- def self.open( fname, mode, &blk )
23
- blk.call(self)
24
- end
25
- def self.read( fname=nil )
26
- @mock_content.clone
27
- end
28
- def self.write( str )
29
- @mock_content = str
30
- end
31
- def self.<<( str )
32
- (@mock_content ||="") << str
33
- end
15
+ class MockFile < File
16
+ def self.open( fname, mode, &blk )
17
+ blk.call(self)
34
18
  end
19
+ def self.read( fname=nil )
20
+ @mock_content.clone
21
+ end
22
+ def self.write( str )
23
+ @mock_content = str
24
+ end
25
+ def self.<<( str )
26
+ (@mock_content ||="") << str
27
+ end
28
+ end
35
29
 
36
- # tests
37
-
38
- class TestFile < Test::Unit::TestCase
39
-
40
- # TODO Write file identity tests.
41
-
42
- def test_sanitize_01
43
- assert_equal( "This_is_a_test", File.sanitize('This is a test') )
44
- end
30
+ # tests
45
31
 
46
- def test_sanitize_02
47
- assert_equal( "test", File.sanitize('This\is\test') )
48
- end
32
+ class TestFile < Test::Unit::TestCase
49
33
 
50
- def test_sanitize_03
51
- assert_equal( "test", File.sanitize('This/is/test') )
52
- end
34
+ # TODO Write file identity tests.
53
35
 
54
- def test_sanitize_04
55
- assert_equal( "te_____st", File.sanitize('This/te#$#@!st') )
56
- end
36
+ def test_sanitize_01
37
+ assert_equal( "This_is_a_test", MockFile.sanitize('This is a test') )
38
+ end
57
39
 
58
- def test_sanitize_05
59
- assert_equal( "_.", File.sanitize('.') )
60
- end
40
+ def test_sanitize_02
41
+ assert_equal( "test", MockFile.sanitize('This\is\test') )
42
+ end
61
43
 
62
- def test_sanitize_06
63
- assert_equal( "_....", File.sanitize('....') )
64
- end
44
+ def test_sanitize_03
45
+ assert_equal( "test", MockFile.sanitize('This/is/test') )
46
+ end
65
47
 
66
- def test_split_all
67
- fp = "this/is/test"
68
- assert_equal( ['this', 'is', 'test'], File.split_all(fp) )
69
- end
48
+ def test_sanitize_04
49
+ assert_equal( "te_____st", MockFile.sanitize('This/te#$#@!st') )
50
+ end
70
51
 
52
+ def test_sanitize_05
53
+ assert_equal( "_.", MockFile.sanitize('.') )
71
54
  end
72
55
 
56
+ def test_sanitize_06
57
+ assert_equal( "_....", MockFile.sanitize('....') )
58
+ end
73
59
 
60
+ def test_split_all
61
+ fp = "this/is/test"
62
+ assert_equal( ['this', 'is', 'test'], MockFile.split_all(fp) )
63
+ end
74
64
 
65
+ end
@@ -0,0 +1,82 @@
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for facets/file/write.rb
8
+
9
+ # TODO Needs a file mock.
10
+
11
+ require 'facets/file/write.rb'
12
+ require 'test/unit'
13
+ require 'tempfile'
14
+
15
+ class TC_FileWrite < Test::Unit::TestCase
16
+
17
+ def setup
18
+ tmp_dir = Dir::tmpdir # ENV["TMP"] || ENV["TEMP"] || "/tmp"
19
+ raise "Can't find temporary directory" unless File.directory?(tmp_dir)
20
+ @path = File.join(tmp_dir, "ruby_io_test")
21
+ end
22
+
23
+ # Test File.write
24
+ def test_file_write
25
+ data_in = "Test data\n"
26
+ nbytes = File.write(@path, data_in)
27
+ data_out = File.read(@path) # This is standard class method.
28
+ assert_equal(data_in, data_out)
29
+ assert_equal(data_out.size, nbytes)
30
+ end
31
+
32
+ # Test File.writelines
33
+ def test_file_writelines
34
+ data_in = %w[one two three four five]
35
+ File.writelines(@path, data_in)
36
+ data_out = File.readlines(@path) # This is standard class method.
37
+ assert_equal(data_in, data_out.map { |l| l.chomp })
38
+ end
39
+
40
+ end
41
+
42
+
43
+ # TODO This isn't right, and I'm concerned about acidentally writing a real file.
44
+
45
+ # class TestFileWrite < Test::Unit::TestCase
46
+ #
47
+ # class MockFile < ::File
48
+ # def open( fname, mode, &blk )
49
+ # blk.call(self)
50
+ # end
51
+ # def ead( fname=nil )
52
+ # @mrock_content.clone
53
+ # end
54
+ # def write( str )
55
+ # @mock_content = str
56
+ # end
57
+ # def <<( str )
58
+ # (@mock_content ||="") << str
59
+ # end
60
+ # end
61
+ #
62
+ # File = MockFile.new
63
+ #
64
+ # def test_create
65
+ # f = "not a real file"
66
+ # t = 'This is a test'
67
+ # File.create( f, t )
68
+ # s = File.read( f )
69
+ # assert_equal( t, s )
70
+ # end
71
+ #
72
+ # def test_rewrite
73
+ # f = "not a real file"
74
+ # t = 'This is a test'
75
+ # File.write( t )
76
+ # File.rewrite(f) { |s| s.reverse! }
77
+ # s = File.read(f)
78
+ # assert_equal( t.reverse, s )
79
+ # end
80
+ #
81
+ # end
82
+