io-like 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.yardopts +1 -0
  2. data/LICENSE +22 -57
  3. data/{LICENSE.rubyspec → LICENSE-rubyspec} +0 -0
  4. data/{NEWS → NEWS.md} +10 -5
  5. data/README.md +269 -0
  6. data/Rakefile +228 -0
  7. data/ruby.1.8.mspec +7 -0
  8. data/spec/binmode_spec.rb +29 -0
  9. data/spec/close_read_spec.rb +64 -0
  10. data/spec/close_spec.rb +36 -0
  11. data/spec/close_write_spec.rb +61 -0
  12. data/spec/closed_spec.rb +16 -0
  13. data/spec/each_byte_spec.rb +38 -0
  14. data/spec/each_line_spec.rb +11 -0
  15. data/spec/each_spec.rb +11 -0
  16. data/spec/eof_spec.rb +11 -0
  17. data/spec/fixtures/classes.rb +96 -0
  18. data/spec/fixtures/gets.txt +9 -0
  19. data/spec/fixtures/numbered_lines.txt +5 -0
  20. data/spec/fixtures/one_byte.txt +1 -0
  21. data/spec/fixtures/paragraphs.txt +7 -0
  22. data/spec/fixtures/readlines.txt +6 -0
  23. data/spec/flush_spec.rb +8 -0
  24. data/spec/getc_spec.rb +44 -0
  25. data/spec/gets_spec.rb +212 -0
  26. data/spec/isatty_spec.rb +6 -0
  27. data/spec/lineno_spec.rb +84 -0
  28. data/spec/output_spec.rb +47 -0
  29. data/spec/pos_spec.rb +53 -0
  30. data/spec/print_spec.rb +97 -0
  31. data/spec/printf_spec.rb +24 -0
  32. data/spec/putc_spec.rb +57 -0
  33. data/spec/puts_spec.rb +99 -0
  34. data/spec/read_spec.rb +162 -0
  35. data/spec/readchar_spec.rb +49 -0
  36. data/spec/readline_spec.rb +60 -0
  37. data/spec/readlines_spec.rb +140 -0
  38. data/spec/readpartial_spec.rb +92 -0
  39. data/spec/rewind_spec.rb +56 -0
  40. data/spec/seek_spec.rb +72 -0
  41. data/spec/shared/each.rb +204 -0
  42. data/spec/shared/eof.rb +116 -0
  43. data/spec/shared/pos.rb +39 -0
  44. data/spec/shared/tty.rb +12 -0
  45. data/spec/shared/write.rb +53 -0
  46. data/spec/sync_spec.rb +56 -0
  47. data/spec/sysread_spec.rb +87 -0
  48. data/spec/sysseek_spec.rb +68 -0
  49. data/spec/syswrite_spec.rb +60 -0
  50. data/spec/tell_spec.rb +7 -0
  51. data/spec/to_io_spec.rb +19 -0
  52. data/spec/tty_spec.rb +6 -0
  53. data/spec/ungetc_spec.rb +118 -0
  54. data/spec/write_spec.rb +61 -0
  55. data/spec_helper.rb +49 -0
  56. metadata +223 -32
  57. data/CONTRIBUTORS +0 -15
  58. data/GPL +0 -676
  59. data/HACKING +0 -123
  60. data/LEGAL +0 -56
  61. data/MANIFEST +0 -10
  62. data/README +0 -150
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/fixtures/classes'
3
+ require File.dirname(__FILE__) + '/shared/pos'
4
+
5
+ describe "IO::Like#tell" do
6
+ it_behaves_like(:io_like__pos, :tell)
7
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/fixtures/classes'
3
+
4
+ describe "IO::Like#to_io" do
5
+ it "returns self for open stream" do
6
+ IOSpecs.readable_iowrapper do |iowrapper|
7
+ iowrapper.to_io.should == iowrapper
8
+ end
9
+
10
+ IOSpecs.writable_iowrapper do |iowrapper|
11
+ iowrapper.to_io.should == iowrapper
12
+ end
13
+ end
14
+
15
+ it "returns self for closed stream" do
16
+ io = IOSpecs.closed_file
17
+ io.to_io.should == io
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/shared/tty'
3
+
4
+ describe "IO::Like#tty?" do
5
+ it_behaves_like :io_like__tty, :tty?
6
+ end
@@ -0,0 +1,118 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/fixtures/classes'
3
+
4
+ describe "IO::Like#ungetc" do
5
+ before :each do
6
+ @file_name = File.dirname(__FILE__) + '/fixtures/readlines.txt'
7
+ @file = File.open(@file_name, 'r')
8
+ @iowrapper = ReadableIOWrapper.open(@file)
9
+ end
10
+
11
+ after :each do
12
+ @iowrapper.close unless @iowrapper.closed?
13
+ @file.close unless @file.closed?
14
+ end
15
+
16
+ it "pushes back one character onto stream" do
17
+ @iowrapper.getc.should == 86
18
+ @iowrapper.ungetc(86)
19
+ @iowrapper.getc.should == 86
20
+
21
+ @iowrapper.ungetc(10)
22
+ @iowrapper.getc.should == 10
23
+
24
+ @iowrapper.getc.should == 111
25
+ @iowrapper.getc.should == 105
26
+ # read the rest of line
27
+ @iowrapper.readline.should == "ci la ligne une.\n"
28
+ @iowrapper.getc.should == 81
29
+ @iowrapper.ungetc(99)
30
+ @iowrapper.getc.should == 99
31
+ end
32
+
33
+ it "pushes back one character when invoked at the end of the stream" do
34
+ # read entire content
35
+ @iowrapper.read
36
+ @iowrapper.ungetc(100)
37
+ @iowrapper.getc.should == 100
38
+ end
39
+
40
+ it "pushes back one character when invoked at the start of the stream" do
41
+ @iowrapper.read(0)
42
+ @iowrapper.ungetc(100)
43
+ @iowrapper.getc.should == 100
44
+ end
45
+
46
+ it "pushes back one character when invoked on empty stream" do
47
+ path = tmp('empty.txt')
48
+ File.open(path, "w+") do |empty|
49
+ IOWrapper.open(empty) do |iowrapper|
50
+ iowrapper.getc().should == nil
51
+ iowrapper.ungetc(10)
52
+ iowrapper.getc.should == 10
53
+ end
54
+ end
55
+ File.unlink(path)
56
+ end
57
+
58
+ it "affects EOF state" do
59
+ path = tmp('empty.txt')
60
+ File.open(path, "w+") do |empty|
61
+ IOWrapper.open(empty) do |iowrapper|
62
+ iowrapper.eof?.should == true
63
+ iowrapper.getc.should == nil
64
+ iowrapper.ungetc(100)
65
+ iowrapper.eof?.should == false
66
+ end
67
+ end
68
+ File.unlink(path)
69
+ end
70
+
71
+ it "adjusts the stream position" do
72
+ @iowrapper.pos.should == 0
73
+
74
+ # read one char
75
+ c = @iowrapper.getc
76
+ @iowrapper.pos.should == 1
77
+ @iowrapper.ungetc(c)
78
+ @iowrapper.pos.should == 0
79
+
80
+ # read all
81
+ @iowrapper.read
82
+ pos = @iowrapper.pos
83
+ @iowrapper.ungetc(98)
84
+ @iowrapper.pos.should == pos - 1
85
+ end
86
+
87
+ # TODO: file MRI bug
88
+ # Another specified behavior that MRI doesn't follow:
89
+ # "Has no effect with unbuffered reads (such as IO#sysread)."
90
+ #
91
+ #it "has no effect with unbuffered reads" do
92
+ # length = File.size(@file_name)
93
+ # content = @iowrapper.sysread(length)
94
+ # @iowrapper.rewind
95
+ # @iowrapper.ungetc(100)
96
+ # @iowrapper.sysread(length).should == content
97
+ #end
98
+
99
+ it "makes subsequent unbuffered operations to raise IOError" do
100
+ @iowrapper.getc
101
+ @iowrapper.ungetc(100)
102
+ lambda { @iowrapper.sysread(1) }.should raise_error(IOError)
103
+ end
104
+
105
+ # WORKS AS DESIGNED:
106
+ # Since IO::Like has complete control over the read buffer, it supports
107
+ # pushing unlimited data into that buffer at any time on any readable stream.
108
+ #
109
+ #it "raises IOError when invoked on stream that was not yet read" do
110
+ # lambda { @iowrapper.ungetc(100) }.should raise_error(IOError)
111
+ #end
112
+
113
+ it "raises IOError on closed stream" do
114
+ @iowrapper.getc
115
+ @iowrapper.close
116
+ lambda { @iowrapper.ungetc(100) }.should raise_error(IOError)
117
+ end
118
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/fixtures/classes'
3
+ require File.dirname(__FILE__) + '/shared/write'
4
+
5
+ describe "IO::Like#write" do
6
+ before :each do
7
+ @filename = tmp("IO_Like__write_test")
8
+ @content = "012345678901234567890123456789"
9
+ File.open(@filename, "w") { |f| f.syswrite(@content) }
10
+ @file = File.open(@filename, "r+")
11
+ @iowrapper = IOWrapper.open(@file)
12
+ end
13
+
14
+ after :each do
15
+ @iowrapper.close unless @iowrapper.closed?
16
+ @file.close unless @file.closed?
17
+ File.delete(@filename)
18
+ end
19
+
20
+ # TODO: impl detail? discuss this with matz. This spec is useless. - rdavis
21
+ it "writes all of the string's bytes but buffers them" do
22
+ written = @iowrapper.write("abcde")
23
+ written.should == 5
24
+ File.open(@filename) do |file|
25
+ file.read.should == "012345678901234567890123456789"
26
+ @iowrapper.flush
27
+ file.rewind
28
+ file.read.should == "abcde5678901234567890123456789"
29
+ end
30
+ end
31
+
32
+ it "returns the number of bytes written" do
33
+ @iowrapper.write('').should == 0
34
+ @iowrapper.write('abcde').should == 5
35
+ end
36
+
37
+ it "writes all of the string's bytes without buffering if mode is sync" do
38
+ @iowrapper.sync = true
39
+ written = @iowrapper.write("abcde")
40
+ written.should == 5
41
+ File.open(@filename) do |file|
42
+ file.read(10).should == "abcde56789"
43
+ end
44
+ end
45
+
46
+ it "does not raise IOError on read-only stream if writing zero bytes" do
47
+ lambda do
48
+ IOSpecs.readable_iowrapper do |iowrapper|
49
+ iowrapper.write("")
50
+ end
51
+ end.should_not raise_error
52
+ end
53
+
54
+ it "does not raise IOError on closed stream if writing zero bytes" do
55
+ lambda { IOSpecs.closed_file.write("") }.should_not raise_error
56
+ end
57
+ end
58
+
59
+ describe "IO::Like#write" do
60
+ it_behaves_like :io_like__write, :write
61
+ end
@@ -0,0 +1,49 @@
1
+ unless ENV['MSPEC_RUNNER']
2
+ begin
3
+ require "pp"
4
+ require 'mspec/version'
5
+ require 'mspec/helpers'
6
+ require 'mspec/guards'
7
+ require 'mspec/runner/shared'
8
+ require 'mspec/matchers/be_ancestor_of'
9
+ require 'mspec/matchers/output'
10
+ require 'mspec/matchers/output_to_fd'
11
+ require 'mspec/matchers/complain'
12
+ require 'mspec/matchers/equal_element'
13
+ require 'mspec/matchers/equal_utf16'
14
+ require 'mspec/matchers/match_yaml'
15
+
16
+ # Code to setup HOME directory correctly on Windows
17
+ # This duplicates Ruby 1.9 semantics for defining HOME
18
+ platform_is :windows do
19
+ if ENV['HOME']
20
+ ENV['HOME'] = ENV['HOME'].tr '\\', '/'
21
+ elsif ENV['HOMEDIR'] && ENV['HOMEDRIVE']
22
+ ENV['HOME'] = File.join(ENV['HOMEDRIVE'], ENV['HOMEDIR'])
23
+ elsif ENV['HOMEDIR']
24
+ ENV['HOME'] = ENV['HOMEDIR']
25
+ elsif ENV['HOMEDRIVE']
26
+ ENV['HOME'] = ENV['HOMEDRIVE']
27
+ elsif ENV['USERPROFILE']
28
+ ENV['HOME'] = ENV['USERPROFILE']
29
+ else
30
+ puts "No suitable HOME environment found. This means that all of"
31
+ puts "HOME, HOMEDIR, HOMEDRIVE, and USERPROFILE are not set"
32
+ exit 1
33
+ end
34
+ end
35
+
36
+ TOLERANCE = 0.00003 unless Object.const_defined?(:TOLERANCE)
37
+ rescue LoadError
38
+ puts "Please install the MSpec gem to run the specs."
39
+ exit 1
40
+ end
41
+ end
42
+
43
+ minimum_version = "1.5.9"
44
+ unless MSpec::VERSION >= minimum_version
45
+ puts "Please install MSpec version >= #{minimum_version} to run the specs"
46
+ exit 1
47
+ end
48
+
49
+ $VERBOSE = nil unless ENV['OUTPUT_WARNINGS']
metadata CHANGED
@@ -1,46 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-like
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Jeremy Bopp
14
+ - Jarred Holman
15
+ - Grant Gardner
16
+ - Jordan Pickwell
8
17
  autorequire:
