Skip to content

Commit ef2e59a

Browse files
committed
Handle Bib tests
1 parent 41ec702 commit ef2e59a

File tree

3 files changed

+154
-19
lines changed

3 files changed

+154
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ strum = { version = "0.26", features = ["derive"], optional = true }
3535

3636
[dev-dependencies]
3737
heck = "0.5"
38+
html_parser = "0.7"
3839
serde_json = "1"
3940

4041
[[bin]]

tests/citeproc-pass.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ affix_InterveningEmpty
88
affix_TextNodeWithMacro
99
bugreports_Abnt
1010
bugreports_ArabicLocale
11+
bugreports_AsaSpacing
1112
bugreports_AuthorYear
1213
bugreports_BadCitationUpdate
14+
bugreports_ByBy
1315
bugreports_ChineseCharactersFamilyOnlyPluralLabel
1416
bugreports_ContextualPluralWithMainItemFields
1517
bugreports_EmptyIfMatchNoneFail
18+
bugreports_MatchedAuthorAndDate
1619
bugreports_SectionAndLocator
20+
bugreports_SimpleBib
1721
bugreports_SingletonIfMatchNoneFail
1822
bugreports_TitleCase
23+
bugreports_UndefinedInName2
1924
bugreports_YearSuffixLingers
2025
bugreports_disambiguate
2126
bugreports_effingBug
@@ -40,18 +45,21 @@ condition_NameAndTextVars
4045
condition_NumberIsNumeric
4146
condition_NumeralIsNumeric
4247
condition_NumeralWithTextIsNumeric
48+
condition_RefTypeBranching
4349
condition_SingletonIfMatchNone
4450
condition_TextIsNotNumeric
4551
condition_VariableAll
4652
condition_VariableAny
4753
condition_VariableNone
4854
date_Accessed
55+
date_AccessedCrash
4956
date_DateAD
5057
date_DateNoDateWithTest
5158
date_DisappearingBug
5259
date_EmptyStrings
5360
date_IgnoreNonexistentSort
5461
date_January
62+
date_KeyVariable
5563
date_LiteralFailGracefullyIfNoValue
5664
date_LocalizedDateFormats-af-ZA
5765
date_LocalizedDateFormats-ar-AR
@@ -109,6 +117,7 @@ date_LocalizedTextYearWithAffixes
109117
date_LongMonth
110118
date_MaskNonexistentWithCondition
111119
date_NoDate
120+
decorations_Baseline
112121
decorations_SimpleQuotes
113122
disambiguate_AddNamesSuccess
114123
disambiguate_ByCiteGivennameNoShortFormInitializeWith
@@ -121,21 +130,26 @@ disambiguate_DifferentSpacingInInitials
121130
disambiguate_DisambiguateTrueAndYearSuffixOne
122131
disambiguate_FailWithYearSuffix
123132
disambiguate_FamilyNameOnly
133+
disambiguate_HonorFullnameInBibliography
134+
disambiguate_ImplicitYearSuffixOnceOnly
124135
disambiguate_LastOnlyFailWithByCite
125136
disambiguate_NoTextElementUsesYearSuffixVariable
126137
disambiguate_PrimaryNameWithNonDroppingParticle
138+
disambiguate_ThreeNoAuthorNoTitleEntries
127139
disambiguate_WithOriginalYear
128140
disambiguate_YearCollapseWithInstitution
129141
disambiguate_YearSuffixMacroSameYearExplicit
130142
disambiguate_YearSuffixMacroSameYearImplicit
131143
disambiguate_YearSuffixWithEtAlSubsequent
144+
display_DisplayBlock
132145
flipflop_OrphanQuote
133146
form_TitleShort
134147
form_TitleShortNoLong
135148
form_TitleTestNoLongFalse
136149
fullstyles_APA
137150
group_ShortOutputOnly
138151
group_SuppressValueWithEmptySubgroup
152+
group_SuppressWithEmptyNestedDateNode
139153
integration_CitationSort
140154
integration_CitationSortTwice
141155
label_CompactNamesAfterFullNames
@@ -192,9 +206,12 @@ name_CeltsAndToffsWithHyphens
192206
name_CiteGroupDelimiterWithYearCollapse
193207
name_CollapseRoleLabels
194208
name_Delimiter
209+
name_EditorTranslatorBoth
195210
name_EditorTranslatorSameEmptyTerm
196211
name_EditorTranslatorSameWithTerm
212+
name_EditorTranslatorWithTranslatorOnlyBib
197213
name_EtAlKanji
214+
name_EtAlUseLast
198215
name_FirstInitialFullForm
199216
name_FormattingOfParticles
200217
name_GreekSimple
@@ -206,6 +223,7 @@ name_InstitutionDecoration
206223
name_LabelAfterPlural
207224
name_LabelAfterPluralDecorations
208225
name_LabelFormatBug
226+
name_LiteralWithComma
209227
name_NoNameNode
210228
name_NonDroppingParticleDefault
211229
name_OnlyFamilyname
@@ -215,6 +233,7 @@ name_PeriodAfterInitials
215233
name_QuashOrdinaryVariableRenderedViaSubstitute
216234
name_RomanianTwo
217235
name_SemicolonWithAnd
236+
name_SubsequentAuthorSubstituteMultipleNames
218237
name_SubstituteMacroInheritDecorations
219238
name_SubstituteName
220239
name_SubstituteOnDateGroupSpanFail
@@ -229,48 +248,98 @@ name_WesternTwoAuthors
229248
name_WithNonBreakingSpace
230249
name_namepartAffixesNameAsSortOrder
231250
name_namepartAffixesNameAsSortOrderDemoteNonDroppingParticle
251+
nameattr_AndOnBibliographyInBibliography
232252
nameattr_AndOnBibliographyInCitation
253+
nameattr_AndOnCitationInBibliography
233254
nameattr_AndOnCitationInCitation
255+
nameattr_AndOnNamesInBibliography
234256
nameattr_AndOnNamesInCitation
257+
nameattr_AndOnStyleInBibliography
258+
nameattr_AndOnStyleInCitation
259+
nameattr_DelimiterPrecedesEtAlOnBibliographyInBibliography
235260
nameattr_DelimiterPrecedesEtAlOnBibliographyInCitation
261+
nameattr_DelimiterPrecedesEtAlOnCitationInBibliography
236262
nameattr_DelimiterPrecedesEtAlOnCitationInCitation
263+
nameattr_DelimiterPrecedesEtAlOnNamesInBibliography
237264
nameattr_DelimiterPrecedesEtAlOnNamesInCitation
265+
nameattr_DelimiterPrecedesEtAlOnStyleInBibliography
238266
nameattr_DelimiterPrecedesEtAlOnStyleInCitation
267+
nameattr_DelimiterPrecedesLastOnBibliographyInBibliography
239268
nameattr_DelimiterPrecedesLastOnBibliographyInCitation
269+
nameattr_DelimiterPrecedesLastOnCitationInBibliography
240270
nameattr_DelimiterPrecedesLastOnCitationInCitation
271+
nameattr_DelimiterPrecedesLastOnNamesInBibliography
241272
nameattr_DelimiterPrecedesLastOnNamesInCitation
273+
nameattr_DelimiterPrecedesLastOnStyleInBibliography
242274
nameattr_DelimiterPrecedesLastOnStyleInCitation
275+
nameattr_EtAlMinOnBibliographyInBibliography
243276
nameattr_EtAlMinOnBibliographyInCitation
277+
nameattr_EtAlMinOnCitationInBibliography
244278
nameattr_EtAlMinOnCitationInCitation
279+
nameattr_EtAlMinOnNamesInBibliography
245280
nameattr_EtAlMinOnNamesInCitation
281+
nameattr_EtAlMinOnStyleInBibliography
246282
nameattr_EtAlMinOnStyleInCitation
283+
nameattr_EtAlSubsequentMinOnBibliographyInBibliography
247284
nameattr_EtAlSubsequentMinOnBibliographyInCitation
285+
nameattr_EtAlSubsequentMinOnCitationInBibliography
286+
nameattr_EtAlSubsequentMinOnNamesInBibliography
287+
nameattr_EtAlSubsequentMinOnStyleInBibliography
288+
nameattr_EtAlSubsequentUseFirstOnBibliographyInBibliography
248289
nameattr_EtAlSubsequentUseFirstOnBibliographyInCitation
290+
nameattr_EtAlSubsequentUseFirstOnCitationInBibliography
291+
nameattr_EtAlSubsequentUseFirstOnStyleInBibliography
292+
nameattr_EtAlUseFirstOnBibliographyInBibliography
249293
nameattr_EtAlUseFirstOnBibliographyInCitation
294+
nameattr_EtAlUseFirstOnCitationInBibliography
250295
nameattr_EtAlUseFirstOnCitationInCitation
296+
nameattr_EtAlUseFirstOnNamesInBibliography
251297
nameattr_EtAlUseFirstOnNamesInCitation
298+
nameattr_EtAlUseFirstOnStyleInBibliography
252299
nameattr_EtAlUseFirstOnStyleInCitation
300+
nameattr_InitializeWithOnBibliographyInBibliography
253301
nameattr_InitializeWithOnBibliographyInCitation
302+
nameattr_InitializeWithOnCitationInBibliography
254303
nameattr_InitializeWithOnCitationInCitation
304+
nameattr_InitializeWithOnNamesInBibliography
255305
nameattr_InitializeWithOnNamesInCitation
306+
nameattr_InitializeWithOnStyleInBibliography
256307
nameattr_InitializeWithOnStyleInCitation
308+
nameattr_NameAsSortOrderOnBibliographyInBibliography
257309
nameattr_NameAsSortOrderOnBibliographyInCitation
310+
nameattr_NameAsSortOrderOnCitationInBibliography
258311
nameattr_NameAsSortOrderOnCitationInCitation
312+
nameattr_NameAsSortOrderOnNamesInBibliography
259313
nameattr_NameAsSortOrderOnNamesInCitation
314+
nameattr_NameAsSortOrderOnStyleInBibliography
260315
nameattr_NameAsSortOrderOnStyleInCitation
316+
nameattr_NameDelimiterOnBibliographyInBibliography
261317
nameattr_NameDelimiterOnBibliographyInCitation
318+
nameattr_NameDelimiterOnCitationInBibliography
262319
nameattr_NameDelimiterOnCitationInCitation
320+
nameattr_NameDelimiterOnNamesInBibliography
263321
nameattr_NameDelimiterOnNamesInCitation
322+
nameattr_NameDelimiterOnStyleInBibliography
264323
nameattr_NameDelimiterOnStyleInCitation
324+
nameattr_NameFormOnBibliographyInBibliography
265325
nameattr_NameFormOnBibliographyInCitation
326+
nameattr_NameFormOnCitationInBibliography
266327
nameattr_NameFormOnCitationInCitation
328+
nameattr_NameFormOnNamesInBibliography
267329
nameattr_NameFormOnNamesInCitation
330+
nameattr_NameFormOnStyleInBibliography
268331
nameattr_NameFormOnStyleInCitation
269332
nameattr_NamesDelimiterOnBibliographyInCitation
333+
nameattr_NamesDelimiterOnCitationInBibliography
334+
nameattr_NamesDelimiterOnNamesInBibliography
270335
nameattr_NamesDelimiterOnNamesInCitation
336+
nameattr_SortSeparatorOnBibliographyInBibliography
271337
nameattr_SortSeparatorOnBibliographyInCitation
338+
nameattr_SortSeparatorOnCitationInBibliography
272339
nameattr_SortSeparatorOnCitationInCitation
340+
nameattr_SortSeparatorOnNamesInBibliography
273341
nameattr_SortSeparatorOnNamesInCitation
342+
nameattr_SortSeparatorOnStyleInBibliography
274343
nameattr_SortSeparatorOnStyleInCitation
275344
nameorder_Long
276345
nameorder_LongNameAsSortDemoteDisplayAndSort
@@ -279,6 +348,7 @@ nameorder_Short
279348
nameorder_ShortDemoteDisplayAndSort
280349
nameorder_ShortNameAsSortDemoteNever
281350
namespaces_NonNada3
351+
number_FailingDelimiters
282352
number_IsNumericWithAlpha
283353
number_MixedPageRange
284354
number_PageFirst
@@ -294,22 +364,38 @@ page_NumberPageFirst
294364
page_PluralDetectWithEndash
295365
page_WithLocaleAndWeirdDelimiter
296366
plural_LabelForced
367+
position_IbidWithSuffix
297368
position_NearNoteUnsupported
298369
position_TrueInCitation
299370
punctuation_DateStripPeriods
371+
punctuation_DelimiterWithStripPeriodsAndSubstitute1
372+
punctuation_DelimiterWithStripPeriodsAndSubstitute2
373+
punctuation_DelimiterWithStripPeriodsAndSubstitute3
300374
punctuation_DoNotSuppressColonAfterPeriod
301375
punctuation_NoSuppressOfPeriodBeforeSemicolon
376+
quotes_Punctuation
377+
sort_BibliographyResortOnUpdate
378+
sort_CaseInsensitiveBibliography
302379
sort_CaseInsensitiveCitation
303380
sort_Citation
381+
sort_CitationNumberPrimaryAscendingViaMacroBibliography
382+
sort_CitationNumberPrimaryAscendingViaVariableBibliography
304383
sort_CitationSecondaryKey
305384
sort_CiteGroupDelimiter
385+
sort_DaleDalebout
306386
sort_DateVariable
307387
sort_DateVariableMixedElementsAscendingA
308388
sort_DateVariableMixedElementsAscendingB
309389
sort_DateVariableMixedElementsDescendingA
310390
sort_DateVariableMixedElementsDescendingB
391+
sort_EtAlUseLast
392+
sort_FamilyOnly
311393
sort_LatinUnicode
312394
sort_LocalizedDateLimitedParts
395+
sort_NameParticleInNameSortFalse
396+
sort_NameParticleInNameSortTrue
397+
sort_NamesUseLast
398+
sort_StatusFieldDescending
313399
sort_TestInheritance
314400
sortseparator_SortSeparatorEmpty
315401
substitute_RepeatedNamesOk

