| Marc Kupietz | ab0a733 | 2024-04-26 13:25:16 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | TESTDIR=$(dirname $0) |
| 3 | ASSERTSH=${TESTDIR}/assert.sh |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 4 | # set -e |
| Marc Kupietz | ab0a733 | 2024-04-26 13:25:16 +0200 | [diff] [blame] | 5 | . ${ASSERTSH} |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 6 | ERRORS=0 |
| Marc Kupietz | ab0a733 | 2024-04-26 13:25:16 +0200 | [diff] [blame] | 7 | TEXTS=6 |
| 8 | I5_FILE=target/dnb18.i5.xml |
| 9 | if [ ! -f "$I5_FILE" ]; then |
| 10 | log_failure "File $I5_FILE does not exist" |
| 11 | exit 1 |
| 12 | fi |
| 13 | |
| 14 | |
| 15 | observed=$(xmlstarlet sel --net -t -v "count(//idsText)" $I5_FILE) |
| 16 | |
| 17 | if $(assert_eq "$observed" "$TEXTS"); then |
| 18 | log_success "$I5_FILE contains $TEXTS idsText elements" |
| 19 | else |
| Marc Kupietz | 41c4238 | 2024-04-26 17:02:53 +0200 | [diff] [blame] | 20 | log_failure "$I5_FILE does not contain $TEXTS idsText elements, but: $observed" |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 21 | ((ERRORS++)) |
| Marc Kupietz | ab0a733 | 2024-04-26 13:25:16 +0200 | [diff] [blame] | 22 | fi |
| 23 | |
| 24 | |
| 25 | observed=$(xmlstarlet sel --net -t -v "count(/idsCorpus/idsDoc/idsText/idsHeader/fileDesc/sourceDesc/biblStruct/monogr/h.author[normalize-space(.)])" $I5_FILE) |
| 26 | if $(assert_eq "$observed" "$TEXTS"); then |
| 27 | log_success "$I5_FILE contains $TEXTS non-empty h.author elements" |
| 28 | else |
| Marc Kupietz | 41c4238 | 2024-04-26 17:02:53 +0200 | [diff] [blame] | 29 | log_failure "$I5_FILE does not contain $TEXTS non-empty h.author elements: $observed" |
| Marc Kupietz | 5df1b16 | 2024-04-27 10:07:18 +0200 | [diff] [blame^] | 30 | ((ERRORS++)) |
| Marc Kupietz | 41c4238 | 2024-04-26 17:02:53 +0200 | [diff] [blame] | 31 | fi |
| 32 | |
| 33 | observed=$(xmlstarlet sel --net -t -v "/idsCorpus/idsHeader/fileDesc/titleStmt/c.title" target/dnb13.i5.xml) |
| 34 | if $(assert_eq "$observed" "Deutsche Nationalbibliothek: Belletristik 2013"); then |
| 35 | log_success "c.title contains yeaar" |
| 36 | else |
| 37 | log_failure "c.title does not contain year: $observed" |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 38 | ((ERRORS++)) |
| Marc Kupietz | ab0a733 | 2024-04-26 13:25:16 +0200 | [diff] [blame] | 39 | fi |
| 40 | |
| Marc Kupietz | fddbb51 | 2024-04-26 16:49:02 +0200 | [diff] [blame] | 41 | observed=$(xmlstarlet sel --net -t -v "count(/idsCorpus/idsDoc/idsText/idsHeader/fileDesc/sourceDesc/biblStruct/monogr/h.author[contains(., '[')])" target/dnb13.i5.xml) |
| Marc Kupietz | ab0a733 | 2024-04-26 13:25:16 +0200 | [diff] [blame] | 42 | if $(assert_eq "$observed" "0"); then |
| 43 | log_success "authors do not contain []" |
| 44 | else |
| Marc Kupietz | 41c4238 | 2024-04-26 17:02:53 +0200 | [diff] [blame] | 45 | log_failure "authors contain []: $observed" |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 46 | ((ERRORS++)) |
| 47 | fi |
| 48 | |
| Marc Kupietz | eaa9013 | 2024-04-26 18:14:40 +0200 | [diff] [blame] | 49 | observed=$(xmlstarlet sel --net -t -v "/idsCorpus/idsDoc/idsText/idsHeader/fileDesc/sourceDesc/biblStruct/monogr/editor[@role='translator'][1]" target/dnb13.i5.xml) |
| 50 | if $(assert_eq "$observed" "Zwack, Heinz"); then |
| 51 | log_success "translator is correctly identified" |
| 52 | else |
| 53 | log_failure "translator is not correctly identified: $observed" |
| 54 | ((ERRORS++)) |
| 55 | fi |
| 56 | |
| Marc Kupietz | 54ec28b | 2024-04-27 10:07:06 +0200 | [diff] [blame] | 57 | observed=$(grep -Ec '^Copyright' target/dnb13.i5.xml) |
| 58 | if $(assert_eq "$observed" "2"); then |
| 59 | log_success "spaces at <br> elements are inserted correctly" |
| 60 | else |
| 61 | log_failure "spaces at <br> elements are not inserted correctly" |
| 62 | ((ERRORS++)) |
| 63 | fi |
| 64 | |
| Marc Kupietz | eaa9013 | 2024-04-26 18:14:40 +0200 | [diff] [blame] | 65 | |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 66 | if [ $ERRORS -gt 0 ]; then |
| 67 | log_failure "There were $ERRORS errors" |
| 68 | exit 1 |
| 69 | else |
| 70 | log_success "All tests passed" |
| 71 | fi |