<commit_before>require "spec_helper"

class CollectionTestCase < Fog::Collection
  def all
  end
  def map(*_args)
    %w(foo bar)
  end

  def self.attributes
    %w(this that)
  end

  def this
    %w(this that)
  end

  def that
    %w(that this)
  end
end

class NonCollectionTestCase 
end

test_case_str1 = <<-EOL
  <CollectionTestCase
    this=["this", "that"],
    that=["that", "this"]
    [
      foo, 
      bar    
    ]
  >
EOL
test_case_str1.chomp!

test_case_str2 = <<-EOL
  <CollectionTestCase
    this=["this", "that"],
    that=["that", "this"]
  >
EOL
test_case_str2.chomp!

test_case_str3 = <<-EOL
  <NonCollectionTestCase
  >
EOL
test_case_str3.chomp!

describe Fog::Formatador do

  def setup
    @collection_test = CollectionTestCase.new
    @collection_test << 'this'
    @non_collection_test = NonCollectionTestCase.new
  end

  it "should give a string representation of object with proper indentation" do
    Fog::Formatador.format(@collection_test).must_equal test_case_str1
  end

  it 'should not include nested objects' do
    opts = { :include_nested => false }
    Fog::Formatador.format(@collection_test, opts).must_equal test_case_str2
  end 

  it 'should not raise if object does not response to :empty? or :map' do
    Fog::Formatador.format(@non_collection_test).must_equal test_case_str3
  end
end
<commit_msg>Clean up specs around `Fog::Formatador`<commit_after>require "spec_helper"

describe Fog::Formatador do
  describe "when object is Fog::Collection instance" do
    before do
      @member_class = Class.new(Fog::Model) do
        attribute :name

        def self.name
          "MemberGadget"
        end
      end

      @collection_class = Class.new(Fog::Collection) do
        model @member_class

        attribute :attr_one
        attribute :attr_two

        def self.name
          "InspectionGadget"
        end

        def all
          self
        end
      end

      @collection = @collection_class.new(:attr_one => "String", :attr_two => 5)
      @collection << @member_class.new(:name => "<NAME>")
      @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
        <InspectionGadget
          attr_one=\"String\",
          attr_two=5
          [
                        <MemberGadget
              name=\"<NAME>\"
            >    
          ]
        >
      EOS
    end

    it "returns formatted representation" do
      Fog::Formatador.format(@collection).must_equal @expected
    end
  end

  describe "when object is Fog::Collection without attributes" do
    before do
      @collection_class = Class.new(Fog::Collection) do
        def all
          self
        end
      end

      @collection = @collection_class.new
      @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
        <
          [
                
          ]
        >
      EOS
    end

    it "returns formatted representation" do
      Fog::Formatador.format(@collection).must_equal @expected
    end
  end

  describe "when object has is Fog::Collection but ignoring nested objects" do
    before do
      @collection_class = Class.new(Fog::Collection) do
        attribute :name

        def all
          self
        end
      end
      @collection = @collection_class.new(:name => "Name")
      @collection << "this"
    end

    it "returns formatted representation" do
      @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
        <
          name=\"Name\"
        >
      EOS

      opts = { :include_nested => false }
      Fog::Formatador.format(@collection, opts).must_equal @expected
    end
  end

  describe "when object is not enumerable" do
    before do
      @class = Class.new
      @subject = @class.new
      @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
        <
        >
      EOS
    end

    it "returns formatted representation" do
      Fog::Formatador.format(@subject).must_equal @expected
    end
  end
end

{'fraction_non_alphanumeric': 0.10535852964017603, 'fraction_numerical': 0.0038829924928811804, 'mean_word_length': 2.2119700748129674, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5181678', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1196, 'n_words': 302}