X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2FClassSortRoutine_LCC.t;h=9ec37cfc690417370521ed0158ee146270a7e801;hb=07cfcc77c580e8a16a9f12982525c5b1f6ff8c38;hp=9a5e007425a4972adfc3f2c51c8f1b6bd1daac67;hpb=5145eb59b786bd2010eb324197034dd210504543;p=koha.git diff --git a/t/ClassSortRoutine_LCC.t b/t/ClassSortRoutine_LCC.t index 9a5e007425..9ec37cfc69 100755 --- a/t/ClassSortRoutine_LCC.t +++ b/t/ClassSortRoutine_LCC.t @@ -6,9 +6,40 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 10; BEGIN { use_ok('C4::ClassSortRoutine::LCC'); } +#Obvious cases +is(C4::ClassSortRoutine::LCC::get_class_sort_key(), "", "No arguments returns an empty string"); +is(C4::ClassSortRoutine::LCC::get_class_sort_key('a','b'), "A B", "Arguments 'a','b' return 'A B'"); + +#spaces in arguements +is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','b'), "B", "Arguments ' ','b' return 'B'"); +is(C4::ClassSortRoutine::LCC::get_class_sort_key('a',' '), "A", "Arguments 'a',' ' return 'A'"); +is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ',' '), "", "Arguments ' ',' ' return ''"); + +#'funky cases' based on regex in code +is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','b'), "", "Arguments '.','b' return ''"); +is(C4::ClassSortRoutine::LCC::get_class_sort_key('....','........'), "", "Arguments '....','........' return ''"); +is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','.'), "", "Arguments '.','.' return ''"); + +# list of example call numbers -- these +# are intentionally in the _reverse_ of +# the correct sort order +my @call_numbers = ( + 'SB410.9 .P26 1993', + 'SB410.A26 I75 2000', + 'QC995 .E29 1997', + 'QC145.45 .H4 D65 1998', + 'QC145 .A57 V.12 1980', + 'QC100 .U57 NO. 555 1986', +); + +my @sorted_call_numbers = map { $_->{call_number} } + sort { $a->{sortkey} cmp $b->{sortkey} } + map { { call_number => $_, sortkey => C4::ClassSortRoutine::LCC::get_class_sort_key($_, '') } } + @call_numbers; +is_deeply(\@sorted_call_numbers, [ reverse @call_numbers ], 'LC call numbers sorted in correct order');