facets 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/lib/core/facets.rb +1 -1
  2. data/lib/core/facets/conversion.rb +6 -1
  3. data/lib/core/facets/enumerable/collate.rb +13 -24
  4. data/lib/core/facets/{main.rb → facets.rb} +0 -0
  5. data/lib/methods/facets/facets/require_core.rb +1 -1
  6. data/lib/more/facets/advice.rb +28 -1
  7. data/lib/more/facets/aop.rb +2 -9
  8. data/log/history.rd +5 -0
  9. data/meta/MANIFEST +2 -4
  10. data/meta/{rollrc → ROLLRC} +1 -1
  11. data/task/release +1 -3
  12. data/task/test/general +2 -2
  13. data/task/test/loadtest +1 -1
  14. data/test/unit/enumerable/test_collate.rb +46 -50
  15. data/test/unit/test_advice.rb +2 -0
  16. data/test/unit/test_annotations.rb +2 -0
  17. data/test/unit/test_arguments.rb +45 -61
  18. data/test/unit/test_association.rb +1 -7
  19. data/test/unit/test_attributes.rb +1 -7
  20. data/test/unit/test_autoarray.rb +1 -8
  21. data/test/unit/test_basicobject.rb +40 -56
  22. data/test/unit/test_bbcode.rb +14 -30
  23. data/test/unit/test_binreadable.rb +35 -51
  24. data/test/unit/test_boolean.rb +64 -80
  25. data/test/unit/test_buildable.rb +26 -41
  26. data/test/unit/test_buildingblock.rb +24 -39
  27. data/test/unit/test_bytes.rb +50 -66
  28. data/test/unit/test_class_extension.rb +43 -59
  29. data/test/unit/test_classmethods.rb +42 -58
  30. data/test/unit/test_compare_on.rb +40 -54
  31. data/test/unit/test_conversion.rb +143 -159
  32. data/test/unit/test_coroutine.rb +31 -47
  33. data/test/unit/test_crypt.rb +2 -11
  34. data/test/unit/test_curry.rb +19 -35
  35. data/test/unit/test_cut.rb +14 -30
  36. data/test/unit/test_date.rb +31 -47
  37. data/test/unit/test_dependency.rb +49 -64
  38. data/test/unit/test_dictionary.rb +1 -7
  39. data/test/unit/test_elementor.rb +45 -61
  40. data/test/unit/test_enumerablepass.rb +57 -73
  41. data/test/unit/test_functor.rb +21 -34
  42. data/test/unit/test_getoptlong.rb +17 -33
  43. data/test/unit/test_infinity.rb +1 -7
  44. data/test/unit/test_inheritor.rb +1 -7
  45. data/test/unit/test_instantiable.rb +14 -30
  46. data/test/unit/test_instantise.rb +20 -36
  47. data/test/unit/test_interface.rb +58 -65
  48. data/test/unit/test_interval.rb +1 -7
  49. data/test/unit/test_let.rb +11 -25
  50. data/test/unit/test_linkedlist.rb +38 -52
  51. data/test/unit/test_lrucache.rb +6 -22
  52. data/test/unit/test_mapsend.rb +12 -28
  53. data/test/unit/test_memoize.rb +17 -32
  54. data/test/unit/test_multipliers.rb +72 -87
  55. data/test/unit/test_namespace.rb +35 -51
  56. data/test/unit/test_opencascade.rb +47 -63
  57. data/test/unit/test_openobject.rb +94 -110
  58. data/test/unit/test_ostruct.rb +1 -7
  59. data/test/unit/test_overload.rb +1 -6
  60. data/test/unit/test_paramix.rb +1 -7
  61. data/test/unit/test_pp_s.rb +1 -7
  62. data/test/unit/test_prototype.rb +1 -6
  63. data/test/unit/test_recorder.rb +22 -37
  64. data/test/unit/test_snapshot.rb +2 -14
  65. data/test/unit/test_stylize.rb +113 -127
  66. data/test/unit/test_syncarray.rb +2 -15
  67. data/test/unit/test_synchash.rb +16 -28
  68. data/test/unit/test_timer.rb +2 -14
  69. data/test/unit/test_times.rb +64 -80
  70. data/test/unit/test_tuple.rb +40 -56
  71. data/test/unit/test_typecast.rb +29 -40
  72. data/test/unit/test_uninheritable.rb +30 -42
  73. metadata +4 -8
  74. data/test/lib/rq.rb +0 -15
