naturalsort 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzVkY2U1YzA2YjJkMDNjNGNmNGZlMjM4NTBkZGU0MjY0OWMxMzE5OA==
5
- data.tar.gz: !binary |-
6
- NWQzNzM1ODExZmQ5MDkzYzVkODZlZWQ5N2FiNjhmNDU5N2I2Yjc3Yg==
2
+ SHA256:
3
+ metadata.gz: 587a1c0cf0b42077845643ce2ad013bead1f21bb57418446bf222195385dab37
4
+ data.tar.gz: 9cc750189f4fc09d05e2c660fa1e6cfc25a4c098d5c9517880766e72e3e9b1a3
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MDNhMTkyNWRiMGY0MGUwMzA2MDc5Yjg0ZjRmZTUzZWRiMzEzMjcyYmNmYzQ3
10
- YWI0MGU1ODYzNDhmOTIzMDc0N2E3YWFlNDZiNDIxMmYyYjI0MTc2YmNjMWU0
11
- ZWQzMDMzMjA5YzkxOGI1NmI1YjY4ZTExZDQ3MDg1Mzg4MjU3NzI=
12
- data.tar.gz: !binary |-
13
- MWFmMmNhZmIxZjY2ZGNhODVkOTZiMzU2Y2I4NGM4NmVmNjM4ZGM5OTQ0ZDY3
14
- Zjg1YTZlZmIxMWJjNjM3YTBhMTkxYWUwMzMxOGIzZTg3ZjJjNTdjNzAxYjUy
15
- ZWY1MWM4OTExNzFiOTJlMzJhOWQyZDQ3ZTIzYmMwNTgzZTQzZjY=
6
+ metadata.gz: c24a24d6dac5e791157df9c868aebcfd1b8134480b197bd66a14536c9d14a2ae5174d22852346ab1c2c8c5938ace451913fc5c37d7c7af4b5ed613db1f740292
7
+ data.tar.gz: 0fb932df47946a2799e3defaeae455ffcf72dcc08b66f6589dbcb62c0b656b6990c822b4d05f0014853f0d2a642f31469172d506951053ec8b030570230ec604
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.0 - 2024-10-20
4
+
5
+ * Remove `NaturalSort::Kernel` module.
6
+ * Drop support for Ruby 2.7 and prior.
7
+ * Add Github Actions and remove Travis CI.
8
+ * Fixes issue where blank string breaks sorting.
9
+
3
10
  ## 1.2.0 - 2013-10-10
4
11
 
5
12
  * DEPRECATION: deprecate `NaturalSort.naturalsort` and replace with `NaturalSort.sort`
