spec/naturally_spec.rb in naturally-1.3.2 vs spec/naturally_spec.rb in naturally-1.4.0
- old
+ new
@@ -1,6 +1,5 @@
-# encoding: utf-8
require 'naturally'
describe Naturally do
def it_sorts(this:, to_this:)
actual = Naturally.sort(this)
@@ -61,10 +60,38 @@
it_sorts(
this: %w(12а 12б 12в 13а 13б 2 3 4 5 10 11 12),
to_this: %w(2 3 4 5 10 11 12 12а 12б 12в 13а 13б)
)
end
+
+ it 'sorts letters with digits correctly' do
+ it_sorts(
+ this: %w(1 a 2 b 3 c),
+ to_this: %w(1 2 3 a b c)
+ )
+ end
+
+ it 'sorts complex numbers with digits correctly' do
+ it_sorts(
+ this: %w(1 a 2 b 3 c 1.1 a.1 1.2 a.2 1.3 a.3 b.1 ),
+ to_this: %w(1 1.1 1.2 1.3 2 3 a a.1 a.2 a.3 b b.1 c)
+ )
+ end
+
+ it 'sorts complex mixes of numbers and digits correctly' do
+ it_sorts(
+ this: %w( 1.a.1 1.1 ),
+ to_this: %w( 1.1 1.a.1 )
+ )
+ end
+
+ it 'sorts complex mixes of numbers and digits correctly' do
+ it_sorts(
+ this: %w( 1a1 1aa aaa ),
+ to_this: %w( 1aa 1a1 aaa )
+ )
+ end
end
describe '#sort_naturally_by' do
it 'sorts by an attribute' do
UbuntuVersion = Struct.new(:name, :version)
@@ -106,8 +133,21 @@
Калуга
Киев
Москва
Париж
)
+ end
+
+ it 'sorts by an attribute which contains product names' do
+ Product = Struct.new(:name)
+ objects = [
+ Product.new('2 awesome decks'),
+ Product.new('Awesome deck')
+ ]
+ actual = Naturally.sort_by(objects, :name)
+ expect(actual.map(&:name)).to eq [
+ '2 awesome decks',
+ 'Awesome deck'
+ ]
end
end
end