Extract shared XLIFF test-document builders to remove ~130 duplicated lines

オープン
#171 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
testing

調査の方向性

L10NSharp.Tests プロジェクトと L10NSharp.Windows.Forms.Tests プロジェクトの LocalizationManagerTestsBase、XLiffLocalizationManagerTests、XliffLocalizationManagerWinforms から始めます。重複している builder メソッドと定数を比較し、その後、両方のプロジェクトのテストスイートを実行します。XLIFF の共有 builder 定義が 1 つになり、不要な abstract factory メンバーがなく、テストの動作が変わらず、両方のプロジェクトが成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.Tests already has a ProjectReference to L10NSharp.Tests, and
    already reaches across it for L10NSharp.Tests.TempFolder.
  • There is no competing XLiffDocument in L10NSharp.Windows.Forms.XLiffUtils (it holds
    only XliffLocalizationManagerWinforms and XliffLocalizedStringCacheWinforms), so both
    classes are already building the same L10NSharp.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.Tests and L10NSharp.Windows.Forms.Tests pass 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].

主要言語
C#
スター
3
フォーク
10
平均マージ
2時間
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sillsdev/l10nsharp のほかの issue

sillsdev/l10nsharp の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。