data/lib/core/facets.rb CHANGED
@@ -1 +1 @@
1
- require 'facets/main.rb'
1
+ require 'facets/facets.rb'
@@ -41,7 +41,12 @@ class Array
41
41
  #each{ |e| h[e.first] = e.slice(1..-1) }
42
42
  each{ |k,*v| h[k] = v }
43
43
  else
44
- h = Hash[*(self.flatten)]
44
+ #h = Hash[*flatten(1)] # TODO Use in 1.9 instead.
45
+ ary = []
46
+ each do |a|
47
+ Array===a ? ary.concat(a) : ary << a
48
+ end
49
+ h = Hash[*ary]
45
50
  end
46
51
  h
47
52
  end
@@ -1,20 +1,4 @@
1
- # TITLE:
2
- #
3
- # Enumerable Collate
4
- #
5
- # DESCRIPTION:
6
- #
7
- # Collate is a Hash collection method.
8
- #
9
- # AUTHORS:
10
- #
11
- # CREDIT 7ransVent
12
- #
13
- # NOTES:
14
- #
15
- # NOTE Hash#collate! is only useful for Hash. It is not generally
16
- # applicable to Enumerable.
17
- #++
1
+ require 'enumerator'
18
2
 
19
3
  module Enumerable
20
4
 
@@ -22,23 +6,25 @@ module Enumerable
22
6
  # is expected to return two values: the key and the value for the new hash.
23
7
  #
24
8
  # numbers = (1..3)
25
- # squares = numbers.graph { |n| [n, n*n] } # { 1=>1, 2=>4, 3=>9 }
26
- # sq_roots = numbers.graph { |n| [n*n, n] } # { 1=>1, 4=>2, 9=>3 }
9
+ # squares = numbers.collate { |n| [n, n*n] } # { 1=>1, 2=>4, 3=>9 }
10
+ # sq_roots = numbers.collate { |n| [n*n, n] } # { 1=>1, 4=>2, 9=>3 }
11
+ #
12
+ # CREDIT: Trans
13
+ # CREDIT: Andrew Dudzik (adudzik)
27
14
 
28
15
  def collate(&yld)
29
16
  if yld
30
- inject({}) do |h,kv|
31
- nk, nv = *yld[*kv].to_a.flatten
17
+ inject({}) do |h, *kv| # Used to be inject({}) do |h,kv|
18
+ r = *yld[*kv] # The *-op works differnt from to_a on single element hash!!!
19
+ nk, nv = *r # Used to be nk, nv = *yld[*kv].to_a.flatten
32
20
  h[nk] = nv
33
21
  h
34
22
  end
35
23
  else
36
- Hash[*self.to_a.flatten]
24
+ Enumerator.new(self,:collate) # Used to be Hash[*self.to_a] or Hash[*self.to_a.flatten]
37
25
  end
38
26
  end
39
27
 
40
- # Alias for #collate (THIS WILL BE DEPRECATED)
41
-
42
28
  alias :graph :collate
43
29
 
44
30
  # Returns a new hash built by iterating through each key,value
@@ -55,6 +41,9 @@ end
55
41
  class Hash
56
42
 
57
43
  # In place version of #collate.
44
+ #
45
+ # NOTE Hash#collate! is only useful for Hash. It is not generally
46
+ # applicable to Enumerable.
58
47
 
59
48
  def collate!(&yld)
60
49
  replace(collate(&yld))
File without changes
@@ -1 +1 @@
1
- require 'facets/main.rb'
1
+ require 'facets/facets.rb'
@@ -1,8 +1,35 @@
1
+ # = TITLE:
2
+ #
3
+ # Advice
4
+ #
5
+ # = SUMMARY:
6
+ #
7
+ # Add before, after and around advice in dynamic fashion.
8
+ #
9
+ # = COPYRIGHT:
10
+ #
11
+ # Copyright (c) 2007 Thomas Sawyer
12
+ #
13
+ # = LICENSE:
14
+ #
15
+ # Ruby License
16
+ #
17
+ # This module is free software. You may use, modify, and/or redistribute this
18
+ # software under the same terms as Ruby.
19
+ #
20
+ # This program is distributed in the hope that it will be useful, but WITHOUT
21
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22
+ # FOR A PARTICULAR PURPOSE.
23
+ #
24
+ # = AUTHORS:
25
+ #
26
+ # - TransAspect
27
+
1
28
  require 'facets/1stclassmethod'
