diff --git a/lib/edn/core_ext.rb b/lib/edn/core_ext.rb index 316ce2c..61ab5d7 100644 --- a/lib/edn/core_ext.rb +++ b/lib/edn/core_ext.rb @@ -16,11 +16,11 @@ def allows_metadata? end end - module Bignum - def to_edn - self.to_s + 'M' - end - end + # module Bignum + # def to_edn + # self.to_s + 'M' + # end + # end module BigDecimal def to_edn @@ -94,7 +94,7 @@ def to_edn end Numeric.send(:include, EDN::CoreExt::Unquoted) -Bignum.send(:include, EDN::CoreExt::Bignum) +#Bignum.send(:include, EDN::CoreExt::Bignum) BigDecimal.send(:include, EDN::CoreExt::BigDecimal) TrueClass.send(:include, EDN::CoreExt::Unquoted) FalseClass.send(:include, EDN::CoreExt::Unquoted) diff --git a/spec/edn/char_stream_spec.rb b/spec/edn/char_stream_spec.rb index e049110..b3ebd87 100644 --- a/spec/edn/char_stream_spec.rb +++ b/spec/edn/char_stream_spec.rb @@ -2,110 +2,110 @@ describe EDN::CharStream do it "reads a stream in order" do - s = EDN::CharStream.new(io_for("abc")) - s.current.should == "a" - s.advance.should == "b" - s.advance.should == "c" - s.advance.should == :eof - s.current.should == :eof + s = EDN::CharStream.new(io_for('abc')) + expect(s.current).to eq('a') + expect(s.advance).to eq('b') + expect(s.advance).to eq('c') + expect(s.advance).to eq(:eof) + expect(s.current).to eq(:eof) end it "keeps returning the current until your advance" do - s = EDN::CharStream.new(io_for("abc")) - s.current.should == "a" - s.current.should == "a" - s.advance.should == "b" + s = EDN::CharStream.new(io_for('abc')) + expect(s.current).to eq('a') + expect(s.current).to eq('a') + expect(s.advance).to eq('b') end it "knows if the current char is a digit" do - s = EDN::CharStream.new(io_for("4f")) - s.digit?.should be_truthy + s = EDN::CharStream.new(io_for('4f')) + expect(s.digit?).to be_truthy s.advance - s.digit?.should be_falsey + expect(s.digit?).to be_falsey end it "knows if the current char is an alpha" do - s = EDN::CharStream.new(io_for("a9")) - s.alpha?.should be_truthy + s = EDN::CharStream.new(io_for('a9')) + expect(s.alpha?).to be_truthy s.advance - s.alpha?.should be_falsey + expect(s.alpha?).to be_falsey end it "knows if the current char is whitespace" do s = EDN::CharStream.new(io_for("a b\nc\td,")) - s.ws?.should be_falsey # a + expect(s.ws?).to be_falsey # a s.advance - s.ws?.should be_truthy # " " + expect(s.ws?).to be_truthy # " " s.advance - s.ws?.should be_falsey # b + expect(s.ws?).to be_falsey # b s.advance - s.ws?.should be_truthy # \n + expect(s.ws?).to be_truthy # \n s.advance - s.ws?.should be_falsey # c + expect(s.ws?).to be_falsey # c s.advance - s.ws?.should be_truthy # \t + expect(s.ws?).to be_truthy # \t s.advance - s.ws?.should be_falsey # d + expect(s.ws?).to be_falsey # d s.advance - s.ws?.should be_truthy # , + expect(s.ws?).to be_truthy # , end it "knows if the current char is a newline" do s = EDN::CharStream.new(io_for("a\nb\rc")) - s.newline?.should be_falsey # a + expect(s.newline?).to be_falsey # a s.advance - s.newline?.should be_truthy # \n + expect(s.newline?).to be_truthy # \n s.advance - s.newline?.should be_falsey # b + expect(s.newline?).to be_falsey # b s.advance - s.newline?.should be_truthy # \r + expect(s.newline?).to be_truthy # \r s.advance - s.newline?.should be_falsey # c + expect(s.newline?).to be_falsey # c end it "knows if it is at the eof" do - s = EDN::CharStream.new(io_for("abc")) - s.eof?.should be_falsey # a + s = EDN::CharStream.new(io_for('abc')) + expect(s.eof?).to be_falsey # a s.advance - s.eof?.should be_falsey # b + expect(s.eof?).to be_falsey # b s.advance - s.eof?.should be_falsey # c + expect(s.eof?).to be_falsey # c s.advance - s.eof?.should be_truthy + expect(s.eof?).to be_truthy end it "knows how to skip past a char" do - s = EDN::CharStream.new(io_for("abc")) - s.skip_past("a").should == "a" - s.current.should == "b" + s = EDN::CharStream.new(io_for('abc')) + expect(s.skip_past('a')).to eq('a') + expect(s.current).to eq('b') end it "knows how not to skip a char" do - s = EDN::CharStream.new(io_for("abc")) - s.skip_past("X").should be_nil + s = EDN::CharStream.new(io_for('abc')) + expect(s.skip_past('X')).to be_nil end it "knows how skip to the end of a line" do s = EDN::CharStream.new(io_for("abc\ndef")) s.skip_to_eol - s.current.should == "\n" - s.advance.should == "d" + expect(s.current).to eq("\n") + expect(s.advance).to eq('d') end it "knows how skip whitespace" do s = EDN::CharStream.new(io_for(" \n \t,,,,abc")) s.skip_ws - s.current.should == "a" + expect(s.current).to eq('a') end end diff --git a/spec/edn/metadata_spec.rb b/spec/edn/metadata_spec.rb index 8e14e54..0ea03fa 100644 --- a/spec/edn/metadata_spec.rb +++ b/spec/edn/metadata_spec.rb @@ -3,18 +3,18 @@ describe EDN do describe "metadata" do it "reads metadata, which does not change the element's equality" do - EDN.read('[1 2 3]').should == EDN.read('^{:doc "My vec"} [1 2 3]') + expect(EDN.read('[1 2 3]')).to eq(EDN.read('^{:doc "My vec"} [1 2 3]')) end it "reads metadata recursively from right to left" do element = EDN.read('^String ^:foo ^{:foo false :tag Boolean :bar 2} [1 2]') - element.should == [1, 2] - element.metadata.should == {:tag => ~"String", :foo => true, :bar => 2} + expect(element).to eq([1, 2]) + expect(element.metadata).to eq({:tag => ~"String", :foo => true, :bar => 2}) end it "writes metadata" do element = EDN.read('^{:doc "My vec"} [1 2 3]') - element.to_edn.should == '^{:doc "My vec"} [1 2 3]' + expect(element.to_edn).to eq('^{:doc "My vec"} [1 2 3]') end it "only writes metadata for elements that can have it" do @@ -24,13 +24,13 @@ o } - apply_metadata[[1, 2]].to_edn.should == '^{:foo 1} [1 2]' - apply_metadata[~[1, 2]].to_edn.should == '^{:foo 1} (1 2)' - apply_metadata[{1 => 2}].to_edn.should == '^{:foo 1} {1 2}' - apply_metadata[Set.new([1, 2])].to_edn.should == '^{:foo 1} #{1 2}' - apply_metadata[~"bar"].to_edn.should == '^{:foo 1} bar' + expect(apply_metadata[[1, 2]].to_edn).to eq('^{:foo 1} [1 2]') + expect(apply_metadata[~[1, 2]].to_edn).to eq('^{:foo 1} (1 2)') + expect(apply_metadata[{1 => 2}].to_edn).to eq('^{:foo 1} {1 2}') + expect(apply_metadata[Set.new([1, 2])].to_edn).to eq('^{:foo 1} #{1 2}') + expect(apply_metadata[~'bar'].to_edn).to eq('^{:foo 1} bar') - apply_metadata["bar"].to_edn.should == '"bar"' + expect(apply_metadata['bar'].to_edn).to eq('"bar"') # Cannot extend symbols, booleans, and nil, so no test for them. end diff --git a/spec/edn/parser_spec.rb b/spec/edn/parser_spec.rb index 51afdd2..6014f54 100644 --- a/spec/edn/parser_spec.rb +++ b/spec/edn/parser_spec.rb @@ -7,32 +7,32 @@ it "can contain comments" do edn = ";; This is some sample data\n[1 2 ;; the first two values\n3]" - EDN.read(edn).should == [1, 2, 3] + expect(EDN.read(edn)).to eq([1, 2, 3]) end it "can discard using the discard reader macro" do - edn = "[1 2 #_3 {:foo #_bar :baz}]" - EDN.read(edn).should == [1, 2, {:foo => :baz}] + edn = '[1 2 #_3 {:foo #_bar :baz}]' + expect(EDN.read(edn)).to eq([1, 2, {:foo => :baz}]) end context "element" do it "should consume metadata with the element" do x = EDN.read('^{:doc "test"} [1 2]') - x.should == [1, 2] - x.metadata.should == {doc: "test"} + expect(x).to eq([1, 2]) + expect(x.metadata).to eq({doc: 'test'}) end end context "integer" do it "should consume integers" do rant(RantlyHelpers::INTEGER).each do |int| - (EDN.read int.to_s).should == int.to_i + expect((EDN.read int.to_s)).to eq(int.to_i) end end it "should consume integers prefixed with a +" do rant(RantlyHelpers::INTEGER).each do |int| - (EDN.read "+#{int.to_i.abs.to_s}").should == int.to_i.abs + expect((EDN.read "+#{int.to_i.abs.to_s}")).to eq(int.to_i.abs) end end end @@ -40,19 +40,19 @@ context "float" do it "should consume simple floats" do rant(RantlyHelpers::FLOAT).each do |float| - EDN.read(float.to_s).should == float.to_f + expect(EDN.read(float.to_s)).to eq(float.to_f) end end it "should consume floats with exponents" do rant(RantlyHelpers::FLOAT_WITH_EXP).each do |float| - EDN.read(float.to_s).should == float.to_f + expect(EDN.read(float.to_s)).to eq(float.to_f) end end it "should consume floats prefixed with a +" do rant(RantlyHelpers::FLOAT).each do |float| - EDN.read("+#{float.to_f.abs.to_s}").should == float.to_f.abs + expect(EDN.read("+#{float.to_f.abs.to_s}")).to eq(float.to_f.abs) end end end @@ -60,15 +60,15 @@ context "symbol" do context "special cases" do it "should consume '/'" do - EDN.read('/').should == EDN::Type::Symbol.new(:"/") + expect(EDN.read('/')).to eq(EDN::Type::Symbol.new(:'/')) end it "should consume '.'" do - EDN.read('.').should == EDN::Type::Symbol.new(:".") + expect(EDN.read('.')).to eq(EDN::Type::Symbol.new(:'.')) end it "should consume '-'" do - EDN.read('-').should == EDN::Type::Symbol.new(:"-") + expect(EDN.read('-')).to eq(EDN::Type::Symbol.new(:'-')) end end end @@ -76,7 +76,7 @@ context "keyword" do it "should consume any keywords" do rant(RantlyHelpers::SYMBOL).each do |symbol| - EDN.read(":#{symbol}").should == symbol.to_sym + expect(EDN.read(":#{symbol}")).to eq(symbol.to_sym) end end end @@ -84,7 +84,7 @@ context "string" do it "should consume any string" do rant(RantlyHelpers::RUBY_STRING).each do |string| - EDN.read(string.to_edn).should == string + expect(EDN.read(string.to_edn)).to eq(string) end end end @@ -92,15 +92,15 @@ context "character" do it "should consume any character" do rant(RantlyHelpers::RUBY_CHAR).each do |char| - EDN.read(char.to_edn).should == char + expect(EDN.read(char.to_edn)).to eq(char) end end end context "vector" do it "should consume an empty vector" do - EDN.read('[]').should == [] - EDN.read('[ ]').should == [] + expect(EDN.read('[]')).to eq([]) + expect(EDN.read('[ ]')).to eq([]) end it "should consume vectors of mixed elements" do @@ -112,8 +112,8 @@ context "list" do it "should consume an empty list" do - EDN.read('()').should == [] - EDN.read('( )').should == [] + expect(EDN.read('()')).to eq([]) + expect(EDN.read('( )')).to eq([]) end it "should consume lists of mixed elements" do @@ -125,8 +125,8 @@ context "set" do it "should consume an empty set" do - EDN.read('#{}').should == Set.new - EDN.read('#{ }').should == Set.new + expect(EDN.read('#{}')).to eq(Set.new) + expect(EDN.read('#{ }')).to eq(Set.new) end it "should consume sets of mixed elements" do diff --git a/spec/edn/reader_spec.rb b/spec/edn/reader_spec.rb index 527cbdd..e9ec90f 100644 --- a/spec/edn/reader_spec.rb +++ b/spec/edn/reader_spec.rb @@ -1,23 +1,23 @@ require 'spec_helper' describe EDN::Reader do - let(:reader) { EDN::Reader.new("[1 2] 3 :a {:b c} ") } + let(:reader) { EDN::Reader.new('[1 2] 3 :a {:b c} ') } it "should read each value" do - reader.read.should == [1, 2] - reader.read.should == 3 - reader.read.should == :a - reader.read.should == {:b => ~"c"} + expect(reader.read).to eq([1, 2]) + expect(reader.read).to eq(3) + expect(reader.read).to eq(:a) + expect(reader.read).to eq({:b => ~'c'}) end it "should respond to each" do reader.each do |element| - element.should_not be_nil + expect(element).to_not be_nil end end it "returns a special end of file value if asked" do - 4.times { reader.read(:the_end).should_not == :the_end } - reader.read(:no_more).should == :no_more + 4.times { expect(reader.read(:the_end)).to_not eq(:the_end) } + expect(reader.read(:no_more)).to eq(:no_more) end end diff --git a/spec/edn_spec.rb b/spec/edn_spec.rb index 1f46efb..2f666e9 100644 --- a/spec/edn_spec.rb +++ b/spec/edn_spec.rb @@ -13,14 +13,14 @@ it "reads file #{File.basename(edn_file)} correctly" do expected = eval(File.read(rb_file)) actual = EDN.read(File.read(edn_file)) - actual.should == expected + expect(actual).to eq(expected) end it "round trips the value in #{File.basename(edn_file)} correctly" do expected = eval(File.read(rb_file)) actual = EDN.read(File.read(edn_file)) round_trip = EDN.read(actual.to_edn) - round_trip.should == expected + expect(round_trip).to eq(expected) end end end @@ -28,47 +28,47 @@ context "#read" do #it "reads from a stream" do - # io = StringIO.new("123") + # io = StringIO.new('123') # EDN.read(io).should == 123 #end #it "reads mutiple values from a stream" do - # io = StringIO.new("123 456 789") + # io = StringIO.new('123 456 789') # EDN.read(io).should == 123 # EDN.read(io).should == 456 # EDN.read(io).should == 789 #end it "raises an exception on eof by default" do - expect { EDN.read('') }.to raise_error + expect { EDN.read('') }.to raise_error(RuntimeError) end #it "allows you to specify an eof value" do - # io = StringIO.new("123 456") + # io = StringIO.new('123 456') # EDN.read(io, :my_eof).should == 123 # EDN.read(io, :my_eof).should == 456 # EDN.read(io, :my_eof).should == :my_eof #end it "allows you to specify nil as an eof value" do - EDN.read("", nil).should == nil + expect(EDN.read('', nil)).to be_nil end end context "reading data" do it "treats carriage returns like whitespace" do - EDN.read("\r\n[\r\n]\r\n").should == [] - EDN.read("\r[\r]\r\r").should == [] + expect(EDN.read("\r\n[\r\n]\r\n")).to eq([]) + expect(EDN.read("\r[\r]\r\r")).to eq([]) end it "reads any valid element" do elements = rant(RantlyHelpers::ELEMENT) elements.each do |element| begin - if element == "nil" - EDN.read(element).should be_nil + if element == 'nil' + expect(EDN.read(element)).to be_nil else - EDN.read(element).should_not be_nil + expect(EDN.read(element)).to_not be_nil end rescue Exception => ex puts "Bad element: #{element}" @@ -80,8 +80,8 @@ context "#register" do it "uses the identity function when no handler is given" do - EDN.register "some/tag" - EDN.read("#some/tag {}").class.should == Hash + EDN.register 'some/tag' + expect(EDN.read('#some/tag {}').class).to eq(Hash) end end @@ -104,9 +104,9 @@ elements = rant(RantlyHelpers::ELEMENT) elements.each do |element| ruby_element = EDN.read(element) - ruby_element.should == EDN.read(ruby_element.to_edn) + expect(ruby_element).to eq(EDN.read(ruby_element.to_edn)) if ruby_element.respond_to?(:metadata) - ruby_element.metadata.should == EDN.read(ruby_element.to_edn).metadata + expect(ruby_element.metadata).to eq(EDN.read(ruby_element.to_edn).metadata) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c9d080b..5aed00b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,7 +10,8 @@ c.fail_fast = true c.filter_run_including :focused => true c.alias_example_to :fit, :focused => true - c.treat_symbols_as_metadata_keys_with_true_values = true + # now always set to true +# c.treat_symbols_as_metadata_keys_with_true_values = true c.run_all_when_everything_filtered = true c.filter_run :focus