9
18
  bindir: bin
10
19
  cert_chain: []
11
20
 
12
- date: 2009-04-29 00:00:00 -05:00
13
- default_executable:
14
- dependencies: []
21
+ date: 2020-02-09 00:00:00 Z
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 37
30
+ segments:
31
+ - 10
32
+ - 3
33
+ version: "10.3"
34
+ version_requirements: *id001
35
+ name: rake
36
+ type: :development
37
+ prerelease: false
38
+ - !ruby/object:Gem::Dependency
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 5
45
+ segments:
46
+ - 1
47
+ - 5
48
+ version: "1.5"
49
+ version_requirements: *id002
50
+ name: mspec
51
+ type: :development
52
+ prerelease: false
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 27
60
+ segments:
61
+ - 0
62
+ - 8
63
+ version: "0.8"
64
+ version_requirements: *id003
65
+ name: yard
66
+ type: :development
67
+ prerelease: false
68
+ - !ruby/object:Gem::Dependency
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 11
75
+ segments:
76
+ - 0
77
+ - 0
78
+ version: "0.0"
79
+ version_requirements: *id004
80
+ name: yard-redcarpet-ext
81
+ type: :development
82
+ prerelease: false
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 11
90
+ segments:
91
+ - 1
92
+ - 2
93
+ version: "1.2"
94
+ version_requirements: *id005
95
+ name: github-markup
96
+ type: :development
97
+ prerelease: false
98
+ description: |
99
+ The IO::Like module provides all of the methods of typical IO implementations
100
+ such as File; most importantly the read, write, and seek series of methods. A
101
+ class which includes IO::Like needs to provide only a few methods in order to
102
+ enable the higher level methods. Buffering is automatically provided by default
103
+ for the methods which normally provide it in IO.
15
104
 
