view release on metacpan or search on metacpan
Revision history for Perl extension Sort::Naturally::ICU.
0.7.7 Mon June 12 22:24:00 2017
- Created a fork of the Sort::Naturally::XS module
0.7.8 Tue Oct 03 19:35:00 2017
- Synced a fork
}
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, collator);
}
MODULE = Sort::Naturally::ICU PACKAGE = Sort::Naturally::ICU
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:
Makefile.PL view on Meta::CPAN
print "Check for ICU library installed...\n";
my @args = (qw/pkg-config --libs icu-uc icu-io/);
system(@args) == 0 or exit(1);
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Sort::Naturally::ICU',
VERSION_FROM => 'lib/Sort/Naturally/ICU.pm', # finds $VERSION
BUILD_REQUIRES => {'Test::More' => 0.0},
PREREQ_PM => {}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Sort/Naturally/ICU.pm', # retrieve abstract from module
AUTHOR => 'Sergey Yurzin <jurzin.s@gmail.com>') : ()),
LIBS => is_mac_os() ? '-L/usr/local/opt/icu4c/lib' : '',
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => '-I. ' . (is_mac_os() ? '-I/usr/local/opt/icu4c/include' : ''),
# Un-comment this if you add C files to link with later:
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::ICU',
NAMES => \@names,
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
);
}
else {
use File::Copy;
use File::Spec;
Sort-Naturally-ICU version 0.7.8
================================
DESCRIPTION
Sort::Naturally::ICU - Perl extension for human-friendly ("natural") sort order, which using ICU library for locale
aware sorting.
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
Prior to installation you MUST have installed ICU library.
# Sort-Naturally-ICU
[](
https://travis-ci.org/CaballerosTeam/Sort-Naturally-ICU)
## NAME
Sort::Naturally::ICU - Perl extension for human-friendly ("natural") sort order, which using ICU library for locale
aware sorting.
## INSTALL
Prior to installation you MUST have installed ICU library. To install this module type the following, for Unix-like OS:
```
perl Makefile.PL
make
make test
make install
```
## SYNOPSIS
```perl
use Sort::Naturally::ICU;
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::ICU::sorted(\@mixed_list, locale => 'en-CA-u-va-posix'); # 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::ICU qw/sorted/;
my $result = sorted($list);
$result = sorted($list, reverse => 1); # $list will be sorted in descending order
$result = sorted($list, locale => 'en-US-u-va-posix'); # $list will be sorted according to US POSIX-like 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::ICU;
my @list = ('a'..'c', 'A'..'C');
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. `locale` should be LDML locale identifier:
```perl
use Sort::Naturally::ICU qw/sorted/;
my $list = ['a'..'c', 'A'..'C'];
my $result_us = sorted($list, locale => 'en-US-u-va-posix');
# $result_us contains A, B, C, a, b, c
my $result_ca = sorted($list, locale => 'en-CA-u-va-posix');
# $result_ca contains a, A, b, B, c, C
```
## EXPORT
By default the module exports `ncmp` and `nsort` subroutines.
## BENCHMARK
```perl
require Benchmark;
require Sort::Naturally::ICU;
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::ICU::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::ICU::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::ICU
```
* Due to a significant overhead it is not recommended for sorting lists consisting of letters or digits only.
## SEE ALSO
* [module on PrePAN](http://prepan.org/module/nYfNhvSqeDp)
* [Sort::Naturally::XS module](http://search.cpan.org/~serval/Sort-Naturally-XS-0.7.8/lib/Sort/Naturally/XS.pm)
## AUTHOR
Sergey Yurzin, [jurzin.s@gmail.com](mailto:jurzin.s@gmail.com)
## COPYRIGHT AND LICENSE
Copyright (C) 2017 by Sergey Yurzin
This library is free software; you can redistribute it and/or modify
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::ICU", 'constant', 'IV', $types, undef, 3, @names) ) {
print $_, "\n"; # C constant subs
}
print "\n#### XS Section:\n";
print XS_constant ("Sort::Naturally::ICU", $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::ICU macro", s));
PUSHs(sv);
break;
case PERL_constant_NOTDEF:
sv = sv_2mortal(newSVpvf(
"Your vendor has not defined Sort::Naturally::ICU 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::ICU macro %s, used",
type, s));
PUSHs(sv);
}
lib/Sort/Naturally/ICU.pm view on Meta::CPAN
package Sort::Naturally::ICU;
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.8';
require XSLoader;
XSLoader::load('Sort::Naturally::ICU', $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/ICU.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::ICU - Perl extension for human-friendly ("natural") sort order
=head1 SYNOPSIS
use Sort::Naturally::ICU;
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/ICU.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::ICU 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::ICU;
my @list = ('a'..'c', 'A'..'C');
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/ICU.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::ICU qw/sorted/;
my $list = ['a'..'c', 'A'..'C'];
my $result_us = sorted($list, locale => 'en-US-u-va-posix');
# $result_us contains A, B, C, a, b, c
my $result_ca = sorted($list, locale => 'en-CA-u-va-posix');
# $result_ca contains a, A, b, B, c, C
Note: due to the complexity of a cross-platform support, a locale aware sorting is guaranteed on Unix-like operating
lib/Sort/Naturally/ICU.pm view on Meta::CPAN
=head1 EXPORT
By default the module exports C<ncmp> and C<nsort> subroutines.
=head1 BENCHMARK
require Benchmark;
require Sort::Naturally::ICU;
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::ICU::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::ICU::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::ICU
=item Due to a significant overhead it is not recommended for sorting lists consisting of letters or digits only.
=back
=head1 SEE ALSO
L<Module repository|https://github.com/CaballerosTeam/Sort-Naturally-ICU>
=head1 AUTHOR
src/Makefile.PL view on Meta::CPAN
use strict;
use Config;
use ExtUtils::MakeMaker;
$Verbose = 1;
WriteMakefile(
NAME => 'Sort::Naturally::ICU::nsort',
clean => {'FILES' => 'libnsort$(LIB_EXT)'},
LIBS => is_mac_os() ? '-L/usr/local/opt/icu4c/lib' : '',
INC => '-I. ' . (is_mac_os() ? '-I/usr/local/opt/icu4c/include' : ''),
);
sub MY::top_targets {
'
all :: static
pure_all :: static
static :: libnsort$(LIB_EXT)
t/Sort-Naturally-ICU-ncmp.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Encode;
use Sort::Naturally::ICU;
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-ICU-nsort.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Encode;
use Sort::Naturally::ICU;
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');
# 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-ICU-sorted.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Encode;
use Sort::Naturally::ICU qw/sorted/;
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');
my $ar_digit = [reverse(map {$_ x 2} (1..10))];
my $ar_digit__expected = [reverse(@{$ar_digit})];
ok(eq_array($ar_digit__expected, sorted($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, 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-ICU.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
BEGIN { use_ok('Sort::Naturally::ICU') }
ok(defined &ncmp, 'ncmp subroutine exported');
ok(defined &nsort, 'nsort subroutine exported');
done_testing();