hexy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/CHANGELOG +14 -0
- data/COPYING +728 -0
- data/LICENSE +58 -0
- data/README +79 -0
- data/Rakefile +124 -0
- data/THANKS +0 -0
- data/TODO +5 -0
- data/lib/hexy.rb +136 -0
- data/test/hexy_text.rb +127 -0
- metadata +76 -0
data/LICENSE
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
This package is copyrighted free software by Tim Becker <tim@kuriositaet.de>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the GPL
|
3
|
+
(see COPYING.txt file), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) rename any non-standard executables so the names do not conflict
|
21
|
+
with standard executables, which must also be provided.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or executable
|
26
|
+
form, provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the executables and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c) give non-standard executables non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under this terms.
|
43
|
+
|
44
|
+
They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
|
45
|
+
files under the ./missing directory. See each file for the copying
|
46
|
+
condition.
|
47
|
+
|
48
|
+
5. The scripts and library files supplied as input to or produced as
|
49
|
+
output from the software do not automatically fall under the
|
50
|
+
copyright of the software, but belong to whomever generated them,
|
51
|
+
and may be sold commercially, and may be aggregated with this
|
52
|
+
software.
|
53
|
+
|
54
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
55
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
56
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
57
|
+
PURPOSE.
|
58
|
+
|
data/README
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
= hexy -- utility to create hex dumps
|
3
|
+
|
4
|
+
`hexy` is a ruby library that's easy to use to create hex dumps from
|
5
|
+
within your ruby scripts. It contains a number of options to configure
|
6
|
+
how the hex dumb will end up looking.
|
7
|
+
|
8
|
+
It should create a pleasant looking hex dumb by default:
|
9
|
+
|
10
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789"
|
11
|
+
puts b.to_s
|
12
|
+
|
13
|
+
results in this dump:
|
14
|
+
|
15
|
+
0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a .......b cdefghij
|
16
|
+
0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a klmnopqr stuvwxyz
|
17
|
+
0000020: 30 31 32 33 34 35 36 37 38 39 01234567 89
|
18
|
+
|
19
|
+
but it's also possible to configure:
|
20
|
+
|
21
|
+
* Line numbering
|
22
|
+
* Line width
|
23
|
+
* Format
|
24
|
+
* Case of hex decimals
|
25
|
+
* Presence of the ASCII annotation in the right column.
|
26
|
+
|
27
|
+
This mean you can do exciting dumps like:
|
28
|
+
|
29
|
+
0000000: 0001 0305 1f0a 0962 .... ...b
|
30
|
+
0000008: 6364 6566 6768 696a cdef ghij
|
31
|
+
0000010: 6b6c 6d6e 6f70 7172 klmn opqr
|
32
|
+
0000018: 7374 7576 7778 797a stuv wxyz
|
33
|
+
0000020: 3031 3233 3435 3637 0123 4567
|
34
|
+
0000028: 3839 89
|
35
|
+
|
36
|
+
or even:
|
37
|
+
|
38
|
+
0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a
|
39
|
+
0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a
|
40
|
+
0000020: 30 31 32 33 34 35 36 37 38 39
|
41
|
+
|
42
|
+
with hexy!
|
43
|
+
|
44
|
+
|
45
|
+
== Installing
|
46
|
+
|
47
|
+
Having a "Installing" section is a bit of a chicken or egg question.
|
48
|
+
Someone reading this README has, in all likelyhood already installed the
|
49
|
+
package.
|
50
|
+
|
51
|
+
You can install the +hexy+ package by executing:
|
52
|
+
|
53
|
+
gem install hexy -r
|
54
|
+
|
55
|
+
alternatively, you can download +.tar.gz+ or +.zip+ archives from
|
56
|
+
Rubyforge[http://rubyforge.org/frs/?group_id=2203].
|
57
|
+
|
58
|
+
|
59
|
+
== Mail
|
60
|
+
|
61
|
+
In case you discover bugs, spelling errors, offer suggestions for
|
62
|
+
improvements or would like to help out with the project, you can contact
|
63
|
+
me directly (tim@kuriositaet.de).
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
=
|
data/Rakefile
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require "rake/rdoctask"
|
2
|
+
require "rake/gempackagetask"
|
3
|
+
require "rake/testtask"
|
4
|
+
require "rake/clean"
|
5
|
+
require "rubygems"
|
6
|
+
|
7
|
+
# Some definitions that you'll need to edit in case you reuse this
|
8
|
+
# Rakefile for your own project.
|
9
|
+
|
10
|
+
SHORTNAME ='hexy' # this should be the rubyforge project name
|
11
|
+
DESC ='Utility for hexdumps'
|
12
|
+
PKG_VERSION ='0.1.0'
|
13
|
+
LONG_DESC = <<END_DESC
|
14
|
+
This is a short project description.
|
15
|
+
END_DESC
|
16
|
+
RUBYFORGE_USER ='a2800276'
|
17
|
+
|
18
|
+
# Specifies the default task to execute. This is often the "test" task
|
19
|
+
# and we'll change things around as soon as we have some tests.
|
20
|
+
|
21
|
+
task :default => [:rdoc]
|
22
|
+
|
23
|
+
# The directory to generate +rdoc+ in.
|
24
|
+
RDOC_DIR="doc/html"
|
25
|
+
|
26
|
+
# This global variable contains files that will be erased by the `clean` task.
|
27
|
+
# The `clean` task itself is automatically generated by requiring `rake/clean`.
|
28
|
+
|
29
|
+
CLEAN << RDOC_DIR << "pkg"
|
30
|
+
|
31
|
+
|
32
|
+
# This is the task that generates the +rdoc+ documentation from the
|
33
|
+
# source files. Instantiating Rake::RDocTask automatically generates a
|
34
|
+
# task called `rdoc`.
|
35
|
+
|
36
|
+
Rake::RDocTask.new do |rd|
|
37
|
+
# Options for documenation generation are specified inside of
|
38
|
+
# this block. For example the following line specifies that the
|
39
|
+
# content of the README file should be the main page of the
|
40
|
+
# documenation.
|
41
|
+
rd.main = "README"
|
42
|
+
|
43
|
+
# The following line specifies all the files to extract
|
44
|
+
# documenation from.
|
45
|
+
rd.rdoc_files.include( "README", "AUTHORS", "LICENSE", "TODO",
|
46
|
+
"CHANGELOG", "bin/**/*", "lib/**/*.rb",
|
47
|
+
"examples/**/*rb","test/**/*.rb", "doc/*.rdoc")
|
48
|
+
# This one specifies the output directory ...
|
49
|
+
rd.rdoc_dir = "doc/html"
|
50
|
+
|
51
|
+
# Or the HTML title of the generated documentation set.
|
52
|
+
rd.title = "#{SHORTNAME}: #{DESC}"
|
53
|
+
|
54
|
+
# These are options specifiying how source code inlined in the
|
55
|
+
# documentation should be formatted.
|
56
|
+
|
57
|
+
rd.options = ["--line-numbers", "--inline-source"]
|
58
|
+
|
59
|
+
# Check:
|
60
|
+
# `rdoc --help` for more rdoc options
|
61
|
+
# the {rdoc documenation home}[http://www.ruby-doc.org/stdlib/libdoc/rdoc/rdoc/index.html]
|
62
|
+
# or the documentation for the +Rake::RDocTask+ task[http://rake.rubyforge.org/classes/Rake/RDocTask.html]
|
63
|
+
end
|
64
|
+
|
65
|
+
# The GemPackageTask facilitates getting all your files collected
|
66
|
+
# together into gem archives. You can also use it to generate tarball
|
67
|
+
# and zip archives.
|
68
|
+
|
69
|
+
# First you'll need to assemble a gemspec
|
70
|
+
|
71
|
+
PKG_FILES = FileList['lib/**/*.rb', 'bin/**/*', 'examples/**/*', '[A-Z]*', 'test/**/*'].to_a
|
72
|
+
|
73
|
+
spec = Gem::Specification.new do |s|
|
74
|
+
s.platform = Gem::Platform::RUBY
|
75
|
+
s.summary = "#{SHORTNAME}: #{DESC}"
|
76
|
+
s.name = SHORTNAME
|
77
|
+
s.version = PKG_VERSION
|
78
|
+
s.files = PKG_FILES
|
79
|
+
s.requirements << "none"
|
80
|
+
s.require_path = 'lib'
|
81
|
+
s.description = LONG_DESC
|
82
|
+
end
|
83
|
+
|
84
|
+
# Adding a new GemPackageTask adds a task named `package`, which generates
|
85
|
+
# packages as gems, tarball and zip archives.
|
86
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
87
|
+
pkg.need_zip = true
|
88
|
+
pkg.need_tar_gz = true
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# This task is used to demonstrate how to upload files to Rubyforge.
|
93
|
+
# Calling `upload_page` creates a current version of the +rdoc+
|
94
|
+
# documentation and uploads it to the Rubyforge homepage of the project,
|
95
|
+
# assuming it's hosted there and naming conventions haven't changed.
|
96
|
+
#
|
97
|
+
# This task uses `sh` to call the `scp` binary, which is plattform
|
98
|
+
# dependant and may not be installed on your computer if you're using
|
99
|
+
# Windows. I'm currently not aware of any pure ruby way to do scp
|
100
|
+
# transfers.
|
101
|
+
|
102
|
+
RubyForgeProject=SHORTNAME
|
103
|
+
|
104
|
+
desc "Upload the web pages to the web."
|
105
|
+
task :upload_pages => ["rdoc"] do
|
106
|
+
if RubyForgeProject then
|
107
|
+
path = "/var/www/gforge-projects/#{RubyForgeProject}"
|
108
|
+
sh "scp -r doc/html/* #{RUBYFORGE_USER}@rubyforge.org:#{path}"
|
109
|
+
sh "scp doc/images/*.png #{RUBYFORGE_USER}@rubyforge.org:#{path}/images"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# This task will run the unit tests provided in files called
|
114
|
+
# `test/test*.rb`. The task itself can be run with a call to `rake test`
|
115
|
+
|
116
|
+
Rake::TestTask.new do |t|
|
117
|
+
t.libs << "test"
|
118
|
+
t.libs << "lib"
|
119
|
+
t.test_files = FileList['test/*.rb']
|
120
|
+
t.verbose = true
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
data/THANKS
ADDED
File without changes
|
data/TODO
ADDED
data/lib/hexy.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class Hexy
|
4
|
+
|
5
|
+
def self.dump bytes, config={}
|
6
|
+
Hexy.new(bytes, config).to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
#
|
10
|
+
# Constructor is passed the bytes to format as a hex dump and
|
11
|
+
# an optinal configuration hash. Configuration parameters are:
|
12
|
+
#
|
13
|
+
# [:+width+] how many bytes per line (default: 16)
|
14
|
+
# [:+numbering+] currently the only supported options are <tt>:hex_bytes</tt> and <tt>:none</tt>. Default is <tt>:hex_bytes</tt>
|
15
|
+
# [:+format+] currently supported are :+twos+ (every two hex digits are separated by a space, default), :+fours+ or :+none+
|
16
|
+
# [:+case+] :+upper+ or :+lower+, default :+lower+
|
17
|
+
# [:+annotate+] :+ascii+ or :+none+, default :+ascii+
|
18
|
+
# [:+prefix+] a prefix to include literally in front of each line, default ""
|
19
|
+
# [:+indent+] number of spaces to prefix in front of each line, default 0
|
20
|
+
#
|
21
|
+
#
|
22
|
+
#
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# ==Examples
|
26
|
+
# (Width = 16, Line Numbers = :hex_bytes, Format = :twos)
|
27
|
+
# 0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a .......b cdefghij
|
28
|
+
# 0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a klmnopqr stuvwxyz
|
29
|
+
# 0000020: 30 31 32 33 34 35 36 37 38 39 01234567 89
|
30
|
+
#
|
31
|
+
# (Width = 16, Line Numbers = :none, Format = :fours)
|
32
|
+
# 0001 0305 1f0a 0962 6364 6566 6768 696a .......b cdefghij
|
33
|
+
# 6b6c 6d6e 6f70 7172 7374 7576 7778 797a klmnopqr stuvwxyz
|
34
|
+
# 3031 3233 3435 3637 3839 01234567 89
|
35
|
+
#
|
36
|
+
# ==Usage
|
37
|
+
#
|
38
|
+
# The examples above were generated with the following:
|
39
|
+
#
|
40
|
+
# b = Hexy.new "\x00\x01\x03(...)"
|
41
|
+
# puts p.to_s
|
42
|
+
#
|
43
|
+
# b = Hexy.new "\x00\x01\x03(...)", :numbering=>:none, :format=>:fours
|
44
|
+
# puts p.to_s
|
45
|
+
#
|
46
|
+
def initialize bytes, config = {}
|
47
|
+
@bytes = bytes
|
48
|
+
@width = config[:width] || 16
|
49
|
+
@numbering = config[:numbering] == :none ? :none : :hex_bytes
|
50
|
+
@format = case config[:format]
|
51
|
+
when :none, :fours
|
52
|
+
config[:format]
|
53
|
+
else
|
54
|
+
:twos
|
55
|
+
end
|
56
|
+
@case = config[:case] == :upper ? :upper: :lower
|
57
|
+
@annotate = config[:annotate] == :none ? :none : :ascii
|
58
|
+
@prefix = config[:prefix] ||= ""
|
59
|
+
@indent = config[:indent] ||= 0
|
60
|
+
1.upto(@indent) {@prefix += " "}
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_s
|
64
|
+
str = ""
|
65
|
+
0.step(@bytes.length, @width) {|i|
|
66
|
+
string = @bytes[i,@width]
|
67
|
+
|
68
|
+
hex = string.unpack("H*")[0]
|
69
|
+
hex.upcase! if @case == :upper
|
70
|
+
|
71
|
+
|
72
|
+
if @format == :fours
|
73
|
+
hex.gsub!(/(.{4})/) {|m|
|
74
|
+
m+" "
|
75
|
+
}
|
76
|
+
elsif @format == :twos
|
77
|
+
hex.sub!(/(.{#{@width}})/) { |m|
|
78
|
+
m+" "
|
79
|
+
}
|
80
|
+
hex.gsub!(/(\S\S)/) { |m|
|
81
|
+
m+" "
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
string.gsub!(/[\000-\040\177-\377]/, ".")
|
86
|
+
string.gsub!(/(.{#{@width/2}})/) { |m|
|
87
|
+
m+" "
|
88
|
+
}
|
89
|
+
len = case @format
|
90
|
+
when :fours
|
91
|
+
(@width*2)+(@width/2)
|
92
|
+
when :twos
|
93
|
+
(@width * 3)+2
|
94
|
+
else
|
95
|
+
@width *2
|
96
|
+
end
|
97
|
+
str << @prefix
|
98
|
+
str << "%07X: " % (i) if @numbering == :hex_bytes
|
99
|
+
str << ("%-#{len}s" % hex)
|
100
|
+
str << " #{string}" if @annotate == :ascii
|
101
|
+
str << "\n"
|
102
|
+
|
103
|
+
}
|
104
|
+
str << "\n"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if $0 == __FILE__
|
109
|
+
|
110
|
+
b = Hexy.new "abc"
|
111
|
+
puts b.to_s
|
112
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789"
|
113
|
+
puts b.to_s
|
114
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :format=>:none
|
115
|
+
puts b.to_s
|
116
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :annotate=>:none
|
117
|
+
puts b.to_s
|
118
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :format=>:fours)
|
119
|
+
puts b.to_s
|
120
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :format=>:fours, :case=>:upper)
|
121
|
+
puts b.to_s
|
122
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :format=>:fours)
|
123
|
+
puts b.to_s
|
124
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :width=>8)
|
125
|
+
puts b.to_s
|
126
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=> 8)
|
127
|
+
puts b.to_s
|
128
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=> 8, :format=>:fours)
|
129
|
+
puts b.to_s
|
130
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :width=>32)
|
131
|
+
puts b.to_s
|
132
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=>32)
|
133
|
+
puts b.to_s
|
134
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=>32, :format=>:fours)
|
135
|
+
puts b.to_s
|
136
|
+
end
|
data/test/hexy_text.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/hexy'
|
3
|
+
|
4
|
+
# The way these tests are grouped is more or less arbitary, it more or less follows
|
5
|
+
# the features available in the config hash and tries to cover several permutations.
|
6
|
+
# The tests in the current form are taken from runs of the actual code:
|
7
|
+
# they're devoped until the results are satisfactory and then transfered back into
|
8
|
+
# these test cases.
|
9
|
+
#
|
10
|
+
# There's probably a nicer way to do to this, but this way does ensure that new features don't mess up the old results.
|
11
|
+
class TestHexy < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_class_meth
|
17
|
+
bytes = "\123\234\345\456\123\321\012"
|
18
|
+
h = Hexy.new bytes
|
19
|
+
|
20
|
+
assert_equal h.to_s, Hexy.dump(bytes,{})
|
21
|
+
|
22
|
+
end
|
23
|
+
def test_dump
|
24
|
+
b = Hexy.new "abc"
|
25
|
+
assert_equal %Q(0000000: 61 62 63 abc
|
26
|
+
|
27
|
+
), b.to_s
|
28
|
+
|
29
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789"
|
30
|
+
assert_equal %Q(0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a .......b cdefghij
|
31
|
+
0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a klmnopqr stuvwxyz
|
32
|
+
0000020: 30 31 32 33 34 35 36 37 38 39 01234567 89
|
33
|
+
|
34
|
+
), b.to_s
|
35
|
+
|
36
|
+
|
37
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=> 8)
|
38
|
+
assert_equal %Q(0000000: 00 01 03 05 1f 0a 09 62 .... ...b
|
39
|
+
0000008: 63 64 65 66 67 68 69 6a cdef ghij
|
40
|
+
0000010: 6b 6c 6d 6e 6f 70 71 72 klmn opqr
|
41
|
+
0000018: 73 74 75 76 77 78 79 7a stuv wxyz
|
42
|
+
0000020: 30 31 32 33 34 35 36 37 0123 4567
|
43
|
+
0000028: 38 39 89
|
44
|
+
|
45
|
+
), b.to_s
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_numbering
|
53
|
+
|
54
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :format=>:fours)
|
55
|
+
assert_equal %Q(0001 0305 1f0a 0962 6364 6566 6768 696a .......b cdefghij \n6b6c 6d6e 6f70 7172 7374 7576 7778 797a klmnopqr stuvwxyz \n3031 3233 3435 3637 3839 01234567 89\n\n), b.to_s
|
56
|
+
|
57
|
+
|
58
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :width=>32)
|
59
|
+
assert_equal %Q(00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a .......bcdefghij klmnopqrstuvwxyz \n30 31 32 33 34 35 36 37 38 39 0123456789\n\n), b.to_s
|
60
|
+
|
61
|
+
end
|
62
|
+
def test_format
|
63
|
+
|
64
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :format=>:none
|
65
|
+
assert_equal %Q(0000000: 000103051f0a0962636465666768696a .......b cdefghij
|
66
|
+
0000010: 6b6c6d6e6f707172737475767778797a klmnopqr stuvwxyz
|
67
|
+
0000020: 30313233343536373839 01234567 89
|
68
|
+
|
69
|
+
), b.to_s
|
70
|
+
|
71
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :format=>:fours)
|
72
|
+
assert_equal %Q(0000000: 0001 0305 1f0a 0962 6364 6566 6768 696a .......b cdefghij
|
73
|
+
0000010: 6b6c 6d6e 6f70 7172 7374 7576 7778 797a klmnopqr stuvwxyz
|
74
|
+
0000020: 3031 3233 3435 3637 3839 01234567 89
|
75
|
+
|
76
|
+
), b.to_s
|
77
|
+
|
78
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=>32, :format=>:fours)
|
79
|
+
assert_equal %Q(0000000: 0001 0305 1f0a 0962 6364 6566 6768 696a 6b6c 6d6e 6f70 7172 7374 7576 7778 797a .......bcdefghij klmnopqrstuvwxyz
|
80
|
+
0000020: 3031 3233 3435 3637 3839 0123456789
|
81
|
+
|
82
|
+
), b.to_s
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_case
|
86
|
+
|
87
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :format=>:fours, :case=>:upper)
|
88
|
+
assert_equal %Q(0001 0305 1F0A 0962 6364 6566 6768 696A .......b cdefghij
|
89
|
+
6B6C 6D6E 6F70 7172 7374 7576 7778 797A klmnopqr stuvwxyz
|
90
|
+
3031 3233 3435 3637 3839 01234567 89
|
91
|
+
|
92
|
+
), b.to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_annotate
|
96
|
+
|
97
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :annotate=>:none
|
98
|
+
assert_equal %Q(0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a
|
99
|
+
0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a
|
100
|
+
0000020: 30 31 32 33 34 35 36 37 38 39 \n\n), b.to_s
|
101
|
+
end
|
102
|
+
def test_width
|
103
|
+
|
104
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=> 8, :format=>:fours)
|
105
|
+
assert_equal %Q(0000000: 0001 0305 1f0a 0962 .... ...b \n0000008: 6364 6566 6768 696a cdef ghij \n0000010: 6b6c 6d6e 6f70 7172 klmn opqr \n0000018: 7374 7576 7778 797a stuv wxyz \n0000020: 3031 3233 3435 3637 0123 4567 \n0000028: 3839 89\n\n), b.to_s
|
106
|
+
|
107
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:none, :width=>8)
|
108
|
+
assert_equal %Q(00 01 03 05 1f 0a 09 62 .... ...b \n63 64 65 66 67 68 69 6a cdef ghij \n6b 6c 6d 6e 6f 70 71 72 klmn opqr \n73 74 75 76 77 78 79 7a stuv wxyz \n30 31 32 33 34 35 36 37 0123 4567 \n38 39 89\n\n), b.to_s
|
109
|
+
|
110
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :numbering=>:hex_bytes, :width=>32)
|
111
|
+
assert_equal %Q(0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a .......bcdefghij klmnopqrstuvwxyz \n0000020: 30 31 32 33 34 35 36 37 38 39 0123456789\n\n), b.to_s
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_prefix_indent
|
115
|
+
b = Hexy.new("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789",
|
116
|
+
:numbering=>:hex_bytes,
|
117
|
+
:width=> 8,
|
118
|
+
:format=>:fours,
|
119
|
+
:prefix=>"yo! :"
|
120
|
+
)
|
121
|
+
assert_equal %Q(yo! :0000000: 0001 0305 1f0a 0962 .... ...b \nyo! :0000008: 6364 6566 6768 696a cdef ghij \nyo! :0000010: 6b6c 6d6e 6f70 7172 klmn opqr \nyo! :0000018: 7374 7576 7778 797a stuv wxyz \nyo! :0000020: 3031 3233 3435 3637 0123 4567 \nyo! :0000028: 3839 89\n\n), b.to_s
|
122
|
+
|
123
|
+
b = Hexy.new "\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789", :annotate=>:none, :indent=>4
|
124
|
+
assert_equal %Q( 0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a \n 0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a \n 0000020: 30 31 32 33 34 35 36 37 38 39 \n\n), b.to_s
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|