16
- description: "The IO::Like module provides the methods of an IO object based upon on a few simple methods provided by the including class: unbuffered_read, unbuffered_write, and unbuffered_seek. These methods provide the underlying read, write, and seek support respectively, and only the method or methods necessary to the correct operation of the IO aspects of the including class need to be provided. Missing functionality will cause the resulting object to appear read-only, write-only, and/or unseekable depending on which underlying methods are absent. Additionally, read and write operations which are buffered in IO are buffered with independently configurable buffer sizes. Duplexed objects (those with separate read and write streams) are also supported."
17
- email: jeremy at bopp dot net
105
+ email:
106
+ - jeremy@bopp.net
107
+ - jarred.holman@gmail.com
108
+ - grant@lastweekend.com.au
109
+ - jpickwell@users.noreply.github.com
18
110
  executables: []
19
111
 
20
112
  extensions: []
21
113
 
22
114
  extra_rdoc_files:
23
- - CONTRIBUTORS
24
- - HACKING
25
115
  - LICENSE
26
- - LICENSE.rubyspec
27
- - GPL
28
- - LEGAL
29
- - NEWS
30
- - README
116
+ - LICENSE-rubyspec
117
+ - NEWS.md
118
+ - README.md
31
119
  files:
32
- - lib/io/like.rb
33
- - CONTRIBUTORS
34
- - HACKING
120
+ - .yardopts
35
121
  - LICENSE
