| 1 |
#!/usr/bin/env perl |
| 2 |
# ============================================================================= |
| 3 |
# |
| 4 |
# This file is part of BibTool. |
| 5 |
# It is distributed under the GNU General Public License. |
| 6 |
# See the file COPYING for details. |
| 7 |
# |
| 8 |
# (c) 2016-2020 Gerd Neugebauer |
| 9 |
# |
| 10 |
# Net: [email protected] |
| 11 |
# |
| 12 |
# This program is free software; you can redistribute it and/or modify |
| 13 |
# it under the terms of the GNU General Public License as published by |
| 14 |
# the Free Software Foundation; either version 2, or (at your option) |
| 15 |
# any later version. |
| 16 |
# |
| 17 |
# This program is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
# GNU General Public License for more details. |
| 21 |
# |
| 22 |
# You should have received a copy of the GNU General Public License |
| 23 |
# along with this program; if not, write to the Free Software |
| 24 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 |
# |
| 26 |
#*============================================================================= |
| 27 |
|
| 28 |
=head1 NAME |
| 29 |
|
| 30 |
keep_field.t - Test suite for BibTool keep.field. |
| 31 |
|
| 32 |
=head1 SYNOPSIS |
| 33 |
|
| 34 |
keep_field.t |
| 35 |
|
| 36 |
=head1 DESCRIPTION |
| 37 |
|
| 38 |
This module contains some test cases. Running this module as program |
| 39 |
will run all test cases and print a summary for each. Optionally files |
| 40 |
*.out and *.err are left if the expected result does not match the |
| 41 |
actual result. |
| 42 |
|
| 43 |
=head1 OPTIONS |
| 44 |
|
| 45 |
none |
| 46 |
|
| 47 |
=head1 AUTHOR |
| 48 |
|
| 49 |
Gerd Neugebauer |
| 50 |
|
| 51 |
=cut |
| 52 |
|
| 53 |
use strict; |
| 54 |
use BUnit;use warnings; |
| 55 |
|
| 56 |
|
| 57 |
#------------------------------------------------------------------------------ |
| 58 |
BUnit::run(name => 'keep_field_err_01', |
| 59 |
resource => <<__EOF__, |
| 60 |
keep.field{} |
| 61 |
__EOF__ |
| 62 |
args => 'bib/x1.bib', |
| 63 |
expected_out => <<__EOF__, |
| 64 |
|
| 65 |
\@Manual{ bibtool, |
| 66 |
title = {BibTool}, |
| 67 |
author = {Gerd Neugebauer}, |
| 68 |
year = 2018 |
| 69 |
} |
| 70 |
__EOF__ |
| 71 |
expected_err => <<__EOF__ |
| 72 |
|
| 73 |
|
| 74 |
^ |
| 75 |
*** BibTool ERROR: List of symbols expected. |
| 76 |
__EOF__ |
| 77 |
); |
| 78 |
|
| 79 |
#------------------------------------------------------------------------------ |
| 80 |
BUnit::run(name => 'keep_field_err_02', |
| 81 |
resource => <<__EOF__, |
| 82 |
keep.field{"abc"} |
| 83 |
__EOF__ |
| 84 |
args => 'bib/x1.bib', |
| 85 |
expected_out => <<__EOF__, |
| 86 |
|
| 87 |
\@Manual{ bibtool, |
| 88 |
title = {BibTool}, |
| 89 |
author = {Gerd Neugebauer}, |
| 90 |
year = 2018 |
| 91 |
} |
| 92 |
__EOF__ |
| 93 |
expected_err => <<__EOF__ |
| 94 |
|
| 95 |
"abc" |
| 96 |
^ |
| 97 |
*** BibTool ERROR: List of symbols expected. |
| 98 |
__EOF__ |
| 99 |
); |
| 100 |
|
| 101 |
#------------------------------------------------------------------------------ |
| 102 |
BUnit::run(name => 'keep_field_err_03', |
| 103 |
resource => <<__EOF__, |
| 104 |
keep.field{title 123} |
| 105 |
__EOF__ |
| 106 |
args => 'bib/x1.bib', |
| 107 |
expected_out => <<__EOF__, |
| 108 |
|
| 109 |
\@Manual{ bibtool, |
| 110 |
title = {BibTool}, |
| 111 |
author = {Gerd Neugebauer}, |
| 112 |
year = 2018 |
| 113 |
} |
| 114 |
__EOF__ |
| 115 |
expected_err => <<__EOF__ |
| 116 |
|
| 117 |
title 123 |
| 118 |
______^ |
| 119 |
*** BibTool ERROR: Unexpected characters at end of string. |
| 120 |
__EOF__ |
| 121 |
); |
| 122 |
|
| 123 |
#------------------------------------------------------------------------------ |
| 124 |
BUnit::run(name => 'keep_field_err_04', |
| 125 |
resource => <<__EOF__, |
| 126 |
keep.field{title if abc} |
| 127 |
__EOF__ |
| 128 |
args => 'bib/x1.bib', |
| 129 |
expected_out => <<__EOF__, |
| 130 |
|
| 131 |
\@Manual{ bibtool, |
| 132 |
title = {BibTool}, |
| 133 |
author = {Gerd Neugebauer}, |
| 134 |
year = 2018 |
| 135 |
} |
| 136 |
__EOF__ |
| 137 |
expected_err => <<__EOF__ |
| 138 |
|
| 139 |
title if abc |
| 140 |
____________^ |
| 141 |
*** BibTool ERROR: Symbol expected. |
| 142 |
__EOF__ |
| 143 |
); |
| 144 |
|
| 145 |
#------------------------------------------------------------------------------ |
| 146 |
BUnit::run(name => 'keep_field_err_05', |
| 147 |
resource => <<__EOF__, |
| 148 |
keep.field{title if abc = } |
| 149 |
__EOF__ |
| 150 |
args => 'bib/x1.bib', |
| 151 |
expected_out => <<__EOF__, |
| 152 |
|
| 153 |
\@Manual{ bibtool, |
| 154 |
title = {BibTool}, |
| 155 |
author = {Gerd Neugebauer}, |
| 156 |
year = 2018 |
| 157 |
} |
| 158 |
__EOF__ |
| 159 |
expected_err => <<__EOF__ |
| 160 |
|
| 161 |
title if abc = |
| 162 |
_______________^ |
| 163 |
*** BibTool ERROR: Symbol expected. |
| 164 |
__EOF__ |
| 165 |
); |
| 166 |
|
| 167 |
#------------------------------------------------------------------------------ |
| 168 |
BUnit::run(name => 'keep_field_01', |
| 169 |
resource => <<__EOF__, |
| 170 |
keep.field{title} |
| 171 |
__EOF__ |
| 172 |
bib => <<__EOF__, |
| 173 |
\@Article{ bibtool, |
| 174 |
title = {The BibTool Manual}, |
| 175 |
author = {Gerd Neugebauer}, |
| 176 |
year = 2018 |
| 177 |
} |
| 178 |
|
| 179 |
\@Manual{ bibtool2, |
| 180 |
title = {The BibTool Manual}, |
| 181 |
author = {Gerd Neugebauer}, |
| 182 |
year = 2018 |
| 183 |
} |
| 184 |
__EOF__ |
| 185 |
expected_out => <<__EOF__, |
| 186 |
|
| 187 |
\@Article{ bibtool, |
| 188 |
title = {The BibTool Manual} |
| 189 |
} |
| 190 |
|
| 191 |
\@Manual{ bibtool2, |
| 192 |
title = {The BibTool Manual} |
| 193 |
} |
| 194 |
__EOF__ |
| 195 |
expected_err => '' ); |
| 196 |
|
| 197 |
#------------------------------------------------------------------------------ |
| 198 |
BUnit::run(name => 'keep_field_02', |
| 199 |
resource => <<__EOF__, |
| 200 |
keep.field{{title author}} |
| 201 |
__EOF__ |
| 202 |
bib => <<__EOF__, |
| 203 |
\@Article{ bibtool, |
| 204 |
title = {The BibTool Manual}, |
| 205 |
author = {Gerd Neugebauer}, |
| 206 |
year = 2018 |
| 207 |
} |
| 208 |
|
| 209 |
\@Manual{ bibtool2, |
| 210 |
title = {The BibTool Manual}, |
| 211 |
author = {Gerd Neugebauer}, |
| 212 |
year = 2018 |
| 213 |
} |
| 214 |
__EOF__ |
| 215 |
expected_out => <<__EOF__, |
| 216 |
|
| 217 |
\@Article{ bibtool, |
| 218 |
title = {The BibTool Manual}, |
| 219 |
author = {Gerd Neugebauer} |
| 220 |
} |
| 221 |
|
| 222 |
\@Manual{ bibtool2, |
| 223 |
title = {The BibTool Manual}, |
| 224 |
author = {Gerd Neugebauer} |
| 225 |
} |
| 226 |
__EOF__ |
| 227 |
expected_err => '' ); |
| 228 |
|
| 229 |
#------------------------------------------------------------------------------ |
| 230 |
BUnit::run(name => 'keep_field_11', |
| 231 |
resource => <<__EOF__, |
| 232 |
keep.field{title} |
| 233 |
keep.field{author if \$type = "article"} |
| 234 |
__EOF__ |
| 235 |
bib => <<__EOF__, |
| 236 |
\@Article{ bibtool, |
| 237 |
title = {The BibTool Manual}, |
| 238 |
author = {Gerd Neugebauer}, |
| 239 |
year = 2018 |
| 240 |
} |
| 241 |
|
| 242 |
\@Manual{ bibtool2, |
| 243 |
title = {The BibTool Manual}, |
| 244 |
author = {Gerd Neugebauer}, |
| 245 |
year = 2018 |
| 246 |
} |
| 247 |
__EOF__ |
| 248 |
expected_out => <<__EOF__, |
| 249 |
|
| 250 |
\@Article{ bibtool, |
| 251 |
title = {The BibTool Manual}, |
| 252 |
author = {Gerd Neugebauer} |
| 253 |
} |
| 254 |
|
| 255 |
\@Manual{ bibtool2, |
| 256 |
title = {The BibTool Manual} |
| 257 |
} |
| 258 |
__EOF__ |
| 259 |
expected_err => '' ); |
| 260 |
|
| 261 |
#------------------------------------------------------------------------------ |
| 262 |
BUnit::run(name => 'keep_field_21', |
| 263 |
resource => <<__EOF__, |
| 264 |
keep.field{*} |
| 265 |
__EOF__ |
| 266 |
bib => <<__EOF__, |
| 267 |
\@Article{ bibtool, |
| 268 |
title = {The BibTool Manual}, |
| 269 |
author = {Gerd Neugebauer}, |
| 270 |
year = 2018 |
| 271 |
} |
| 272 |
|
| 273 |
\@Manual{ bibtool2, |
| 274 |
title = {The BibTool Manual}, |
| 275 |
author = {Gerd Neugebauer}, |
| 276 |
year = 2018 |
| 277 |
} |
| 278 |
__EOF__ |
| 279 |
expected_out => <<__EOF__, |
| 280 |
|
| 281 |
\@Article{ bibtool, |
| 282 |
title = {The BibTool Manual}, |
| 283 |
author = {Gerd Neugebauer}, |
| 284 |
year = 2018 |
| 285 |
} |
| 286 |
|
| 287 |
\@Manual{ bibtool2, |
| 288 |
title = {The BibTool Manual}, |
| 289 |
author = {Gerd Neugebauer}, |
| 290 |
year = 2018 |
| 291 |
} |
| 292 |
__EOF__ |
| 293 |
expected_err => '' ); |
| 294 |
|
| 295 |
#------------------------------------------------------------------------------ |
| 296 |
BUnit::run(name => 'keep_field_22', |
| 297 |
resource => <<__EOF__, |
| 298 |
keep.field{* if \$type = article} |
| 299 |
__EOF__ |
| 300 |
bib => <<__EOF__, |
| 301 |
\@Article{ bibtool, |
| 302 |
title = {The BibTool Manual}, |
| 303 |
author = {Gerd Neugebauer}, |
| 304 |
year = 2018 |
| 305 |
} |
| 306 |
|
| 307 |
\@Manual{ bibtool2, |
| 308 |
title = {The BibTool Manual}, |
| 309 |
author = {Gerd Neugebauer}, |
| 310 |
year = 2018 |
| 311 |
} |
| 312 |
__EOF__ |
| 313 |
expected_out => <<__EOF__, |
| 314 |
|
| 315 |
\@Article{ bibtool, |
| 316 |
title = {The BibTool Manual}, |
| 317 |
author = {Gerd Neugebauer}, |
| 318 |
year = 2018 |
| 319 |
} |
| 320 |
|
| 321 |
\@Manual{ bibtool2 |
| 322 |
} |
| 323 |
__EOF__ |
| 324 |
expected_err => '' ); |
| 325 |
|
| 326 |
#------------------------------------------------------------------------------ |
| 327 |
BUnit::run(name => 'keep_field_23', |
| 328 |
resource => <<__EOF__, |
| 329 |
keep.field{{abc *} if \$type = article} |
| 330 |
__EOF__ |
| 331 |
bib => <<__EOF__, |
| 332 |
\@Article{ bibtool, |
| 333 |
title = {The BibTool Manual}, |
| 334 |
author = {Gerd Neugebauer}, |
| 335 |
year = 2018 |
| 336 |
} |
| 337 |
|
| 338 |
\@Manual{ bibtool2, |
| 339 |
title = {The BibTool Manual}, |
| 340 |
author = {Gerd Neugebauer}, |
| 341 |
year = 2018 |
| 342 |
} |
| 343 |
__EOF__ |
| 344 |
expected_out => <<__EOF__, |
| 345 |
|
| 346 |
\@Article{ bibtool, |
| 347 |
title = {The BibTool Manual}, |
| 348 |
author = {Gerd Neugebauer}, |
| 349 |
year = 2018 |
| 350 |
} |
| 351 |
|
| 352 |
\@Manual{ bibtool2 |
| 353 |
} |
| 354 |
__EOF__ |
| 355 |
expected_err => '' ); |
| 356 |
|
| 357 |
1; |
| 358 |
#------------------------------------------------------------------------------ |
| 359 |
# Local Variables: |
| 360 |
# mode: perl |
| 361 |
# End: |