2
29
  require 'facets/unboundmethod/arguments'
3
30
  #require 'facets/binding'
4
31
 
5
-
32
+ #
6
33
  class Method
7
34
  attr_accessor :advised
8
35
 
@@ -176,14 +176,7 @@ class Class
176
176
  end
177
177
 
178
178
 
179
-
180
-
181
-
182
- #
183
- # Basic Test
184
- #
185
-
186
- if $0 == __FILE__
179
+ =begin demo
187
180
 
188
181
  class X
189
182
  def x; "x"; end
@@ -209,4 +202,4 @@ if $0 == __FILE__
209
202
  print '"y" == ' ; p x1.y
210
203
  print '"<{x}>" == ' ; p x1.q
211
204
 
212
- end
205
+ =end
data/log/history.rd CHANGED
@@ -1,5 +1,10 @@
1
1
  = Facets Revision History
2
2
 
3
+ == 2.1.3 / 2007-11-28
4
+
5
+ * Fixed minor oddity in Enumerable/collate.
6
+ * Fixed major issue with 2.1.2 where it would not core facets correctly.
7
+
3
8
  == 2.1.2 / 2007-11-22
4
9
 
5
10
  * Dir::multiglob no longer handels -/+ modifiers. Use FileList instead.
data/meta/MANIFEST CHANGED
@@ -68,6 +68,7 @@ lib/core/facets/enumerable.rb
68
68
  lib/core/facets/exception
69
69
  lib/core/facets/exception/detail.rb
70
70
  lib/core/facets/exception.rb
71
+ lib/core/facets/facets.rb
71
72
  lib/core/facets/file
72
73
  lib/core/facets/file/read.rb
73
74
  lib/core/facets/file/topath.rb
@@ -126,7 +127,6 @@ lib/core/facets/kernel/tap.rb
126
127
  lib/core/facets/kernel/val.rb
127
128
  lib/core/facets/kernel/withattr.rb
128
129
  lib/core/facets/kernel.rb
129
- lib/core/facets/main.rb
130
130
  lib/core/facets/matchdata
131
131
  lib/core/facets/matchdata/matchset.rb
132
132
  lib/core/facets/matchdata.rb
@@ -751,10 +751,10 @@ log/history.rd
751
751
  log/todo.rd
752
752
  meta
753
753
  meta/MANIFEST
754
+ meta/ROLLRC
754
755
  meta/google_ad.html
755
756
  meta/icli.yaml
756
757
  meta/project.yaml
757
- meta/rollrc
758
758
  task
759
759
  task/changes
760
760
  task/clean
@@ -784,8 +784,6 @@ task/test/loadtest
784
784
  task/test/pairs
785
785
  task/test/syntax
786
786
  test
787
- test/lib
788
- test/lib/rq.rb
789
787
  test/unit
790
788
  test/unit/array
791
789
  test/unit/array/test_delete.rb
@@ -1,4 +1,4 @@
1
- facets 2.1.2 stable 2007-11-22
1
+ facets 2.1.3 stable 2007-11-29 facets.rb
2
2
  lib/core/facets
3
3
  lib/more/facets
4
4
  lib/methods/facets
data/task/release CHANGED
@@ -3,9 +3,7 @@
3
3
  # release packages
4
4
 
5
5
  main :release do
6
- fname = Dir.glob('meta/*.roll').first
7
- pname = File.basename(fname).chomp('.roll')
8
- name, version = *pname.split('-')
6
+ name, version = rollrc.name, rollrc.version
9
7
 
10
8
  icli "rubyforge release --version=#{version}"
11
9
  end
data/task/test/general CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Run unit tests
4
4
 
5
- live = ARGV.delete('--live')
5
+ live = commandline.flag?('--live')
6
6
 
7
7
  unless live
8
8
  $LOAD_PATH.unshift(File.expand_path('lib/methods'))
@@ -11,7 +11,7 @@ unless live
11
11
  end
12
12
 
13
13
  main :test do
14
- if find = argv[0]
14
+ if find = commandline[0]
15
15
  unless file?(find)
16
16
  find = File.join(find, '**', 'test_*.rb')
17
17
  end
data/task/test/loadtest CHANGED
@@ -12,7 +12,7 @@ main :syntax do
12
12
  scripts.each do |s|