36
- - LICENSE.rubyspec
37
- - GPL
38
- - LEGAL
39
- - NEWS
40
- - README
41
- - MANIFEST
42
- has_rdoc: true
43
- homepage: http://io-like.rubyforge.org
122
+ - LICENSE-rubyspec
123
+ - NEWS.md
124
+ - README.md
125
+ - Rakefile
126
+ - lib/io/like.rb
127
+ - ruby.1.8.mspec
128
+ - spec/binmode_spec.rb
129
+ - spec/close_read_spec.rb
130
+ - spec/close_spec.rb
131
+ - spec/close_write_spec.rb
132
+ - spec/closed_spec.rb
133
+ - spec/each_byte_spec.rb
134
+ - spec/each_line_spec.rb
135
+ - spec/each_spec.rb
136
+ - spec/eof_spec.rb
137
+ - spec/fixtures/classes.rb
138
+ - spec/fixtures/gets.txt
139
+ - spec/fixtures/numbered_lines.txt
140
+ - spec/fixtures/one_byte.txt
141
+ - spec/fixtures/paragraphs.txt
142
+ - spec/fixtures/readlines.txt
143
+ - spec/flush_spec.rb
144
+ - spec/getc_spec.rb
145
+ - spec/gets_spec.rb
146
+ - spec/isatty_spec.rb
147
+ - spec/lineno_spec.rb
148
+ - spec/output_spec.rb
149
+ - spec/pos_spec.rb
150
+ - spec/print_spec.rb
151
+ - spec/printf_spec.rb
152
+ - spec/putc_spec.rb
153
+ - spec/puts_spec.rb
154
+ - spec/read_spec.rb
155
+ - spec/readchar_spec.rb
156
+ - spec/readline_spec.rb
157
+ - spec/readlines_spec.rb
158
+ - spec/readpartial_spec.rb
159
+ - spec/rewind_spec.rb
160
+ - spec/seek_spec.rb
161
+ - spec/shared/each.rb
162
+ - spec/shared/eof.rb
163
+ - spec/shared/pos.rb
164
+ - spec/shared/tty.rb
165
+ - spec/shared/write.rb
166
+ - spec/sync_spec.rb
167
+ - spec/sysread_spec.rb
168
+ - spec/sysseek_spec.rb
169
+ - spec/syswrite_spec.rb
170
+ - spec/tell_spec.rb
171
+ - spec/to_io_spec.rb
172
+ - spec/tty_spec.rb
173
+ - spec/ungetc_spec.rb
174
+ - spec/write_spec.rb
175
+ - spec_helper.rb
176
+ homepage: http://github.com/javanthropus/io-like
177
+ licenses:
178
+ - MIT
44
179
  post_install_message:
