view release on metacpan or search on metacpan
Revision history for Perl extension Sort::Naturally::XS.
0.1.0 Sat Oct 22 21:59:46 2016
- original version; created by h2xs 1.23 with options
-O -n Sort::Naturally::XS ./Sort-Naturally-XS/src/nsort.h
0.2.0 Wed Oct 26 22:40:00 2016
- beta implemented; initial commit
0.3.0 Fri Oct 26 18:25:00 2016
- support Sort::Naturally API, add ncmp subroutine
0.4.0 Sun Nov 13 22:17:00 2016
- add nsort subroutine and minimal documentation
0.5.0 Thu Nov 17 11:21:00 2016
- add light pre-process to comparator, increase performance
0.6.0 Wed Nov 23 22:08:00 2016
- refactor pre-process in comparator, properly sort dimensions (like 2400x2600), improve tests
Makefile.PL view on Meta::CPAN
use 5.010001;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Sort::Naturally::XS',
VERSION_FROM => 'lib/Sort/Naturally/XS.pm', # finds $VERSION
PREREQ_PM => {}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Sort/Naturally/XS.pm', # retrieve abstract from module
AUTHOR => 'Sergey Yurzin <jurzin.s@gmail.com>') : ()),
LIBS => [''], # e.g., '-lm'
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => '-I.', # e.g., '-I. -I/usr/include/other'
# Un-comment this if you add C files to link with later:
# OBJECT => '$(O_FILES)', # link all the C files too
Makefile.PL view on Meta::CPAN
if (eval {
require ExtUtils::Constant;
1
}) {
# If you edit these definitions to change the constants used by this module,
# you will need to use the generated const-c.inc and const-xs.inc
# files to replace their "fallback" counterparts before distributing your
# changes.
my @names = (qw());
ExtUtils::Constant::WriteConstants(
NAME => 'Sort::Naturally::XS',
NAMES => \@names,
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
);
}
else {
use File::Copy;
use File::Spec;
Sort-Naturally-XS version 0.7.9
===============================
DESCRIPTION
Sort::Naturally::XS - Perl extension for human-friendly ("natural") sort order.
Natural sort order is an ordering of mixed strings (consist of characters and digits) in alphabetical order, except that
digital parts are ordered as numbers. Natural sorting can be considered as a replacement of a standard machine-oriented
alphabetical sorting, because it is more convenient for human understanding.
INSTALL
perl Makefile.PL
make
make test
# Sort-Naturally-XS
[](
https://travis-ci.org/CaballerosTeam/Sort-Naturally-XS)
## NAME
Sort::Naturally::XS - Perl extension for human-friendly ("natural") sort order
## INSTALL
To install this module type the following, for Unix-like OS:
```
perl Makefile.PL
make
make test
make install
```
```
perl Makefile.PL
dmake
dmake test
dmake install
```
## SYNOPSIS
```perl
use Sort::Naturally::XS;
my @mixed_list = qw/test21 test20 test10 test11 test2 test1/;
my @result = nsort(@mixed_list); # @result is: test1 test2 test10 test11 test20 test21
@result = sort ncmp @mixed_list; # same, but use standard sort function
@result = sort {ncmp($a, $b)} @mixed_list; # same as ncmp, but argument pass explicitly
my $result = Sort::Naturally::XS::sorted(\@mixed_list, locale => 'ru_RU.utf8'); # pass custom locale
```
## DESCRIPTION
Natural sort order is an ordering of mixed strings (consist of characters and digits) in alphabetical order, except that
digital parts are ordered as numbers. Natural sorting can be considered as a replacement of a standard machine-oriented
alphabetical sorting, because it is more convenient for human understanding. For example, the following list:
```perl
test21 test20 test10 test11 test2 test1
#### `sorted`
> sorted(ARRAY_REF, KWARGS)
Returns an ARRAY ref to a sorted list. First argument is an ARRAY ref to the source list, followed by keyword arguments,
such as `reverse` and `locale`. If `reverse` is true the source list is sorted in reverse order. If `locale` is
specified, the sorting will be performed according to the locale aware settings.
```perl
use Sort::Naturally::XS qw/sorted/;
my $result = sorted($list);
$result = sorted($list, reverse => 1); # $list will be sorted in descending order
$result = sorted($list, locale => 'en_US.utf8'); # $list will be sorted according to en_US.utf8 locale
```
## LOCALE AWARE SORTING
By default the `sort` function sorts according to a standard C locale or, if a `use locale` pragma is in effect,
according to OS settings, which can be changed with the help of the `setlocale` function. The use of both `use locale`
and `setlocale` has no effect on `ncmp` and `nsort`. The following example demonstrates this behavior:
```perl
use POSIX;
use Sort::Naturally::XS;
my @list = ('a.'.'c', 'A'..'B');
my @result_std = sort @list;
my @result_ncmp = sort {ncmp($a, $b)} @list;
# @result_std contains A, B, C, a, b, c
# @result_ncmp contains A, B, C, a, b, c
use locale;
# assumed that current locale is en_US.utf8
@result_std = sort @list;
@result_ncmp = sort {ncmp($a, $b)} @list;
# @result_std contains A, a, B, b, C, c
# @result_ncmp contains A, B, C, a, b, c
```
To be able to sort a list with an arbitrary locale it is necessary to use the `sorted` function with a `locale` keyword
argument:
```perl
use Sort::Naturally::XS qw/sorted/;
my $list = ['a.'.'c', 'A'..'B'];
my $result_us = sorted($list, locale => 'en_US.utf8');
# $result_us contains a, A, b, B, c, C
my $result_ca = sorted($list, locale => 'en_CA.utf8');
# $result_ca contains A, a, B, b, C, c
```
Also, make sure your list does not contain "wide characters", otherwise "Wide character in subroutine entry" exception
will be thrown. Be vigilant if `use utf8` is in effect or your source code contains multibyte characters. It's a
developer's responsibility to explicitly encode characters in a target encoding:
```perl
use utf8;
use Encode;
use Sort::Naturally::XS qw/sorted/;
my $fruits = [qw/Ñблоко банан манго киви гÑÑÑа/];
my $result = sorted([map {Encode::encode('utf8', $_)} @{$fruits}], locale => 'ru_RU.utf8');
```
Note: due to the complexity of a cross-platform support, a locale aware sorting is guaranteed on Unix-like operating
systems only.
## EXPORT
By default the module exports `ncmp` and `nsort` subroutines.
## BENCHMARK
```perl
require Benchmark;
require Sort::Naturally::XS;
require Sort::Naturally;
my @list = (
'H4', 'T25', 'H5', 'T27', 'H8', 'T30', 'HEX', 'T35', 'M10', 'T4', 'M12', 'T40', 'M13',
'T45', 'M14', 'T47', 'M16', 'T5', 'M4', 'T50', 'M5', 'T55', 'M6', 'T6', 'M7', 'T60',
'M8', 'T7', 'M9', 'T70', 'Ph0', 'T8', 'Ph1', 'T9', 'Ph2', 'TT10', 'Ph3', 'TT15', 'Ph4',
'TT20', 'Pz0', 'TT25', 'Pz1', 'TT27', 'Pz2', 'TT30', 'Pz3', 'TT40', 'Pz4', 'TT45',
'R10', 'TT50', 'R12', 'TT55', 'R13', 'TT6', 'R14', 'TT60', 'R5', 'TT7', 'R6', 'TT70',
'R7', 'TT8', 'R8', 'TT9', 'S', 'TX', 'Sl', 'XZN', 'T10', 'T15', 'T20'
);
Benchmark::cmpthese(-3, {
my => sub { Sort::Naturally::XS::nsort(@list) },
other => sub { Sort::Naturally::nsort(@list) },
});
# Rate other my
# other 561/s -- -97%
# my 20693/s 3588% --
Benchmark::cmpthese(-10, {
std => sub { sort @list },
other => sub { sort {Sort::Naturally::ncmp($a, $b)} @list },
my => sub { sort {Sort::Naturally::XS::ncmp($a, $b)} @list },
});
# Rate other std my
# other 7977106/s -- -3% -5%
# std 8232321/s 3% -- -2%
# my 8426303/s 6% 2% --
```
## NOTES
* There are differences in sorting outcomes compared with the `Sort::Naturally` module. Capital letters always come
before lower case letters, digits always come before letters.
```
9x 14 foo fooa foolio Foolio foo12 foo12a Foo12a foo12z foo13a # Sort::Naturally
9x 14 Foo12a Foolio foo foo12 foo12a foo12z foo13a fooa foolio # Sort::Naturally::XS
```
* Due to a significant strain it is not recommended for sorting lists consisting of letters or digits only.
* Due to the complexity of a cross-platform support, a locale aware sorting is guaranteed on Unix-like operating systems
only.
* Windows support added in ver. 0.7.6
## SEE ALSO
* [module on PrePAN](http://prepan.org/module/nYcMhBVby72)
* [module on CPAN](http://search.cpan.org/dist/Sort-Naturally-XS/lib/Sort/Naturally/XS.pm)
}
static I32
S_sv_ncoll_reverse(pTHX_ SV *a, SV *b)
{
const char *ia = (const char *) SvPVbyte_nolen(a);
const char *ib = (const char *) SvPVbyte_nolen(b);
return _ncmp(ia, ib, 1, 1);
}
MODULE = Sort::Naturally::XS PACKAGE = Sort::Naturally::XS
INCLUDE: const-xs.inc
int
ncmp(arg_a, arg_b)
const char * arg_a
const char * arg_b
CODE:
RETVAL = _ncmp(arg_a, arg_b, 0, 0);
OUTPUT:
const-c.inc view on Meta::CPAN
Regenerate these constant functions by feeding this entire source file to
perl -x
#!/usr/bin/perl -w
use ExtUtils::Constant qw (constant_types C_constant XS_constant);
my $types = {map {($_, 1)} qw()};
my @names = (qw());
print constant_types(), "\n"; # macro defs
foreach (C_constant ("Sort::Naturally::XS", 'constant', 'IV', $types, undef, 3, @names) ) {
print $_, "\n"; # C constant subs
}
print "\n#### XS Section:\n";
print XS_constant ("Sort::Naturally::XS", $types);
__END__
*/
switch (len) {
}
return PERL_constant_NOTFOUND;
}
const-xs.inc view on Meta::CPAN
INPUT:
SV * sv;
const char * s = SvPV(sv, len);
PPCODE:
type = constant(aTHX_ s, len);
/* Return 1 or 2 items. First is error message, or undef if no error.
Second, if present, is found value */
switch (type) {
case PERL_constant_NOTFOUND:
sv =
sv_2mortal(newSVpvf("%s is not a valid Sort::Naturally::XS macro", s));
PUSHs(sv);
break;
case PERL_constant_NOTDEF:
sv = sv_2mortal(newSVpvf(
"Your vendor has not defined Sort::Naturally::XS macro %s, used",
s));
PUSHs(sv);
break;
/* Uncomment this if you need to return IVs
case PERL_constant_ISIV:
EXTEND(SP, 1);
PUSHs(&PL_sv_undef);
PUSHi(iv);
break; */
/* Uncomment this if you need to return NOs
const-xs.inc view on Meta::CPAN
PUSHu((UV)iv);
break; */
/* Uncomment this if you need to return YESs
case PERL_constant_ISYES:
EXTEND(SP, 1);
PUSHs(&PL_sv_undef);
PUSHs(&PL_sv_yes);
break; */
default:
sv = sv_2mortal(newSVpvf(
"Unexpected return type %d while processing Sort::Naturally::XS macro %s, used",
type, s));
PUSHs(sv);
}
lib/Sort/Naturally/XS.pm view on Meta::CPAN
package Sort::Naturally::XS;
use 5.010001;
use strict;
use warnings;
use Carp;
require Exporter;
use AutoLoader;
our @ISA = qw/Exporter/;
our @EXPORT = qw/ncmp nsort/;
our @EXPORT_OK = qw/sorted/;
our $VERSION = '0.7.9';
require XSLoader;
XSLoader::load('Sort::Naturally::XS', $VERSION);
sub sorted {
my ($ar, %kwargs) = @_;
Carp::confess('Not an ARRAY ref') if (ref $ar ne 'ARRAY');
my $ar_copy = [@{$ar}];
my $reverse = $kwargs{reverse} ? 1 : 0;
my $locale = $kwargs{locale} || '';
lib/Sort/Naturally/XS.pm view on Meta::CPAN
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
=encoding utf8
=head1 NAME
Sort::Naturally::XS - Perl extension for human-friendly ("natural") sort order
=head1 SYNOPSIS
use Sort::Naturally::XS;
my @mixed_list = qw/test21 test20 test10 test11 test2 test1/;
my @result = nsort(@mixed_list); # @result is: test1 test2 test10 test11 test20 test21
@result = sort ncmp @mixed_list; # same, but use standard sort function
@result = sort {ncmp($a, $b)} @mixed_list; # same as ncmp, but argument pass explicitly
=head1 DESCRIPTION
lib/Sort/Naturally/XS.pm view on Meta::CPAN
In list context returns a LIST sorted copy.
my @result = nsort(@list);
=item C<sorted(ARRAY_REF, KWARGS)>
Returns an ARRAY ref to a sorted list. First argument is an ARRAY ref to the source list, followed by keyword arguments,
such as C<reverse> and C<locale>. If C<reverse> is true the source list is sorted in reverse order. If C<locale> is
specified, the sorting will be performed according to the locale aware settings.
use Sort::Naturally::XS qw/sorted/;
my $result = sorted($list);
$result = sorted($list, reverse => 1); # $list will be sorted in descending order
# $list will be sorted according to en_US.utf8 locale
$result = sorted($list, locale => 'en_US.utf8');
=back
=head1 LOCALE AWARE SORTING
By default the sort function sorts according to a standard C locale or, if a C<use locale> pragma is in effect,
according to OS settings, which can be changed with the help of the C<setlocale> function. The use of both C<use locale>
and C<setlocale> has no effect on C<ncmp> and C<nsort>. The following example demonstrates this behavior:
use POSIX;
use Sort::Naturally::XS;
my @list = ('a.'.'c', 'A'..'B');
my @result_std = sort @list;
my @result_ncmp = sort {ncmp($a, $b)} @list;
# @result_std contains A, B, C, a, b, c
# @result_ncmp contains A, B, C, a, b, c
use locale;
# assumed that current locale is en_US.utf8
lib/Sort/Naturally/XS.pm view on Meta::CPAN
setlocale(POSIX::LC_ALL, 'en_CA.utf8');
@result_std = sort @list;
@result_ncmp = sort {ncmp($a, $b)} @list;
# @result_std contains A, a, B, b, C, c
# @result_ncmp contains A, B, C, a, b, c
To be able to sort a list with an arbitrary locale it is necessary to use the C<sorted> function with a C<locale>
keyword argument:
use Sort::Naturally::XS qw/sorted/;
my $list = ['a.'.'c', 'A'..'B'];
my $result_us = sorted($list, locale => 'en_US.utf8');
# $result_us contains a, A, b, B, c, C
my $result_ca = sorted($list, locale => 'en_CA.utf8');
# $result_ca contains A, a, B, b, C, c
Also, make sure your list does not contain "wide characters", otherwise "Wide character in subroutine entry" exception
will be thrown. Be vigilant if C<use utf8> is in effect or your source code contains multibyte characters. It's a
developer's responsibility to explicitly encode characters in a target encoding:
use utf8;
use Encode;
use Sort::Naturally::XS qw/sorted/;
my $fruits = [qw/Ñблоко банан манго киви гÑÑÑа/];
my $result = sorted([map {Encode::encode('utf8', $_)} @{$fruits}], locale => 'ru_RU.utf8');
Note: due to the complexity of a cross-platform support, a locale aware sorting is guaranteed on Unix-like operating
systems only.
=head1 EXPORT
By default the module exports C<ncmp> and C<nsort> subroutines.
=head1 BENCHMARK
require Benchmark;
require Sort::Naturally::XS;
require Sort::Naturally;
my @list = (
'H4', 'T25', 'H5', 'T27', 'H8', 'T30', 'HEX', 'T35', 'M10', 'T4', 'M12', 'T40', 'M13',
'T45', 'M14', 'T47', 'M16', 'T5', 'M4', 'T50', 'M5', 'T55', 'M6', 'T6', 'M7', 'T60',
'M8', 'T7', 'M9', 'T70', 'Ph0', 'T8', 'Ph1', 'T9', 'Ph2', 'TT10', 'Ph3', 'TT15', 'Ph4',
'TT20', 'Pz0', 'TT25', 'Pz1', 'TT27', 'Pz2', 'TT30', 'Pz3', 'TT40', 'Pz4', 'TT45',
'R10', 'TT50', 'R12', 'TT55', 'R13', 'TT6', 'R14', 'TT60', 'R5', 'TT7', 'R6', 'TT70',
'R7', 'TT8', 'R8', 'TT9', 'S', 'TX', 'Sl', 'XZN', 'T10', 'T15', 'T20'
);
Benchmark::cmpthese(-3, {
my => sub { Sort::Naturally::XS::nsort(@list) },
other => sub { Sort::Naturally::nsort(@list) },
});
# Rate other my
# other 561/s -- -97%
# my 20693/s 3588% --
Benchmark::cmpthese(-10, {
std => sub { sort @list },
other => sub { sort {Sort::Naturally::ncmp($a, $b)} @list },
my => sub { sort {Sort::Naturally::XS::ncmp($a, $b)} @list },
});
# Rate other std my
# other 7977106/s -- -3% -5%
# std 8232321/s 3% -- -2%
# my 8426303/s 6% 2% --
=head1 NOTES
=over 4
=item There are differences in sorting outcomes compared with the Sort::Naturally module. Capital letters always come
before lower case letters, digits always come before letters.
9x 14 foo fooa foolio Foolio foo12 foo12a Foo12a foo12z foo13a # Sort::Naturally
9x 14 Foo12a Foolio foo foo12 foo12a foo12z foo13a fooa foolio # Sort::Naturally::XS
=item Due to a significant overhead it is not recommended for sorting lists consisting of letters or digits only.
=item Due to the complexity of a cross-platform support, a locale aware sorting is guaranteed on Unix-like operating
systems only.
=item Windows support added in ver. 0.7.6
=back
src/Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
$Verbose = 1;
WriteMakefile(
NAME => 'Sort::Naturally::XS::nsort',
clean => {'FILES' => 'libnsort$(LIB_EXT)'},
);
sub MY::top_targets {
'
all :: static
pure_all :: static
static :: libnsort$(LIB_EXT)
libnsort$(LIB_EXT): $(O_FILES)
$(AR) cr libnsort$(LIB_EXT) $(O_FILES)
t/Sort-Naturally-XS-ncmp.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Encode;
use Sort::Naturally::XS;
my $ar_wo_digit = [reverse(map {$_ x 2} ('a'..'z'))];
my $ar_wo_digit__expected = [reverse(@{$ar_wo_digit})];
ok(eq_array($ar_wo_digit__expected, [sort {ncmp($a, $b)} @{$ar_wo_digit}]), 'Char only sort');
my $ar_digit = [reverse(map {$_ x 2} (1..10))];
my $ar_digit__expected = [reverse(@{$ar_digit})];
ok(eq_array($ar_digit__expected, [sort {ncmp($a, $b)} @{$ar_digit}]), 'Digit only sort');
# CCXX-1 test
my $ar_mostly_digit = [qw/1100x1400 2000x2200 1400x2050 2200x2400 1500x2000 2200x2600 1720x2050 2400x2400 1800x2200
2400x2600/];
my $ar_mostly_digit__expected = [qw/1100x1400 1400x2050 1500x2000 1720x2050 1800x2200 2000x2200 2200x2400 2200x2600
2400x2400 2400x2600/];
ok(eq_array($ar_mostly_digit__expected, [sort {ncmp($a, $b)} @{$ar_mostly_digit}]), 'Dimensions sort');
my $ar_mixed_simple = [qw/test21 test20 test10 test11 test2 test1/];
my $ar_mixed_simple__expected = [qw/test1 test2 test10 test11 test20 test21/];
ok(eq_array($ar_mixed_simple__expected, [sort {ncmp($a, $b)} @{$ar_mixed_simple}]), 'Mixed sort');
# Sort::Naturally example
my $ar_mixed_example = [qw/foo12a foo12z foo13a foo 14 9x foo12 fooa foolio Foolio Foo12a/];
my $ar_mixed_example__expected = [qw/9x 14 Foo12a Foolio foo foo12 foo12a foo12z foo13a fooa foolio/];
ok(eq_array($ar_mixed_example__expected, [sort {ncmp($a, $b)} @{$ar_mixed_example}]), 'Sort::Naturally example');
# CCXX-2 test
my $ar_mixed_strong = [qw/H4 T25 H5 T27 H8 T30 HEX T35 M10 T4 M12 T40 M13 T45 M14 T47 M16 T5 M4 T50 M5 T55 M6 T6 M7 T60
M8 T7 M9 T70 Ph0 T8 Ph1 T9 Ph2 TT10 Ph3 TT15 Ph4 TT20 Pz0 TT25 Pz1 TT27 Pz2 TT30 Pz3 TT40 Pz4 TT45 R10 TT50 R12 TT55
R13 TT6 R14 TT60 R5 TT7 R6 TT70 R7 TT8 R8 TT9 S TX Sl XZN T10 деÑжаÑÐµÐ»Ñ T15 Ð½Ð°Ð±Ð¾Ñ T20/];
my $ar_mixed_strong__expected = [qw/H4 H5 H8 HEX M4 M5 M6 M7 M8 M9 M10 M12 M13 M14 M16 Ph0 Ph1 Ph2 Ph3 Ph4 Pz0 Pz1 Pz2
Pz3 Pz4 R5 R6 R7 R8 R10 R12 R13 R14 S Sl T4 T5 T6 T7 T8 T9 T10 T15 T20 T25 T27 T30 T35 T40 T45 T47 T50 T55 T60 T70
TT6 TT7 TT8 TT9 TT10 TT15 TT20 TT25 TT27 TT30 TT40 TT45 TT50 TT55 TT60 TT70 TX XZN деÑжаÑÐµÐ»Ñ Ð½Ð°Ð±Ð¾Ñ/];
ok(eq_array($ar_mixed_strong__expected, [sort {ncmp($a, $b)} @{$ar_mixed_strong}]), 'CCXX test');
t/Sort-Naturally-XS-nsort.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Encode;
use Sort::Naturally::XS;
my $ar_wo_digit = [reverse(map {$_ x 2} ('a'..'z'))];
my $ar_wo_digit__expected = [reverse(@{$ar_wo_digit})];
ok(eq_array($ar_wo_digit__expected, [nsort(@{$ar_wo_digit})]), 'Char only sort');
my $ar_digit = [reverse(map {$_ x 2} (1..10))];
my $ar_digit__expected = [reverse(@{$ar_digit})];
ok(eq_array($ar_digit__expected, [nsort(@{$ar_digit})]), 'Digit only sort');
# CCXX-1 test
my $ar_mostly_digit = [qw/1100x1400 2000x2200 1400x2050 2200x2400 1500x2000 2200x2600 1720x2050 2400x2400 1800x2200
2400x2600/];
my $ar_mostly_digit__expected = [qw/1100x1400 1400x2050 1500x2000 1720x2050 1800x2200 2000x2200 2200x2400 2200x2600
2400x2400 2400x2600/];
ok(eq_array($ar_mostly_digit__expected, [nsort(@{$ar_mostly_digit})]), 'Dimensions sort');
my $ar_mixed_simple = [qw/test21 test20 test10 test11 test2 test1/];
my $ar_mixed_simple__expected = [qw/test1 test2 test10 test11 test20 test21/];
ok(eq_array($ar_mixed_simple__expected, [nsort(@{$ar_mixed_simple})]), 'Mixed sort');
# Sort::Naturally example
my $ar_mixed_example = [qw/foo12a foo12z foo13a foo 14 9x foo12 fooa foolio Foolio Foo12a/];
my $ar_mixed_example__expected = [qw/9x 14 Foo12a Foolio foo foo12 foo12a foo12z foo13a fooa foolio/];
ok(eq_array($ar_mixed_example__expected, [nsort(@{$ar_mixed_example})]), 'Sort::Naturally example');
# compatibility with Sort::Naturally test
my @mixed_list = (qw/foo12a foo12z foo13a foo 14 9x foo12 fooa foolio Foolio Foo12a/);
my @mixed_list__original = @mixed_list;
my @mixed_list__expected = (qw/9x 14 Foo12a Foolio foo foo12 foo12a foo12z foo13a fooa foolio/);
my @mixed_list__actual = nsort(@mixed_list);
ok(eq_array(\@mixed_list__expected, \@mixed_list__actual), 'Sort::Naturally sorting OK');
ok(eq_array(\@mixed_list__original, \@mixed_list), 'Sort::Naturally original list is not changed');
# CCXX-2 test
my $ar_mixed_strong = [qw/H4 T25 H5 T27 H8 T30 HEX T35 M10 T4 M12 T40 M13 T45 M14 T47 M16 T5 M4 T50 M5 T55 M6 T6 M7 T60
M8 T7 M9 T70 Ph0 T8 Ph1 T9 Ph2 TT10 Ph3 TT15 Ph4 TT20 Pz0 TT25 Pz1 TT27 Pz2 TT30 Pz3 TT40 Pz4 TT45 R10 TT50 R12 TT55
R13 TT6 R14 TT60 R5 TT7 R6 TT70 R7 TT8 R8 TT9 S TX Sl XZN T10 деÑжаÑÐµÐ»Ñ T15 Ð½Ð°Ð±Ð¾Ñ T20/];
my $ar_mixed_strong__expected = [qw/H4 H5 H8 HEX M4 M5 M6 M7 M8 M9 M10 M12 M13 M14 M16 Ph0 Ph1 Ph2 Ph3 Ph4 Pz0 Pz1 Pz2
Pz3 Pz4 R5 R6 R7 R8 R10 R12 R13 R14 S Sl T4 T5 T6 T7 T8 T9 T10 T15 T20 T25 T27 T30 T35 T40 T45 T47 T50 T55 T60 T70
TT6 TT7 TT8 TT9 TT10 TT15 TT20 TT25 TT27 TT30 TT40 TT45 TT50 TT55 TT60 TT70 TX XZN деÑжаÑÐµÐ»Ñ Ð½Ð°Ð±Ð¾Ñ/];
ok(eq_array($ar_mixed_strong__expected, [nsort(@{$ar_mixed_strong})]), 'CCXX test');
t/Sort-Naturally-XS-sorted.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Encode;
use Config;
use List::Util qw/first/;
use Sort::Naturally::XS qw/sorted/;
my $locale_skip = {
freebsd => 'FreeBSD',
darwin => 'MacOS',
};
my $ar_wo_digit = [reverse(map {$_ x 2} ('a'..'z'))];
my $ar_wo_digit__expected = [reverse(@{$ar_wo_digit})];
ok(eq_array($ar_wo_digit__expected, sorted($ar_wo_digit)), 'Char only sort');
t/Sort-Naturally-XS-sorted.t view on Meta::CPAN
my $ar_mostly_digit = [qw/1100x1400 2000x2200 1400x2050 2200x2400 1500x2000 2200x2600 1720x2050 2400x2400 1800x2200
2400x2600/];
my $ar_mostly_digit__expected = [qw/1100x1400 1400x2050 1500x2000 1720x2050 1800x2200 2000x2200 2200x2400 2200x2600
2400x2400 2400x2600/];
ok(eq_array($ar_mostly_digit__expected, sorted($ar_mostly_digit)), 'Dimensions sort');
my $ar_mixed_simple = [qw/test21 test20 test10 test11 test2 test1/];
my $ar_mixed_simple__expected = [qw/test1 test2 test10 test11 test20 test21/];
ok(eq_array($ar_mixed_simple__expected, sorted($ar_mixed_simple)), 'Mixed sort');
# Sort::Naturally example
my $ar_mixed_example = [qw/foo12a foo12z foo13a foo 14 9x foo12 fooa foolio Foolio Foo12a/];
my $ar_mixed_example__expected = [qw/9x 14 Foo12a Foolio foo foo12 foo12a foo12z foo13a fooa foolio/];
ok(eq_array($ar_mixed_example__expected, sorted($ar_mixed_example)), 'Sort::Naturally example');
# CCXX-2 test
my $ar_mixed_strong = [qw/H4 T25 H5 T27 H8 T30 HEX T35 M10 T4 M12 T40 M13 T45 M14 T47 M16 T5 M4 T50 M5 T55 M6 T6 M7 T60
M8 T7 M9 T70 Ph0 T8 Ph1 T9 Ph2 TT10 Ph3 TT15 Ph4 TT20 Pz0 TT25 Pz1 TT27 Pz2 TT30 Pz3 TT40 Pz4 TT45 R10 TT50 R12 TT55
R13 TT6 R14 TT60 R5 TT7 R6 TT70 R7 TT8 R8 TT9 S TX Sl XZN T10 деÑжаÑÐµÐ»Ñ T15 Ð½Ð°Ð±Ð¾Ñ T20/];
my $ar_mixed_strong__expected = [qw/H4 H5 H8 HEX M4 M5 M6 M7 M8 M9 M10 M12 M13 M14 M16 Ph0 Ph1 Ph2 Ph3 Ph4 Pz0 Pz1 Pz2
Pz3 Pz4 R5 R6 R7 R8 R10 R12 R13 R14 S Sl T4 T5 T6 T7 T8 T9 T10 T15 T20 T25 T27 T30 T35 T40 T45 T47 T50 T55 T60 T70
TT6 TT7 TT8 TT9 TT10 TT15 TT20 TT25 TT27 TT30 TT40 TT45 TT50 TT55 TT60 TT70 TX XZN деÑжаÑÐµÐ»Ñ Ð½Ð°Ð±Ð¾Ñ/];
ok(eq_array($ar_mixed_strong__expected, sorted($ar_mixed_strong)), 'CCXX test');
t/Sort-Naturally-XS-wchar.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Sort::Naturally::XS qw/nsort ncmp sorted/;
use List::Util qw/first/;
use utf8;
use Config;
my $ar_mixed_utf8 = [qw/Як-100 Ðа-8 Ðи-20 Ðа-10 Ðа-26 Ðа-15 Ðа-25 Ðи-4 Ðи-6 Ðи-8 Ðа-31 Ðи-14 Ðи-24 Ðа-18 Ðа-22 Ðи-26
Ðи-30 Ðи-171 Як-24 Як-60 Ðа-27 Ðа-29 Ðа-32 Ðа-126 Ðи-10 Ðи-1/];
my $ar_mixed_utf8__expected = [qw/Ðа-8 Ðа-10 Ðа-15 Ðа-18 Ðа-22 Ðа-25 Ðа-26 Ðа-27 Ðа-29 Ðа-31 Ðа-32 Ðа-126 Ðи-1 Ðи-4 Ðи-6
Ðи-8 Ðи-10 Ðи-14 Ðи-20 Ðи-24 Ðи-26 Ðи-30 Ðи-171 Як-24 Як-60 Як-100/];
ok(eq_array($ar_mixed_utf8__expected, [nsort(@{$ar_mixed_utf8})]), "Wide characters in input of 'nsort'");
t/Sort-Naturally-XS.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
BEGIN { use_ok('Sort::Naturally::XS') }
ok(defined &ncmp, 'ncmp subroutine exported');
ok(defined &nsort, 'nsort subroutine exported');
done_testing();