#import "/src/core/authors.typ"

#set page(height: 1cm, width: 1cm)

//
// parsing
//
#import authors: parse-title, parse-name, parse-author

// title
#let prof = (
  main: "Prof.",
  suffix: none,
)
#let dr = (
  rer-nat: (
    main: "Dr.",
    suffix: "rer. nat.",
  ),
  sc-nat: (
    main: "Dr.",
    suffix: "sc. nat.",
  ),
)
#assert.eq(parse-title("Prof."), prof)
#assert.eq(parse-title("Dr. rer. nat."), dr.rer-nat)
#assert.eq(parse-title("Dr. sc. nat."), dr.sc-nat)

// single name
#assert.eq(parse-name("Frank"), (first: ("Frank",), last: ()))

// first and last
#let turing = (
  first: ("Alan",),
  last: ("Turing",),
)
#assert.eq(parse-name("<NAME>"), turing)
#assert.eq(parse-name("<NAME>"), turing)

// first, second and last single
#let dumbledore = (
  first: ("Albus", "Percival", "Wulfric", "Brian"),
  last: ("Dumbledore",),
)
#assert.eq(parse-name("<NAME> <NAME>"), dumbledore)
#assert.eq(parse-name("Dumbledore, <NAME>"), dumbledore)

// last mutliple
#let scott-moncrieff = (
  first: ("Charles", "Kenneth"),
  last: ("Scott", "Moncrieff"),
)
#let lloyd-webber = (
  first: ("Andrew",),
  last: ("Lloyd", "Webber",),
)
#assert.eq(parse-name("<NAME>, <NAME>"), scott-moncrieff)
#assert.eq(parse-name("<NAME>, Andrew"), lloyd-webber)

// abbreviations
#let knuth = (
  first: ("Donald", "E."),
  last: ("Knuth",),
)
#assert.eq(parse-name("<NAME>"), knuth)
#assert.eq(parse-name("<NAME>."), knuth)

// author
#let tingerrr = (
  titles: (
    (
      main: "B.",
      suffix: "Sc.",
    ),
  ),
  name: (
    first: ("tingerrr",),
    last: (),
  ),
  email: "<EMAIL>",
)
#assert.eq(parse-author("B. Sc. tingerrr <<EMAIL>>"), tingerrr)

#let kpj = (
  titles: (
    (main: "Prof.", suffix: none),
    (main: "Dr.", suffix: "rer. nat."),
    (main: "Dr.", suffix: "sc. nat."),
  ),
  name: (
    first: ("Klaus", "Peter"),
    last: ("Jantke",),
  ),
  email: none,
)
#assert.eq(parse-author("B. Sc. tingerrr <<EMAIL>>"), tingerrr)
#assert.eq(parse-author("Prof. Dr. rer. nat. Dr. sc. nat. <NAME>"), kpj)

//
// formatting
//
#import authors: format-title, format-name, format-author

// title
#assert.eq(format-title(prof), "Prof.")
#assert.eq(format-title(dr.rer-nat), "Dr. rer. nat.")
#assert.eq(format-title(dr.sc-nat), "Dr. sc. nat.")

// name
#assert.eq(format-name(turing), "<NAME>")
#assert.eq(format-name(knuth), "<NAME>")

// comma format
#assert.eq(format-name(dumbledore, last-first: true), "Dumbledore, <NAME>")

// name abbreviation
#assert.eq(format-name(scott-moncrieff, abbreviate: true), "<NAME>")
#assert.eq(format-name(knuth, abbreviate: true), "<NAME>")

// author
#assert.eq(format-author(tingerrr, link: false), "<NAME> <<EMAIL>>")
#assert.eq(format-author(kpj, link: false), "Prof. Dr. rer. nat. Dr. sc. nat. <NAME>")
