<commit_before>require "minitest_helper"

module Hermod

  NamedXML = XmlSection.build(xml_name: "Testing") { |builder| }
  UnnamedXML = XmlSection.build { |builder| }
  OrderingXML = XmlSection.build do |builder|
    builder.string_node :first
    builder.string_node :repeated
    builder.string_node :last
  end

  describe XmlSection do
    describe "building an XML generating class with no arguments" do
      subject do
        UnnamedXML.new {}
      end

      it "should use the class name as the XML node name" do
        subject.to_xml.name.must_equal "UnnamedXML"
      end
    end

    describe "building an XML generating class with a custom node name" do
      subject do
        NamedXML.new {}
      end

      it "should use the class name as the XML node name" do
        subject.to_xml.name.must_equal "Testing"
      end
    end

    describe "#to_xml" do
      subject do
        OrderingXML.new do |ordering|
          ordering.repeated "beta"
          ordering.last "epsilon"
          ordering.repeated "gamma"
          ordering.first "alpha"
        end
      end<commit_msg>Add tests for default formats<commit_after>require "minitest_helper"

module Hermod

  NamedXML = XmlSection.build(xml_name: "Testing") { |builder| }
  UnnamedXML = XmlSection.build { |builder| }
  OrderingXML = XmlSection.build do |builder|
    builder.string_node :first
    builder.string_node :repeated
    builder.string_node :last
  end
  FormattedXML = XmlSection.build do |builder|
    builder.date_node :birthday
    builder.monetary_node :allowance
  end

  describe XmlSection do
    describe "building an XML generating class with no arguments" do
      subject do
        UnnamedXML.new
      end

      it "should use the class name as the XML node name" do
        subject.to_xml.name.must_equal "UnnamedXML"
      end
    end

    describe "building an XML generating class with a custom node name" do
      subject do
        NamedXML.new
      end

      it "should use the class name as the XML node name" do
        subject.to_xml.name.must_equal "Testing"
      end
    end

    describe "default formats" do
      subject do
        FormattedXML.new do |formatted|
          formatted.birthday Date.new(1988, 8, 13)
          formatted.allowance BigDecimal.new("20")
        end
      end

      it "formats dates in yyyy-mm-dd form" do
        value_of_node("Birthday").must_equal("1988-08-13")
      end

      it "formats money to two decimal places" do
        value_of_node("Allowance").must_equal("20.00")
      end
    end

    describe "#to_xml" do
      subject do
        OrderingXML.new do |ordering|
          ordering.repeated "beta"
          ordering.last "epsilon"
          ordering.repeated "gamma"
          ordering.first "alpha"
        end
      end
{'fraction_non_alphanumeric': 0.07007508044333215, 'fraction_numerical': 0.007508044333214158, 'mean_word_length': 2.354916067146283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6178341', 'n_tokens_mistral': 849, 'n_tokens_neox': 802, 'n_words': 259}