hexdump 0.3.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -6
  3. data/.gitignore +1 -0
  4. data/.yardopts +1 -1
  5. data/ChangeLog.md +79 -6
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +1 -1
  8. data/README.md +500 -137
  9. data/benchmark.rb +29 -22
  10. data/gemspec.yml +2 -1
  11. data/hexdump.gemspec +1 -4
  12. data/lib/hexdump/chars.rb +46 -0
  13. data/lib/hexdump/core_ext/file.rb +68 -6
  14. data/lib/hexdump/core_ext/io.rb +2 -2
  15. data/lib/hexdump/core_ext/kernel.rb +5 -0
  16. data/lib/hexdump/core_ext/string.rb +2 -2
  17. data/lib/hexdump/core_ext/string_io.rb +2 -2
  18. data/lib/hexdump/core_ext.rb +5 -4
  19. data/lib/hexdump/format_string.rb +43 -0
  20. data/lib/hexdump/hexdump.rb +766 -75
  21. data/lib/hexdump/mixin.rb +192 -0
  22. data/lib/hexdump/module_methods.rb +132 -0
  23. data/lib/hexdump/numeric/binary.rb +55 -0
  24. data/lib/hexdump/numeric/char_or_int.rb +95 -0
  25. data/lib/hexdump/numeric/decimal.rb +56 -0
  26. data/lib/hexdump/numeric/exceptions.rb +11 -0
  27. data/lib/hexdump/numeric/hexadecimal.rb +59 -0
  28. data/lib/hexdump/numeric/octal.rb +55 -0
  29. data/lib/hexdump/numeric.rb +5 -0
  30. data/lib/hexdump/reader.rb +313 -0
  31. data/lib/hexdump/theme/ansi.rb +82 -0
  32. data/lib/hexdump/theme/rule.rb +159 -0
  33. data/lib/hexdump/theme.rb +61 -0
  34. data/lib/hexdump/type.rb +233 -0
  35. data/lib/hexdump/types.rb +108 -0
  36. data/lib/hexdump/version.rb +1 -1
  37. data/lib/hexdump.rb +14 -3
  38. data/spec/chars_spec.rb +76 -0
  39. data/spec/core_ext_spec.rb +10 -6
  40. data/spec/format_string_spec.rb +22 -0
  41. data/spec/hexdump_class_spec.rb +1708 -0
  42. data/spec/hexdump_module_spec.rb +23 -0
  43. data/spec/mixin_spec.rb +37 -0
  44. data/spec/numeric/binary_spec.rb +239 -0
  45. data/spec/numeric/char_or_int_spec.rb +210 -0
  46. data/spec/numeric/decimal_spec.rb +317 -0
  47. data/spec/numeric/hexadecimal_spec.rb +320 -0
  48. data/spec/numeric/octal_spec.rb +239 -0
  49. data/spec/reader_spec.rb +866 -0
  50. data/spec/spec_helper.rb +2 -0
  51. data/spec/theme/ansi_spec.rb +242 -0
  52. data/spec/theme/rule_spec.rb +199 -0
  53. data/spec/theme_spec.rb +94 -0
  54. data/spec/type_spec.rb +317 -0
  55. data/spec/types_spec.rb +904 -0
  56. metadata +42 -12
  57. data/.gemtest +0 -0
  58. data/lib/hexdump/dumper.rb +0 -419
  59. data/lib/hexdump/extensions.rb +0 -2
  60. data/spec/dumper_spec.rb +0 -329
  61. data/spec/hexdump_spec.rb +0 -30