13
13
  next unless File.file?(s)
14
14
  #if not system "ruby -c -Ibin:lib:test #{s} &> /dev/null" then
15
- if r = system "ruby -I#{libpath} #{s} > /dev/null"
15
+ if system("ruby -I#{libpath} #{s} > /dev/null")
16
16
  puts "#{s} [PASS]" #if verbose?
17
17
  else
18
18
  puts "Load Issue: #{s}"
@@ -1,55 +1,51 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/enumerable/collate.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
12
-
13
- require 'facets/enumerable/collate.rb'
14
-
15
-
16
-
17
- require 'test/unit'
18
-
19
- class TestEnumerableCollate < Test::Unit::TestCase
20
-
21
- def test_collate_01
22
- a = { :a => 1, :b => 2, :c => 3 }
23
- e = { :a => 2, :b => 3, :c => 4 }
24
- assert_equal( e, a.collate{ |k,v| { k => v+1 } } )
25
- end
26
-
27
- def test_collate_02
28
- numbers = (1..3)
29
- squares = numbers.collate{ |n| [n, n*n] }
30
- assert_equal( {1=>1, 2=>4, 3=>9}, squares )
31
- end
32
-
33
- def test_collate_03
34
- numbers = (1..3)
35
- sq_roots = numbers.collate{ |n| [n*n, n] }
36
- assert_equal( {1=>1, 4=>2, 9=>3}, sq_roots )
37
- end
38
-
39
- def test_collate_01!
40
- a = { :a => 1, :b => 2, :c => 3 }
41
- e = { :a => 2, :b => 3, :c => 4 }
42
- a.collate!{ |k,v| { k => v+1 } }
43
- assert_equal( e, a )
44
- end
45
-
46
- def test_collate_02!
47
- h = {:a=>1,:b=>2,:c=>3}
48
- h.collate!{ |k,v| [v, v*v] }
49
- assert_equal( {1=>1, 2=>4, 3=>9}, h )
50
- end
1
+ # Test facets/enumerable/collate.rb
51
2
 
3
+ require 'facets/enumerable/collate.rb'
4
+ require 'test/unit'
5
+
6
+ class TestEnumerableCollate < Test::Unit::TestCase
7
+
8
+ def test_collate_hash_return
9
+ a = { :a => 1, :b => 2, :c => 3 }
10
+ e = { :a => 2, :b => 3, :c => 4 }
11
+ assert_equal( e, a.collate{ |k,v| {k => v+1} } )
12
+ end
13
+
14
+ def test_collate_hash_of_array
15
+ a = { :a => [1,2], :b => [2,3], :c => [3,4] }
16
+ e = { :a => 2, :b => 6, :c => 12 }
17
+ assert_equal( e, a.collate{ |k,v| [k, v[0]*v[1] ] } )
18
+ end
19
+
20
+ def test_collate_array_of_array
21
+ a = [ [1,2], [2,3], [3,4] ]
22
+ e = { [1,2] => 2, [2,3] => 6, [3,4] => 12 }
23
+ assert_equal( e, a.collate{ |a| [a, a[0]*a[1] ] } )
52
24
  end
53
25
 
26
+ def test_collate_squares
27
+ numbers = (1..3)
28
+ squares = numbers.collate{ |n| [n, n*n] }
29
+ assert_equal( {1=>1, 2=>4, 3=>9}, squares )
30
+ end
31
+
32
+ def test_collate_roots
33
+ numbers = (1..3)
34
+ sq_roots = numbers.collate{ |n| [n*n, n] }
35
+ assert_equal( {1=>1, 4=>2, 9=>3}, sq_roots )
36
+ end
54
37
 
38
+ def test_collate_inplace!
39
+ a = { :a => 1, :b => 2, :c => 3 }
40
+ e = { :a => 2, :b => 3, :c => 4 }
41
+ a.collate!{ |k,v| { k => v+1 } }
42
+ assert_equal( e, a )
43
+ end
44
+
45
+ def test_collate_inplace_again!
46
+ h = {:a=>1,:b=>2,:c=>3}
47
+ h.collate!{ |k,v| [v, v*v] }
48
+ assert_equal( {1=>1, 2=>4, 3=>9}, h )
49
+ end
55
50
 
51
+ end
@@ -1,3 +1,5 @@
1
+ # Test for facets/advice.rb
2
+
1
3
  require 'test/unit'