data/README.md CHANGED
@@ -1,24 +1,15 @@
1
1
  # NaturalSort
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/johnnyshields/naturalsort.png?branch=master)](http://travis-ci.org/johnnyshields/naturalsort)
4
- [![Code Climate](https://codeclimate.com/github/johnnyshields/naturalsort.png)](https://codeclimate.com/github/johnnyshields/naturalsort)
5
-
6
3
  NaturalSort is a simple library which implements a natural, human-friendly alphanumeric sort in Ruby.
7
4
 
8
- #### Fork from RubyForge-hosted NaturalSort gem
9
-
10
- This Github repo `johnyshields/naturalsort` is an update of the Benjamin Francisoud's original NaturalSort gem,
11
- hosted on RubyForge at http://rubyforge.org/projects/naturalsort. It has been forked from version 1.1.1
12
- which was released on 2010-07-21. The first new release from this Github repo is version 1.2.0.
13
-
14
5
  ## Examples
15
6
 
16
7
  ```ruby
17
- %w(a1 a11 a12 a2 a21).natural_sort #=> %w(a1 a2 a11 a12 a21)
18
- %w(a b c A B C).natural_sort #=> %w(A a B b C c)
19
- %w(x__2 x_1).natural_sort #=> %w(x_1 x__2)
20
- %w(x2-y08 x2-g8 x2-y7 x8-y8).natural_sort #=> %w(x2-g8 x2-y7 x2-y08 x8-y8)
21
- %w(x02-y08 x02-g8 x2-y7 x8-y8).natural_sort #=> %w(x02-g8 x2-y7 x02-y08 x8-y8)
8
+ %w[a1 a11 a12 a2 a21].natural_sort #=> %w[a1 a2 a11 a12 a21]
9
+ %w[a b c A B C].natural_sort #=> %w[A a B b C c]
10
+ %w[x__2 x_1].natural_sort #=> %w[x_1 x__2]
11
+ %w[x2-y08 x2-g8 x2-y7 x8-y8].natural_sort #=> %w[x2-g8 x2-y7 x2-y08 x8-y8]
12
+ %w[x02-y08 x02-g8 x2-y7 x8-y8].natural_sort #=> %w[x02-g8 x2-y7 x02-y08 x8-y8]
22
13
  ```
23
14
 
24
15
  ## Features
@@ -41,7 +32,7 @@ gem 'naturalsort'
41
32
  or to optionally extend Ruby native objects:
42
33
 
43
34
  ```ruby
44
- gem 'naturalsort', :require => 'natural_sort_kernel'
35
+ gem 'naturalsort', require: 'natural_sort_kernel'
45
36
  ```
46
37
 
47
38
  #### From Command Line
@@ -59,7 +50,7 @@ $ gem install naturalsort
59
50
  ```ruby
60
51
  require 'natural_sort_kernel'
61
52
 
62
- sorted = %w(a b c A B C).natural_sort
53
+ %w[a b c A B C].natural_sort
63
54
  ```
64
55
 
65
56
  #### Use as a module function
@@ -67,7 +58,7 @@ $ gem install naturalsort
67
58
  ```ruby
68
59
  require 'natural_sort' # unless using Bundler
69
60
 
70
- sorted = NaturalSort.sort %w(a b c d A B C D)
61
+ NaturalSort.sort %w[a b c d A B C D]
71
62
  ```
72
63
 
73
64
  #### Use comparator function as a standalone
@@ -81,7 +72,7 @@ Adds `natural_sort` methods to Ruby native enumerable objects (Array, Hash, etc.
81
72
 
82
73
  [person_1, person_2, person_3].sort{|a,b| NaturalSort.comparator(a.name, b.name)} #=> [person_3, person_2, person_1]
83
74
 
84
- sorted = %w(a b c A B C).natural_sort
75
+ %w[a b c A B C].natural_sort
85
76
  ```
86
77
 
87
78
  #### Include into your own objects
@@ -98,7 +89,7 @@ Can be used to add `#natural_sort` method to on any enumerable object or any obj
98
89
  todo_list << 'Water plants'
99
90
  todo_list << 'Feed dog'
100
91
 
101
- todo_list.natural_sort #=> ['Feed dog', 'Wash car', 'Water plants']
92
+ todo_list.natural_sort #=> ['Feed dog', 'Wash car', 'Water plants']
102
93
  ```
103
94
 
104
95
  ## Authors
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Public: The public interface for NaturalSort module
2
4
  # For method descriptions refer to NaturalSort::Engine
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Internal: Singleton module which sorts elements in a natural,
2
4
  # human-friendly alphanumeric order.
3
5
  module NaturalSort::Engine
@@ -51,7 +53,7 @@ module NaturalSort::Engine
51
53
  ma, mb = multireg(REGEXP,sa), multireg(REGEXP,sb)
52
54
  it = 0
53
55
  equal = 0
54
- ret = ['', '']
56
+ ret = [sa, sb]
55
57
  while (it < [ma.size,mb.size].min) and (equal==0)
56
58
  if (ma[it] and mb[it]) and (ma[it][1] and mb[it][1]) and (NUMERIC.match ma[it][0] and NUMERIC.match mb[it][0])
57
59
  l = [ma[it][2].size,mb[it][2].size].max
@@ -1,11 +1,4 @@
1
- # Public: Adds #natural_sort instance method to Ruby Kernel enumerable objects.
2
- #
3
- # Examples
4
- #
5
- # require 'natural_sort_kernel'
6
- # defined?(NaturalSort::Kernel) #=> true
7
- # ['a', 'b', 'A', 'B'].natural_sort #=> ['A', 'a', 'B', 'b']
8
- module NaturalSort::Kernel; end
1
+ # frozen_string_literal: true
9
2
 
10
3
  module Enumerable
11
4
  # Add #natural_sort method to Enumerable module.
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NaturalSort
2
4
  module Version
3
- VERSION = '1.2.0'
5
+ VERSION = '1.3.0'
4
6
  end
5
7
  end
data/lib/natural_sort.rb CHANGED
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
3
+ require 'forwardable'
2
4
  require 'natural_sort/version'
3
5
  require 'natural_sort/engine'
4
6
  require 'natural_sort/base'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'natural_sort'
3
4
  require 'natural_sort/kernel'
metadata CHANGED
@@ -1,96 +1,81 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naturalsort
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Benjamin Francisoud
8
- autorequire:
7
+ - Johnny Shields
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2024-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: ! 'Example: %w(1 2a A1 a11 A12 a2 a21 x__2 X_1).natural_sort => %w(1
42
- 2a A1 a11 A12 a2 a21 x__2 X_1)'
43
- email:
44
- - pub.cog@gmail.com
41
+ description: 'Example: %w[1 2a A1 a11 A12 a2 a21 x__2 X_1].natural_sort => %w[1 2a
42
+ A1 a11 A12 a2 a21 x__2 X_1]'
43
+ email: info@tablecheck.com
45
44
  executables: []
46
45
  extensions: []
47
46
  extra_rdoc_files: []
48
47
  files:
49
- - .gitignore
50
- - .travis.yml
51
48
  - CHANGELOG.md
52
- - Gemfile
53
49
  - LICENSE
54
50
  - README.md
55
- - Rakefile
56
51
  - lib/natural_sort.rb
57
52
  - lib/natural_sort/base.rb
58
53
  - lib/natural_sort/engine.rb
59
54
  - lib/natural_sort/kernel.rb
60
55
  - lib/natural_sort/version.rb
61
56
  - lib/natural_sort_kernel.rb
62
- - naturalsort.gemspec
63
- - test/test_helper.rb
64
- - test/test_natural_sort.rb
65
- - test/test_natural_sort_alone.rb
66
- - test/test_natural_sort_kernel.rb
67
- homepage: http://rubyforge.org/projects/naturalsort/
57
+ homepage: https://github.com/johnnyshields/naturalsort
68
58
  licenses:
69
59
  - MIT
70
60
  metadata: {}
71
- post_install_message:
61
+ post_install_message:
72
62
  rdoc_options: []
73
63
  require_paths:
74
64
  - lib
75
65
  required_ruby_version: !ruby/object:Gem::Requirement
76
66
  requirements:
77
- - - ! '>='
67
+ - - ">="
78
68
  - !ruby/object:Gem::Version
79
69
  version: '0'
80
70
  required_rubygems_version: !ruby/object:Gem::Requirement
81
71
  requirements:
82
- - - ! '>='
72
+ - - ">="
83
73
  - !ruby/object:Gem::Version
84
74
  version: '0'
85
75
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 2.4.5
88
- signing_key:
76
+ rubygems_version: 3.5.11
77
+ signing_key:
89
78
  specification_version: 4
90
79
  summary: NaturalSort is a simple library which implements a natural, human-friendly
91
80
  alphanumeric sort in Ruby
92
- test_files:
93
- - test/test_helper.rb
94
- - test/test_natural_sort.rb
95
- - test/test_natural_sort_alone.rb
96
- - test/test_natural_sort_kernel.rb
81
+ test_files: []
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- Gemfile.lock
2
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
6
- .yardoc
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .idea
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - 2.0.0
7
- - ruby-head
8
- - rbx-19mode
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env rake
2
- # -*- mode: ruby -*-
3
-
4
- require 'rubygems'
5
- require './lib/natural_sort.rb'
6
- require 'rake/testtask'
7
-
8
- task :default => :test
9
-
10
- Rake::TestTask.new do |t|
11
- t.libs << 'test'
12
- t.test_files = FileList['test/**/test_*.rb']
13
- end
data/naturalsort.gemspec DELETED
@@ -1,22 +0,0 @@
1
- # coding: utf-8
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'natural_sort/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'naturalsort'
7
- spec.version = NaturalSort::Version::VERSION
8
- spec.authors = ['Benjamin Francisoud']
9
- spec.email = ['pub.cog@gmail.com']
10
- spec.summary = %q{NaturalSort is a simple library which implements a natural, human-friendly alphanumeric sort in Ruby}
11
- spec.description = %q{Example: %w(1 2a A1 a11 A12 a2 a21 x__2 X_1).natural_sort => %w(1 2a A1 a11 A12 a2 a21 x__2 X_1)}
12
- spec.homepage = 'http://rubyforge.org/projects/naturalsort/'
13
- spec.license = 'MIT'
14
-
15
- spec.files = `git ls-files`.split($/)
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ['lib']
19
-
20
- spec.add_development_dependency 'minitest'
21
- spec.add_development_dependency 'rake'
22
- end
data/test/test_helper.rb DELETED
@@ -1,36 +0,0 @@
1
- gem 'minitest'
2
- require 'minitest/autorun'
3
-
4
- module TestHelper
5
- SimpleUnsorted = %w(a b c d A B C D)
6
- SimpleSorted = %w(A a B b C c D d)
7
-
8
- ComplexUnsorted = ['1000X Radonius Maximus', '10X Radonius', '200X Radonius', '20X Radonius',
9
- '20X Radonius Prime', '30X Radonius', '40X Radonius', 'Allegia 50 Clasteron',
10
- 'Allegia 500 Clasteron', 'Allegia 51 Clasteron', 'Allegia 51B Clasteron', 'Allegia 52 Clasteron',
11
- 'Allegia 60 Clasteron', 'Alpha 100', 'Alpha 2', 'Alpha 200', 'Alpha 2A', 'Alpha 2A-8000',
12
- 'Alpha 2A-900', 'Callisto Morphamax', 'Callisto Morphamax 500', 'Callisto Morphamax 5000',
13
- 'Callisto Morphamax 600', 'Callisto Morphamax 700', 'Callisto Morphamax 7000',
14
- 'Callisto Morphamax 7000 SE', 'Callisto Morphamax 7000 SE2', 'QRS-60 Intrinsia Machine',
15
- 'QRS-60F Intrinsia Machine', 'QRS-62 Intrinsia Machine', 'QRS-62F Intrinsia Machine',
16
- 'Xiph Xlater 10000', 'Xiph Xlater 2000', 'Xiph Xlater 300', 'Xiph Xlater 40',
17
- 'Xiph Xlater 5', 'Xiph Xlater 50', 'Xiph Xlater 500', 'Xiph Xlater 5000', 'Xiph Xlater 58']
18
-
19
- ComplexSorted = ['10X Radonius', '20X Radonius', '20X Radonius Prime', '30X Radonius',
20
- '40X Radonius', '200X Radonius', '1000X Radonius Maximus', 'Allegia 50 Clasteron',
21
- 'Allegia 51 Clasteron', 'Allegia 51B Clasteron', 'Allegia 52 Clasteron',
22
- 'Allegia 60 Clasteron', 'Allegia 500 Clasteron', 'Alpha 2', 'Alpha 2A', 'Alpha 2A-900',
23
- 'Alpha 2A-8000', 'Alpha 100', 'Alpha 200', 'Callisto Morphamax', 'Callisto Morphamax 500',
24
- 'Callisto Morphamax 600', 'Callisto Morphamax 700', 'Callisto Morphamax 5000',
25
- 'Callisto Morphamax 7000', 'Callisto Morphamax 7000 SE', 'Callisto Morphamax 7000 SE2',
26
- 'QRS-60 Intrinsia Machine', 'QRS-60F Intrinsia Machine', 'QRS-62 Intrinsia Machine',
27
- 'QRS-62F Intrinsia Machine', 'Xiph Xlater 5', 'Xiph Xlater 40', 'Xiph Xlater 50',
28
- 'Xiph Xlater 58', 'Xiph Xlater 300', 'Xiph Xlater 500', 'Xiph Xlater 2000',
29
- 'Xiph Xlater 5000', 'Xiph Xlater 10000']
30
-
31
- # TODO: the AlphanumUnsorted initial order below yields a failing result
32
- # %w(100 101 11 A2AA A10 A999 AA1 999A 9999 A1 A2 A2A A2A1 1 1A 2 2C 9 AA99 #AB1 AB1A AB99 B1 B1A 10 10X AA2 B2 B999 Z1 Z9999)
33
-
34
- AlphanumUnsorted = %w(1 1A 2 2C 9 10 10X 11 100 101 999A 9999 A1 A2 A2A A2A1 A2AA A10 A999 AA1 AA2 AA99 AB1 AB1A AB99 B1 B1A B2 B999 Z1 Z9999)
35
- AlphanumSorted = %w(1 1A 2 2C 9 10 10X 11 100 101 999A 9999 A1 A2 A2A A2A1 A2AA A10 A999 AA1 AA2 AA99 AB1 AB1A AB99 B1 B1A B2 B999 Z1 Z9999)
36
- end
@@ -1,55 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require File.dirname(__FILE__) + '/../lib/natural_sort.rb'
3
-
4
- class MyClass
5
- include NaturalSort
6
-
7
- def initialize(array = TestHelper::SimpleUnsorted)
8
- @array = array
9
- end
10
-
11
- def to_a
12
- @array
13
- end
14
- end
15
-
16
- # Test without include
17
- class TestNaturalSortSelf < Minitest::Test
18
- def test_self
19
- assert_equal TestHelper::SimpleSorted, NaturalSort.sort(TestHelper::SimpleUnsorted)
20
- end
21
- end
22
-
23
- # Test using include
24
- class TestNaturalSort < Minitest::Test
25
- include NaturalSort
26
-
27
- def setup
28
- @obj = MyClass.new
29
- end
30
-
31
- def test_case_sensitive
32
- sorted = @obj.natural_sort
33
- assert_equal TestHelper::SimpleSorted, sorted
34
- end
35
-
36
- def test_mixed
37
- obj = MyClass.new %w(a1 a12 A11 a2 a10 A3 a21 A29)
38
- assert_equal %w(a1 a2 A3 a10 A11 a12 a21 A29), obj.natural_sort
39
- end
40
-
41
- def test_numbers
42
- obj = MyClass.new %w(a1 a12 a11 a2 a10 a3 a21 a29)
43
- assert_equal %w(a1 a2 a3 a10 a11 a12 a21 a29), obj.natural_sort
44
- end
45
-
46
- def test_first_no_number
47
- obj = MyClass.new %w(aaa2 aaa3 aaa4 aaa)
48
- assert_equal %w(aaa aaa2 aaa3 aaa4), obj.natural_sort
49
- end
50
-
51
- def test_number_leading_zero
52
- obj = MyClass.new %w(A001 A08 A007 A003 A011 A20 A200)
53
- assert_equal %w(A001 A003 A007 A08 A011 A20 A200), obj.natural_sort
54
- end
55
- end
@@ -1,17 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require File.dirname(__FILE__) + '/../lib/natural_sort.rb'
3
-
4
- # Test without include
5
- class TestNaturalSortAlone < Minitest::Test
6
- def test_simple
7
- assert_equal TestHelper::SimpleSorted, NaturalSort.sort(TestHelper::SimpleUnsorted)
8
- end
9
-
10
- def test_complex
11
- assert_equal TestHelper::ComplexSorted, NaturalSort.sort(TestHelper::ComplexUnsorted)
12
- end
13
-
14
- def test_alphanum
15
- assert_equal TestHelper::AlphanumSorted, NaturalSort.sort(TestHelper::AlphanumUnsorted)
16
- end
17
- end
@@ -1,110 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require File.dirname(__FILE__) + '/../lib/natural_sort_kernel.rb'
3
-
4
- class TestEnum
5
- include Enumerable
6
- def to_a
7
- TestHelper::SimpleUnsorted
8
- end
9
- end
10
-
11
- class TestNaturalSortKernel < Minitest::Test
12
-
13
- def test_empty
14
- assert_equal(['', ''], ['', ''].natural_sort)
15
- end
16
-
17
- def test_enum
18
- enum = TestEnum.new
19
- assert_equal TestHelper::SimpleSorted, enum.natural_sort
20
- end
21
-
22
- def test_array
23
- assert_equal TestHelper::SimpleSorted, TestHelper::SimpleUnsorted.natural_sort
24
- end
25
-
26
- def test_range
27
- expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
28
- assert_equal expected, (1..21).natural_sort
29
- end
30
-
31
- def test_set
32
- set = Set.new TestHelper::SimpleUnsorted
33
- assert_equal TestHelper::SimpleSorted, set.natural_sort
34
- end
35
-
36
- def test_hash
37
- expected = [["A", "value"], ["a", "value"], ["B", "value"], ["b", "value"],
38
- ["C", "value"], ["c", "value"], ["D", "value"], ["d", "value"]]
39
- hash = { "a" => "value", "b" => "value", "c" => "value", "d" => "value", "A" => "value", "B" => "value", "C" => "value", "D" => "value" }
40
- assert_equal expected, hash.natural_sort
41
- end
42
-
43
- def test_identical_simple
44
- assert_equal(%w(x x), %w(x x).natural_sort)
45
- end
46
-
47
- def test_identical_two_groups
48
- assert_equal(%w(x1 x1), %w(x1 x1).natural_sort)
49
- end
50
-
51
- def test_ordered_simple
52
- assert_equal(%w(x y), %w(x y).natural_sort)
53
- end
54
-
55
- def test_ordered_simple_start_backwards
56
- assert_equal(%w(x y), %w(y x).natural_sort)
57
- end
58
-
59
- def test_ordered_two_groups
60
- assert_equal(%w(x1 x2), %w(x1 x2).natural_sort)
61
- end
62
-
63
- def test_ordered_two_groups_start_backwards
64
- assert_equal(%w(x1 x2), %w(x2 x1).natural_sort)
65
- end
66
-
67
- def test_ordered_two_groups_separated
68
- assert_equal(%w(x_1 x_2), %w(x_2 x_1).natural_sort)
69
- end
70
-
71
- def test_ordered_two_groups_separated_different_distances
72
- assert_equal(%w(x_1 x__2), %w(x__2 x_1).natural_sort)
73
- end
74
-
75
- def test_ordered_two_groups_separated_different_distances_swapped
76
- assert_equal(%w(x__1 x_2), %w(x_2 x__1).natural_sort)
77
- end
78
-
79
- def test_three_groups
80
- assert_equal(
81
- ['hello 2 world', 'hello world', 'hello world 2'],
82
- ['hello world', 'hello world 2', 'hello 2 world'].natural_sort
83
- )
84
- end
85
-
86
- # TODO: fix test below
87
- def test_decimal
88
- # 1.001 < 1.002 < 1.010 < 1.02 < 1.1 < 1.3
89
- # assert_equal ['1.001', '1.002', '1.010', '1.02', '1.1', '1.3'], ['1.1', '1.001', '1.002', '1.010', '1.02', '1.3'].natural_sort, "FIXME this test doesn't pass and need to be fix"
90
- end
91
-
92
- def test_multiple_string_number
93
- # x2-g8 < x2-y7 < x2-y08 < x8-y8
94
- assert_equal %w(x2-g8 x2-y7 x2-y08 x8-y8), %w(x2-y08 x8-y8 x2-y7 x2-g8).natural_sort
95
- end
96
-
97
- # same as test_multiple_string_number but first number has (sometimes) leading zero
98
- def test_multiple_string_number_2
99
- # x2-g8 < x2-y7 < x2-y08 < x8-y8
100
- assert_equal %w(x02-g8 x2-y7 x02-y08 x8-y8), %w(x02-y08 x8-y8 x2-y7 x02-g8).natural_sort
101
- end
102
-
103
- def test_filename
104
- assert_equal %w(img1.png img2.png img10.png img12.png), %w(img12.png img10.png img2.png img1.png).natural_sort
105
- end
106
-
107
- def test_complex
108
- assert_equal TestHelper::ComplexSorted, TestHelper::ComplexUnsorted.natural_sort
109
- end
110
- end