<commit_before>require 'hanami/utils/string'

RSpec.describe Hanami::Utils::String do
  describe ".transform" do
    it "applies multiple transformations" do
      input = "hanami/utils"
      actual = Hanami::Utils::String.transform(input, :underscore, :classify)

      expect(input).to  eq("hanami/utils")
      expect(actual).to eq("Hanami::Utils")
      expect(actual).to be_kind_of(::String)
    end

    it "applies multiple transformations with args" do
      input = "hanami/utils/string"
      actual = Hanami::Utils::String.transform(input, [:rsub, %r{/}, "#"])

      expect(input).to  eq("hanami/utils/string")
      expect(actual).to eq("hanami/utils#string")
      expect(actual).to be_kind_of(::String)
    end

    it "applies transformations from proc" do
      input = "Hanami"
      actual = Hanami::Utils::String.transform(input, ->(i) { i.upcase })

      expect(input).to  eq("Hanami")
      expect(actual).to eq("HANAMI")
      expect(actual).to be_kind_of(::String)
    end

    it "applies transformations from ::String" do
      input = "Hanami::Utils::String"
      actual = Hanami::Utils::String.transform(input, :demodulize, :downcase)

      expect(input).to  eq("Hanami::Utils::String")
      expect(actual).to eq("string")
      expect(actual).to be_kind_of(::String)
    end

    it "applies multiple transformations from ::String" do
      input = "Hanami::Utils::String"
      actual = Hanami::Utils::String.transform(input, [:gsub, /[aeiouy]/, "*"], :namespace)

      expect(input).to  eq("Hanami::Utils::String")
      expect(actual).to eq("H*n*m*")
      expect(actual).to be_kind_of(::String)
    end

    it "raises error when try to apply unknown transformation" do
      input = "Sakura"

      expect { Hanami::Utils::String.transform(input, :unknown) }.to raise_error(NoMethodError, %(undefined method `:unknown' for "Sakura":String))
    end

    it "raises error when given proc has arity not equal to 1" do
      input = "Cherry"

      message = if Hanami::Utils.jruby?
                  "wrong number of arguments (1 for 0)"
                else
                  "wrong number of arguments (given 1, expected 0)"
                end

      expect { Hanami::Utils::String.transform(input, -> { "blossom" }) }.to raise_error(ArgumentError, message)
    end
  end

  describe '.titleize' do
    it 'returns an instance of ::String' do
      expect(Hanami::Utils::String.titleize('hanami')).to be_kind_of(::String)
    end

    it "doesn't mutate input" do
      input = 'hanami'
      Hanami::Utils::String.titleize(input)
<commit_msg>Agnostic ArgumentError's message check in utils/string_spec.rb (#309)<commit_after>require 'hanami/utils/string'

RSpec.describe Hanami::Utils::String do
  describe ".transform" do
    it "applies multiple transformations" do
      input = "hanami/utils"
      actual = Hanami::Utils::String.transform(input, :underscore, :classify)

      expect(input).to  eq("hanami/utils")
      expect(actual).to eq("Hanami::Utils")
      expect(actual).to be_kind_of(::String)
    end

    it "applies multiple transformations with args" do
      input = "hanami/utils/string"
      actual = Hanami::Utils::String.transform(input, [:rsub, %r{/}, "#"])

      expect(input).to  eq("hanami/utils/string")
      expect(actual).to eq("hanami/utils#string")
      expect(actual).to be_kind_of(::String)
    end

    it "applies transformations from proc" do
      input = "Hanami"
      actual = Hanami::Utils::String.transform(input, ->(i) { i.upcase })

      expect(input).to  eq("Hanami")
      expect(actual).to eq("HANAMI")
      expect(actual).to be_kind_of(::String)
    end

    it "applies transformations from ::String" do
      input = "Hanami::Utils::String"
      actual = Hanami::Utils::String.transform(input, :demodulize, :downcase)

      expect(input).to  eq("Hanami::Utils::String")
      expect(actual).to eq("string")
      expect(actual).to be_kind_of(::String)
    end

    it "applies multiple transformations from ::String" do
      input = "Hanami::Utils::String"
      actual = Hanami::Utils::String.transform(input, [:gsub, /[aeiouy]/, "*"], :namespace)

      expect(input).to  eq("Hanami::Utils::String")
      expect(actual).to eq("H*n*m*")
      expect(actual).to be_kind_of(::String)
    end

    it "raises error when try to apply unknown transformation" do
      input = "Sakura"

      expect { Hanami::Utils::String.transform(input, :unknown) }.to raise_error(NoMethodError, %(undefined method `:unknown' for "Sakura":String))
    end

    it "raises error when given proc has arity not equal to 1" do
      input = "Cherry"

      expect do
        Hanami::Utils::String.transform(input, -> { "blossom" })
      end.to raise_error(ArgumentError, /wrong number of arguments (.*1.*0)/)
    end
  end

  describe '.titleize' do
    it 'returns an instance of ::String' do
      expect(Hanami::Utils::String.titleize('hanami')).to be_kind_of(::String)
    end

    it "doesn't mutate input" do
      input = 'hanami'
      Hanami::Utils::String.titleize(input)

{'fraction_non_alphanumeric': 0.14415481832543445, 'fraction_numerical': 0.0021721958925750395, 'mean_word_length': 3.292372881355932, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, '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': '2872660', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1577, 'n_words': 375}