bzip2-ruby 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,152 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- # This is the test from rubicon
4
-
5
- $LOAD_PATH.unshift(*%w{.. tests})
6
- require 'rubygems'
7
- require 'bzip2'
8
- require 'runit_'
9
-
10
- Inh = defined?(RUNIT) ? RUNIT : Test::Unit
11
-
12
- $file = "_10lines_"
13
-
14
- class Dummy
15
- def to_s
16
- "dummy"
17
- end
18
- end
19
-
20
- class TestWriter < Inh::TestCase
21
-
22
- def test_f_LSHIFT # '<<'
23
- Bzip2::Writer.open($file, "w") do |file|
24
- file << 1 << "\n" << Dummy.new << "\n" << "cat\n"
25
- end
26
- expected = [ "1\n", "dummy\n", "cat\n"]
27
- Bzip2::Reader.foreach($file) do |line|
28
- assert_equal(expected.shift, line)
29
- end
30
- assert_equal([], expected)
31
- end
32
-
33
- def test_f_error
34
- io = File.new($file, "w")
35
- bz2 = Bzip2::Writer.new(io)
36
- bz2 << 1 << "\n" << Dummy.new << "\n" << "cat\n"
37
- bz = Bzip2::Reader.new($file)
38
- assert_raises(Bzip2::Error) { bz.gets }
39
- bz = Bzip2::Reader.open($file)
40
- assert_raises(Bzip2::EOZError) { bz.gets }
41
- io.close
42
- assert_raises(IOError) { Bzip2::Reader.new(io) }
43
- end
44
-
45
- def test_f_gets_para
46
- Bzip2::Writer.open($file) do |file|
47
- file.print "foo\n"*4096, "\n"*4096, "bar"*4096, "\n"*4096, "zot\n"*1024
48
- end
49
- Bzip2::Reader.open($file) do |file|
50
- assert_equal("foo\n"*4096+"\n", file.gets(""))
51
- assert_equal("bar"*4096+"\n\n", file.gets(""))
52
- assert_equal("zot\n"*1024, file.gets(""))
53
- end
54
- end
55
-
56
- def test_f_print
57
- Bzip2::Writer.open($file) do |file|
58
- file.print "hello"
59
- file.print 1,2
60
- $_ = "wombat\n"
61
- file.print
62
- $\ = ":"
63
- $, = ","
64
- file.print 3, 4
65
- file.print 5, 6
66
- $\ = nil
67
- file.print "\n"
68
- $, = nil
69
- end
70
-
71
- Bzip2::Reader.open($file) do |file|
72
- content = file.gets(nil)
73
- assert_equal("hello12wombat\n3,4:5,6:\n", content)
74
- end
75
- end
76
-
77
- def test_f_putc
78
- Bzip2::Writer.open($file, "wb") do |file|
79
- file.putc "A"
80
- 0.upto(255) { |ch| file.putc ch }
81
- end
82
-
83
- Bzip2::Reader.open($file, "rb") do |file|
84
- assert_equal(?A, file.getc)
85
- 0.upto(255) { |ch| assert_equal(ch, file.getc) }
86
- end
87
- end
88
-
89
- def test_f_puts
90
- Bzip2::Writer.open($file, "w") do |file|
91
- file.puts "line 1", "line 2"
92
- file.puts [ Dummy.new, 4 ]
93
- end
94
-
95
- Bzip2::Reader.open($file) do |file|
96
- assert_equal("line 1\n", file.gets)
97
- assert_equal("line 2\n", file.gets)
98
- assert_equal("dummy\n", file.gets)
99
- assert_equal("4\n", file.gets)
100
- end
101
- end
102
-
103
- def test_f_write
104
- Bzip2::Writer.open($file, "w") do |file|
105
- assert_equal(10, file.write('*' * 10))
106
- assert_equal(5, file.write('!' * 5))
107
- assert_equal(0, file.write(''))
108
- assert_equal(1, file.write(1))
109
- assert_equal(3, file.write(2.30000))
110
- assert_equal(1, file.write("\n"))
111
- end
112
-
113
- Bzip2::Reader.open($file) do |file|
114
- assert_equal("**********!!!!!12.3\n", file.gets)
115
- end
116
- end
117
-
118
- def test_s_string
119
- file = Bzip2::Writer.new
120
- assert_equal(10, file.write('*' * 10))
121
- assert_equal(5, file.write('!' * 5))
122
- assert_equal(0, file.write(''))
123
- assert_equal(1, file.write(1))
124
- assert_equal(3, file.write(2.30000))
125
- assert_equal(1, file.write("\n"))
126
- line = Bzip2::bunzip2(file.flush)
127
- assert_equal("**********!!!!!12.3\n", line)
128
-
129
- line = Bzip2::bunzip2(Bzip2::bzip2("**********!!!!!12.3\n"))
130
- assert_equal("**********!!!!!12.3\n", line)
131
-
132
- test = "foo\n"*4096 + "\n"*4096 + "bar"*4096 + "\n"*4096 + "zot\n"*1024
133
- line = Bzip2::bunzip2(Bzip2::bzip2(test))
134
- assert_equal(test, line)
135
-
136
- assert(Bzip2::bzip2("aaaaaaaaa".taint).tainted?)
137
- assert(Bzip2::bunzip2(Bzip2::bzip2("aaaaaaaaa".taint)).tainted?)
138
- assert(!Bzip2::bzip2("aaaaaaaaa").tainted?)
139
- assert(!Bzip2::bunzip2(Bzip2::bzip2("aaaaaaaaa")).tainted?)
140
-
141
- end
142
-
143
- def test_zzz
144
- File.unlink($file)
145
- end
146
- end
147
-
148
- if defined?(RUNIT)
149
- RUNIT::CUI::TestRunner.run(TestWriter.suite)
150
- end
151
-
152
-