require 'babelyoda/tanker' describe "tanker XML serialization" do it "should serialize non-plural values" do value = Babelyoda::LocalizationValue.new(:en, "Some translation") builder = Nokogiri::XML::Builder.new do |xml| value.to_xml(xml) end builder.to_xml.should == "\nSome translation\n" end it "should serialize plural values" do value = Babelyoda::LocalizationValue.new(:en, "some plural %u translation") value.pluralize! builder = Nokogiri::XML::Builder.new do |xml| value.to_xml(xml) end builder.to_xml.should == '' + "\n" + '' + "\n" + ' ' + "\n" + ' some plural %u translation' + "\n" + ' ' + "\n" + ' ' + "\n" + ' ' + "\n" + ' ' + "\n" + '' + "\n" end it "should serialize non-plural keys" do key = Babelyoda::LocalizationKey.new("Some key", "Some context") value = Babelyoda::LocalizationValue.new(:en, "Some translation") key << value builder = Nokogiri::XML::Builder.new do |xml| key.to_xml(xml) end builder.to_xml.should == "\n" + "\n" + " Some context\n" + " Some translation\n" + "\n" end it "should serialize plural keys" do key = Babelyoda::LocalizationKey.new("Some %[one]d plural key", "Some context") value = Babelyoda::LocalizationValue.new(:en, "Some translation for one") value.pluralize!(:one) key << value value = Babelyoda::LocalizationValue.new(:en, "Some translation for some") value.pluralize!(:some) key << value builder = Nokogiri::XML::Builder.new do |xml| key.to_xml(xml) end builder.to_xml.should == <<-EOF Some context Some translation for one Some translation for some EOF end it "should parse non-plural value" do doc = Nokogiri::XML.parse( <<-EOF Some translation EOF ) value = Babelyoda::LocalizationValue.parse_xml(doc.root) value.language.should == :en value.status.should == :requires_translation value.text.should == 'Some translation' value.plural?.should == false end it "should parse plural value" do doc = Nokogiri::XML.parse( <<-EOF Some translation for one Some translation for some EOF ) value = Babelyoda::LocalizationValue.parse_xml(doc.root) value.language.should == :en value.status.should == :requires_translation value.plural?.should == true value.text[:one].should == 'Some translation for one' value.text[:some].should == 'Some translation for some' value.text[:many].should == nil value.text[:noen].should == nil end it "should parse non-plural key" do doc = Nokogiri::XML.parse( <<-EOF Some translation EOF ) key = Babelyoda::LocalizationKey.parse_xml(doc.root) key.id.should == "Some key" key.plural?.should == false key.values.size.should == 1 value = key.values[:en] value.should_not == nil value.text.should == "Some translation" end it "should parse plural key" do doc = Nokogiri::XML.parse( <<-EOF Some translation for %d one Some translation for %d some EOF ) key = Babelyoda::LocalizationKey.parse_xml(doc.root) key.id.should == "Some %[plural]d key" key.plural?.should == true key.values.size.should == 1 value = key.values[:en] value.should_not == nil value.text[:one].should == 'Some translation for %d one' value.text[:some].should == 'Some translation for %d some' value.text[:many].should == nil value.text[:none].should == nil end end