45
180
  rdoc_options:
46
181
  - --title
@@ -52,23 +187,79 @@ rdoc_options:
52
187
  require_paths:
53
188
  - lib
54
189
  required_ruby_version: !ruby/object:Gem::Requirement
190
+ none: false
55
191
  requirements:
56
192
  - - ">="
57
193
  - !ruby/object:Gem::Version
194
+ hash: 53
195
+ segments:
196
+ - 1
197
+ - 8
198
+ - 1
58
199
  version: 1.8.1
59
- version:
60
200
  required_rubygems_version: !ruby/object:Gem::Requirement
201
+ none: false
61
202
  requirements:
62
203
  - - ">="
63
204
  - !ruby/object:Gem::Version
205
+ hash: 3
206
+ segments:
207
+ - 0
64
208
  version: "0"
65
- version:
66
209
  requirements: []
67
210
 
68
- rubyforge_project: io-like
69
- rubygems_version: 1.3.1
211
+ rubyforge_project:
212
+ rubygems_version: 1.8.15
70
213
  signing_key:
71
- specification_version: 2
72
- summary: A module which provides the functionality of an IO object to any class which provides a couple of simple methods.
73
- test_files: []
74
-
214
+ specification_version: 3
215
+ summary: A module which provides the functionality of an IO object to any including class which provides a couple of simple methods.
216
+ test_files:
217
+ - ruby.1.8.mspec
218
+ - spec/binmode_spec.rb
219
+ - spec/close_read_spec.rb
220
+ - spec/close_spec.rb
221
+ - spec/close_write_spec.rb
222
+ - spec/closed_spec.rb
223
+ - spec/each_byte_spec.rb
224
+ - spec/each_line_spec.rb
225
+ - spec/each_spec.rb
226
+ - spec/eof_spec.rb
227
+ - spec/fixtures/classes.rb
228
+ - spec/fixtures/gets.txt
229
+ - spec/fixtures/numbered_lines.txt
230
+ - spec/fixtures/one_byte.txt
231
+ - spec/fixtures/paragraphs.txt
232
+ - spec/fixtures/readlines.txt
233
+ - spec/flush_spec.rb
234
+ - spec/getc_spec.rb
235
+ - spec/gets_spec.rb
236
+ - spec/isatty_spec.rb
237
+ - spec/lineno_spec.rb
238
+ - spec/output_spec.rb
239
+ - spec/pos_spec.rb
240
+ - spec/print_spec.rb
241
+ - spec/printf_spec.rb
242
+ - spec/putc_spec.rb
243
+ - spec/puts_spec.rb
244
+ - spec/read_spec.rb
245
+ - spec/readchar_spec.rb
246
+ - spec/readline_spec.rb
247
+ - spec/readlines_spec.rb
248
+ - spec/readpartial_spec.rb
249
+ - spec/rewind_spec.rb
250
+ - spec/seek_spec.rb
251
+ - spec/shared/each.rb
252
+ - spec/shared/eof.rb
253
+ - spec/shared/pos.rb
254
+ - spec/shared/tty.rb
255
+ - spec/shared/write.rb
256
+ - spec/sync_spec.rb
257
+ - spec/sysread_spec.rb
258
+ - spec/sysseek_spec.rb
259
+ - spec/syswrite_spec.rb
260
+ - spec/tell_spec.rb
261
+ - spec/to_io_spec.rb
262
+ - spec/tty_spec.rb
263
+ - spec/ungetc_spec.rb
264
+ - spec/write_spec.rb
265
+ - spec_helper.rb