Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

name_ParticlesDemoteNonDroppingNever depends on non-spec formatting #69

Open
Jason-Abbott opened this issue Jul 10, 2023 · 0 comments
Open

Comments

@Jason-Abbott
Copy link
Contributor

Jason-Abbott commented Jul 10, 2023

I don’t think I need help on this one but wanted to note this test likely needs to be re-written so it doesn’t depend on formatting that could legitimately vary between processors.

I added this description to the test in PR #68 :

This test depends on the particular way citeproc-js applies formatting to names and so may not pass
for other CSL processors that nonetheless parse name particles correctly.

Specifically, it expects bold and italic pseudo-HTML to be applied separately to name particles
before they are appended to the given or family name. For example, with a main family name of
"George", this test would expect

<b>St. George</b>
<b>de</b> <b>George</b>

identifying "de" as a non-dropping particle and "St." as part of the family name, not a particle.

From a formatting perspective, however, these are the same

<b>de George</b>
<b>de</b> <b>George</b>

and so CSL processors may reasonably prefer the former, causing this test to fail incorrectly.

This kind of verification may be better suited to unit rather than integration testing. To that end, here, for reference, is the internal test I wrote to perform the same checks:

func testParticleDecode() throws {
    let json = JSONDecoder()
    let input: [(
        name: (given: String?, family: String?),
        expect: (given: String?, dropping: String?, nonDropping: String?, family: String?)
    )] = [
        (("Hui-Xiao Li Yuan", "Liu"), ("Hui-Xiao Li Yuan", nil, nil, "Liu")),
        (("Vincent", "van Gogh"), ("Vincent", nil, "van", "Gogh")),
        (("Tawfiq", "al-Hakim"), ("Tawfiq", nil, "al-", "Hakim")),
        (("Jean", "de La Fontaine"), ("Jean", nil, "de", "La Fontaine")),
        (("Eric", "van der Vlist"), ("Eric", nil, "van der", "Vlist")),
        // sort_LeadingApostropheOnNameParticle.txt
        (("Peter A.D.", "in 't Horvath"), ("Peter A.D.", nil, "in 't", "Horvath")),
        (("Bevis", "de' Frinkle"), ("Bevis", nil, "de'", "Frinkle")),
        (("William", "d'Wander"), ("William", nil, "d'", "Wander")),
        // name_ParticlesDemoteNonDroppingNever.txt
        (("Givenname al", "Familyname"), ("Givenname", "al", nil, "Familyname")),
        (("Givenname de", "Las Familyname"), ("Givenname", "de", nil, "Las Familyname")),
        (("Givenname", "de Familyname"), ("Givenname", nil, "de", "Familyname")),
        (("Givenname", "v.d. Familyname"), ("Givenname", nil, "v.d.", "Familyname")),
        (("Givenname", "van het Familyname"), ("Givenname", nil, "van het", "Familyname")),
        (("Givenname", "in 't Familyname"), ("Givenname", nil, "in 't", "Familyname")),
        (("Givenname", "'t Familyname"), ("Givenname", nil, "'t", "Familyname")),
        (("Givenname von", "Familyname"), ("Givenname", "von", nil, "Familyname")),
        (("Givenname", "v. Familyname"), ("Givenname", nil, "v.", "Familyname")),
    ]

    for (name, expect) in input {
        var parts: [String] = []
        if let given = name.given { parts.append("\"given\": \"\(given)\"") }
        if let family = name.family { parts.append("\"family\": \"\(family)\"") }
        let raw = "{ \(parts.joined(separator: ", ")) }"
        let parsed = try json.decode(ContributorName.self, from: raw.data(using: .utf8)!)

        XCTAssertEqual(parsed.given, expect.given)
        XCTAssertEqual(parsed.family, expect.family)
        XCTAssertEqual(parsed.droppingParticle, expect.dropping)
        XCTAssertEqual(parsed.nonDroppingParticle, expect.nonDropping)
    }
}

I will try to rewrite the test in the suite myself after my current processor work reaches MVP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant