utilrb 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Changes.txt +20 -0
  2. data/License.txt +26 -0
  3. data/Manifest.txt +64 -0
  4. data/README.txt +44 -0
  5. data/Rakefile +46 -0
  6. data/bm/allocation.rb +7 -0
  7. data/bm/speed.rb +19 -0
  8. data/ext/extconf.rb +5 -0
  9. data/ext/faster.cc +48 -0
  10. data/ext/swap.cc +61 -0
  11. data/ext/value_set.cc +290 -0
  12. data/lib/utilrb.rb +2 -0
  13. data/lib/utilrb/array.rb +2 -0
  14. data/lib/utilrb/array/to_s.rb +16 -0
  15. data/lib/utilrb/common.rb +50 -0
  16. data/lib/utilrb/enumerable.rb +2 -0
  17. data/lib/utilrb/enumerable/null.rb +18 -0
  18. data/lib/utilrb/enumerable/random_element.rb +16 -0
  19. data/lib/utilrb/enumerable/sequence.rb +24 -0
  20. data/lib/utilrb/enumerable/uniq.rb +61 -0
  21. data/lib/utilrb/exception.rb +2 -0
  22. data/lib/utilrb/exception/full_message.rb +8 -0
  23. data/lib/utilrb/gc.rb +2 -0
  24. data/lib/utilrb/gc/force.rb +11 -0
  25. data/lib/utilrb/hash.rb +2 -0
  26. data/lib/utilrb/hash/slice.rb +6 -0
  27. data/lib/utilrb/hash/to_s.rb +6 -0
  28. data/lib/utilrb/hash/to_sym_keys.rb +6 -0
  29. data/lib/utilrb/kernel.rb +2 -0
  30. data/lib/utilrb/kernel/arity.rb +10 -0
  31. data/lib/utilrb/kernel/options.rb +69 -0
  32. data/lib/utilrb/kernel/poll.rb +24 -0
  33. data/lib/utilrb/kernel/require.rb +12 -0
  34. data/lib/utilrb/kernel/swap.rb +2 -0
  35. data/lib/utilrb/logger.rb +3 -0
  36. data/lib/utilrb/logger/forward.rb +15 -0
  37. data/lib/utilrb/logger/hierarchy.rb +34 -0
  38. data/lib/utilrb/module.rb +2 -0
  39. data/lib/utilrb/module/ancestor_p.rb +6 -0
  40. data/lib/utilrb/module/attr_enumerable.rb +28 -0
  41. data/lib/utilrb/module/define_method.rb +30 -0
  42. data/lib/utilrb/module/include.rb +30 -0
  43. data/lib/utilrb/module/inherited_enumerable.rb +122 -0
  44. data/lib/utilrb/object.rb +2 -0
  45. data/lib/utilrb/object/address.rb +14 -0
  46. data/lib/utilrb/object/attribute.rb +89 -0
  47. data/lib/utilrb/object/singleton_class.rb +53 -0
  48. data/lib/utilrb/objectstats.rb +52 -0
  49. data/lib/utilrb/time.rb +2 -0
  50. data/lib/utilrb/time/to_hms.rb +6 -0
  51. data/lib/utilrb/unbound_method.rb +2 -0
  52. data/lib/utilrb/unbound_method/call.rb +5 -0
  53. data/lib/utilrb/value_set.rb +17 -0
  54. data/test/test_array.rb +9 -0
  55. data/test/test_config.rb +4 -0
  56. data/test/test_enumerable.rb +89 -0
  57. data/test/test_gc.rb +39 -0
  58. data/test/test_hash.rb +22 -0
  59. data/test/test_kernel.rb +70 -0
  60. data/test/test_misc.rb +42 -0
  61. data/test/test_module.rb +127 -0
  62. data/test/test_object.rb +65 -0
  63. data/test/test_objectstats.rb +19 -0
  64. data/test/test_unbound_method.rb +23 -0
  65. metadata +128 -0
