summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/bibtex/biber/t/10-sort-complex.t
blob: 2f618e151fa8510354971eb0c051be1461874315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use strict;
use warnings;
use utf8;
no warnings 'utf8';

use Test::More tests => 8;

use Biber;
use Biber::Output::BBL;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($ERROR);
chdir("t/tdata") ;

# Set up Biber object
my $biber = Biber->new(noconf => 1);
$biber->parse_ctrlfile('sort-complex.bcf');
$biber->set_output_obj(Biber::Output::BBL->new());

# Options - we could set these in the control file but it's nice to see what we're
# relying on here for tests

# Biber options
Biber::Config->setoption('fastsort', 1);

# Biblatex options
Biber::Config->setblxoption('labelalpha', 1);
Biber::Config->setblxoption('labelyear', undef);

# Now generate the information
$biber->prepare;
my $section = $biber->sections->get_section(0);
my $main = $section->get_list('MAIN');
my $shs = $section->get_list('SHORTHANDS');
my $out = $biber->get_output_obj;

isa_ok($biber, "Biber");

my $sc = [
           [
            {},
            {'presort'    => {}}
           ],
           [
            {final          => 1,
             },
            {'sortkey'    => {}}
           ],
           [
            {},
            {'labelalpha'    => {}},
           ],
           [
            {},
            {'sortname'   => {}},
            {'author'     => {}},
            {'editor'     => {}},
            {'translator' => {}},
            {'sorttitle'  => {}},
            {'title'      => {}}
           ],
           [
            {},
            {'sortyear'  => {}},
            {'year'      => {}}
           ],
           [
            {},
            {'sorttitle'       => {}},
            {'title'       => {}}
           ],
           [
            {},
            {'volume'     => {pad_char => '0',
                              pad_side => 'left',
                              pad_width => '4'}},
            {'0000'       => {}}
           ],
          ];

my $sc3 = q|  \entry{L4}{book}{}
    \true{morelabelname}
    \name{labelname}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \true{moreauthor}
    \name{author}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \list{location}{1}{%
      {Cambridge}%
    }
    \list{publisher}{1}{%
      {Another press}%
    }
    \strng{namehash}{DJo1}
    \strng{fullhash}{DJo1}
    \field{labelalpha}{Doe\textbf{+}95}
    \field{sortinit}{D}
    \field{extraalpha}{2}
    \field{title}{Some title about sorting}
    \field{year}{1995}
  \endentry

|;

my $sc4 = q|  \entry{L1}{book}{}
    \name{labelname}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \name{author}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \list{location}{1}{%
      {Cambridge}%
    }
    \list{publisher}{1}{%
      {A press}%
    }
    \strng{namehash}{DJ1}
    \strng{fullhash}{DJ1}
    \field{labelalpha}{Doe95}
    \field{sortinit}{D}
    \field{extraalpha}{1}
    \field{title}{Algorithms For Sorting}
    \field{year}{1995}
  \endentry

|;

my $sc5 = q|  \entry{L2}{book}{}
    \name{labelname}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \name{author}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \list{location}{1}{%
      {Cambridge}%
    }
    \list{publisher}{1}{%
      {A press}%
    }
    \strng{namehash}{DJ1}
    \strng{fullhash}{DJ1}
    \field{labelalpha}{Doe95}
    \field{sortinit}{D}
    \field{extraalpha}{3}
    \field{title}{Sorting Algorithms}
    \field{year}{1995}
  \endentry

|;

my $sc6 = q|  \entry{L3}{book}{}
    \name{labelname}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \name{author}{1}{%
      {{Doe}{D.}{John}{J.}{}{}{}{}}%
    }
    \list{location}{1}{%
      {Cambridge}%
    }
    \list{publisher}{1}{%
      {A press}%
    }
    \strng{namehash}{DJ1}
    \strng{fullhash}{DJ1}
    \field{labelalpha}{Doe95}
    \field{sortinit}{D}
    \field{extraalpha}{2}
    \field{title}{More and More Algorithms}
    \field{year}{1995}
  \endentry

|;

is_deeply( $main->get_sortscheme , $sc, 'sort scheme');
is( $out->get_output_entry($main,'l4'), $sc3, '\alphaothers set by "and others"');
is( $out->get_output_entry($main,'l1'), $sc4, '2-pass - labelalpha after title');
is( $out->get_output_entry($main,'l2'), $sc5, '2-pass - labelalpha after title');
is( $out->get_output_entry($main,'l3'), $sc6, '2-pass - labelalpha after title');
is_deeply([ $main->get_keys ], ['L5', 'L4', 'L1', 'L3', 'L2'], 'citeorder - 1');

# This should be the same as $main citeorder as both $main and $shs use same
# global sort spec. $shs should also get the keys from the sort cache as a result.
# Can't do the usual SHORTHAND filter on SHORTHAND field in .bcf as adding SHORTHAND
# fields to the entries changes the sort order of $main (as SHORTHAND overrides the default
# label)
is_deeply([ $shs->get_keys ], ['L5', 'L4', 'L1', 'L3', 'L2'], 'citeorder - 2');


unlink <*.utf8>;