| 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) 2015-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 |
rename_field.t - Test suite for BibTool rename.field. |
| 31 |
|
| 32 |
=head1 SYNOPSIS |
| 33 |
|
| 34 |
rename_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 => 'rename_field_0', |
| 59 |
args => 'bib/x1.bib', |
| 60 |
resource => 'rename.field={xyzzy = booktitle}', |
| 61 |
expected_out => <<__EOF__, |
| 62 |
|
| 63 |
\@Manual{ bibtool, |
| 64 |
title = {BibTool}, |
| 65 |
author = {Gerd Neugebauer}, |
| 66 |
year = 2018 |
| 67 |
} |
| 68 |
__EOF__ |
| 69 |
expected_err => '' ); |
| 70 |
|
| 71 |
#------------------------------------------------------------------------------ |
| 72 |
BUnit::run(name => 'rename_field_1', |
| 73 |
args => 'bib/x1.bib', |
| 74 |
resource => 'rename.field={title = booktitle}', |
| 75 |
expected_out => <<__EOF__, |
| 76 |
|
| 77 |
\@Manual{ bibtool, |
| 78 |
booktitle = {BibTool}, |
| 79 |
author = {Gerd Neugebauer}, |
| 80 |
year = 2018 |
| 81 |
} |
| 82 |
__EOF__ |
| 83 |
expected_err => '' ); |
| 84 |
|
| 85 |
#------------------------------------------------------------------------------ |
| 86 |
BUnit::run(name => 'rename_field_2', |
| 87 |
args => 'bib/x1.bib', |
| 88 |
resource => 'rename.field={Title = booktitle}', |
| 89 |
expected_out => <<__EOF__, |
| 90 |
|
| 91 |
\@Manual{ bibtool, |
| 92 |
booktitle = {BibTool}, |
| 93 |
author = {Gerd Neugebauer}, |
| 94 |
year = 2018 |
| 95 |
} |
| 96 |
__EOF__ |
| 97 |
expected_err => '' ); |
| 98 |
|
| 99 |
#------------------------------------------------------------------------------ |
| 100 |
BUnit::run(name => 'rename_field_err_1', |
| 101 |
args => 'bib/x1.bib', |
| 102 |
resource => 'rename.field={Title}', |
| 103 |
expected_out => <<__EOF__, |
| 104 |
|
| 105 |
\@Manual{ bibtool, |
| 106 |
title = {BibTool}, |
| 107 |
author = {Gerd Neugebauer}, |
| 108 |
year = 2018 |
| 109 |
} |
| 110 |
__EOF__ |
| 111 |
expected_err => <<__EOF__, |
| 112 |
|
| 113 |
Title |
| 114 |
_____^ |
| 115 |
*** BibTool ERROR: Symbol expected. |
| 116 |
__EOF__ |
| 117 |
); |
| 118 |
|
| 119 |
|
| 120 |
#------------------------------------------------------------------------------ |
| 121 |
BUnit::run(name => 'rename_field_err_2', |
| 122 |
args => 'bib/x1.bib', |
| 123 |
resource => 'rename.field={Title booktitle xxx}', |
| 124 |
expected_out => <<__EOF__, |
| 125 |
|
| 126 |
\@Manual{ bibtool, |
| 127 |
title = {BibTool}, |
| 128 |
author = {Gerd Neugebauer}, |
| 129 |
year = 2018 |
| 130 |
} |
| 131 |
__EOF__ |
| 132 |
expected_err => <<__EOF__, |
| 133 |
|
| 134 |
Title booktitle xxx |
| 135 |
________________^ |
| 136 |
*** BibTool ERROR: Unexpected characters at end of string. |
| 137 |
__EOF__ |
| 138 |
); |
| 139 |
|
| 140 |
#------------------------------------------------------------------------------ |
| 141 |
BUnit::run(name => 'rename_field_10', |
| 142 |
args => 'bib/x1.bib', |
| 143 |
resource => 'rename.field={Title = booktitle if author "Neu"}', |
| 144 |
expected_out => <<__EOF__, |
| 145 |
|
| 146 |
\@Manual{ bibtool, |
| 147 |
booktitle = {BibTool}, |
| 148 |
author = {Gerd Neugebauer}, |
| 149 |
year = 2018 |
| 150 |
} |
| 151 |
__EOF__ |
| 152 |
expected_err => '' ); |
| 153 |
|
| 154 |
#------------------------------------------------------------------------------ |
| 155 |
BUnit::run(name => 'rename_field_11', |
| 156 |
args => 'bib/x1.bib', |
| 157 |
resource => 'rename.field={Title = booktitle if $type "Book"}', |
| 158 |
expected_out => <<__EOF__, |
| 159 |
|
| 160 |
\@Manual{ bibtool, |
| 161 |
title = {BibTool}, |
| 162 |
author = {Gerd Neugebauer}, |
| 163 |
year = 2018 |
| 164 |
} |
| 165 |
__EOF__ |
| 166 |
expected_err => '' ); |
| 167 |
|
| 168 |
1; |
| 169 |
#------------------------------------------------------------------------------ |
| 170 |
# Local Variables: |
| 171 |
# mode: perl |
| 172 |
# End: |