tests/citeproc.rs

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use hayagriva::{
1717
BibliographyDriver, BibliographyRequest, CitationItem, CitationRequest, CitePurpose,
1818
Entry, LocatorPayload, SpecificLocator,
1919
};
20+
use html_parser::{Dom, Element, Node};
2021
use unscanny::Scanner;
2122

2223
const TEST_REPO_NAME: &str = "test-suite";
@@ -270,14 +271,20 @@ impl<'s> TestCaseBuilder<'s> {
270271
}
271272

272273
fn finish(self) -> Result<TestCase, TestParseError> {
274+
let mode = self
275+
.mode
276+
.ok_or(TestParseError::MissingRequiredSection(SectionTag::Mode))?;
277+
let result = self
278+
.result
279+
.ok_or(TestParseError::MissingRequiredSection(SectionTag::Result))?
280+
.replace("&#38;", "&");
273281
Ok(TestCase {
274-
mode: self
275-
.mode
276-
.ok_or(TestParseError::MissingRequiredSection(SectionTag::Mode))?,
277-
result: self
278-
.result
279-
.ok_or(TestParseError::MissingRequiredSection(SectionTag::Result))?
280-
.replace("&#38;", "&"),
282+
mode,
283+
result: if mode == TestMode::Bibliography && result.starts_with("<div") {
284+
extract_from_html(&result)
285+
} else {
286+
result
287+
},
281288
csl: Style::from_xml(
282289
self.csl
283290
.ok_or(TestParseError::MissingRequiredSection(SectionTag::Csl))?,
@@ -303,6 +310,37 @@ impl<'s> TestCaseBuilder<'s> {
303310
}
304311
}
305312

313+
fn extract_from_html(html: &str) -> String {
314+
let mut res = String::new();
315+
let dom = Dom::parse(html).expect("Could not parse HTML");
316+
assert_eq!(1, dom.children.len());
317+
let node = &dom.children[0];
318+
let mut item = String::new();
319+
for child in node.into_iter() {
320+
match child {
321+
Node::Element(Element { name, classes, .. })
322+
if name == "div"
323+
&& classes.get(0).map(|c| c == "csl-entry").unwrap_or(false) =>
324+
{
325+
if !item.is_empty() {
326+
res.push_str(&item);
327+
res.push('\n');
328+
item = String::new();
329+
}
330+
}
331+
Node::Text(s) => item.push_str(s),
332+
_ => {}
333+
}
334+
}
335+
336+
if !item.is_empty() {
337+
res.push_str(&item);
338+
item = String::new();
339+
}
340+
341+
res
342+
}
343+
306344
#[test]
307345
fn test_parse_tests() {
308346
let mut results = TestSuiteResults::obtain();
@@ -489,12 +527,7 @@ where
489527
.map_or(false, |d| d.end.is_some())
490528
});
491529

492-
if case.mode == TestMode::Bibliography {
493-
if print {
494-
eprintln!("Skipping test {}\t(cause: Bibliography mode)", display());
495-
}
496-
false
497-
} else if !can_test {
530+
if !can_test {
498531
if print {
499532
eprintln!("Skipping test {}\t(cause: unsupported test feature)", display());
500533
}
@@ -577,12 +610,27 @@ where
577610

578611
let rendered = driver.finish(BibliographyRequest::new(&style, None, locales));
579612

580-
for citation in rendered.citations {
581-
citation
582-
.citation
583-
.write_buf(&mut output, hayagriva::BufWriteFormat::Plain)
584-
.unwrap();
585-
output.push('\n');
613+
match case.mode {
614+
TestMode::Citation => {
615+
for citation in rendered.citations {
616+
citation
617+
.citation
618+
.write_buf(&mut output, hayagriva::BufWriteFormat::Plain)
619+
.unwrap();
620+
output.push('\n');
621+
}
622+
}
623+
TestMode::Bibliography => {
624+
let bib = rendered
625+
.bibliography
626+
.expect("Bibliography mode test but no bibliography was rendered");
627+
for item in bib.items {
628+
item.content
629+
.write_buf(&mut output, hayagriva::BufWriteFormat::Plain)
630+
.unwrap();
631+
output.push('\n');
632+
}
633+
}
586634
}
587635

588636
if output.trim() == case.result.trim() {

0 commit comments

Comments
 (0)