Skip to content

Commit

Permalink
Fix odd bug, where SXP.read_file and SXP.read_url were only retur…
Browse files Browse the repository at this point in the history
…ning the first expression read. This was likely an over-simplification for when the file contained only a single expression, and we didn't want to see this contained within an array.

@bendiken, if something relies on the old behavior, we could return the first expression if the result contains only a single expression, but that would seem to be less consistent behavior.

Fixes #14
  • Loading branch information
gkellogg committed Jan 20, 2017
1 parent 468bd25 commit 9e17ff9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ Resources
* <http://rubydoc.info/gems/sxp>
* <http://github.com/dryruby/sxp>
* <http://rubygems.org/gems/sxp>
* <http://rubyforge.org/projects/sxp/>
* <http://raa.ruby-lang.org/project/sxp>

Authors
-------
Expand All @@ -128,4 +126,3 @@ information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
[Scheme]: http://scheme.info/
[Common Lisp]: http://en.wikipedia.org/wiki/Common_Lisp
[SPARQL]: http://openjena.org/wiki/SSE
[Backports]: http://rubygems.org/gems/backports
4 changes: 2 additions & 2 deletions lib/sxp/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EOF < Error; end
# @return [Enumerable<Object>]
def self.read_url(url, options = {})
require 'open-uri'
open(url.to_s, 'rb', nil, options) { |io| read_all(io, options).first }
open(url.to_s, 'rb', nil, options) { |io| read_all(io, options) }
end

##
Expand Down Expand Up @@ -52,7 +52,7 @@ def read_files(*filenames)
# See {#read}
# @return [Enumerable<Object>]
def self.read_file(filename, options = {})
File.open(filename.to_s, 'rb') { |io| read_all(io, options).first }
File.open(filename.to_s, 'rb') { |io| read_all(io, options) }
end

##
Expand Down
10 changes: 10 additions & 0 deletions spec/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
end
end

it ".read_file" do
expect(File).to receive(:open).with("foo.sxp", "rb").and_yield(StringIO.new("(1 2 3)\n(4 5 6)"))
expect(SXP.read_file("foo.sxp")).to eq [[1, 2, 3], [4, 5, 6]]
end

it ".read_url" do
expect(File).to receive(:open).with("http://example/foo.sxp", "rb").and_yield(StringIO.new("(1 2 3)\n(4 5 6)"))
expect(SXP.read_file("http://example/foo.sxp")).to eq [[1, 2, 3], [4, 5, 6]]
end

def read(input, options = {})
SXP::Reader::Basic.read(input.freeze, options)
end
Expand Down

0 comments on commit 9e17ff9

Please sign in to comment.