Sha256: 04f39a710ab94ec612c98e3fb44cf84cfdab82f23d8265fb4e24662c1f8dbfff

Contents?: true

Size: 617 Bytes

Versions: 8

Compression:

Stored size: 617 Bytes

Contents

require 'roqua/core_ext/enumerable/sort_by_alphanum'

describe Enumerable do
  describe '#sort_by_alphanum' do
    let(:input) { ["004some11thing", "004some10thing", "3another"] }
    it 'sorts by chunks' do
      expect(input.sort_by_alphanum).to eq ["3another", "004some10thing", "004some11thing"]
    end

    it 'can take a block which can transform values before comparison' do
      expect(input.sort_by_alphanum(&:reverse)).to eq ["004some10thing", "004some11thing", "3another"]
    end

    it 'compares number chunks as integers' do
      expect(%w(004 3).sort_by_alphanum).to eq %w(3 004)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
roqua-support-0.4.1 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
roqua-support-0.4.0 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
roqua-support-0.3.5 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
roqua-support-0.3.4 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
roqua-support-0.3.3 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
roqua-support-0.3.2 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
roqua-support-0.3.1 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
roqua-support-0.3.0 spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb