| 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" |
| 30 | fi |
| 31 | |
| 32 | observed=$(xmlstarlet sel --net -t -v "/idsCorpus/idsHeader/fileDesc/titleStmt/c.title" target/dnb13.i5.xml) |
| 33 | if $(assert_eq "$observed" "Deutsche Nationalbibliothek: Belletristik 2013"); then |
| 34 | log_success "c.title contains yeaar" |
| 35 | else |
| 36 | log_failure "c.title does not contain year: $observed" |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 37 | ((ERRORS++)) |
| Marc Kupietz | ab0a733 | 2024-04-26 13:25:16 +0200 | [diff] [blame] | 38 | fi |
| 39 | |
| Marc Kupietz | fddbb51 | 2024-04-26 16:49:02 +0200 | [diff] [blame] | 40 | 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] | 41 | if $(assert_eq "$observed" "0"); then |
| 42 | log_success "authors do not contain []" |
| 43 | else |
| Marc Kupietz | 41c4238 | 2024-04-26 17:02:53 +0200 | [diff] [blame] | 44 | log_failure "authors contain []: $observed" |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 45 | ((ERRORS++)) |
| 46 | fi |
| 47 | |
| Marc Kupietz | eaa9013 | 2024-04-26 18:14:40 +0200 | [diff] [blame] | 48 | observed=$(xmlstarlet sel --net -t -v "/idsCorpus/idsDoc/idsText/idsHeader/fileDesc/sourceDesc/biblStruct/monogr/editor[@role='translator'][1]" target/dnb13.i5.xml) |
| 49 | if $(assert_eq "$observed" "Zwack, Heinz"); then |
| 50 | log_success "translator is correctly identified" |
| 51 | else |
| 52 | log_failure "translator is not correctly identified: $observed" |
| 53 | ((ERRORS++)) |
| 54 | fi |
| 55 | |
| 56 | |
| Marc Kupietz | 73a26bf | 2024-04-26 17:36:44 +0200 | [diff] [blame] | 57 | if [ $ERRORS -gt 0 ]; then |
| 58 | log_failure "There were $ERRORS errors" |
| 59 | exit 1 |
| 60 | else |
| 61 | log_success "All tests passed" |
| 62 | fi |