@@ -0,0 +1,65 @@
1
+ require 'test_config'
2
+
3
+ require 'utilrb/object'
4
+
5
+ class TC_Object < Test::Unit::TestCase
6
+ def test_address
7
+ foo = Object.new
8
+ foo.to_s =~ /#<Object:0x([0-9a-f]+)>/
9
+ foo_address = $1
10
+ assert_equal(foo_address, foo.address.to_s(16), "#{foo} #{foo.address} #{foo.object_id}")
11
+ end
12
+
13
+ def check_attribute(object)
14
+ assert(object.respond_to?(:as_hash))
15
+ assert(object.respond_to?(:as_hash=))
16
+ assert(object.respond_to?(:block))
17
+ assert(object.respond_to?(:block=))
18
+ hash_attribute = object.as_hash
19
+ block_attribute = object.block
20
+ assert(Hash === hash_attribute)
21
+ assert(Array === block_attribute)
22
+
23
+ new_value = Time.now
24
+
25
+ assert_same(hash_attribute, object.as_hash)
26
+ object.as_hash = new_value
27
+ assert_same(new_value, object.as_hash)
28
+
29
+ assert_same(block_attribute, object.block)
30
+ object.block = new_value
31
+ assert_same(object.block, new_value)
32
+ end
33
+ def test_attribute
34
+ klass = Class.new do
35
+ attribute :as_hash => Hash.new
36
+ attribute(:block) { Array.new }
37
+ class_attribute :as_hash => Hash.new # do NOT use :hash here as it would override #hash which is a quite useful method ...
38
+ class_attribute(:block) { Array.new }
39
+ end
40
+
41
+ obj1, obj2 = klass.new, klass.new
42
+ check_attribute(obj1)
43
+ check_attribute(obj2)
44
+
45
+ obj1, obj2 = klass.new, klass.new
46
+ assert_same(obj1.as_hash, obj2.as_hash)
47
+ obj1.as_hash = Hash.new
48
+ assert_not_same(obj1.as_hash, obj2.as_hash)
49
+
50
+ assert_not_same(obj1.block, obj2.block)
51
+ obj1.block = obj2.block
52
+ assert_same(obj1.block, obj2.block)
53
+ end
54
+
55
+ def test_singleton_class
56
+ klass = Class.new
57
+ object = klass.new
58
+ assert(! object.has_singleton?)
59
+ assert_equal(object, object.singleton_class.singleton_instance)
60
+ assert(object.has_singleton?)
61
+ assert_equal(klass, object.singleton_class.superclass)
62
+ assert_equal([object.singleton_class, klass, Object, Kernel], object.singleton_class.ancestors)
63
+ end
64
+ end
65
+
@@ -0,0 +1,19 @@
1
+ require 'test_config'
2
+
3
+ require 'utilrb/objectstats'
4
+
5
+ class TC_ObjectStats < Test::Unit::TestCase
6
+ def test_object_stats
7
+ assert( ObjectStats.profile { ObjectStats.count }.empty?, "Object allocation profile changed" )
8
+ assert_equal({ Hash => 1 }, ObjectStats.profile { ObjectStats.count_by_class }, "Object allocation profile changed")
9
+ assert_equal({ Array => 1 }, ObjectStats.profile { test = [] })
10
+ assert_equal({ Array => 2, Hash => 1 }, ObjectStats.profile { a, b = [], {} })
11
+
12
+ GC.start
13
+ GC.disable
14
+ Hash.new
15
+ assert([Hash, 1], ObjectStats.profile { Hash.new }.collect { |klass, count| [klass, count] })
16
+ assert([Hash, -1], ObjectStats.profile { GC.start }.collect { |klass, count| [klass, count] })
17
+ end
18
+ end
19
+
@@ -0,0 +1,23 @@
1
+ require 'test_config'
2
+ require 'utilrb/unbound_method'
3
+ require 'flexmock'
4
+
5
+ class TC_UnboundMethod < Test::Unit::TestCase
6
+ def test_call
7
+ FlexMock.use do |mock|
8
+ klass = Class.new do
9
+ define_method(:mock) { mock }
10
+ def tag(value, &block)
11
+ mock.method_called(value)
12
+ block.call(value)
13
+ end
14
+ end
15
+ obj = klass.new
16
+
17
+ mock.should_receive(:method_called).with(42).once
18
+ mock.should_receive(:block_called).with(42).once
19
+ klass.instance_method(:tag).call(obj, 42) { |value| mock.block_called(value) }
20
+ end
21
+ end
22
+ end
23
+
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: utilrb
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.2"
7
+ date: 2006-11-22 00:00:00 +01:00
8
+ summary: Yet another Ruby toolkit
9
+ require_paths:
10
+ - lib
11
+ - ext
12
+ email: sylvain.joyeux@m4x.org
13
+ homepage: " http://utilrb.rubyforge.org"
14
+ rubyforge_project: utilrb
15
+ description: "This work is licensed under the BSD license. See License.txt for details == What is Utilrb ? Utilrb is yet another Ruby toolkit, in the spirit of facets. It includes all the standard class extensions I use in my own projects like Genom.rb. == Utilrb's C extension Utilrb includes a C extension in ext/. It is optional, but some of the functionalities will be disabled if it is not present. Trying to require a file in which there is a C-only feature will yield a warning on STDOUT. * some features have a Ruby version, but a C version is provided for performance: - Enumerable#each_uniq"
16
+ autorequire:
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: true
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - Sylvain Joyeux
32
+ files:
33
+ - bm/allocation.rb
34
+ - bm/speed.rb
35
+ - Changes.txt
36
+ - ext/extconf.rb
37
+ - ext/faster.cc
38
+ - ext/swap.cc
39
+ - ext/value_set.cc
40
+ - lib/utilrb/array.rb
41
+ - lib/utilrb/array/to_s.rb
42
+ - lib/utilrb/common.rb
43
+ - lib/utilrb/enumerable/null.rb
44
+ - lib/utilrb/enumerable/random_element.rb
45
+ - lib/utilrb/enumerable.rb
46
+ - lib/utilrb/enumerable/sequence.rb
47
+ - lib/utilrb/enumerable/uniq.rb
48
+ - lib/utilrb/exception/full_message.rb
49
+ - lib/utilrb/exception.rb
50
+ - lib/utilrb/gc/force.rb
51
+ - lib/utilrb/gc.rb
52
+ - lib/utilrb/hash.rb
53
+ - lib/utilrb/hash/slice.rb
54
+ - lib/utilrb/hash/to_s.rb
55
+ - lib/utilrb/hash/to_sym_keys.rb
56
+ - lib/utilrb/kernel/arity.rb
57
+ - lib/utilrb/kernel/options.rb
58
+ - lib/utilrb/kernel/poll.rb
59
+ - lib/utilrb/kernel.rb
60
+ - lib/utilrb/kernel/require.rb
61
+ - lib/utilrb/kernel/swap.rb
62
+ - lib/utilrb/logger/forward.rb
63
+ - lib/utilrb/logger/hierarchy.rb
64
+ - lib/utilrb/logger.rb
65
+ - lib/utilrb/module/ancestor_p.rb
66
+ - lib/utilrb/module/attr_enumerable.rb
67
+ - lib/utilrb/module/define_method.rb
68
+ - lib/utilrb/module/include.rb
69
+ - lib/utilrb/module/inherited_enumerable.rb
70
+ - lib/utilrb/module.rb
71
+ - lib/utilrb/object/address.rb
72
+ - lib/utilrb/object/attribute.rb
73
+ - lib/utilrb/object.rb
74
+ - lib/utilrb/object/singleton_class.rb
75
+ - lib/utilrb/objectstats.rb
76
+ - lib/utilrb.rb
77
+ - lib/utilrb/time.rb
78
+ - lib/utilrb/time/to_hms.rb
79
+ - lib/utilrb/unbound_method/call.rb
80
+ - lib/utilrb/unbound_method.rb
81
+ - lib/utilrb/value_set.rb
82
+ - License.txt
83
+ - Manifest.txt
84
+ - Rakefile
85
+ - README.txt
86
+ - test/test_array.rb
87
+ - test/test_config.rb
88
+ - test/test_enumerable.rb
89
+ - test/test_gc.rb
90
+ - test/test_hash.rb
91
+ - test/test_kernel.rb
92
+ - test/test_misc.rb
93
+ - test/test_module.rb
94
+ - test/test_object.rb
95
+ - test/test_objectstats.rb
96
+ - test/test_unbound_method.rb
97
+ test_files:
98
+ - test/test_misc.rb
99
+ - test/test_module.rb
100
+ - test/test_unbound_method.rb
101
+ - test/test_config.rb
102
+ - test/test_kernel.rb
103
+ - test/test_object.rb
104
+ - test/test_gc.rb
105
+ - test/test_array.rb
106
+ - test/test_enumerable.rb
107
+ - test/test_hash.rb
108
+ - test/test_objectstats.rb
109
+ rdoc_options: []
110
+
111
+ extra_rdoc_files: []
112
+
113
+ executables: []
114
+
115
+ extensions: []
116
+
117
+ requirements: []
118
+
119
+ dependencies:
120
+ - !ruby/object:Gem::Dependency
121
+ name: facets
122
+ version_requirement:
123
+ version_requirements: !ruby/object:Gem::Version::Requirement
124
+ requirements:
125
+ - - ">"
126
+ - !ruby/object:Gem::Version
127
+ version: 0.0.0
128
+ version: