Commit a2a9b6cb authored by User expired's avatar User expired
Browse files

Test and fix field delimiters after sorting

parent 1a27e63a
Pipeline #26388 passed with stage
in 1 minute and 28 seconds
......@@ -263,9 +263,22 @@ BEGIN {
printf("%s", a[NF-1])
}
# Check if first entry in bibtex file.
# (RS does not remove initial @ from first entry.)
if (a[NF-2+loopshift] == "@") {
firstentry = 1
} else {
firstentry = 0
}
# Print fields.
for (i=1+loopshift; i<NF-1+loopshift; i++) {
for (i=1+loopshift; i<NF-1+loopshift-firstentry; i++) {
if (a[i] != "") {
if (i < NF-2+loopshift-firstentry) {
gsub("} *$", "},", a[i])
} else {
gsub("}, *$", "}", a[i])
}
printf("%s%s", OFS, a[i])
}
}
......@@ -280,5 +293,4 @@ END {
printf("\n")
}
}
' \
| grep -v '^@$'
'
......@@ -101,6 +101,7 @@ testUnitingSeparatedFiles() {
"cat by_citekey/*.bib by_citekey/*/*.bib | diff $fileOne -"
assertTrue 'United file is identical to original file' \
"bib-unite by_citekey/*.bib by_citekey/*/*.bib | diff $fileOne -"
bib-unite by_citekey/*.bib by_citekey/*/*.bib | diff $fileOne -
}
testRemovingJabRefComments() {
......@@ -124,5 +125,41 @@ testDropDuplicates() {
assertFalse 'Keep differing duplicates (-r)' "bib-unite -r $fileOne $fileTwo | diff $fileTwo -"
}
testSortingFields() {
# Unsorted entry with final delimiters.
cat > $fileOne <<EOF
@Article{Czako2019b:pccp,
Year = {2019}
Journal = {Phys. Chem. Chem. Phys.},
Author = {Czak\'{o}, G\'{a}bor and Olasz, Bal\'{a}zs},
}
EOF
# Sorted entry.
cat > $fileTwo <<EOF
@Article{Czako2019b:pccp,
Author = {Czak\'{o}, G\'{a}bor and Olasz, Bal\'{a}zs},
Journal = {Phys. Chem. Chem. Phys.},
Year = {2019}
}
EOF
assertTrue 'Fields are sorted' "bib-unite $fileOne | diff $fileTwo -"
bib-unite $fileOne | diff $fileTwo -
# Unsorted entry with correct delimiters.
cat > $fileOne <<EOF
@Article{Czako2019b:pccp,
Year = {2019},
Journal = {Phys. Chem. Chem. Phys.},
Author = {Czak\'{o}, G\'{a}bor and Olasz, Bal\'{a}zs}
}
EOF
assertTrue 'Field delimiters are corrected' "bib-unite $fileOne | diff $fileTwo -"
bib-unite $fileOne | diff $fileTwo -
}
# 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