2
4
  require 'facets/advice'
3
5
 
@@ -1,3 +1,5 @@
1
+ # Test for facets/annotations.rb
2
+
1
3
  require 'test/unit'
2
4
  require 'facets/annotations'
3
5
 
@@ -1,71 +1,55 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/arguments.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:08 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
1
+ # Test for facets/arguments.rb.
12
2
 
13
- require 'facets/arguments.rb'
3
+ require 'test/unit'
4
+ require 'facets/arguments.rb'
14
5
 
6
+ class TestArguments < Test::Unit::TestCase
15
7
 
8
+ include Console
16
9
 
17
- require 'test/unit'
18
-
19
- class TestArguments < Test::Unit::TestCase
20
-
21
- include Console
22
-
23
- def test_parameters
24
- line = "-x baz --foo=8 bar"
25
- cargs = Arguments.new(line)
26
- args, keys = cargs.parameters
27
- assert_equal(['baz','bar'], args)
28
- assert_equal({'foo'=>'8','x'=>true}, keys)
29
- end
30
-
31
- def test_parameters_with_arity
32
- line = "-g a -x b -x c"
33
- cargs = Arguments.new(line, :g=>1, :x=>1)
34
- args, keys = cargs.parameters
35
- assert_equal({'g'=>'a','x'=>['b','c']}, keys)
36
- assert_equal([], args)
37
- end
38
-
39
- def test_flags
40
- line = "-x baz --foo=8 bar"
41
- cargs = Arguments.new(line)
42
- flags = cargs.flags
43
- assert_equal(['x'], flags)
44
- end
45
-
46
- def test_repeat
47
- line = "-x baz --foo=1 --foo=2 bar"
48
- cargs = Arguments.new(line)
49
- args, keys = cargs.parameters
50
- assert_equal(['baz','bar'], args)
51
- assert_equal({'x'=>true,'foo'=>['1','2']}, keys)
52
- end
10
+ def test_parameters
11
+ line = "-x baz --foo=8 bar"
12
+ cargs = Arguments.new(line)
13
+ args, keys = cargs.parameters
14
+ assert_equal(['baz','bar'], args)
15
+ assert_equal({'foo'=>'8','x'=>true}, keys)
16
+ end
53
17
 
54
- def test_preoptions
55
- line = "-x --foo=7 baz -y bar"
56
- cargs = Arguments.new(line)
57
- flags = cargs.preoptions
58
- assert_equal({'x'=>true,'foo'=>'7'}, flags)
59
- end
18
+ def test_parameters_with_arity
19
+ line = "-g a -x b -x c"
20
+ cargs = Arguments.new(line, :g=>1, :x=>1)
21
+ args, keys = cargs.parameters
22
+ assert_equal({'g'=>'a','x'=>['b','c']}, keys)
23
+ assert_equal([], args)
24
+ end
60
25
 
61
- def test_with_arity
62
- line = "-q baz --aq 5 bar"
63
- cargs = Arguments.new(line,'aq'=>1)
64
- words, flags = cargs.parameters
65
- assert_equal(['baz','bar'],words)
66
- assert_equal({'q'=>true,'aq'=>'5'},flags)
67
- end
26
+ def test_flags
27
+ line = "-x baz --foo=8 bar"
28
+ cargs = Arguments.new(line)
29
+ flags = cargs.flags
30
+ assert_equal(['x'], flags)
68
31
  end
69
32
 
33
+ def test_repeat
34
+ line = "-x baz --foo=1 --foo=2 bar"
35
+ cargs = Arguments.new(line)
36
+ args, keys = cargs.parameters
37
+ assert_equal(['baz','bar'], args)
38
+ assert_equal({'x'=>true,'foo'=>['1','2']}, keys)
39
+ end
70
40
 
41
+ def test_preoptions
42
+ line = "-x --foo=7 baz -y bar"
43
+ cargs = Arguments.new(line)
44
+ flags = cargs.preoptions
45
+ assert_equal({'x'=>true,'foo'=>'7'}, flags)
46
+ end
71
47
 
48
+ def test_with_arity
49
+ line = "-q baz --aq 5 bar"
50
+ cargs = Arguments.new(line,'aq'=>1)
51
+ words, flags = cargs.parameters
52
+ assert_equal(['baz','bar'],words)
53
+ assert_equal({'q'=>true,'aq'=>'5'},flags)
54
+ end
55
+ end