test/delimited_reader_test.rb in iostreams-0.8.2 vs test/delimited_reader_test.rb in iostreams-0.9.0
- old
+ new
@@ -1,69 +1,79 @@
require_relative 'test_helper'
# Unit Test for IOStreams::File
module Streams
class DelimitedReaderTest < Minitest::Test
- describe IOStreams::File::Reader do
+ describe IOStreams::Delimited::Reader do
before do
@file_name = File.join(File.dirname(__FILE__), 'files', 'text.txt')
@data = []
File.open(@file_name, 'rt') do |file|
while !file.eof?
@data << file.readline.strip
end
end
end
- describe '.open' do
+ describe '#each' do
it 'each_line file' do
lines = []
IOStreams::Delimited::Reader.open(@file_name) do |io|
- io.each_line { |line| lines << line }
+ io.each { |line| lines << line }
end
assert_equal @data, lines
end
it 'each_line stream' do
lines = []
File.open(@file_name) do |file|
IOStreams::Delimited::Reader.open(file) do |io|
- io.each_line { |line| lines << line }
+ io.each { |line| lines << line }
end
end
assert_equal @data, lines
end
["\r\n", "\n\r", "\n", "\r"].each do |delimiter|
it "autodetect delimiter: #{delimiter.inspect}" do
lines = []
stream = StringIO.new(@data.join(delimiter))
IOStreams::Delimited::Reader.open(stream, buffer_size: 15) do |io|
- io.each_line { |line| lines << line }
+ io.each { |line| lines << line }
end
assert_equal @data, lines
end
end
['@', 'BLAH'].each do |delimiter|
- it "read delimited #{delimiter.inspect}" do
+ it "reads delimited #{delimiter.inspect}" do
lines = []
stream = StringIO.new(@data.join(delimiter))
IOStreams::Delimited::Reader.open(stream, buffer_size: 15, delimiter: delimiter) do |io|
- io.each_line { |line| lines << line }
+ io.each { |line| lines << line }
end
assert_equal @data, lines
end
end
- it "read binary delimited" do
+ it 'reads binary delimited' do
delimiter = "\x01"
lines = []
stream = StringIO.new(@data.join(delimiter))
IOStreams::Delimited::Reader.open(stream, buffer_size: 15, delimiter: delimiter, encoding: IOStreams::BINARY_ENCODING) do |io|
- io.each_line { |line| lines << line }
+ io.each { |line| lines << line }
end
assert_equal @data, lines
+ end
+ end
+
+ describe '.read' do
+ it 'reads without delimiter' do
+ result = IOStreams::Delimited::Reader.open(@file_name) do |io|
+ io.read
+ end
+ file = File.read(@file_name)
+ assert_equal file, result
end
end
end
end