tracksperanto 2.6.3 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,128 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/helper'
2
-
3
- class TestProgressiveIO < Test::Unit::TestCase
4
-
5
- def e(s)
6
-
7
- # Make a mock File object from a string
8
- io = StringIO.new(s)
9
- mock_stat = flexmock(:size => s.length)
10
- flexmock(io).should_receive(:stat).and_return(mock_stat)
11
-
12
- Tracksperanto::ProgressiveIO.new(io)
13
- end
14
-
15
- def test_each
16
- io, messages = e("Mary\nHad\nA little\nLamb"), []
17
-
18
- io.progress_block = lambda do | offset, total |
19
- messages.push([offset, total])
20
- end
21
-
22
- lines = []
23
- io.each {|line| lines.push(line) }
24
- assert_equal ["Mary\n", "Had\n", "A little\n", "Lamb"], lines
25
- assert_equal [[5, 22], [9, 22], [18, 22], [22, 22]], messages
26
- end
27
-
28
- def test_each_byte
29
- io, messages = e("123"), []
30
-
31
- io.progress_block = lambda do | offset, total |
32
- messages.push([offset, total])
33
- end
34
-
35
- bytes = []
36
- io.each_byte{|s| bytes << s }
37
- assert_equal [49, 50, 51], bytes
38
- assert_equal [[1, 3], [2, 3], [3, 3]], messages
39
- end
40
-
41
- def test_getc
42
- io = e("123")
43
- io.progress_block = lambda do | offset, total |
44
- assert_equal [1, 3], [offset, total]
45
- end
46
- if RUBY_VERSION < "1.9"
47
- assert_equal 49, io.getc
48
- else
49
- assert_equal "1", io.getc
50
- end
51
- end
52
-
53
- def test_gets
54
- io = e("Mary\nHad\nA little\nLamb")
55
- io.progress_block = lambda do | offset, total |
56
- assert_equal [5, 22], [offset, total]
57
- end
58
- assert_equal "Mary\n", io.gets
59
- end
60
-
61
- def test_read
62
- io = e("Mary\nHad\nA little\nLamb")
63
- io.progress_block = lambda do | offset, total |
64
- assert_equal [15, 22], [offset, total]
65
- end
66
- assert_equal "Mary\nHad\nA litt", io.read(15)
67
- end
68
-
69
- def test_readchar
70
- io = e("123")
71
- io.progress_block = lambda do | offset, total |
72
- assert_equal [1, 3], [offset, total]
73
- end
74
-
75
- if RUBY_VERSION < "1.9"
76
- assert_equal 49, io.getc
77
- else
78
- assert_equal "1", io.getc
79
- end
80
- end
81
-
82
- def test_readline
83
- io = e("Mary\nHad\nA little\nLamb")
84
- io.progress_block = lambda do | offset, total |
85
- assert_equal [5, 22], [offset, total]
86
- end
87
- assert_equal "Mary\n", io.readline
88
- end
89
-
90
- def test_readlines
91
- io = e("Mary\nHad\nA little\nLamb")
92
- m = []
93
- io.progress_block = lambda do | offset, total |
94
- m.push([offset, total])
95
- end
96
-
97
- assert_equal ["Mary\n", "Had\n", "A little\n", "Lamb"], io.readlines
98
- assert_equal [[22, 22]], m
99
- end
100
-
101
- def test_seek
102
- io = e("Mary\nHad\nA little\nLamb")
103
- io.progress_block = lambda do | offset, total |
104
- assert_equal [6, 22], [offset, total]
105
- end
106
- io.seek(6)
107
- end
108
-
109
- def test_ungetc
110
- io = e("Mary\nHad\nA little\nLamb")
111
- m = []
112
- io.progress_block = lambda do | offset, total |
113
- m.push([offset, total])
114
- end
115
-
116
- io.getc
117
- io.ungetc(2)
118
- assert_equal [[1, 22], [0, 22]], m
119
- end
120
-
121
- def test_poseq
122
- io = e("Mary\nHad\nA little\nLamb")
123
- io.progress_block = lambda do | offset, total |
124
- assert_equal [2, 22], [offset, total]
125
- end
126
- io.pos = 2
127
- end
128
- end