require 'spec_helper' describe "MARC4J4R::DataField & SubField basics" do it "proivdes a trivial ==" do df1 = MARC4J4R::DataField.new('010', '1', '2') df2 = MARC4J4R::DataField.new('010', '1', '2') df1.should.equal df2 df2.should.equal df1 df3 = MARC4J4R::DataField.new('010', '0', '0') df4 = MARC4J4R::DataField.new('011', '1', '2') df1.should.not.equal df3 df1.should.not.equal df4 df3.should.not.equal df4 end it "proivdes a deep ==" do df1 = MARC4J4R::DataField.new('010', '1', '2') df2 = MARC4J4R::DataField.new('010', '1', '2') df3 = MARC4J4R::DataField.new('010', '1', '2') df4 = MARC4J4R::DataField.new('010', '1', '2') [df1, df2, df3, df4].each do |df| df << MARC4J4R::SubField.new('a', 'one') df << MARC4J4R::SubField.new('b', 'two') df << MARC4J4R::SubField.new('c', 'three') end df3 << MARC4J4R::SubField.new('d', 'four') df4 << MARC4J4R::SubField.new('d', 'five') df1.should.equal df2 df2.should.equal df1 df1.should.not.equal df3 df1.should.equal df1 df3.should.equal df3 df3.should.not.equal df4 end it "can round-trip tags and indicators" do df = MARC4J4R::DataField.new('010', '1', '2') df.tag.should.equal '010' df.ind1.should.equal '1' df.ind2.should.equal '2' df.ind1 = '0' df.ind1.should.equal '0' end it "is not a control field" do df = MARC4J4R::DataField.new('010', '1', '2') df.controlField?.should.equal false end it "can create an empty df with blank constructor" do df = MARC4J4R::DataField.new df.tag.should.equal nil df.ind1.should.equal ' ' df.ind2.should.equal ' ' end it "should defalt to spaces in ind1/ind2" do df = MARC4J4R::DataField.new('010') df.ind1.should.equal ' ' df.ind2.should.equal ' ' end end describe "Datafield with subfields" do begin @df = MARC4J4R::DataField.new('010', '1', '2') @a = MARC4J4R::SubField.new('a', 'one') @b = MARC4J4R::SubField.new('b', 'two') @df << @a @df << @b end it "works with subs" do @df.subs.size.should.equal 2 @df.subs('a').should.equal [@a] @df.subs('b').should.equal [@b] @df.subs('c').should.equal [] @df.subs(['a', 'b']).sort{|a,b|a.code <=> b.code}.should.equal [@a,@b].sort{|a,b| a.code <=> b.code} end it "gets values" do @df.value.should.equal "one two" @df.value('|').should.equal "one|two" @df.sub_values('a').should.equal ['one'] @df.sub_values(['a', 'b']).should.equal ['one', 'two'] @df << MARC4J4R::SubField.new('a', 'three') @df['a'].should.equal 'one' @df['b'].should.equal 'two' @df['c'].should.equal nil @df.sub_values('a').should.equal ['one','three'] end end describe "SubFields" do before do @df = MARC4J4R::DataField.new('010', '1', '2') @a = MARC4J4R::SubField.new('a', 'one') @df << @a end it "should allow creation of subfield wiht any info" do lambda{ sf = MARC4J4R::SubField.new('a', 'value') sf = MARC4J4R::SubField.new('a') sf = MARC4J4R::SubField.new() }.should.not.raise Exception end it "should get/set" do @a.code.should.equal 'a' @a.value.should.equal 'one' @a.data.should.equal 'one' @a.value = 'two' @a.value.should.equal 'two' @a.code = 'b' @a.code.should.equal 'b' end end