1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# DISCLAIMER: ALL THIS CODE IS AI GENERATED
# Generates a marshal file exercising every type the reikland parser handles,
# including edge-case values for numeric types.
#
# Usage: ruby generate.rb
# Output: all_types.marshal in the same directory as this script
; end
@x = x
@y = y
end
end
= Struct.new(:x, :y)
attr_reader :payload
@payload = payload
end
@payload
end
new(str)
end
end
attr_reader :data
@data = data
end
@data
end
@data = obj
end
end
; end
# A string used twice to trigger ObjectReference (@)
shared_string =
# A hash with a default value to trigger HashDefault (})
hash_with_default = Hash.new(42)
hash_with_default[:a] = 1
hash_with_default[:b] = 2
# An object extended with a module to trigger Extended (e)
extended_obj = TestObject.new(10, 20)
extended_obj.extend(TestModule)
data = [
# -- Nil, True, False --
nil,
true,
false,
# -- Fixnum edge cases --
# Zero (encoded as 0x00)
0,
# Single-byte positive (encoded as value + 5, range 1..122)
1,
122,
# Single-byte negative (encoded as value - 5, range -123..-1)
-1,
-123,
# 1-byte positive (0x01 prefix)
123,
255,
# 1-byte negative (0xff prefix)
-124,
-256,
# 2-byte positive (0x02 prefix)
256,
65535,
# 2-byte negative (0xfe prefix)
-257,
-65536,
# 3-byte positive (0x03 prefix)
65536,
16777215,
# 3-byte negative (0xfd prefix)
-65537,
-16777216,
# 4-byte (0x04/0xfc prefix)
16777216,
1073741823, # max fixnum (2^30 - 1)
-16777217,
-1073741824, # min fixnum -(2^30)
# -- Float edge cases --
0.0,
-0.0,
1.5,
-1.5,
Float::INFINITY,
-Float::INFINITY,
Float::NAN,
1.7976931348623157e+308, # Float::MAX (DBL_MAX)
2.2250738585072014e-308, # Float::MIN (smallest normal)
5.0e-324, # smallest subnormal (Float::MIN * Float::EPSILON)
# -- Bignum edge cases --
2**30, # just above fixnum range (positive)
-(2**30 + 1), # just below fixnum range (negative)
2**64, # large positive
-(2**64), # large negative
2**128, # very large
# -- Symbol and SymbolLink --
# :test_symbol is new -> Symbol (:)
# it will appear again inside hashes/objects -> SymbolLink (;)
:test_symbol,
# -- String (wrapped in Instance for encoding) --
,
,
.b, # ASCII-8BIT / binary encoding
, # multi-byte UTF-8
# -- Regex (wrapped in Instance for encoding) --
,
,
# -- Array --
[],
[1, , :three, 4.0],
# -- Hash --
{},
{ a: 1, b: , c: :three },
# -- HashDefault (}) --
hash_with_default,
# -- Object (o) --
TestObject.new(42, ),
# -- Struct (S) --
TestStruct.new(100, 200),
# -- Extended (e) --
extended_obj,
# -- Class (c) --
String,
# -- Module (m) --
Kernel,
# -- UserDefined (u) --
UserDefinedClass.new(),
# -- UserMarshal (U) --
UserMarshalClass.new([10, 20, 30]),
# -- UserString (C) --
MyString.new(),
# -- ObjectReference (@) --
# shared_string appears twice; second occurrence triggers @
shared_string,
shared_string,
]
output_path = File.join(__dir__, )
File.binwrite(output_path, Marshal.dump(data))
puts