data/spec/type_spec.rb ADDED
@@ -0,0 +1,317 @@
1
+ require 'spec_helper'
2
+ require 'hexdump/type'
3
+
4
+ describe Hexdump::Type do
5
+ describe "#initialize" do
6
+ let(:size) { 4 }
7
+ let(:signed) { true }
8
+
9
+ subject { described_class.new(size: size, signed: signed) }
10
+
11
+ it "must set #size" do
12
+ expect(subject.size).to eq(size)
13
+ end
14
+
15
+ it "must not set #endian" do
16
+ expect(subject.endian).to be(nil)
17
+ end
18
+
19
+ it "must set #signed?" do
20
+ expect(subject.signed?).to eq(signed)
21
+ end
22
+
23
+ context "when given endian:" do
24
+ let(:endian) { :big }
25
+
26
+ subject do
27
+ described_class.new(size: size, endian: endian, signed: signed)
28
+ end
29
+
30
+ it "must set #endian" do
31
+ expect(subject.endian).to eq(endian)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#signed?" do
37
+ let(:size) { 4 }
38
+
39
+ subject { described_class.new(size: size, signed: signed) }
40
+
41
+ context "when initialized with signed: true" do
42
+ let(:signed) { true }
43
+
44
+ it do
45
+ expect(subject.signed?).to be(true)
46
+ end
47
+ end
48
+
49
+ context "when initialized with signed: false" do
50
+ let(:signed) { false }
51
+
52
+ it do
53
+ expect(subject.signed?).to be(false)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#unsigned?" do
59
+ let(:size) { 4 }
60
+
61
+ subject { described_class.new(size: size, signed: signed) }
62
+
63
+ context "when initialized with signed: true" do
64
+ let(:signed) { true }
65
+
66
+ it do
67
+ expect(subject.unsigned?).to be(false)
68
+ end
69
+ end
70
+
71
+ context "when initialized with signed: false" do
72
+ let(:signed) { false }
73
+
74
+ it do
75
+ expect(subject.unsigned?).to be(true)
76
+ end
77
+ end
78
+ end
79
+
80
+ describe Hexdump::Type::UInt do
81
+ subject { described_class.new(size: 4) }
82
+
83
+ describe "#initialize" do
84
+ it "must default #signed? to false" do
85
+ expect(subject.signed?).to be(false)
86
+ end
87
+
88
+ it "must default #endian to NATIVE_ENDIAN" do
89
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
90
+ end
91
+ end
92
+ end
93
+
94
+ describe Hexdump::Type::UInt8 do
95
+ it { expect(subject).kind_of?(Hexdump::Type::UInt) }
96
+
97
+ describe "#initialize" do
98
+ it "must default #signed? to false" do
99
+ expect(subject.signed?).to be(false)
100
+ end
101
+
102
+ it "must default #size to 1" do
103
+ expect(subject.size).to be(1)
104
+ end
105
+
106
+ it "must default #endian to nil" do
107
+ expect(subject.endian).to be(nil)
108
+ end
109
+ end
110
+ end
111
+
112
+ describe Hexdump::Type::UInt16 do
113
+ it { expect(subject).kind_of?(Hexdump::Type::UInt) }
114
+
115
+ describe "#initialize" do
116
+ it "must default #signed? to false" do
117
+ expect(subject.signed?).to be(false)
118
+ end
119
+
120
+ it "must default #size to 2" do
121
+ expect(subject.size).to be(2)
122
+ end
123
+
124
+ it "must default #endian to NATIVE_ENDIAN" do
125
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
126
+ end
127
+ end
128
+ end
129
+
130
+ describe Hexdump::Type::UInt32 do
131
+ it { expect(subject).kind_of?(Hexdump::Type::UInt) }
132
+
133
+ describe "#initialize" do
134
+ it "must default #signed? to false" do
135
+ expect(subject.signed?).to be(false)
136
+ end
137
+
138
+ it "must default #size to 4" do
139
+ expect(subject.size).to be(4)
140
+ end
141
+
142
+ it "must default #endian to NATIVE_ENDIAN" do
143
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
144
+ end
145
+ end
146
+ end
147
+
148
+ describe Hexdump::Type::UInt64 do
149
+ it { expect(subject).kind_of?(Hexdump::Type::UInt) }
150
+
151
+ describe "#initialize" do
152
+ it "must default #signed? to false" do
153
+ expect(subject.signed?).to be(false)
154
+ end
155
+
156
+ it "must default #size to 8" do
157
+ expect(subject.size).to be(8)
158
+ end
159
+
160
+ it "must default #endian to NATIVE_ENDIAN" do
161
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
162
+ end
163
+ end
164
+ end
165
+
166
+ describe Hexdump::Type::Int do
167
+ subject { described_class.new(size: 4) }
168
+
169
+ describe "#initialize" do
170
+ it "must default #signed? to true" do
171
+ expect(subject.signed?).to be(true)
172
+ end
173
+
174
+ it "must default #endian to NATIVE_ENDIAN" do
175
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
176
+ end
177
+ end
178
+ end
179
+
180
+ describe Hexdump::Type::Int8 do
181
+ it { expect(subject).kind_of?(Hexdump::Type::Int) }
182
+
183
+ describe "#initialize" do
184
+ it "must default #signed? to true" do
185
+ expect(subject.signed?).to be(true)
186
+ end
187
+
188
+ it "must default #size to 1" do
189
+ expect(subject.size).to be(1)
190
+ end
191
+
192
+ it "must default #endian to nil" do
193
+ expect(subject.endian).to be(nil)
194
+ end
195
+ end
196
+ end
197
+
198
+ describe Hexdump::Type::Int16 do
199
+ it { expect(subject).kind_of?(Hexdump::Type::Int) }
200
+
201
+ describe "#initialize" do
202
+ it "must default #signed? to true" do
203
+ expect(subject.signed?).to be(true)
204
+ end
205
+
206
+ it "must default #size to 2" do
207
+ expect(subject.size).to be(2)
208
+ end
209
+
210
+ it "must default #endian to NATIVE_ENDIAN" do
211
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
212
+ end
213
+ end
214
+ end
215
+
216
+ describe Hexdump::Type::Int32 do
217
+ it { expect(subject).kind_of?(Hexdump::Type::Int) }
218
+
219
+ describe "#initialize" do
220
+ it "must default #signed? to true" do
221
+ expect(subject.signed?).to be(true)
222
+ end
223
+
224
+ it "must default #size to 4" do
225
+ expect(subject.size).to be(4)
226
+ end
227
+
228
+ it "must default #endian to NATIVE_ENDIAN" do
229
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
230
+ end
231
+ end
232
+ end
233
+
234
+ describe Hexdump::Type::Int64 do
235
+ it { expect(subject).kind_of?(Hexdump::Type::Int) }
236
+
237
+ describe "#initialize" do
238
+ it "must default #signed? to true" do
239
+ expect(subject.signed?).to be(true)
240
+ end
241
+
242
+ it "must default #size to 8" do
243
+ expect(subject.size).to be(8)
244
+ end
245
+
246
+ it "must default #endian to NATIVE_ENDIAN" do
247
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
248
+ end
249
+ end
250
+ end
251
+
252
+ describe Hexdump::Type::Char do
253
+ describe "#initialize" do
254
+ it "must set #signed? to true" do
255
+ expect(subject.signed?).to be(true)
256
+ end
257
+
258
+ it "must set #size to 1" do
259
+ expect(subject.size).to eq(1)
260
+ end
261
+
262
+ it "must set #endian to nil" do
263
+ expect(subject.endian).to be(nil)
264
+ end
265
+ end
266
+ end
267
+
268
+ describe Hexdump::Type::UChar do
269
+ describe "#initialize" do
270
+ it "must set #signed? to false" do
271
+ expect(subject.signed?).to be(false)
272
+ end
273
+
274
+ it "must set #size to 1" do
275
+ expect(subject.size).to eq(1)
276
+ end
277
+
278
+ it "must set #endian to nil" do
279
+ expect(subject.endian).to be(nil)
280
+ end
281
+ end
282
+ end
283
+
284
+ describe Hexdump::Type::Float do
285
+ subject { described_class.new(size: 4) }
286
+
287
+ describe "#initialize" do
288
+ it "must default #signed? to true" do
289
+ expect(subject.signed?).to be(true)
290
+ end
291
+
292
+ it "must default #endian to NATIVE_ENDIAN" do
293
+ expect(subject.endian).to eq(Hexdump::Type::NATIVE_ENDIAN)
294
+ end
295
+ end
296
+ end
297
+
298
+ describe Hexdump::Type::Float32 do
299
+ it { expect(subject).to be_kind_of(Hexdump::Type::Float) }
300
+
301
+ describe "#initialize" do
302
+ it "must default #size to 4" do
303
+ expect(subject.size).to be(4)
304
+ end
305
+ end
306
+ end
307
+
308
+ describe Hexdump::Type::Float64 do
309
+ it { expect(subject).to be_kind_of(Hexdump::Type::Float) }
310
+
311
+ describe "#initialize" do
312
+ it "must default #size to 8" do
313
+ expect(subject.size).to be(8)
314
+ end
315
+ end
316
+ end
317
+ end