Skip to content

Commit

Permalink
Support bibliography citeproc tests (#273)
Browse files Browse the repository at this point in the history
* initial bib test support

* Fix bib layout affixes

* remove tests which aren't passing yet

(TODO: bugreports_parenthesis should work... is citeproc trimming
things?)

* add missing passing test with affixes fix

* move regex to a dev dependency

* format

* clippy

* fix second-field-align

* do not output anchor elements for links

* adjust comments

* adjust missing test

* use 'apply_(affix)' for bibliography layout affixes

---------

Co-authored-by: DerDrodt <[email protected]>
  • Loading branch information
PgBiel and DerDrodt authored Feb 5, 2025
1 parent ebfc510 commit 1058be7
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ strum = { version = "0.26", features = ["derive"], optional = true }
[dev-dependencies]
heck = "0.5"
serde_json = "1"
regex = "1"

[[bin]]
name = "hayagriva"
Expand Down
11 changes: 9 additions & 2 deletions src/csl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use citationberg::{
taxonomy as csl_taxonomy, Affixes, BaseLanguage, Citation, CitationFormat, Collapse,
CslMacro, Display, GrammarGender, IndependentStyle, InheritableNameOptions, Layout,
LayoutRenderingElement, Locale, LocaleCode, Names, SecondFieldAlign, StyleCategory,
StyleClass, TermForm, ToFormatting,
StyleClass, TermForm, ToAffixes, ToFormatting,
};
use citationberg::{DateForm, LongShortForm, OrdinalLookup, TextCase};
use indexmap::IndexSet;
Expand Down Expand Up @@ -1386,7 +1386,14 @@ impl<'a> StyleContext<'a> {
let mut ctx = self.ctx(entry, props, locale, term_locale, true);
ctx.writing
.push_name_options(&self.csl.bibliography.as_ref()?.name_options);
self.csl.bibliography.as_ref()?.layout.render(&mut ctx);

let layout = &self.csl.bibliography.as_ref()?.layout;
let affixes = layout.to_affixes();

let affix_loc = ctx.apply_prefix(&affixes);
layout.render(&mut ctx);
ctx.apply_suffix(&affixes, affix_loc);

Some(ctx)
}

Expand Down
98 changes: 98 additions & 0 deletions tests/citeproc-pass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ affix_InterveningEmpty
affix_TextNodeWithMacro
bugreports_Abnt
bugreports_ArabicLocale
bugreports_AsaSpacing
bugreports_AuthorYear
bugreports_BadCitationUpdate
bugreports_ChineseCharactersFamilyOnlyPluralLabel
bugreports_ContextualPluralWithMainItemFields
bugreports_DisambiguationAddNamesBibliography
bugreports_EmptyIfMatchNoneFail
bugreports_MatchedAuthorAndDate
bugreports_NoEventInNestedMacroWithOldProcessor
bugreports_SectionAndLocator
bugreports_SimpleBib
bugreports_SingletonIfMatchNoneFail
bugreports_SortSecondaryKeyBibliography
bugreports_StyleError001
bugreports_TitleCase
bugreports_UndefinedInName2
bugreports_UndefinedNotString
bugreports_UndefinedStr
bugreports_UnisaHarvardInitialization
bugreports_YearSuffixLingers
bugreports_disambiguate
bugreports_effingBug
Expand All @@ -26,6 +37,7 @@ collapse_AuthorCollapseNoDate
collapse_CitationNumberRangesMixed
collapse_CitationNumberRangesMixed2
collapse_CitationNumberRangesMixed3
collapse_CitationNumberRangesOneOnly
collapse_NumericDuplicate
collapse_NumericDuplicate2
collapse_TrailingDelimiter
Expand All @@ -40,18 +52,21 @@ condition_NameAndTextVars
condition_NumberIsNumeric
condition_NumeralIsNumeric
condition_NumeralWithTextIsNumeric
condition_RefTypeBranching
condition_SingletonIfMatchNone
condition_TextIsNotNumeric
condition_VariableAll
condition_VariableAny
condition_VariableNone
date_Accessed
date_AccessedCrash
date_DateAD
date_DateNoDateWithTest
date_DisappearingBug
date_EmptyStrings
date_IgnoreNonexistentSort
date_January
date_KeyVariable
date_LiteralFailGracefullyIfNoValue
date_LocalizedDateFormats-af-ZA
date_LocalizedDateFormats-ar-AR
Expand Down Expand Up @@ -121,21 +136,29 @@ disambiguate_DifferentSpacingInInitials
disambiguate_DisambiguateTrueAndYearSuffixOne
disambiguate_FailWithYearSuffix
disambiguate_FamilyNameOnly
disambiguate_HonorFullnameInBibliography
disambiguate_ImplicitYearSuffixOnceOnly
disambiguate_LastOnlyFailWithByCite
disambiguate_NoTextElementUsesYearSuffixVariable
disambiguate_PrimaryNameWithNonDroppingParticle
disambiguate_ThreeNoAuthorNoTitleEntries
disambiguate_WithOriginalYear
disambiguate_YearCollapseWithInstitution
disambiguate_YearSuffixMacroSameYearExplicit
disambiguate_YearSuffixMacroSameYearImplicit
disambiguate_YearSuffixWithEtAlSubsequent
display_DisplayBlock
etal_CitationAndBibliographyDecorationsInBibliography
flipflop_OrphanQuote
form_TitleShort
form_TitleShortNoLong
form_TitleTestNoLongFalse
fullstyles_ABdNT
fullstyles_APA
fullstyles_ChicagoNoteWithBibliographyWithPublisher
group_ShortOutputOnly
group_SuppressValueWithEmptySubgroup
group_SuppressWithEmptyNestedDateNode
integration_CitationSort
integration_CitationSortTwice
label_CompactNamesAfterFullNames
Expand Down Expand Up @@ -193,9 +216,12 @@ name_CeltsAndToffsWithHyphens
name_CiteGroupDelimiterWithYearCollapse
name_CollapseRoleLabels
name_Delimiter
name_EditorTranslatorBoth
name_EditorTranslatorSameEmptyTerm
name_EditorTranslatorSameWithTerm
name_EditorTranslatorWithTranslatorOnlyBib
name_EtAlKanji
name_EtAlUseLast
name_FirstInitialFullForm
name_FormattingOfParticles
name_GreekSimple
Expand All @@ -207,6 +233,7 @@ name_InstitutionDecoration
name_LabelAfterPlural
name_LabelAfterPluralDecorations
name_LabelFormatBug
name_LiteralWithComma
name_MultipleLiteral
name_NoNameNode
name_NonDroppingParticleDefault
Expand All @@ -231,48 +258,98 @@ name_WesternTwoAuthors
name_WithNonBreakingSpace
name_namepartAffixesNameAsSortOrder
name_namepartAffixesNameAsSortOrderDemoteNonDroppingParticle
nameattr_AndOnBibliographyInBibliography
nameattr_AndOnBibliographyInCitation
nameattr_AndOnCitationInBibliography
nameattr_AndOnCitationInCitation
nameattr_AndOnNamesInBibliography
nameattr_AndOnNamesInCitation
nameattr_AndOnStyleInBibliography
nameattr_AndOnStyleInCitation
nameattr_DelimiterPrecedesEtAlOnBibliographyInBibliography
nameattr_DelimiterPrecedesEtAlOnBibliographyInCitation
nameattr_DelimiterPrecedesEtAlOnCitationInBibliography
nameattr_DelimiterPrecedesEtAlOnCitationInCitation
nameattr_DelimiterPrecedesEtAlOnNamesInBibliography
nameattr_DelimiterPrecedesEtAlOnNamesInCitation
nameattr_DelimiterPrecedesEtAlOnStyleInBibliography
nameattr_DelimiterPrecedesEtAlOnStyleInCitation
nameattr_DelimiterPrecedesLastOnBibliographyInBibliography
nameattr_DelimiterPrecedesLastOnBibliographyInCitation
nameattr_DelimiterPrecedesLastOnCitationInBibliography
nameattr_DelimiterPrecedesLastOnCitationInCitation
nameattr_DelimiterPrecedesLastOnNamesInBibliography
nameattr_DelimiterPrecedesLastOnNamesInCitation
nameattr_DelimiterPrecedesLastOnStyleInBibliography
nameattr_DelimiterPrecedesLastOnStyleInCitation
nameattr_EtAlMinOnBibliographyInBibliography
nameattr_EtAlMinOnBibliographyInCitation
nameattr_EtAlMinOnCitationInBibliography
nameattr_EtAlMinOnCitationInCitation
nameattr_EtAlMinOnNamesInBibliography
nameattr_EtAlMinOnNamesInCitation
nameattr_EtAlMinOnStyleInBibliography
nameattr_EtAlMinOnStyleInCitation
nameattr_EtAlSubsequentMinOnBibliographyInBibliography
nameattr_EtAlSubsequentMinOnBibliographyInCitation
nameattr_EtAlSubsequentMinOnCitationInBibliography
nameattr_EtAlSubsequentMinOnNamesInBibliography
nameattr_EtAlSubsequentMinOnStyleInBibliography
nameattr_EtAlSubsequentUseFirstOnBibliographyInBibliography
nameattr_EtAlSubsequentUseFirstOnBibliographyInCitation
nameattr_EtAlSubsequentUseFirstOnCitationInBibliography
nameattr_EtAlSubsequentUseFirstOnStyleInBibliography
nameattr_EtAlUseFirstOnBibliographyInBibliography
nameattr_EtAlUseFirstOnBibliographyInCitation
nameattr_EtAlUseFirstOnCitationInBibliography
nameattr_EtAlUseFirstOnCitationInCitation
nameattr_EtAlUseFirstOnNamesInBibliography
nameattr_EtAlUseFirstOnNamesInCitation
nameattr_EtAlUseFirstOnStyleInBibliography
nameattr_EtAlUseFirstOnStyleInCitation
nameattr_InitializeWithOnBibliographyInBibliography
nameattr_InitializeWithOnBibliographyInCitation
nameattr_InitializeWithOnCitationInBibliography
nameattr_InitializeWithOnCitationInCitation
nameattr_InitializeWithOnNamesInBibliography
nameattr_InitializeWithOnNamesInCitation
nameattr_InitializeWithOnStyleInBibliography
nameattr_InitializeWithOnStyleInCitation
nameattr_NameAsSortOrderOnBibliographyInBibliography
nameattr_NameAsSortOrderOnBibliographyInCitation
nameattr_NameAsSortOrderOnCitationInBibliography
nameattr_NameAsSortOrderOnCitationInCitation
nameattr_NameAsSortOrderOnNamesInBibliography
nameattr_NameAsSortOrderOnNamesInCitation
nameattr_NameAsSortOrderOnStyleInBibliography
nameattr_NameAsSortOrderOnStyleInCitation
nameattr_NameDelimiterOnBibliographyInBibliography
nameattr_NameDelimiterOnBibliographyInCitation
nameattr_NameDelimiterOnCitationInBibliography
nameattr_NameDelimiterOnCitationInCitation
nameattr_NameDelimiterOnNamesInBibliography
nameattr_NameDelimiterOnNamesInCitation
nameattr_NameDelimiterOnStyleInBibliography
nameattr_NameDelimiterOnStyleInCitation
nameattr_NameFormOnBibliographyInBibliography
nameattr_NameFormOnBibliographyInCitation
nameattr_NameFormOnCitationInBibliography
nameattr_NameFormOnCitationInCitation
nameattr_NameFormOnNamesInBibliography
nameattr_NameFormOnNamesInCitation
nameattr_NameFormOnStyleInBibliography
nameattr_NameFormOnStyleInCitation
nameattr_NamesDelimiterOnBibliographyInCitation
nameattr_NamesDelimiterOnCitationInBibliography
nameattr_NamesDelimiterOnNamesInBibliography
nameattr_NamesDelimiterOnNamesInCitation
nameattr_SortSeparatorOnBibliographyInBibliography
nameattr_SortSeparatorOnBibliographyInCitation
nameattr_SortSeparatorOnCitationInBibliography
nameattr_SortSeparatorOnCitationInCitation
nameattr_SortSeparatorOnNamesInBibliography
nameattr_SortSeparatorOnNamesInCitation
nameattr_SortSeparatorOnStyleInBibliography
nameattr_SortSeparatorOnStyleInCitation
nameorder_Long
nameorder_LongNameAsSortDemoteDisplayAndSort
Expand All @@ -281,6 +358,7 @@ nameorder_Short
nameorder_ShortDemoteDisplayAndSort
nameorder_ShortNameAsSortDemoteNever
namespaces_NonNada3
number_FailingDelimiters
number_IsNumericWithAlpha
number_MixedPageRange
number_PageFirst
Expand All @@ -296,28 +374,48 @@ page_NumberPageFirst
page_PluralDetectWithEndash
page_WithLocaleAndWeirdDelimiter
plural_LabelForced
position_IbidWithSuffix
position_NearNoteUnsupported
position_TrueInCitation
punctuation_DateStripPeriods
punctuation_DelimiterWithStripPeriodsAndSubstitute1
punctuation_DelimiterWithStripPeriodsAndSubstitute2
punctuation_DelimiterWithStripPeriodsAndSubstitute3
punctuation_DoNotSuppressColonAfterPeriod
punctuation_NoSuppressOfPeriodBeforeSemicolon
punctuation_SemicolonDelimiter
quotes_Punctuation
quotes_PunctuationNasty
sort_BibliographyResortOnUpdate
sort_CaseInsensitiveBibliography
sort_CaseInsensitiveCitation
sort_Citation
sort_CitationNumberPrimaryAscendingViaMacroBibliography
sort_CitationNumberPrimaryAscendingViaVariableBibliography
sort_CitationSecondaryKey
sort_CiteGroupDelimiter
sort_DaleDalebout
sort_DateMacroSortWithSecondFieldAlign
sort_DateVariable
sort_DateVariableMixedElementsAscendingA
sort_DateVariableMixedElementsAscendingB
sort_DateVariableMixedElementsDescendingA
sort_DateVariableMixedElementsDescendingB
sort_EtAlUseLast
sort_FamilyOnly
sort_LatinUnicode
sort_LocalizedDateLimitedParts
sort_NameParticleInNameSortFalse
sort_NameParticleInNameSortTrue
sort_NamesUseLast
sort_StatusFieldDescending
sort_TestInheritance
sortseparator_SortSeparatorEmpty
substitute_RepeatedNamesOk
substitute_SubstituteOnlyOnceString
substitute_SubstituteOnlyOnceTerm
substitute_SubstituteOnlyOnceVariable
substitute_SuppressOrdinaryVariable
textcase_AfterQuote
textcase_CapitalsUntouched
textcase_StopWordBeforeHyphen
Expand Down
Loading

0 comments on commit 1058be7

Please sign in to comment.