Commit 51a64963 authored by User expired's avatar User expired
Browse files

bib-keyinsert: Test and fix for Incollection entries

The @ sign impeded determination of the entry type in the first record.
parent af88ad4c
Pipeline #27870 passed with stage
in 1 minute and 16 seconds
......@@ -142,8 +142,10 @@ function updatekeys() { # updatekeys bibfile skipj bibfile [letter]
citekey = array["Citationkey"]
# Bibtex entry type.
entrytype = $1
sub(" *{.*", "", entrytype)
atEntrytype = $1 # starts with "@" in first record
sub(" *{.*", "", atEntrytype)
entrytype = atEntrytype
sub("^@", "", entrytype)
# Otherwise, create it from author, year and journal.
if (!citekey) {
......@@ -216,7 +218,7 @@ function updatekeys() { # updatekeys bibfile skipj bibfile [letter]
}
# Update citation key.
sub(".*", entrytype "{" citekey ",", $1)
sub(".*", atEntrytype "{" citekey ",", $1)
}
# Print record separator as required.
......
......@@ -37,23 +37,45 @@ Czako2009b:jcp'
UNIQ='Czako2009a:jcp
Czako2009b:jcp'
writeFileThree() {
cat <<EOF
@Incollection{Armentrout1996,
Author = {Armentrout, P. B. and Kickel, Bernice L.},
Journal = {Unsupported Field},
Publisher = {Springer, Dordrecht},
Year = {1996},
Editor = {Freiser, B. S.}
}
@Incollection{Valentine1984:me,
Author = {Joan S. Valentine and Andrew R. Miksztal and Donald T. Sawyer},
Year = {1984},
Series = {Methods in Enzymology}
}
EOF
}
# Initially create temporary files for all tests.
oneTimeSetUp() {
fileOne=$(mktemp -u -t tmp.XXXXXX).bib
fileTwo=$(mktemp -u -t tmp.XXXXXX).bib
touch $fileOne $fileTwo
fileThree=$(mktemp -u -t tmp.XXXXXX).bib
touch $fileOne $fileTwo $fileThree
}
# Finally remove temporary files for all tests.
oneTimeTearDown() {
test ! -e $fileOne || rm $fileOne
test ! -e $fileTwo || rm $fileTwo
test ! -e $fileThree || rm $fileThree
}
# For each test reset the temporary file contents.
setUp() {
writeFileOne > $fileOne
writeFileTwo > $fileTwo
writeFileThree > $fileThree
alias bib-keyinsert="bib-keyinsert -s" # Quicker.
}
......@@ -195,5 +217,15 @@ testBadSigns() {
assertEquals 'Abcd' "$(bib-keyinsert $fileOne | getkey)"
}
testIncollection() {
# Expect no changes in case of correct keys.
assertFalse 'No changes expected' "bib-keyinsert -n $fileThree | grep ." \
|| bib-keyinsert -n $fileThree
# Check that actually no changes are applied.
bib-keyinsert $fileThree
assertTrue 'No changes done' "writeFileThree | diff - $fileThree" \
|| writeFileThree | diff - $fileThree
}
# Load and run shUnit2.
. shunit2/shunit2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment