;; crossrefs
;;
;; This file is part of Beastie <https://purl.org/nxg/dist/beastie>
;; SPDX-FileCopyrightText: 2023 Norman Gray <https://nxg.me.uk>
;; SPDX-License-Identifier: BSD-2-Clause

(check
 (let ((no-gnats (DB 'no-gnats))
       (gg-proceedings (DB 'gg-proceedings))
       (gg-more (DB 'gg-more))
       (circular-1 (DB 'circular-1))
       (missing-xr (DB 'missing-xr)))
   ;; I'm not sure I want to expose the entry-crossref function
   (define (crossref-keys e)
     (cond ((entry-crossref e)
            => (λ (xr)
                 (cons (entry-key xr) (or (crossref-keys xr) '()))))
           (else #f)))
   (assert-equal (crossref-keys no-gnats)
                 '(gg-proceedings gg-series))
   (assert-equal (entry-field/crossref no-gnats 'title)
                 #"No Gnats Are Taken for Granite")
   (assert-equal (entry-field/crossref no-gnats 'booktitle)
                 #"The Gnats and Gnus 1988 Proceedings")
   ;; (assert-equal (crossref-keys gg-more)
   ;;               '(gg-series))
   (assert-equal (entry-field/crossref gg-more 'booktitle)
                 #"The Gnats and Gnus 1988 Proceedings")
   ;; (assert-equal (crossref-keys circular-1)
   ;;               '(circular-2))
   (assert-false (entry-field/crossref circular-1 'title))
   ;; (assert-false (crossref-keys (DB 'circular-2)))
   (assert-false (entry-field/crossref missing-xr 'title))
   ;; (assert-false (crossref-keys missing-xr))
   ))


There's no significance to the following being articles rather than proceedings.
It's just because the minimal bst supports only articles.

@article{no-gnats,
      crossref = "gg-proceedings",
      author = "Rocky Gneisser",
      title = "No Gnats Are Taken for Granite",
      pages = "133-139"}

@article{gg-more,
  author =       {Alma Scree},
  title =        {Heavy Stones},
  crossref =     {gg-series}
}

@article{gg-third,
  author =       {Rocky Ford},
  title =        {Another gg-series crossref},
  crossref =     {gg-series}
}

@article{gg-proceedings,
      editor = "Gerald Ford and Jimmy Carter",
      title = "Remarks about Gnats and Gnus",
      crossref = {gg-series}}

@article{gg-series,
  booktitle =        "The Gnats and Gnus 1988 Proceedings",
  year =         1988
}

@Article{circular-1,
  author =       {Circular Author One},
  crossref = "circular-2"
}

@Article{circular-2,
  author =       {Circular Author Two},
  crossref = "circular-1"
}

@article{missing-xr,
         author = "Somebody Somewhere",
         crossref = "missing"}

@article{ordinary,
         author = "Lone Ranger",
         title = "I don't have a crossref"}
