Sha256: 8834afc8a9adf939c6832923421d0edd77bcae0bcaa4a184a085d61b1322e178
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
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 'sorts shorter strings first' do input = %w[a_2_ a_2 a a_1] # curlies are above alpha in utf-8, Ԙ is multi-byte expect(input.sort_by_alphanum).to eq %w[a a_1 a_2 a_2_] 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
roqua-support-0.4.4 | spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb |
roqua-support-0.4.3 | spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb |