Sha256: 96a51157f046ce26705ee114789f2c70c2b71b5a3827952eed4579bb43d471a6
Contents?: true
Size: 996 Bytes
Versions: 1
Compression:
Stored size: 996 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 'treats non-alphanum as lower than alpha and num' do input = %w[b3a b{c bԘb] # curlies are above alpha in utf-8, Ԙ is multi-byte expect(input.sort_by_alphanum).to eq %w[b{c bԘb b3a] end it 'compares number chunks as integers' do expect(%w(004 3).sort_by_alphanum).to eq %w(3 004) end it 'sorts identical integers by asci' do input = %w[b4e b0004e b04e b004e] expect(input.sort_by_alphanum).to eq %w[b0004e b004e b04e b4e] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
roqua-support-0.4.2 | spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb |