Extract shared XLIFF test-document builders to remove ~130 duplicated lines
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
Direzione di ricerca
Inizia con LocalizationManagerTestsBase, XLiffLocalizationManagerTests e XliffLocalizationManagerWinforms nei progetti L10NSharp.Tests e L10NSharp.Windows.Forms.Tests. Confronta i metodi builder e le costanti duplicati, quindi esegui le suite di test di entrambi i progetti. Il lavoro è completato quando esiste un’unica definizione condivisa del builder XLIFF, non sono presenti membri non necessari della factory astratta, il comportamento dei test è invariato ed entrambi i progetti superano i test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Background
Raised by @tombogle while reviewing #147. That PR only adds tests, so the extraction was
deferred to keep it focused. The duplication itself predates #147.
Problem
L10NSharp.Windows.Forms.Tests.XliffLocalizationManagerTests is a standalone class rather
than a subclass of LocalizationManagerTestsBase<T>, because it needs
LocalizationManagerWinforms / XliffLocalizationManagerWinforms and WinForms-only hooks
such as ChooseFallbackLanguageWinforms, which the generic base knows nothing about. That
is a legitimate reason for a separate class — but it does not require duplicating the
document-building helpers, and today it does:
| Method | Lines | Duplicated verbatim? |
|---|---|---|
CreateNewDocument |
14 | body identical; signature differs only in formatting |
CreateTransUnit |
23 | body identical; signature differs only in formatting |
CreateTransUnitVariant |
4 | body identical |
AddEnglishTranslation |
20 | byte-for-byte identical |
AddChineseOfChinaTranslation |
22 | byte-for-byte identical |
AddChineseOfTaiwanTranslation |
22 | byte-for-byte identical |
AddChineseBareTranslation |
22 | byte-for-byte identical |
That is 126 lines, plus the six duplicated const fields (AppId, AppName,
AppVersion, HigherVersion, LowerVersion, LiteralNewline). The practical cost is that
test data has two sources of truth: adding a language variant (as #147 did with
AddChineseBareTranslation) means pasting the same 22 lines into both projects, and the two
copies can silently drift.
Proposal
Extract the builders into a shared static class in L10NSharp.Tests, e.g.
XLiffTestDocumentBuilder, taking folderPath and appId as parameters instead of reading
instance state. Have both
L10NSharp.Tests.XLiffLocalizationManagerTests (via LocalizationManagerTestsBase<T>) and
L10NSharp.Windows.Forms.Tests.XliffLocalizationManagerTests call into it.
This is mechanically feasible today:
L10NSharp.Windows.Forms.Testsalready has aProjectReferencetoL10NSharp.Tests, and
already reaches across it forL10NSharp.Tests.TempFolder.- There is no competing
XLiffDocumentinL10NSharp.Windows.Forms.XLiffUtils(it holds
onlyXliffLocalizationManagerWinformsandXliffLocalizedStringCacheWinforms), so both
classes are already building the sameL10NSharp.XLiffUtils.XLiffDocument.
Also worth folding in
LocalizationManagerTestsBase<T> has exactly one subclass, XLiffLocalizationManagerTests.
The protected abstract CreateNewDocument / CreateTransUnit / CreateTransUnitVariant
indirection therefore has no second implementation to abstract over — the generic T plus
abstract-factory machinery is currently paying for flexibility nothing uses. Routing both
classes through a concrete XLIFF builder removes those three abstract members and leaves less
machinery than there is now, not more.
If a non-XLIFF document format is added later, reintroducing the abstraction against two real
implementations will be easier than guessing at it from one.
Out of scope
The base class's AddArabicTranslation / AddFrenchTranslation / AddSpanishTranslation /
AddRandomTranslation are not duplicated and can move or stay as convenient.
Acceptance
- One definition of each XLIFF test-document builder.
L10NSharp.TestsandL10NSharp.Windows.Forms.Testspass with no change in test behaviour.- Adding a new language variant requires editing one place.
Drafted with Claude Code, model Claude Opus 5 (1M context) / claude-opus-5[1m].
- Lingua principale
- C#
- Stelle
- 3
- Fork
- 10
- Merge medio
- 2h
- PR unite (30g)
- 2
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sillsdev/l10nsharp
-
api change bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Update .NET target from net8.0 to net10.0Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertaenhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
Tutte le issue di sillsdev/l10nsharp
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
QuantConnect/Documentation#2838 ·
I maintainer di solito rispondono entro 1 giorno
-
"Create your app": .sln/.slnx step and Solution Explorer instructions don't match current C# Dev KitApertaarea-tutorials needs-triage
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
dotnet/website-feedback#1844 ·
-
Needs: Attention :wave: v5 v5-preview5
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Azure/azure-functions-core-tools#5852 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
OrchardCMS/OrchardCore#20194 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
Gothic-Unity-Project/Gothic-Unity#487 ·
I maintainer di solito rispondono entro 1 giorno