cgen 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/History.txt +199 -0
- data/README.txt +34 -0
- data/examples/bench.rb +14 -0
- data/examples/complex.rb +63 -0
- data/examples/complex2.rb +48 -0
- data/examples/cshadow-example.rb +55 -0
- data/examples/cshadow-point.rb +58 -0
- data/examples/ctest.rb +34 -0
- data/examples/ctest2.rb +32 -0
- data/examples/ctest3.rb +179 -0
- data/examples/ctest4.rb +18 -0
- data/examples/ctest5.rb +27 -0
- data/examples/example-ruby-talk-30April2004.rb +65 -0
- data/examples/fixed-array.rb +221 -0
- data/examples/inherit-example.rb +26 -0
- data/examples/inherit-example.txt +80 -0
- data/examples/instance-eval.rb +66 -0
- data/examples/ivset.rb +55 -0
- data/examples/marshal-test.rb +19 -0
- data/examples/matrix.rb +91 -0
- data/examples/modular-def.rb +87 -0
- data/examples/objattr.rb +46 -0
- data/examples/opaque-struct-test.rb +36 -0
- data/examples/sample.rb +184 -0
- data/examples/struct.rb +103 -0
- data/examples/test.rb +24 -0
- data/examples/yaml.rb +56 -0
- data/install.rb +1015 -0
- data/lib/cgen/attribute.rb +414 -0
- data/lib/cgen/cgen.rb +2041 -0
- data/lib/cgen/cshadow.rb +1037 -0
- data/lib/cgen/inherit.rb +46 -0
- data/rakefile +42 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- data/test/test-attribute.rb +430 -0
- data/test/test-cgen.rb +127 -0
- data/test/test-cshadow.rb +289 -0
- data/test/test.rb +17 -0
- metadata +123 -0
data/tasks/svn.rake
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
if HAVE_SVN
|
3
|
+
|
4
|
+
unless PROJ.svn.root
|
5
|
+
info = %x/svn info ./
|
6
|
+
m = %r/^Repository Root:\s+(.*)$/.match(info)
|
7
|
+
PROJ.svn.root = (m.nil? ? '' : m[1])
|
8
|
+
end
|
9
|
+
PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
|
10
|
+
|
11
|
+
namespace :svn do
|
12
|
+
|
13
|
+
# A prerequisites task that all other tasks depend upon
|
14
|
+
task :prereqs
|
15
|
+
|
16
|
+
desc 'Show tags from the SVN repository'
|
17
|
+
task :show_tags => 'svn:prereqs' do |t|
|
18
|
+
tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
|
19
|
+
tags.gsub!(%r/\/$/, '')
|
20
|
+
tags = tags.split("\n").sort {|a,b| b <=> a}
|
21
|
+
puts tags
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Create a new tag in the SVN repository'
|
25
|
+
task :create_tag => 'svn:prereqs' do |t|
|
26
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
27
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
28
|
+
|
29
|
+
svn = PROJ.svn
|
30
|
+
trunk = File.join(svn.root, svn.trunk)
|
31
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
32
|
+
tag = File.join(svn.root, svn.tags, tag)
|
33
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
34
|
+
|
35
|
+
puts "Creating SVN tag '#{tag}'"
|
36
|
+
unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
|
37
|
+
abort "Tag creation failed"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end # namespace :svn
|
42
|
+
|
43
|
+
task 'gem:release' => 'svn:create_tag'
|
44
|
+
|
45
|
+
end # if PROJ.svn.path
|
46
|
+
|
47
|
+
# EOF
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = PROJ.libs
|
9
|
+
t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
10
|
+
else PROJ.test.files end
|
11
|
+
t.ruby_opts += PROJ.ruby_opts
|
12
|
+
t.ruby_opts += PROJ.test.opts
|
13
|
+
end
|
14
|
+
|
15
|
+
if HAVE_RCOV
|
16
|
+
desc 'Run rcov on the unit tests'
|
17
|
+
task :rcov => :clobber_rcov do
|
18
|
+
opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
|
19
|
+
opts = opts.join(' ')
|
20
|
+
files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
21
|
+
else PROJ.test.files end
|
22
|
+
files = files.join(' ')
|
23
|
+
sh "#{RCOV} #{files} #{opts}"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :clobber_rcov do
|
27
|
+
rm_r 'coverage' rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :test
|
32
|
+
|
33
|
+
desc 'Alias to test:run'
|
34
|
+
task :test => 'test:run'
|
35
|
+
|
36
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# EOF
|
data/tasks/zentest.rake
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
if HAVE_ZENTEST
|
2
|
+
|
3
|
+
# --------------------------------------------------------------------------
|
4
|
+
if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
|
5
|
+
require 'autotest'
|
6
|
+
|
7
|
+
namespace :test do
|
8
|
+
task :autotest do
|
9
|
+
Autotest.run
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Run the autotest loop"
|
14
|
+
task :autotest => 'test:autotest'
|
15
|
+
|
16
|
+
end # if test
|
17
|
+
|
18
|
+
# --------------------------------------------------------------------------
|
19
|
+
if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
|
20
|
+
require 'autotest/rspec'
|
21
|
+
|
22
|
+
namespace :spec do
|
23
|
+
task :autotest do
|
24
|
+
load '.autotest' if test(?f, '.autotest')
|
25
|
+
Autotest::Rspec.run
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Run the autotest loop"
|
30
|
+
task :autotest => 'spec:autotest'
|
31
|
+
|
32
|
+
end # if rspec
|
33
|
+
|
34
|
+
end # if HAVE_ZENTEST
|
35
|
+
|
36
|
+
# EOF
|
@@ -0,0 +1,430 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'cgen/cshadow'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Tests in this file focus on the behavior of individual attributes:
|
6
|
+
# accessors, initial values, type conversion and checking,
|
7
|
+
# garbage collection (mark and free functions), etc.
|
8
|
+
#
|
9
|
+
|
10
|
+
class AttributeSample
|
11
|
+
include CShadow
|
12
|
+
end
|
13
|
+
|
14
|
+
class AttributeTest < Test::Unit::TestCase
|
15
|
+
def default_test; end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ObjectAttributeTest < AttributeTest
|
19
|
+
class ObjectAttributeSample < AttributeSample
|
20
|
+
def self.foo; end
|
21
|
+
shadow_attr_accessor :x => Object, :y => String,
|
22
|
+
:z => ObjectAttributeSample
|
23
|
+
end
|
24
|
+
|
25
|
+
def test__initial
|
26
|
+
@oas = ObjectAttributeSample.new
|
27
|
+
assert_equal(nil, @oas.x)
|
28
|
+
assert_equal(nil, @oas.y)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_accessor
|
32
|
+
@oas = ObjectAttributeSample.new
|
33
|
+
@oas.x = lx = Object.new
|
34
|
+
@oas.y = ly = "A string"
|
35
|
+
@oas.z = @oas
|
36
|
+
assert_same(lx, @oas.x)
|
37
|
+
assert_same(ly, @oas.y)
|
38
|
+
assert_same(@oas, @oas.z)
|
39
|
+
|
40
|
+
@oas.x = nil
|
41
|
+
@oas.y = nil
|
42
|
+
assert_equal(nil, @oas.x)
|
43
|
+
assert_equal(nil, @oas.y)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_typecheck
|
47
|
+
@oas = ObjectAttributeSample.new
|
48
|
+
assert_raises(TypeError) {
|
49
|
+
@oas.y = 5
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def make_thing c
|
54
|
+
@oas.x = c.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def trash_thing
|
58
|
+
@oas.x = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_gc
|
62
|
+
@oas = ObjectAttributeSample.new
|
63
|
+
c = Class.new
|
64
|
+
|
65
|
+
10.times do
|
66
|
+
make_thing c
|
67
|
+
end
|
68
|
+
GC.start
|
69
|
+
assert_equal(1, ObjectSpace.each_object(c) {})
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_marshal_uninitialized
|
73
|
+
@oas = ObjectAttributeSample.new
|
74
|
+
s = Marshal.dump @oas
|
75
|
+
t = Marshal.load s
|
76
|
+
assert_equal(nil, t.x)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_marshal_nil
|
80
|
+
@oas = ObjectAttributeSample.new
|
81
|
+
@oas.x = nil
|
82
|
+
s = Marshal.dump @oas
|
83
|
+
t = Marshal.load s
|
84
|
+
assert_equal(nil, t.x)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_marshal
|
88
|
+
@oas = ObjectAttributeSample.new
|
89
|
+
|
90
|
+
@oas.x = "fred"
|
91
|
+
copy = Marshal.load(Marshal.dump(@oas))
|
92
|
+
assert_equal("fred", copy.x)
|
93
|
+
|
94
|
+
@oas.x = nil
|
95
|
+
copy = Marshal.load(Marshal.dump(@oas))
|
96
|
+
assert_equal(nil, copy.x)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class ShadowObjectAttributeTest < AttributeTest
|
101
|
+
class ShadowObjectAttributeSample < AttributeSample
|
102
|
+
shadow_attr_accessor :x => [ShadowObjectAttributeSample]
|
103
|
+
shadow_attr_accessor :z => "int z"
|
104
|
+
end
|
105
|
+
|
106
|
+
class Sub < ShadowObjectAttributeSample
|
107
|
+
shadow_attr_accessor :y => "int y"
|
108
|
+
end
|
109
|
+
|
110
|
+
def test__initial
|
111
|
+
@sas = ShadowObjectAttributeSample.new
|
112
|
+
assert_equal(nil, @sas.x)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_accessor
|
116
|
+
@sas = ShadowObjectAttributeSample.new
|
117
|
+
@sas.x = lx = ShadowObjectAttributeSample.new
|
118
|
+
assert_same(lx, @sas.x)
|
119
|
+
@sas.x = nil
|
120
|
+
assert_equal(nil, @sas.x)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_typecheck
|
124
|
+
@sas = ShadowObjectAttributeSample.new
|
125
|
+
assert_raises(TypeError) {
|
126
|
+
@sas.x = 5
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
def make_thing c
|
131
|
+
@sas.x = c.new
|
132
|
+
end
|
133
|
+
|
134
|
+
def trash_thing
|
135
|
+
@sas.x = nil
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_gc
|
139
|
+
@sas = ShadowObjectAttributeSample.new
|
140
|
+
c = ShadowObjectAttributeSample
|
141
|
+
|
142
|
+
GC.start
|
143
|
+
n = ObjectSpace.each_object(c) {}
|
144
|
+
10.times do
|
145
|
+
make_thing c
|
146
|
+
end
|
147
|
+
GC.start
|
148
|
+
assert_equal(n+1, ObjectSpace.each_object(c) {})
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_marshal_uninitialized
|
152
|
+
@sas = ShadowObjectAttributeSample.new
|
153
|
+
s = Marshal.dump @sas
|
154
|
+
t = Marshal.load s
|
155
|
+
assert_equal(nil, t.x)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_marshal_nil
|
159
|
+
@sas = ShadowObjectAttributeSample.new
|
160
|
+
@sas.x = nil
|
161
|
+
s = Marshal.dump @sas
|
162
|
+
t = Marshal.load s
|
163
|
+
assert_equal(nil, t.x)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_marshal
|
167
|
+
@sas1 = ShadowObjectAttributeSample.new
|
168
|
+
@sas2 = ShadowObjectAttributeSample.new
|
169
|
+
|
170
|
+
@sas1.x = @sas2
|
171
|
+
@sas2.x = @sas1
|
172
|
+
s = Marshal.dump @sas1
|
173
|
+
t = Marshal.load s
|
174
|
+
assert_same(t, t.x.x)
|
175
|
+
|
176
|
+
@sas1.x = nil
|
177
|
+
@sas1.z = 3
|
178
|
+
s = Marshal.dump @sas1
|
179
|
+
t = Marshal.load s
|
180
|
+
assert_equal(nil, t.x)
|
181
|
+
assert_equal(3, t.z)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_sub
|
185
|
+
@sas = ShadowObjectAttributeSample.new
|
186
|
+
sub = Sub.new
|
187
|
+
sub.y = 3
|
188
|
+
@sas.x = sub
|
189
|
+
assert_equal(3, @sas.x.y)
|
190
|
+
|
191
|
+
s = Marshal.dump sub
|
192
|
+
t = Marshal.load s
|
193
|
+
assert_equal(3, t.y)
|
194
|
+
|
195
|
+
s = Marshal.dump @sas
|
196
|
+
t = Marshal.load s
|
197
|
+
assert_equal(3, t.x.y)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class IntAttributeTest < AttributeTest
|
202
|
+
class IntAttributeSample < AttributeSample
|
203
|
+
shadow_attr_accessor :x => "int x"
|
204
|
+
end
|
205
|
+
|
206
|
+
def test__initial
|
207
|
+
@ias = IntAttributeSample.new
|
208
|
+
assert_equal(0, @ias.x)
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_accessor
|
212
|
+
@ias = IntAttributeSample.new
|
213
|
+
@ias.x = 5
|
214
|
+
assert_equal(5, @ias.x)
|
215
|
+
@ias.x = -5.1
|
216
|
+
assert_equal(-5, @ias.x)
|
217
|
+
@ias.x = 2**31-1
|
218
|
+
assert_equal(2**31-1, @ias.x)
|
219
|
+
assert_raises(RangeError) {@ias.x = 2**31}
|
220
|
+
@ias.x = -2**31
|
221
|
+
assert_equal(-2**31, @ias.x)
|
222
|
+
assert_raises(RangeError) {@ias.x = -2**31 - 1}
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_conversion
|
226
|
+
@ias = IntAttributeSample.new
|
227
|
+
@ias.x = 5.1
|
228
|
+
assert_equal(5, @ias.x)
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_typecheck
|
232
|
+
@ias = IntAttributeSample.new
|
233
|
+
assert_raises(TypeError) {
|
234
|
+
@ias.x = "Foo"
|
235
|
+
}
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_marshal
|
239
|
+
@ias = IntAttributeSample.new
|
240
|
+
@ias.x = -11
|
241
|
+
s = Marshal.dump @ias
|
242
|
+
t = Marshal.load s
|
243
|
+
assert_equal(@ias.x, t.x)
|
244
|
+
|
245
|
+
@ias.x = 2**31-1
|
246
|
+
s = Marshal.dump @ias
|
247
|
+
t = Marshal.load s
|
248
|
+
assert_equal(@ias.x, t.x)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
class LongAttributeTest < AttributeTest
|
253
|
+
class LongAttributeSample < AttributeSample
|
254
|
+
shadow_attr_accessor :x => "long x"
|
255
|
+
end
|
256
|
+
|
257
|
+
def test__initial
|
258
|
+
@las = LongAttributeSample.new
|
259
|
+
assert_equal(0, @las.x)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_accessor
|
263
|
+
@las = LongAttributeSample.new
|
264
|
+
@las.x = 5
|
265
|
+
assert_equal(5, @las.x)
|
266
|
+
@las.x = -5.1
|
267
|
+
assert_equal(-5, @las.x)
|
268
|
+
@las.x = 2**31-1
|
269
|
+
assert_equal(2**31-1, @las.x)
|
270
|
+
assert_raises(RangeError) {@las.x = 2**31}
|
271
|
+
@las.x = -2**31
|
272
|
+
assert_equal(-2**31, @las.x)
|
273
|
+
assert_raises(RangeError) {@las.x = -2**31 - 1}
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_conversion
|
277
|
+
@las = LongAttributeSample.new
|
278
|
+
@las.x = 5.1
|
279
|
+
assert_equal(5, @las.x)
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_typecheck
|
283
|
+
@las = LongAttributeSample.new
|
284
|
+
assert_raises(TypeError) {
|
285
|
+
@las.x = "Foo"
|
286
|
+
}
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_marshal
|
290
|
+
@las = LongAttributeSample.new
|
291
|
+
@las.x = -11
|
292
|
+
s = Marshal.dump @las
|
293
|
+
t = Marshal.load s
|
294
|
+
assert_equal(@las.x, t.x)
|
295
|
+
|
296
|
+
@las.x = 2**31-1
|
297
|
+
s = Marshal.dump @las
|
298
|
+
t = Marshal.load s
|
299
|
+
assert_equal(@las.x, t.x)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
class DoubleAttributeTest < AttributeTest
|
304
|
+
class DoubleAttributeSample < AttributeSample
|
305
|
+
shadow_attr_accessor :x => "double x"
|
306
|
+
end
|
307
|
+
|
308
|
+
def test__initial
|
309
|
+
@das = DoubleAttributeSample.new
|
310
|
+
assert_equal(0, @das.x)
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_accessor
|
314
|
+
@das = DoubleAttributeSample.new
|
315
|
+
@das.x = 5.1
|
316
|
+
assert_equal(5.1, @das.x)
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_conversion
|
320
|
+
@das = DoubleAttributeSample.new
|
321
|
+
@das.x = 5
|
322
|
+
assert_equal(5, @das.x)
|
323
|
+
end
|
324
|
+
|
325
|
+
def test_typecheck
|
326
|
+
@das = DoubleAttributeSample.new
|
327
|
+
assert_raises(TypeError) {
|
328
|
+
@das.x = "Foo"
|
329
|
+
}
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_marshal
|
333
|
+
@das = DoubleAttributeSample.new
|
334
|
+
@das.x = -11.8
|
335
|
+
s = Marshal.dump @das
|
336
|
+
t = Marshal.load s
|
337
|
+
assert_equal(@das.x, t.x)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
class CharPointerAttributeTest < AttributeTest
|
342
|
+
class CharPointerSample < AttributeSample
|
343
|
+
shadow_attr_accessor :x => "char *x"
|
344
|
+
end
|
345
|
+
|
346
|
+
def test__initial
|
347
|
+
@cps = CharPointerSample.new
|
348
|
+
assert_equal(nil, @cps.x)
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_accessor
|
352
|
+
@cps = CharPointerSample.new
|
353
|
+
str = "foo"
|
354
|
+
@cps.x = str
|
355
|
+
assert_equal("foo", @cps.x)
|
356
|
+
assert(str.object_id != @cps.x.object_id)
|
357
|
+
|
358
|
+
@cps.x = nil
|
359
|
+
assert_equal(nil, @cps.x)
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_typecheck
|
363
|
+
@cps = CharPointerSample.new
|
364
|
+
assert_raises(TypeError) {
|
365
|
+
@cps.x = 5
|
366
|
+
}
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_marshal
|
370
|
+
@cps = CharPointerSample.new
|
371
|
+
@cps.x = "a string"
|
372
|
+
s = Marshal.dump @cps
|
373
|
+
t = Marshal.load s
|
374
|
+
assert_equal(@cps.x, t.x)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
# General test of marshaling shadow objects.
|
379
|
+
class MarshalSample < AttributeSample
|
380
|
+
shadow_attr_accessor :x => Object, :y => String
|
381
|
+
attr_accessor :t
|
382
|
+
end
|
383
|
+
|
384
|
+
class MarshalTest < Test::Unit::TestCase
|
385
|
+
def test_marshal_ivars
|
386
|
+
ms = MarshalSample.new
|
387
|
+
ms.x = ["a", :b]
|
388
|
+
ms.y = "fuzz"
|
389
|
+
ms.t = {3.79 => "zap"}
|
390
|
+
ms.instance_eval {@u = 4}
|
391
|
+
|
392
|
+
str = Marshal.dump ms
|
393
|
+
copy = Marshal.load str
|
394
|
+
|
395
|
+
assert_equal(ms.class, copy.class)
|
396
|
+
assert_equal(ms.x, copy.x)
|
397
|
+
assert_equal(ms.y, copy.y)
|
398
|
+
assert_equal(ms.t, copy.t)
|
399
|
+
assert_equal(ms.instance_eval {@u}, copy.instance_eval {@u})
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_link_and_proc
|
403
|
+
ms1 = MarshalSample.new
|
404
|
+
ms2 = MarshalSample.new
|
405
|
+
ms3 = MarshalSample.new
|
406
|
+
|
407
|
+
ms1.x = ms3
|
408
|
+
ms1.t = ms2
|
409
|
+
|
410
|
+
ms2.x = ms3
|
411
|
+
ms3.x = ms1
|
412
|
+
|
413
|
+
count = 0
|
414
|
+
str = Marshal.dump ms1
|
415
|
+
copy = Marshal.load str, proc { |x|
|
416
|
+
if x.class == MarshalSample then count += 1 end
|
417
|
+
}
|
418
|
+
|
419
|
+
assert_same(copy.x, copy.t.x)
|
420
|
+
assert_same(copy.x.x, copy)
|
421
|
+
assert_equal(3, count)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
require 'fileutils'
|
426
|
+
dir = File.join("tmp", RUBY_VERSION)
|
427
|
+
FileUtils.mkpath dir
|
428
|
+
Dir.chdir dir do
|
429
|
+
AttributeSample.commit
|
430
|
+
end
|