-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from felixbuenemann/refactor-io-wrappers
Refactor IO Wrappers
- Loading branch information
Showing
7 changed files
with
174 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'test_helper' | ||
require 'xlsxtream/io/directory' | ||
require 'pathname' | ||
|
||
module Xlsxtream | ||
module IO | ||
class DirectoryTest < Minitest::Test | ||
|
||
def test_writes_of_multiple_files | ||
Dir.mktmpdir do |dir| | ||
io = Xlsxtream::IO::Directory.new(dir) | ||
io.add_file("book1.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />' | ||
io.add_file("book2.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook>' | ||
io << '</workbook>' | ||
io.add_file("empty.txt") | ||
io.add_file("another.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another />' | ||
io.close | ||
|
||
dir = Pathname(dir) | ||
assert_equal '', dir.join('empty.txt').read | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />', dir.join('book1.xml').read | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook></workbook>', dir.join('book2.xml').read | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another />', dir.join('another.xml').read | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'test_helper' | ||
require 'xlsxtream/io/hash' | ||
|
||
module Xlsxtream | ||
module IO | ||
class HashTest < Minitest::Test | ||
|
||
def test_writes_of_multiple_files | ||
buffer = StringIO.new | ||
|
||
io = Xlsxtream::IO::Hash.new(buffer) | ||
io.add_file("book1.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />' | ||
io.add_file("book2.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook>' | ||
io << '</workbook>' | ||
io.add_file("empty.txt") | ||
io.add_file("another.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another />' | ||
io.close | ||
|
||
file_contents = io.to_h | ||
assert_equal '', file_contents['empty.txt'] | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />', file_contents['book1.xml'] | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook></workbook>', file_contents['book2.xml'] | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another />', file_contents['another.xml'] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'test_helper' | ||
require 'xlsxtream/io/rubyzip' | ||
require 'zip' | ||
|
||
module Xlsxtream | ||
module IO | ||
class RubyZipTest < Minitest::Test | ||
|
||
def test_writes_of_multiple_files | ||
zip_buf = Tempfile.new('ztio-test') | ||
|
||
io = Xlsxtream::IO::RubyZip.new(zip_buf) | ||
io.add_file("book1.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />' | ||
io.add_file("book2.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook>' | ||
io << '</workbook>' | ||
io.add_file("empty.txt") | ||
io.add_file("another.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another />' | ||
io.close | ||
|
||
zip_buf.rewind | ||
|
||
file_contents = {} | ||
::Zip::File.open(zip_buf) do |zip_file| | ||
zip_file.each do |entry| | ||
file_contents[entry.name] = entry.get_input_stream.read | ||
end | ||
end | ||
assert_equal '', file_contents['empty.txt'] | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />', file_contents['book1.xml'] | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook></workbook>', file_contents['book2.xml'] | ||
assert_equal '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another />', file_contents['another.xml'] | ||
ensure | ||
zip_buf.close! if zip_buf | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'test_helper' | ||
require 'xlsxtream/io/stream' | ||
|
||
module Xlsxtream | ||
module IO | ||
class StreamTest < Minitest::Test | ||
|
||
def test_writes_of_multiple_files | ||
buffer = StringIO.new | ||
|
||
io = Xlsxtream::IO::Stream.new(buffer) | ||
io.add_file("book1.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />' | ||
io.add_file("book2.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook>' | ||
io << '</workbook>' | ||
io.add_file("empty.txt") | ||
io.add_file("another.xml") | ||
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another />' | ||
io.close | ||
|
||
file_contents = buffer.string | ||
assert_equal <<-EOF, file_contents | ||
book1.xml | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook /> | ||
book2.xml | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook></workbook> | ||
empty.txt | ||
another.xml | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><another /> | ||
EOF | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters