Wikipedia翻訳支援ツール
Revision | 95313085e3f40544cd47c75296fc3c49c1c5b04f (tree) |
---|---|
Time | 2016-10-28 00:02:30 |
Author | ![]() |
Commiter | honeplus |
結果ファイルのユニットテストで改行コードの一致をみないよう変更, StyleCopの警告対処
@@ -233,7 +233,7 @@ namespace Honememo.Parsers | ||
233 | 233 | /// <remarks>性能対策などで<see cref="TryParse"/>を呼ぶ前に目処を付けたい場合用。</remarks> |
234 | 234 | public override bool IsPossibleParse(char c) |
235 | 235 | { |
236 | - return '<' == c; | |
236 | + return c == '<'; | |
237 | 237 | } |
238 | 238 | |
239 | 239 | #endregion |
@@ -635,13 +635,13 @@ namespace Honememo.Wptscs.Logics | ||
635 | 635 | |
636 | 636 | // テストデータの変換結果を期待される結果と比較する |
637 | 637 | // バージョン表記部分は毎回変化するため、期待される結果のうち該当部分を更新する |
638 | - Assert.AreEqual( | |
638 | + AssertEqualTextPerLines( | |
639 | 639 | File.ReadAllText(Path.Combine(ResultDir, "example_定型句なし.txt")).Replace("<!-- Wikipedia 翻訳支援ツール Ver0.xx", "<!-- " + FormUtils.ApplicationName()), |
640 | 640 | translator.Text); |
641 | 641 | |
642 | 642 | // テストデータの変換ログを期待されるログと比較する |
643 | 643 | // 1行目のパスが一致しないので、期待される結果のうち該当部分を更新する |
644 | - Assert.AreEqual( | |
644 | + AssertEqualTextPerLines( | |
645 | 645 | File.ReadAllText(Path.Combine(ResultDir, "example_定型句なし.log")).Replace("file:///xxx/Data/MediaWiki/en/", from.Location), |
646 | 646 | translator.Log); |
647 | 647 | } |
@@ -673,13 +673,13 @@ namespace Honememo.Wptscs.Logics | ||
673 | 673 | |
674 | 674 | // テストデータの変換結果を期待される結果と比較する |
675 | 675 | // バージョン表記部分は毎回変化するため、期待される結果のうち該当部分を更新する |
676 | - Assert.AreEqual( | |
676 | + AssertEqualTextPerLines( | |
677 | 677 | File.ReadAllText(Path.Combine(ResultDir, "example.txt")).Replace("<!-- Wikipedia 翻訳支援ツール Ver0.73", "<!-- " + FormUtils.ApplicationName()), |
678 | 678 | translator.Text); |
679 | 679 | |
680 | 680 | // テストデータの変換ログを期待されるログと比較する |
681 | 681 | // 1行目のパスが一致しないので、期待される結果のうち該当部分を更新する |
682 | - Assert.AreEqual( | |
682 | + AssertEqualTextPerLines( | |
683 | 683 | File.ReadAllText(Path.Combine(ResultDir, "example.log")).Replace("http://en.wikipedia.org", from.Location), |
684 | 684 | translator.Log); |
685 | 685 | } |
@@ -731,13 +731,13 @@ namespace Honememo.Wptscs.Logics | ||
731 | 731 | |
732 | 732 | // テストデータの変換結果を期待される結果と比較する |
733 | 733 | // バージョン表記部分は毎回変化するため、期待される結果のうち該当部分を更新する |
734 | - Assert.AreEqual( | |
734 | + AssertEqualTextPerLines( | |
735 | 735 | File.ReadAllText(Path.Combine(ResultDir, "example_キャッシュ使用.txt")).Replace("<!-- Wikipedia 翻訳支援ツール Ver0.xx", "<!-- " + FormUtils.ApplicationName()), |
736 | 736 | translator.Text); |
737 | 737 | |
738 | 738 | // テストデータの変換ログを期待されるログと比較する |
739 | 739 | // 1行目のパスが一致しないので、期待される結果のうち該当部分を更新する |
740 | - Assert.AreEqual( | |
740 | + AssertEqualTextPerLines( | |
741 | 741 | File.ReadAllText(Path.Combine(ResultDir, "example_キャッシュ使用.log")).Replace("file:///xxx/Data/MediaWiki/en/", from.Location), |
742 | 742 | translator.Log); |
743 | 743 | } |
@@ -766,13 +766,13 @@ namespace Honememo.Wptscs.Logics | ||
766 | 766 | |
767 | 767 | // テストデータの変換結果を期待される結果と比較する |
768 | 768 | // バージョン表記部分は毎回変化するため、期待される結果のうち該当部分を更新する |
769 | - Assert.AreEqual( | |
769 | + AssertEqualTextPerLines( | |
770 | 770 | File.ReadAllText(Path.Combine(ResultDir, "example_仮リンク有効.txt")).Replace("<!-- Wikipedia 翻訳支援ツール Ver0.73", "<!-- " + FormUtils.ApplicationName()), |
771 | 771 | translator.Text); |
772 | 772 | |
773 | 773 | // テストデータの変換ログを期待されるログと比較する |
774 | 774 | // 1行目のパスが一致しないので、期待される結果のうち該当部分を更新する |
775 | - Assert.AreEqual( | |
775 | + AssertEqualTextPerLines( | |
776 | 776 | File.ReadAllText(Path.Combine(ResultDir, "example.log")).Replace("http://en.wikipedia.org", from.Location), |
777 | 777 | translator.Log); |
778 | 778 | } |
@@ -813,13 +813,13 @@ namespace Honememo.Wptscs.Logics | ||
813 | 813 | |
814 | 814 | // テストデータの変換結果を期待される結果と比較する |
815 | 815 | // バージョン表記部分は毎回変化するため、期待される結果のうち該当部分を更新する |
816 | - Assert.AreEqual( | |
816 | + AssertEqualTextPerLines( | |
817 | 817 | File.ReadAllText(Path.Combine(ResultDir, "スペースシップツー.txt")).Replace("<!-- Wikipedia 翻訳支援ツール Ver0.73", "<!-- " + FormUtils.ApplicationName()), |
818 | 818 | translator.Text); |
819 | 819 | |
820 | 820 | // テストデータの変換ログを期待されるログと比較する |
821 | 821 | // 1行目のパスが一致しないので、期待される結果のうち該当部分を更新する |
822 | - Assert.AreEqual( | |
822 | + AssertEqualTextPerLines( | |
823 | 823 | File.ReadAllText(Path.Combine(ResultDir, "スペースシップツー.log")).Replace("http://ja.wikipedia.org", from.Location), |
824 | 824 | translator.Log); |
825 | 825 | } |
@@ -844,7 +844,7 @@ namespace Honememo.Wptscs.Logics | ||
844 | 844 | catch (ApplicationException) |
845 | 845 | { |
846 | 846 | // 実行ログを期待されるログと比較する |
847 | - Assert.AreEqual( | |
847 | + AssertEqualTextPerLines( | |
848 | 848 | ("http://en.wikipedia.org より [[Nothing Page]] を取得。\r\n" |
849 | 849 | + "→ 翻訳元として指定された記事は存在しません。記事名を確認してください。\r\n") |
850 | 850 | .Replace("http://en.wikipedia.org", from.Location), |
@@ -854,6 +854,31 @@ namespace Honememo.Wptscs.Logics | ||
854 | 854 | |
855 | 855 | #endregion |
856 | 856 | |
857 | + #region テスト用メソッド | |
858 | + | |
859 | + /// <summary> | |
860 | + /// テキストを1行ずつ<see cref="Assert.AreEqual{T}(T, T)"/>で比較する。 | |
861 | + /// </summary> | |
862 | + /// <param name="expected">期待値。</param> | |
863 | + /// <param name="actual">実際の値。</param> | |
864 | + private static void AssertEqualTextPerLines(string expected, string actual) | |
865 | + { | |
866 | + using (StringReader esr = new StringReader(expected)) | |
867 | + { | |
868 | + using (StringReader asr = new StringReader(actual)) | |
869 | + { | |
870 | + while (esr.Peek() > -1 || asr.Peek() > -1) | |
871 | + { | |
872 | + Assert.AreEqual(esr.ReadLine(), asr.ReadLine()); | |
873 | + } | |
874 | + | |
875 | + Assert.AreEqual(esr.Peek(), asr.Peek()); | |
876 | + } | |
877 | + } | |
878 | + } | |
879 | + | |
880 | + #endregion | |
881 | + | |
857 | 882 | #region テスト用クラス |
858 | 883 | |
859 | 884 | /// <summary> |