emonti-rbkb 0.6.2.1 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +32 -0
- data/README.rdoc +10 -7
- data/Rakefile +47 -0
- data/bin/feed +5 -0
- data/bin/plugsrv +3 -3
- data/cli_usage.rdoc +44 -9
- data/doctor-bag.jpg +0 -0
- data/lib/rbkb.rb +47 -2
- data/lib/rbkb/cli.rb +8 -6
- data/lib/rbkb/cli/b64.rb +5 -0
- data/lib/rbkb/cli/bgrep.rb +14 -9
- data/lib/rbkb/cli/chars.rb +2 -1
- data/lib/rbkb/cli/crc32.rb +4 -1
- data/lib/rbkb/cli/d64.rb +3 -0
- data/lib/rbkb/cli/dedump.rb +5 -3
- data/lib/rbkb/cli/feed.rb +223 -0
- data/lib/rbkb/cli/hexify.rb +3 -3
- data/lib/rbkb/cli/len.rb +12 -9
- data/lib/rbkb/cli/rstrings.rb +13 -10
- data/lib/rbkb/cli/slice.rb +1 -0
- data/lib/rbkb/cli/telson.rb +21 -57
- data/lib/rbkb/cli/unhexify.rb +2 -6
- data/lib/rbkb/cli/urldec.rb +1 -0
- data/lib/rbkb/cli/urlenc.rb +1 -0
- data/lib/rbkb/extends.rb +41 -6
- data/lib/rbkb/http.rb +20 -0
- data/lib/rbkb/http/base.rb +172 -0
- data/lib/rbkb/http/body.rb +214 -0
- data/lib/rbkb/http/common.rb +74 -0
- data/lib/rbkb/http/headers.rb +356 -0
- data/lib/rbkb/http/parameters.rb +101 -0
- data/lib/rbkb/http/request.rb +58 -0
- data/lib/rbkb/http/response.rb +86 -0
- data/lib/rbkb/plug.rb +3 -3
- data/lib/rbkb/plug/cli.rb +83 -0
- data/lib/rbkb/plug/feed_import.rb +74 -0
- data/lib/rbkb/plug/plug.rb +36 -19
- data/lib/rbkb/plug/unix_domain.rb +75 -0
- data/rbkb.gemspec +38 -0
- data/spec/rbkb_spec.rb +7 -0
- data/spec/spec_helper.rb +16 -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/test/test_cli_b64.rb +35 -0
- data/test/test_cli_bgrep.rb +137 -0
- data/test/test_cli_blit.rb +11 -0
- data/test/test_cli_chars.rb +21 -0
- data/test/test_cli_crc32.rb +108 -0
- data/test/test_cli_d64.rb +22 -0
- data/test/test_cli_dedump.rb +118 -0
- data/test/test_cli_feed.rb +11 -0
- data/test/test_cli_helper.rb +96 -0
- data/test/test_cli_hexify.rb +63 -0
- data/test/test_cli_len.rb +96 -0
- data/test/test_cli_rstrings.rb +15 -0
- data/test/test_cli_slice.rb +73 -0
- data/test/test_cli_telson.rb +11 -0
- data/test/test_cli_unhexify.rb +43 -0
- data/test/test_cli_urldec.rb +50 -0
- data/test/test_cli_urlenc.rb +44 -0
- data/test/test_cli_xor.rb +71 -0
- data/test/test_helper.rb +5 -0
- data/test/test_http.rb +27 -0
- data/test/test_http_helper.rb +60 -0
- data/test/test_http_request.rb +136 -0
- data/test/test_http_response.rb +222 -0
- data/test/test_rbkb.rb +19 -0
- metadata +127 -21
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
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
require 'rbkb/cli/b64'
|
3
|
+
|
4
|
+
class TestCliB64 < Test::Unit::TestCase
|
5
|
+
include CliTest
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cli_class = Rbkb::Cli::B64
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_basic_string_arg
|
13
|
+
assert_equal 0, run_with_args(%w(fooby))
|
14
|
+
assert_equal "Zm9vYnk=\n", @stdout_io.string
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_stdin
|
18
|
+
@stdin_io.write("fooby") ; @stdin_io.rewind
|
19
|
+
assert_equal 0, run_with_args()
|
20
|
+
assert_equal "Zm9vYnk=\n", @stdout_io.string
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def test_length_arg
|
25
|
+
assert_equal 0, run_with_args(%w(-l 2 fooby))
|
26
|
+
assert_equal "Zm\n9v\nYn\nk=\n", @stdout_io.string
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_bad_length_arg
|
30
|
+
assert_equal 1, run_with_args(%w(-l -2 fooby))
|
31
|
+
assert_match(/length must be > 0/, @stderr_io.string)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
require 'rbkb/cli/bgrep'
|
3
|
+
|
4
|
+
class TestCliBgrep < Test::Unit::TestCase
|
5
|
+
include CliTest
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cli_class = Rbkb::Cli::Bgrep
|
9
|
+
super()
|
10
|
+
|
11
|
+
@rawdat = (0..255).map {|x| x.chr}.join
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_need_search_arg
|
15
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
16
|
+
assert_equal 1, go_with_args()
|
17
|
+
assert_match(/need search argument/i, @stderr_io.string)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_search_arg_exclusive
|
21
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
22
|
+
assert_equal 1, go_with_args(%w(-r ABCD -x 41424344))
|
23
|
+
assert_match(/are mutually exclusive/i, @stderr_io.string)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_stdin_str_grep
|
27
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
28
|
+
assert_equal 0, go_with_args(%w(-r ABCD))
|
29
|
+
assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_stdin_regex_grep
|
33
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
34
|
+
assert_equal 0, go_with_args(%w(-r A..D))
|
35
|
+
assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_stdin_hex_grep
|
39
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
40
|
+
assert_equal 0, go_with_args(%w(-x 41424344))
|
41
|
+
assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_alignment_arg
|
45
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
46
|
+
assert_equal 0, go_with_args(%w(-a 2 -r BCDE))
|
47
|
+
assert_equal %(00000042:00000046:b:"BCDE"\n), @stdout_io.string
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_alignment_arg_not_aligned
|
51
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
52
|
+
assert_equal 0, go_with_args(%w(-a 2 -r ABCD))
|
53
|
+
assert_equal "", @stdout_io.string
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_stdin_str_grep_twohits
|
58
|
+
@stdin_io.write(@rawdat*2) ; @stdin_io.rewind
|
59
|
+
assert_equal 0, go_with_args(%w(-r ABCD))
|
60
|
+
assert_equal %(00000041:00000045:b:"ABCD"\n00000141:00000145:b:"ABCD"\n), @stdout_io.string
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_stdin_hex_grep_twohits
|
64
|
+
@stdin_io.write(@rawdat*2) ; @stdin_io.rewind
|
65
|
+
assert_equal 0, go_with_args(%w(-x 41424344))
|
66
|
+
assert_equal( %(00000041:00000045:b:"ABCD"\n)+
|
67
|
+
%(00000141:00000145:b:"ABCD"\n),
|
68
|
+
@stdout_io.string )
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_file_arg
|
72
|
+
with_testfile do |fname, f|
|
73
|
+
f.write(@rawdat) ; f.close
|
74
|
+
assert_equal 0, go_with_args(%w(-r ABCD) << fname)
|
75
|
+
assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_multi_file_arg
|
80
|
+
with_testfile do |fname1, f1|
|
81
|
+
f1.write(@rawdat) ; f1.close
|
82
|
+
|
83
|
+
with_testfile do |fname2, f2|
|
84
|
+
f2.write(@rawdat) ; f2.close
|
85
|
+
assert_equal 0, go_with_args(["-r", "ABCD", fname1, fname2])
|
86
|
+
assert_equal( %(#{fname1}:00000041:00000045:b:"ABCD"\n)+
|
87
|
+
%(#{fname2}:00000041:00000045:b:"ABCD"\n),
|
88
|
+
@stdout_io.string )
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_multi_file_arg_include_filenames_long
|
94
|
+
with_testfile do |fname1, f1|
|
95
|
+
f1.write(@rawdat) ; f1.close
|
96
|
+
|
97
|
+
with_testfile do |fname2, f2|
|
98
|
+
f2.write(@rawdat) ; f2.close
|
99
|
+
assert_equal 0, go_with_args(%w(--filename -r ABCD) + [fname1, fname2])
|
100
|
+
assert_equal( %(#{fname1}:00000041:00000045:b:"ABCD"\n)+
|
101
|
+
%(#{fname2}:00000041:00000045:b:"ABCD"\n),
|
102
|
+
@stdout_io.string )
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_multi_file_arg_include_filenames_short
|
108
|
+
with_testfile do |fname1, f1|
|
109
|
+
f1.write(@rawdat) ; f1.close
|
110
|
+
|
111
|
+
with_testfile do |fname2, f2|
|
112
|
+
f2.write(@rawdat) ; f2.close
|
113
|
+
assert_equal 0, go_with_args(%w(-n -r ABCD) + [fname1, fname2])
|
114
|
+
assert_equal( %(#{fname1}:00000041:00000045:b:"ABCD"\n)+
|
115
|
+
%(#{fname2}:00000041:00000045:b:"ABCD"\n),
|
116
|
+
@stdout_io.string )
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def test_multi_file_arg_suppress_filenames_long
|
123
|
+
with_testfile do |fname1, f1|
|
124
|
+
f1.write(@rawdat) ; f1.close
|
125
|
+
|
126
|
+
with_testfile do |fname2, f2|
|
127
|
+
f2.write(@rawdat) ; f2.close
|
128
|
+
assert_equal 0, go_with_args(%w(--no-filename -r ABCD)+[fname1, fname2])
|
129
|
+
assert_equal( %(00000041:00000045:b:"ABCD"\n)+
|
130
|
+
%(00000041:00000045:b:"ABCD"\n),
|
131
|
+
@stdout_io.string )
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
|
3
|
+
class TestCliChars < Test::Unit::TestCase
|
4
|
+
include CliTest
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@cli_class = Rbkb::Cli::Chars
|
8
|
+
super()
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_chars
|
12
|
+
assert_equal 0, go_with_args(%w(1000 A))
|
13
|
+
assert_equal "A"*1000, @stdout_io.string
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_bad_arguments
|
17
|
+
assert_equal 1, go_with_args(["asdf"])
|
18
|
+
assert_match(/bad arguments/i, @stderr_io.string)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
require 'rbkb/cli/crc32'
|
3
|
+
|
4
|
+
class TestCliCrc32 < Test::Unit::TestCase
|
5
|
+
include CliTest
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cli_class = Rbkb::Cli::Crc32
|
9
|
+
super()
|
10
|
+
@rawdat = "\306\363\375/l\375\204oK\215o\275\334\037\254\333\276\257\313\267\fr\231\333!\373v|\303W7p\263\307\034X\300~\2671R\252\026\246\263\231\276\314"
|
11
|
+
@rawsz = @rawdat.size
|
12
|
+
@crc_int = 0xa7641684
|
13
|
+
@crc_out ="a7641684\n"
|
14
|
+
@stdin_io.write(@rawdat) ; @stdin_io.rewind
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_stdin
|
18
|
+
assert_equal 0, go_with_args()
|
19
|
+
assert_equal(@crc_out, @stdout_io.string)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_file_input_arg
|
23
|
+
with_testfile do |fname, tf|
|
24
|
+
tf.write @rawdat; tf.close
|
25
|
+
assert_equal 0, go_with_args([fname])
|
26
|
+
assert_equal(@crc_out, @stdout_io.string)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def test_file_input_flag
|
32
|
+
with_testfile do |fname, tf|
|
33
|
+
tf.write @rawdat; tf.close
|
34
|
+
assert_equal 0, go_with_args(["-f", fname])
|
35
|
+
assert_equal(@crc_out, @stdout_io.string)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_start_from_end_zero
|
40
|
+
assert_equal 0, go_with_args(%w(-r 48))
|
41
|
+
assert_equal("00000000\n", @stdout_io.string)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_start_from_end_zero_hex
|
45
|
+
assert_equal 0, go_with_args(%w(-x 00:30))
|
46
|
+
assert_equal(@crc_out, @stdout_io.string)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_range_zero_start
|
50
|
+
assert_equal 0, go_with_args(%w(-r 0:48))
|
51
|
+
assert_equal(@crc_out, @stdout_io.string)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_range
|
55
|
+
assert_equal 0, go_with_args(%w{-x 30})
|
56
|
+
assert_equal("00000000\n", @stdout_io.string)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_range_sixteen_thru_end
|
60
|
+
assert_equal 0, go_with_args(%w(-r 16))
|
61
|
+
assert_equal "de84e464\n", @stdout_io.string
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_range_sixteen_thru_end_hex
|
65
|
+
assert_equal 0, go_with_args(%w(-x 10))
|
66
|
+
assert_equal "de84e464\n", @stdout_io.string
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_range_last_ten
|
70
|
+
assert_equal 0, go_with_args(%w(-r 38:48))
|
71
|
+
assert_equal "7d4bb02a\n", @stdout_io.string
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_range_last_ten_hex
|
75
|
+
assert_equal 0, go_with_args(%w(-x 26:30))
|
76
|
+
assert_equal "7d4bb02a\n", @stdout_io.string
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_invalid_range
|
80
|
+
assert_equal 1, go_with_args(%w(-r 38:z48))
|
81
|
+
assert_match(/invalid range/, @stderr_io.string)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_range_last_ten_hex
|
85
|
+
assert_equal 1, go_with_args(%w(-x 26:z30))
|
86
|
+
assert_match(/invalid range/, @stderr_io.string)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_range_last_ten_using_negative
|
90
|
+
assert_equal 0, go_with_args(%w(-r 38:-1))
|
91
|
+
assert_equal "7d4bb02a\n", @stdout_io.string
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_range_last_ten_using_negative_hex
|
95
|
+
assert_equal 0, go_with_args(%w(-x 26:-1))
|
96
|
+
assert_equal "7d4bb02a\n", @stdout_io.string
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_start_from_end_negative_size
|
100
|
+
assert_equal 0, go_with_args(%w(-r -48))
|
101
|
+
assert_equal(@crc_out, @stdout_io.string)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_start_from_end_negative_size_hex
|
105
|
+
assert_equal 0, go_with_args(%w(-x -30))
|
106
|
+
assert_equal(@crc_out, @stdout_io.string)
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
require 'rbkb/cli/d64'
|
3
|
+
|
4
|
+
class TestCliD64 < Test::Unit::TestCase
|
5
|
+
include CliTest
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cli_class = Rbkb::Cli::D64
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_basic_string_arg
|
13
|
+
assert_equal 0, run_with_args(%w(Zm9vYnk=))
|
14
|
+
assert_equal "fooby", @stdout_io.string
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_stdin
|
18
|
+
@stdin_io.write "Zm9vYnk=" ; @stdin_io.rewind
|
19
|
+
assert_equal 0, run_with_args()
|
20
|
+
assert_equal "fooby", @stdout_io.string
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
require 'rbkb/cli/dedump'
|
3
|
+
|
4
|
+
class TestCliDedump < Test::Unit::TestCase
|
5
|
+
include CliTest
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cli_class = Rbkb::Cli::Dedump
|
9
|
+
super()
|
10
|
+
@tst_string = "this is a \x00\n\n\ntest\x01\x02\xff\x00"
|
11
|
+
@tst_dump = <<_EOF_
|
12
|
+
00000000 74 68 69 73 20 69 73 20 61 20 00 0a 0a 0a 74 65 |this is a ....te|
|
13
|
+
00000010 73 74 01 02 ff 00 |st....|
|
14
|
+
00000016
|
15
|
+
_EOF_
|
16
|
+
|
17
|
+
@bigtst_string = "\000\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\e\034\035\036\037 !\"\#.$.%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377" * 3
|
18
|
+
@bigtst_dump = <<_EOF_
|
19
|
+
00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
|
20
|
+
00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
|
21
|
+
00000020 20 21 22 23 2e 24 2e 25 26 27 28 29 2a 2b 2c 2d | !"#.$.%&'()*+,-|
|
22
|
+
00000030 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d |./0123456789:;<=|
|
23
|
+
00000040 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d |>?@ABCDEFGHIJKLM|
|
24
|
+
00000050 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d |NOPQRSTUVWXYZ[\]|
|
25
|
+
00000060 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d |^_`abcdefghijklm|
|
26
|
+
00000070 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d |nopqrstuvwxyz{|}|
|
27
|
+
00000080 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d |~...............|
|
28
|
+
00000090 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d |................|
|
29
|
+
000000a0 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad |................|
|
30
|
+
000000b0 ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd |................|
|
31
|
+
000000c0 be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd |................|
|
32
|
+
000000d0 ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd |................|
|
33
|
+
000000e0 de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed |................|
|
34
|
+
000000f0 ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd |................|
|
35
|
+
00000100 fe ff 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d |................|
|
36
|
+
00000110 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d |................|
|
37
|
+
00000120 1e 1f 20 21 22 23 2e 24 2e 25 26 27 28 29 2a 2b |.. !"#.$.%&'()*+|
|
38
|
+
00000130 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b |,-./0123456789:;|
|
39
|
+
00000140 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b |<=>?@ABCDEFGHIJK|
|
40
|
+
00000150 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b |LMNOPQRSTUVWXYZ[|
|
41
|
+
00000160 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b |\]^_`abcdefghijk|
|
42
|
+
00000170 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b |lmnopqrstuvwxyz{|
|
43
|
+
00000180 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b ||}~.............|
|
44
|
+
00000190 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b |................|
|
45
|
+
000001a0 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab |................|
|
46
|
+
000001b0 ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb |................|
|
47
|
+
000001c0 bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb |................|
|
48
|
+
000001d0 cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db |................|
|
49
|
+
000001e0 dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb |................|
|
50
|
+
000001f0 ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb |................|
|
51
|
+
00000200 fc fd fe ff 00 01 02 03 04 05 06 07 08 09 0a 0b |................|
|
52
|
+
00000210 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b |................|
|
53
|
+
00000220 1c 1d 1e 1f 20 21 22 23 2e 24 2e 25 26 27 28 29 |.... !"#.$.%&'()|
|
54
|
+
00000230 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 |*+,-./0123456789|
|
55
|
+
00000240 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 |:;<=>?@ABCDEFGHI|
|
56
|
+
00000250 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 |JKLMNOPQRSTUVWXY|
|
57
|
+
00000260 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 |Z[\]^_`abcdefghi|
|
58
|
+
00000270 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 |jklmnopqrstuvwxy|
|
59
|
+
00000280 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 |z{|}~...........|
|
60
|
+
00000290 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 |................|
|
61
|
+
000002a0 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 |................|
|
62
|
+
000002b0 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 |................|
|
63
|
+
000002c0 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 |................|
|
64
|
+
000002d0 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 |................|
|
65
|
+
000002e0 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 |................|
|
66
|
+
000002f0 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 |................|
|
67
|
+
00000300 fa fb fc fd fe ff |......|
|
68
|
+
00000306
|
69
|
+
_EOF_
|
70
|
+
|
71
|
+
end # setup
|
72
|
+
|
73
|
+
def test_file_input_arg
|
74
|
+
with_testfile do |fname, tf|
|
75
|
+
tf.write @tst_dump; tf.close
|
76
|
+
assert_equal 0, go_with_args([fname])
|
77
|
+
assert_equal(@tst_string, @stdout_io.string)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_stdin
|
82
|
+
@stdin_io.write(@tst_dump) ; @stdin_io.rewind
|
83
|
+
assert_equal 0, go_with_args
|
84
|
+
assert_equal(@tst_string, @stdout_io.string)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def test_stdin_big
|
89
|
+
@stdin_io.write(@bigtst_dump) ; @stdin_io.rewind
|
90
|
+
assert_equal 0, go_with_args
|
91
|
+
assert_equal(@bigtst_string, @stdout_io.string)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_bad_len
|
95
|
+
len_dump = <<_EOF_
|
96
|
+
00000000 68 65 6c 75 |helu|
|
97
|
+
00000004 20 66 6f 6f | foo|
|
98
|
+
00000008
|
99
|
+
_EOF_
|
100
|
+
|
101
|
+
@stdin_io.write(len_dump) ; @stdin_io.rewind
|
102
|
+
assert_equal 1, go_with_args(["-l", "2"])
|
103
|
+
assert_equal("helu foo", @stdout_io.string)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_bad_len
|
107
|
+
@stdin_io.write(@bigtst_dump) ; @stdin_io.rewind
|
108
|
+
assert_equal 1, go_with_args(["-l", "-4"])
|
109
|
+
assert_match(/length must be greater than zero/i, @stderr_io.string)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_bad_input
|
113
|
+
@stdin_io.write("bad monkey") ; @stdin_io.rewind
|
114
|
+
assert_equal 1, go_with_args([])
|
115
|
+
assert_match(/parse error/i, @stderr_io.string)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|