Skip to content
Snippets Groups Projects
Commit 894d7109 authored by Henk van der Veen's avatar Henk van der Veen
Browse files

Hh sort by alphanum shorter first

parent 6a04eaaa
No related branches found
No related tags found
1 merge request!48Hh sort by alphanum shorter first
Pipeline #100257 passed
## 0.4.3
* Make sort_by_alphanum sort shorter string first.
## 0.4.2
* Make sort_by_alphanum stable for chunks that parse to the same int like 04 and 4.
......
module Roqua
module Support
VERSION = '0.4.2'.freeze
VERSION = '0.4.3'.freeze
end
end
......@@ -33,6 +33,8 @@ module Enumerable
ret = \
if a_scanner.eos?
-1
elsif b_scanner.eos?
1
elsif (a_chunk = a_scanner.scan(ALL_NUM))
if (b_chunk = b_scanner.scan(ALL_NUM))
if a_chunk.to_i != b_chunk.to_i
......
......@@ -11,6 +11,11 @@ describe Enumerable 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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment