;; 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
 (assert-equal (map entry->list/debug (sort! (map cdr DB) entry<?))
               '((article cite-key (author . #"Poussin") (number . #"99"))
                 (fake-entry fake-database-key
                             (never-to-be-used-field . #"Even if this were a real entry,\n                I could still have a comment inside an entry\n                by making up a fake field"))
                 (misc prime-number-theorem
                       ;; this appears as Vallée, untexified; since parse-bibtex-file
                       ;; untexifies by default
                       (author . #"Charles Louis Xavier Joseph de la Vallée Poussin")
                       (note . #"A strong form of the prime number theorem, 19th century"))
                 (manual scribe
                         (address . #"Pittsburgh")
                         (month . #"apr")
                         (note . #"Chapter twelve and appendices E8 through E10 deal\n                        with bibliographies")
                         (organization . #"Unilogic, Ltd.\n                        ")
                         (title . #"Scribe Document Production System\n\n\n                                                        User Manual")
                         (year . #"1984"))))
 (assert-equal (get-preamble) #"anythinggoes"))

This is the beginning of the btxhak.bib bibliography at
<https://www.ctan.org/tex-archive/biblio/bibtex/base>,
which contains something of a BibTeX torture test.

Further torture:

  * Quote " and braces { and } outside an entry shouldn't confuse things.
  * `string` keys are case-insensitive
  * %-commenta can appear anywhere whitespace can



% Copyright (C) 1988, 2010 Oren Patashnik.
% Unlimited copying and redistribution of this file are permitted if it
% is unmodified.  Modifications (and their redistribution) are also
% permitted, as long as the resulting file is renamed.

@COMMENT(You may put a comment in a `comment' command,
            @comment{boo}
        the way you would with SCRIBE.)

Or you may dispense with the command and simply give the comment,
as long as it's not within an entry.

If you really want to put a comment inside an entry, simply
make up a never-to-be-used field.

@FAKE-ENTRY
        {fake-database-key,
        never-to-be-used-field = "Even if this were a real entry,
                I could still have a comment inside an entry
                by making up a fake field"
        }

@string (SCRIBE-NOTE = {Chapter twelve and appendices E8 through E10 deal
                        with bibliographies})

The next entry shows some of the syntactically legal things that
those with the inclination may use.@

MaNuAl  (scribe,
        TITLE="Scribe Document Production System


                                                        User Manual",
        ORGANIZATION =  {Unilogic,}#" Ltd"# {.
                        },
        ADDRESS = "Pittsburgh",
                                                MONTH
=aPR
        ,YEAR=1984,
        note = scribe-note,
)                               May the inclination not be with you.


@MISC{prime-number-theorem,
   author = "Charles Louis Xavier Joseph de la Vall{\'e}e Poussin",
   note = "A strong form of the prime number theorem, 19th century" }


% This is from Nelson Beebe's bibclean test suite

 @
% this is a comment
 preamble
% this is a comment
 {
% this is a comment
 "anything" #
% this is a comment
 "goes"
% this is a comment
 }

% This next one is similar

 @
% comment
  article
% comment
{cite-key
% comment
,
 %comment
author% comment abutting NAME
  =
% comment ending in CR
"Poussin"
  % comment
  ,
  % comment
    % comment 2
  number
  % comment not abutting NAME
  % more
  =
  % comment
  99
  % comment
}
