bzip2-ruby 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.rdoc +23 -0
- data/Rakefile +19 -0
- data/VERSION.yml +4 -0
- data/bzip2-ruby.gemspec +50 -0
- data/ext/bz2.c +1582 -0
- data/ext/extconf.rb +13 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/extconf/bz2.rake +43 -0
- data/test/reader.rb +369 -0
- data/test/runit_.rb +32 -0
- data/test/writer.rb +151 -0
- metadata +69 -0
data/test/writer.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# This is the test from rubicon
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(*%w{.. tests})
|
6
|
+
require 'bz2'
|
7
|
+
require 'runit_'
|
8
|
+
|
9
|
+
Inh = defined?(RUNIT) ? RUNIT : Test::Unit
|
10
|
+
|
11
|
+
$file = "_10lines_"
|
12
|
+
|
13
|
+
class Dummy
|
14
|
+
def to_s
|
15
|
+
"dummy"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class TestWriter < Inh::TestCase
|
20
|
+
|
21
|
+
def test_f_LSHIFT # '<<'
|
22
|
+
BZ2::Writer.open($file, "w") do |file|
|
23
|
+
file << 1 << "\n" << Dummy.new << "\n" << "cat\n"
|
24
|
+
end
|
25
|
+
expected = [ "1\n", "dummy\n", "cat\n"]
|
26
|
+
BZ2::Reader.foreach($file) do |line|
|
27
|
+
assert_equal(expected.shift, line)
|
28
|
+
end
|
29
|
+
assert_equal([], expected)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_f_error
|
33
|
+
io = File.new($file, "w")
|
34
|
+
bz2 = BZ2::Writer.new(io)
|
35
|
+
bz2 << 1 << "\n" << Dummy.new << "\n" << "cat\n"
|
36
|
+
bz = BZ2::Reader.new($file)
|
37
|
+
assert_raises(BZ2::Error) { bz.gets }
|
38
|
+
bz = BZ2::Reader.open($file)
|
39
|
+
assert_raises(BZ2::EOZError) { bz.gets }
|
40
|
+
io.close
|
41
|
+
assert_raises(IOError) { BZ2::Reader.new(io) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_f_gets_para
|
45
|
+
BZ2::Writer.open($file) do |file|
|
46
|
+
file.print "foo\n"*4096, "\n"*4096, "bar"*4096, "\n"*4096, "zot\n"*1024
|
47
|
+
end
|
48
|
+
BZ2::Reader.open($file) do |file|
|
49
|
+
assert_equal("foo\n"*4096+"\n", file.gets(""))
|
50
|
+
assert_equal("bar"*4096+"\n\n", file.gets(""))
|
51
|
+
assert_equal("zot\n"*1024, file.gets(""))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_f_print
|
56
|
+
BZ2::Writer.open($file) do |file|
|
57
|
+
file.print "hello"
|
58
|
+
file.print 1,2
|
59
|
+
$_ = "wombat\n"
|
60
|
+
file.print
|
61
|
+
$\ = ":"
|
62
|
+
$, = ","
|
63
|
+
file.print 3, 4
|
64
|
+
file.print 5, 6
|
65
|
+
$\ = nil
|
66
|
+
file.print "\n"
|
67
|
+
$, = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
BZ2::Reader.open($file) do |file|
|
71
|
+
content = file.gets(nil)
|
72
|
+
assert_equal("hello12wombat\n3,4:5,6:\n", content)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_f_putc
|
77
|
+
BZ2::Writer.open($file, "wb") do |file|
|
78
|
+
file.putc "A"
|
79
|
+
0.upto(255) { |ch| file.putc ch }
|
80
|
+
end
|
81
|
+
|
82
|
+
BZ2::Reader.open($file, "rb") do |file|
|
83
|
+
assert_equal(?A, file.getc)
|
84
|
+
0.upto(255) { |ch| assert_equal(ch, file.getc) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_f_puts
|
89
|
+
BZ2::Writer.open($file, "w") do |file|
|
90
|
+
file.puts "line 1", "line 2"
|
91
|
+
file.puts [ Dummy.new, 4 ]
|
92
|
+
end
|
93
|
+
|
94
|
+
BZ2::Reader.open($file) do |file|
|
95
|
+
assert_equal("line 1\n", file.gets)
|
96
|
+
assert_equal("line 2\n", file.gets)
|
97
|
+
assert_equal("dummy\n", file.gets)
|
98
|
+
assert_equal("4\n", file.gets)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_f_write
|
103
|
+
BZ2::Writer.open($file, "w") do |file|
|
104
|
+
assert_equal(10, file.write('*' * 10))
|
105
|
+
assert_equal(5, file.write('!' * 5))
|
106
|
+
assert_equal(0, file.write(''))
|
107
|
+
assert_equal(1, file.write(1))
|
108
|
+
assert_equal(3, file.write(2.30000))
|
109
|
+
assert_equal(1, file.write("\n"))
|
110
|
+
end
|
111
|
+
|
112
|
+
BZ2::Reader.open($file) do |file|
|
113
|
+
assert_equal("**********!!!!!12.3\n", file.gets)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_s_string
|
118
|
+
file = BZ2::Writer.new
|
119
|
+
assert_equal(10, file.write('*' * 10))
|
120
|
+
assert_equal(5, file.write('!' * 5))
|
121
|
+
assert_equal(0, file.write(''))
|
122
|
+
assert_equal(1, file.write(1))
|
123
|
+
assert_equal(3, file.write(2.30000))
|
124
|
+
assert_equal(1, file.write("\n"))
|
125
|
+
line = BZ2::bunzip2(file.flush)
|
126
|
+
assert_equal("**********!!!!!12.3\n", line)
|
127
|
+
|
128
|
+
line = BZ2::bunzip2(BZ2::bzip2("**********!!!!!12.3\n"))
|
129
|
+
assert_equal("**********!!!!!12.3\n", line)
|
130
|
+
|
131
|
+
test = "foo\n"*4096 + "\n"*4096 + "bar"*4096 + "\n"*4096 + "zot\n"*1024
|
132
|
+
line = BZ2::bunzip2(BZ2::bzip2(test))
|
133
|
+
assert_equal(test, line)
|
134
|
+
|
135
|
+
assert(BZ2::bzip2("aaaaaaaaa".taint).tainted?)
|
136
|
+
assert(BZ2::bunzip2(BZ2::bzip2("aaaaaaaaa".taint)).tainted?)
|
137
|
+
assert(!BZ2::bzip2("aaaaaaaaa").tainted?)
|
138
|
+
assert(!BZ2::bunzip2(BZ2::bzip2("aaaaaaaaa")).tainted?)
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_zzz
|
143
|
+
File.unlink($file)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
if defined?(RUNIT)
|
148
|
+
RUNIT::CUI::TestRunner.run(TestWriter.suite)
|
149
|
+
end
|
150
|
+
|
151
|
+
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bzip2-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guy Decoux
|
8
|
+
- Brian Lopez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-05-02 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: seniorlopez@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions:
|
22
|
+
- ext/extconf.rb
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- History.txt
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION.yml
|
30
|
+
- bzip2-ruby.gemspec
|
31
|
+
- ext/bz2.c
|
32
|
+
- ext/extconf.rb
|
33
|
+
- tasks/extconf.rake
|
34
|
+
- tasks/extconf/bz2.rake
|
35
|
+
- test/reader.rb
|
36
|
+
- test/runit_.rb
|
37
|
+
- test/writer.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/brianmario/bzip2-ruby
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --charset=UTF-8
|
45
|
+
require_paths:
|
46
|
+
- ext
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Ruby C bindings to libbzip2.
|
66
|
+
test_files:
|
67
|
+
- test/reader.rb
|
68
|
+
- test/runit_.rb
|
69
|
+
- test/writer.rb
|